Commit 9ea3e9c5 authored by Liang Ding's avatar Liang Ding

🎨 登录重定向

parent 87cb683f
...@@ -22,11 +22,16 @@ package org.b3log.solo.model; ...@@ -22,11 +22,16 @@ package org.b3log.solo.model;
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="https://hacpai.com/member/e">Dongxu Wang</a> * @author <a href="https://hacpai.com/member/e">Dongxu Wang</a>
* @version 1.7.0.1, Feb 8, 2019 * @version 1.7.0.2, Feb 11, 2019
* @since 0.3.1 * @since 0.3.1
*/ */
public final class Common { public final class Common {
/**
* Key of referer.
*/
public static final String REFERER = "referer";
/** /**
* Key of upload msg. * Key of upload msg.
*/ */
...@@ -307,11 +312,6 @@ public final class Common { ...@@ -307,11 +312,6 @@ public final class Common {
*/ */
public static final String UNUSED_TAGS = "unusedTags"; public static final String UNUSED_TAGS = "unusedTags";
/**
* Key of go to.
*/
public static final String GOTO = "goto";
/** /**
* Key of online visitor count. * Key of online visitor count.
*/ */
......
...@@ -56,7 +56,7 @@ import java.util.Map; ...@@ -56,7 +56,7 @@ import java.util.Map;
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="https://hacpai.com/member/DASHU">DASHU</a> * @author <a href="https://hacpai.com/member/DASHU">DASHU</a>
* @version 1.2.4.14, Feb 7, 2019 * @version 1.2.4.15, Feb 11, 2019
* @since 0.3.1 * @since 0.3.1
*/ */
@RequestProcessor @RequestProcessor
...@@ -147,31 +147,6 @@ public class IndexProcessor { ...@@ -147,31 +147,6 @@ public class IndexProcessor {
} }
} }
/**
* Shows kill browser page with the specified context.
*
* @param context the specified context
*/
@RequestProcessing(value = "/kill-browser", method = HttpMethod.GET)
public void showKillBrowser(final RequestContext context) {
final HttpServletRequest request = context.getRequest();
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(context, "kill-browser.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
try {
final Map<String, String> langs = langPropsService.getAll(Locales.getLocale(request));
dataModel.putAll(langs);
final JSONObject preference = preferenceQueryService.getPreference();
dataModelService.fillCommon(context, dataModel, preference);
Keys.fillServer(dataModel);
Keys.fillRuntime(dataModel);
dataModelService.fillMinified(dataModel);
} catch (final ServiceException e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
context.sendError(HttpServletResponse.SC_NOT_FOUND);
}
}
/** /**
* Shows start page. * Shows start page.
* *
...@@ -179,19 +154,17 @@ public class IndexProcessor { ...@@ -179,19 +154,17 @@ public class IndexProcessor {
*/ */
@RequestProcessing(value = "/start", method = HttpMethod.GET) @RequestProcessing(value = "/start", method = HttpMethod.GET)
public void showStart(final RequestContext context) { public void showStart(final RequestContext context) {
String destinationURL = context.param(Common.GOTO);
if (StringUtils.isBlank(destinationURL)) {
destinationURL = Latkes.getServePath() + Common.ADMIN_INDEX_URI;
} else if (!isInternalLinks(destinationURL)) {
destinationURL = Latkes.getServePath();
}
if (initService.isInited() && null != Solos.getCurrentUser(context.getRequest(), context.getResponse())) { if (initService.isInited() && null != Solos.getCurrentUser(context.getRequest(), context.getResponse())) {
context.sendRedirect(destinationURL); context.sendRedirect(Latkes.getServePath());
return; return;
} }
String referer = context.header("referer");
if (StringUtils.isBlank(referer) || !isInternalLinks(referer)) {
referer = Latkes.getServePath();
}
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(context, "start.ftl"); final AbstractFreeMarkerRenderer renderer = new SkinRenderer(context, "start.ftl");
final Map<String, Object> dataModel = renderer.getDataModel(); final Map<String, Object> dataModel = renderer.getDataModel();
final HttpServletRequest request = context.getRequest(); final HttpServletRequest request = context.getRequest();
...@@ -200,6 +173,7 @@ public class IndexProcessor { ...@@ -200,6 +173,7 @@ public class IndexProcessor {
dataModel.put(Common.VERSION, SoloServletListener.VERSION); dataModel.put(Common.VERSION, SoloServletListener.VERSION);
dataModel.put(Common.STATIC_RESOURCE_VERSION, Latkes.getStaticResourceVersion()); dataModel.put(Common.STATIC_RESOURCE_VERSION, Latkes.getStaticResourceVersion());
dataModel.put(Common.YEAR, String.valueOf(Calendar.getInstance().get(Calendar.YEAR))); dataModel.put(Common.YEAR, String.valueOf(Calendar.getInstance().get(Calendar.YEAR)));
dataModel.put(Common.REFERER, referer);
Keys.fillRuntime(dataModel); Keys.fillRuntime(dataModel);
dataModelService.fillMinified(dataModel); dataModelService.fillMinified(dataModel);
...@@ -217,13 +191,38 @@ public class IndexProcessor { ...@@ -217,13 +191,38 @@ public class IndexProcessor {
Solos.logout(httpServletRequest, context.getResponse()); Solos.logout(httpServletRequest, context.getResponse());
String destinationURL = context.param(Common.GOTO); String referer = context.header("referer");
if (StringUtils.isBlank(destinationURL) || !isInternalLinks(destinationURL)) { if (StringUtils.isBlank(referer) || !isInternalLinks(referer)) {
destinationURL = Latkes.getServePath(); referer = Latkes.getServePath();
} }
context.sendRedirect(destinationURL);
Solos.addGoogleNoIndex(context); Solos.addGoogleNoIndex(context);
context.sendRedirect(referer);
}
/**
* Shows kill browser page with the specified context.
*
* @param context the specified context
*/
@RequestProcessing(value = "/kill-browser", method = HttpMethod.GET)
public void showKillBrowser(final RequestContext context) {
final HttpServletRequest request = context.getRequest();
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(context, "kill-browser.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
try {
final Map<String, String> langs = langPropsService.getAll(Locales.getLocale(request));
dataModel.putAll(langs);
final JSONObject preference = preferenceQueryService.getPreference();
dataModelService.fillCommon(context, dataModel, preference);
Keys.fillServer(dataModel);
Keys.fillRuntime(dataModel);
dataModelService.fillMinified(dataModel);
} catch (final ServiceException e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
context.sendError(HttpServletResponse.SC_NOT_FOUND);
}
} }
/** /**
...@@ -233,7 +232,7 @@ public class IndexProcessor { ...@@ -233,7 +232,7 @@ public class IndexProcessor {
* *
* @return whether the destinationURL is an internal link * @return whether the destinationURL is an internal link
*/ */
private boolean isInternalLinks(String destinationURL) { private boolean isInternalLinks(final String destinationURL) {
return destinationURL.startsWith(Latkes.getServePath()); return destinationURL.startsWith(Latkes.getServePath());
} }
} }
...@@ -121,7 +121,7 @@ public class OAuthGitHubProcessor { ...@@ -121,7 +121,7 @@ public class OAuthGitHubProcessor {
*/ */
@RequestProcessing(value = "/oauth/github/redirect", method = HttpMethod.GET) @RequestProcessing(value = "/oauth/github/redirect", method = HttpMethod.GET)
public void redirectGitHub(final RequestContext context) { public void redirectGitHub(final RequestContext context) {
String referer = context.header("referer"); String referer = context.param("referer");
if (StringUtils.isBlank(referer)) { if (StringUtils.isBlank(referer)) {
referer = Latkes.getServePath(); referer = Latkes.getServePath();
} }
......
...@@ -36,7 +36,7 @@ $.extend(Admin.prototype, { ...@@ -36,7 +36,7 @@ $.extend(Admin.prototype, {
* @description 登出 * @description 登出
*/ */
logout: function () { logout: function () {
window.location.href = latkeConfig.servePath + "/logout?goto=" + latkeConfig.servePath; window.location.href = latkeConfig.servePath + "/logout";
}, },
toggleMenu: function () { toggleMenu: function () {
if ($('#tabs').css('left') === '-240px') { if ($('#tabs').css('left') === '-240px') {
......
...@@ -29,11 +29,11 @@ ...@@ -29,11 +29,11 @@
<div id="github"> <div id="github">
<div class="github__icon" <div class="github__icon"
onclick="window.location.href = '${servePath}/oauth/github/redirect';$('#github').addClass('github--loading')"> onclick="window.location.href = '${servePath}/oauth/github/redirect?referer=${referer}';$('#github').addClass('github--loading')">
<img src="${staticServePath}/images/github.png"/> <img src="${staticServePath}/images/github.png"/>
</div> </div>
<button class="hover" <button class="hover"
onclick="window.location.href = '${servePath}/oauth/github/redirect';$('#github').addClass('github--loading')">${useGitHubAccountLoginLabel}</button> onclick="window.location.href = '${servePath}/oauth/github/redirect?referer=${referer}';$('#github').addClass('github--loading')">${useGitHubAccountLoginLabel}</button>
</div> </div>
<script type="text/javascript" src="${staticServePath}/js/lib/jquery/jquery.min.js" charset="utf-8"></script> <script type="text/javascript" src="${staticServePath}/js/lib/jquery/jquery.min.js" charset="utf-8"></script>
<script type="text/javascript"> <script type="text/javascript">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment