Fix the issue caused by server.servlet.context-path when logging

This commit is contained in:
StyleTang
2021-07-26 12:26:04 +08:00
committed by GitHub
parent bd85a9db96
commit 7d295fdab7
4 changed files with 16 additions and 16 deletions

View File

@@ -22,10 +22,12 @@ import org.apache.rocketmq.console.model.LoginInfo;
import org.apache.rocketmq.console.model.User;
import org.apache.rocketmq.console.model.UserInfo;
import org.apache.rocketmq.console.service.UserService;
import org.apache.rocketmq.console.support.JsonResult;
import org.apache.rocketmq.console.util.WebUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@@ -47,6 +49,9 @@ public class LoginController {
@Autowired
private UserService userService;
@Value("${server.servlet.context-path:/}")
private String contextPath;
@RequestMapping(value = "/check.query", method = RequestMethod.GET)
@ResponseBody
public Object check(HttpServletRequest request) {
@@ -60,10 +65,10 @@ public class LoginController {
@RequestMapping(value = "/login.do", method = RequestMethod.POST)
@ResponseBody
public Object login(@RequestParam("username") String username,
@RequestParam(value = "password") String password,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
public JsonResult<String> login(@RequestParam("username") String username,
@RequestParam(value = "password") String password,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
logger.info("user:{} login", username);
User user = userService.queryByUsernameAndPassword(username, password);
@@ -75,16 +80,14 @@ public class LoginController {
WebUtil.setSessionValue(request, WebUtil.USER_INFO, userInfo);
WebUtil.setSessionValue(request, WebUtil.USER_NAME, username);
userInfo.setSessionId(WebUtil.getSessionId(request));
return userInfo;
return new JsonResult<>(contextPath);
}
}
@RequestMapping(value = "/logout.do", method = RequestMethod.POST)
@ResponseBody
public Object logout(HttpServletRequest request) {
public JsonResult<String> logout(HttpServletRequest request) {
WebUtil.removeSession(request);
return Boolean.TRUE;
return new JsonResult<>(contextPath);
}
}

View File

@@ -37,7 +37,7 @@ var app = angular.module('app', [
if (initFlag) return;
initFlag = true;
var url = '/login/check.query';
var url = 'login/check.query';
var setting = {
type: "GET",
timeout:15000,
@@ -110,10 +110,9 @@ var app = angular.module('app', [
});
app.factory('abc', function ($http, $window) {
console.log('xxxxxxx');
$http({
method: "GET",
url: "/login/check.query"
url: "login/check.query"
}).success(function (resp) {
if (resp.status == 0) {
alert(resp.data)

View File

@@ -24,7 +24,7 @@ app.controller('AppCtrl', ['$scope','$window','$translate','$http','Notification
method: "POST",
url: "login/logout.do"
}).success(function (resp) {
window.location = "/";
window.location = resp.data;
$window.sessionStorage.clear();
});
}

View File

@@ -34,9 +34,7 @@ app.controller('loginController', ['$scope','$location','$http','Notification','
if (resp.status == 0) {
Notification.info({message: 'Login successful, redirect now', delay: 2000});
$window.sessionStorage.setItem("username", $("#username").val());
//alert("XXXXX resp.data="+resp.data.sessionId);
//$window.sessionStorage.setItem("sessionId", resp.data.sessionId);
window.location = "/";
window.location = resp.data;
initFlag = false;
} else{
Notification.error({message: resp.errMsg, delay: 2000});