推广后台-sa token
This commit is contained in:
@@ -27,9 +27,6 @@ public class LoginInterceptor implements HandlerInterceptor {
|
||||
|
||||
private static final String NEED_LOGOUT = "needLogout";
|
||||
|
||||
@Autowired
|
||||
private JedisService jedisService;
|
||||
|
||||
@Override
|
||||
public boolean preHandle(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response, @NotNull Object handler)
|
||||
throws Exception {
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package com.accompany.flowteam.admin.controller;
|
||||
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.accompany.admin.common.AdminConstants;
|
||||
import com.accompany.admin.frame.MvcContext;
|
||||
import com.accompany.admin.frame.Scope;
|
||||
@@ -47,22 +48,11 @@ public class BaseController {
|
||||
}
|
||||
|
||||
protected String getAdminId() {
|
||||
Object admin = getAttribute(AdminConstants.ADMIN_ID, Scope.SESSION);
|
||||
return admin == null ? null : admin.toString();
|
||||
return StpUtil.getLoginIdAsString();
|
||||
}
|
||||
|
||||
protected String getAdminName() {
|
||||
Object adminName = getAttribute(AdminConstants.ADMIN_NAME, Scope.SESSION);
|
||||
return adminName == null ? null : adminName.toString();
|
||||
}
|
||||
|
||||
protected String getAdminAccount() {
|
||||
Object adminAccount = getAttribute(FlowTeamAdminConstants.ADMIN_ACCOUNT, Scope.SESSION);
|
||||
return adminAccount == null ? null : adminAccount.toString();
|
||||
}
|
||||
|
||||
protected List<FlowTeamMemberDetailVO> getAdminMembers() {
|
||||
Object adminMembers = getAttribute(FlowTeamAdminConstants.ADMIN_MEMBERS, Scope.SESSION);
|
||||
Object adminMembers = StpUtil.getSession().get(FlowTeamAdminConstants.ADMIN_MEMBERS);
|
||||
return adminMembers == null ? Collections.emptyList() : (List<FlowTeamMemberDetailVO>)adminMembers;
|
||||
}
|
||||
|
||||
@@ -77,32 +67,6 @@ public class BaseController {
|
||||
|
||||
return memberIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置请求的属性
|
||||
* @param key
|
||||
* @param obj
|
||||
*/
|
||||
public void setAttribute(String key, Object obj){
|
||||
setAttribute(key, obj, Scope.REQUEST);
|
||||
}
|
||||
|
||||
public void setAttribute(String key, Object obj, Scope scope) {
|
||||
switch (scope) {
|
||||
case REQUEST:
|
||||
getRequest().setAttribute(key, obj);
|
||||
break;
|
||||
case SESSION:
|
||||
getRequest().getSession().setAttribute(key, obj);
|
||||
break;
|
||||
case APPLICATION:
|
||||
getRequest().getSession().getServletContext().setAttribute(key, obj);
|
||||
break;
|
||||
default:
|
||||
getRequest().setAttribute(key, obj);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public Object getAttribute(String key, Scope scope){
|
||||
Object attr = null;
|
||||
|
@@ -1,6 +1,8 @@
|
||||
package com.accompany.flowteam.admin.controller.system;
|
||||
|
||||
|
||||
import cn.dev33.satoken.exception.NotLoginException;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.accompany.admin.common.AdminConstants;
|
||||
import com.accompany.admin.frame.Scope;
|
||||
import com.accompany.admin.util.StringUtil;
|
||||
@@ -66,27 +68,16 @@ public class LoginController extends BaseController {
|
||||
if (result.getCode() == 200) { //参数验证成功
|
||||
List<FlowTeamMemberDetailVO> flowTeamMembers = flowTeamAdminUserService.listMemberUsersDetailByPhone(account);
|
||||
if (CollectionUtils.isNotEmpty(flowTeamMembers)) {
|
||||
String adminName = flowTeamMembers.stream().map(member -> new StringBuilder(member.getTeamName()).append(" - ").append(member.getMemberName())).collect(Collectors.joining("/"));
|
||||
setAttribute(AdminConstants.HAS_LOGIN, "true", Scope.SESSION);
|
||||
setAttribute(AdminConstants.ADMIN_ID, account, Scope.SESSION);
|
||||
setAttribute(AdminConstants.ADMIN_NAME, adminName, Scope.SESSION);
|
||||
setAttribute(FlowTeamAdminConstants.ADMIN_ACCOUNT, CommonUtil.maskPhone(account), Scope.SESSION);
|
||||
setAttribute(FlowTeamAdminConstants.ADMIN_MEMBERS, flowTeamMembers, Scope.SESSION);
|
||||
Cookie cookie1 = new Cookie(AdminConstants.HAS_LOGIN, "true");
|
||||
Cookie cookie2 = new Cookie(AdminConstants.ADMIN_ID, account);
|
||||
Cookie cookie3 = new Cookie(AdminConstants.ADMIN_NAME, URLEncoder.encode(adminName, "utf-8"));
|
||||
getResponse().addCookie(cookie1);
|
||||
getResponse().addCookie(cookie2);
|
||||
getResponse().addCookie(cookie3);
|
||||
StpUtil.login(account);
|
||||
StpUtil.getSession().set(FlowTeamAdminConstants.ADMIN_MEMBERS, flowTeamMembers);
|
||||
// adminUserService.updateLastLogin(adminUser.getId());
|
||||
jedisService.hset(RedisKey.flow_team_admin_httpsession_store.getKey(), account, getRequest().getSession().getId());
|
||||
String smsCode = flowTeamAdminUserService.updateLoginRecord(account);
|
||||
updateCacheAfterLogin(account);
|
||||
// TODO 需加表
|
||||
// adminLogService.insertLog(adminUser.getId(), getClass().getCanonicalName(), "login",
|
||||
// "params===>>account:" + account + ", password:" + password + ", authCode: " + smsCode);
|
||||
logger.info("amdin [" + account + "] login system.");
|
||||
writeJson(true, adminName + "@" + account);
|
||||
writeJson(true, account);
|
||||
return;
|
||||
} else {
|
||||
int surplus = flowTeamAdminUserService.updateLoginErrorCache(account);
|
||||
@@ -118,27 +109,13 @@ public class LoginController extends BaseController {
|
||||
@RequestMapping("/login/logout")
|
||||
public String logout(Model model) {
|
||||
model.addAttribute("smsSwitch", true);
|
||||
String account = getAdminId();
|
||||
if (StringUtils.isNotBlank(account)) {
|
||||
logger.info("admin logout, account is:" + account);
|
||||
getRequest().getSession().removeAttribute(AdminConstants.HAS_LOGIN);
|
||||
getRequest().getSession().removeAttribute(AdminConstants.ADMIN_ID);
|
||||
getRequest().getSession().removeAttribute(AdminConstants.ADMIN_NAME);
|
||||
getRequest().getSession().removeAttribute(FlowTeamAdminConstants.ADMIN_ACCOUNT);
|
||||
getRequest().getSession().removeAttribute(FlowTeamAdminConstants.ADMIN_MEMBERS);
|
||||
Cookie[] cookies = getRequest().getCookies();
|
||||
for (Cookie cookie : cookies) {
|
||||
if (AdminConstants.HAS_LOGIN.equalsIgnoreCase(cookie.getName())
|
||||
|| AdminConstants.ADMIN_ID.equalsIgnoreCase(cookie.getName())
|
||||
|| AdminConstants.ADMIN_NAME.equalsIgnoreCase(cookie.getName())) {
|
||||
Cookie cookieDel = new Cookie(cookie.getName(), null);
|
||||
cookieDel.setPath("/");
|
||||
cookieDel.setMaxAge(0);
|
||||
getResponse().addCookie(cookieDel);
|
||||
}
|
||||
}
|
||||
try {
|
||||
String adminId = getAdminId();
|
||||
logger.info("admin logout, id is:" + adminId);
|
||||
StpUtil.logout();
|
||||
} catch (NotLoginException ignore){
|
||||
|
||||
}
|
||||
jedisService.hdel(RedisKey.flow_team_admin_httpsession_store.getKey(), getAttribute(AdminConstants.ADMIN_ID, Scope.SESSION) + "");
|
||||
return "login";
|
||||
}
|
||||
|
||||
|
@@ -1,9 +1,7 @@
|
||||
package com.accompany.flowteam.admin.controller.system;
|
||||
|
||||
|
||||
import com.xuanyin.flowteam.service.FlowTeamMemberService;
|
||||
import com.accompany.flowteam.admin.controller.BaseController;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -12,9 +10,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@RequestMapping("/admin")
|
||||
public class MainController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private FlowTeamMemberService flowTeamMemberService;
|
||||
|
||||
/**
|
||||
* 跳转到管理首页
|
||||
* @param model
|
||||
@@ -23,11 +18,7 @@ public class MainController extends BaseController {
|
||||
@RequestMapping("/main")
|
||||
public String toMain(Model model){
|
||||
try{
|
||||
String adminName = getAdminName();
|
||||
if(adminName!=null){
|
||||
model.addAttribute("adminName", adminName);
|
||||
}
|
||||
String adminAccount = getAdminAccount();
|
||||
String adminAccount = getAdminId();
|
||||
if (adminAccount != null) {
|
||||
model.addAttribute("adminAccount", adminAccount);
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package com.accompany.flowteam.admin.interceptor;
|
||||
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.common.utils.BlankUtil;
|
||||
import com.accompany.common.utils.StringUtils;
|
||||
@@ -29,7 +30,9 @@ public class LoginInterceptor implements HandlerInterceptor {
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
|
||||
throws Exception {
|
||||
try {
|
||||
Object tmp = request.getSession().getAttribute(FlowTeamAdminConstants.HAS_LOGIN);
|
||||
StpUtil.checkLogin();
|
||||
return true;
|
||||
/*Object tmp = request.getSession().getAttribute(FlowTeamAdminConstants.HAS_LOGIN);
|
||||
if (tmp != null) {
|
||||
String isLogin = tmp.toString();
|
||||
if (!BlankUtil.isBlank(isLogin) && "true".equalsIgnoreCase(isLogin)) {
|
||||
@@ -41,7 +44,7 @@ public class LoginInterceptor implements HandlerInterceptor {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
} catch (Exception e) {
|
||||
logger.warn("getAdminId fail,admin has not login", e);
|
||||
}
|
||||
|
Reference in New Issue
Block a user