forked from github/dataease
perf(登录): 移动端不受多端登录限制
This commit is contained in:
parent
3d2b353a84
commit
cd3f72a876
@ -22,6 +22,10 @@ public interface AuthApi {
|
|||||||
@PostMapping("/login")
|
@PostMapping("/login")
|
||||||
Object login(LoginDto loginDto) throws Exception;
|
Object login(LoginDto loginDto) throws Exception;
|
||||||
|
|
||||||
|
@ApiOperation("移动端登录")
|
||||||
|
@PostMapping("/mobileLogin")
|
||||||
|
Object mobileLogin(LoginDto loginDto) throws Exception;
|
||||||
|
|
||||||
@PostMapping("/seizeLogin")
|
@PostMapping("/seizeLogin")
|
||||||
Object seizeLogin(SeizeLoginDto loginDto) throws Exception;
|
Object seizeLogin(SeizeLoginDto loginDto) throws Exception;
|
||||||
|
|
||||||
|
@ -67,6 +67,46 @@ public class AuthServer implements AuthApi {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private WsService wsService;
|
private WsService wsService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object mobileLogin(@RequestBody LoginDto loginDto) throws Exception {
|
||||||
|
String username = RsaUtil.decryptByPrivateKey(RsaProperties.privateKey, loginDto.getUsername());
|
||||||
|
String pwd = RsaUtil.decryptByPrivateKey(RsaProperties.privateKey, loginDto.getPassword());
|
||||||
|
AccountLockStatus accountLockStatus = authUserService.lockStatus(username, 0);
|
||||||
|
if (accountLockStatus.getLocked()) {
|
||||||
|
String msg = Translator.get("I18N_ACCOUNT_LOCKED");
|
||||||
|
msg = String.format(msg, username, accountLockStatus.getRelieveTimes().toString());
|
||||||
|
DataEaseException.throwException(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
SysUserEntity user = authUserService.getUserByName(username);
|
||||||
|
|
||||||
|
if (ObjectUtils.isEmpty(user)) {
|
||||||
|
AccountLockStatus lockStatus = authUserService.recordLoginFail(username, 0);
|
||||||
|
DataEaseException.throwException(appendLoginErrorMsg(Translator.get("i18n_id_or_pwd_error"), lockStatus));
|
||||||
|
}
|
||||||
|
if (user.getEnabled() == 0) {
|
||||||
|
AccountLockStatus lockStatus = authUserService.recordLoginFail(username, 0);
|
||||||
|
DataEaseException.throwException(appendLoginErrorMsg(Translator.get("i18n_user_is_disable"), lockStatus));
|
||||||
|
}
|
||||||
|
String realPwd = user.getPassword();
|
||||||
|
pwd = CodingUtil.md5(pwd);
|
||||||
|
|
||||||
|
if (!StringUtils.equals(pwd, realPwd)) {
|
||||||
|
AccountLockStatus lockStatus = authUserService.recordLoginFail(username, 0);
|
||||||
|
DataEaseException.throwException(appendLoginErrorMsg(Translator.get("i18n_id_or_pwd_error"), lockStatus));
|
||||||
|
}
|
||||||
|
TokenInfo tokenInfo = TokenInfo.builder().userId(user.getUserId()).username(username).build();
|
||||||
|
String token = JWTUtils.sign(tokenInfo, realPwd, false);
|
||||||
|
// 记录token操作时间
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
result.put("token", token);
|
||||||
|
ServletUtils.setToken(token);
|
||||||
|
DeLogUtils.save(SysLogConstants.OPERATE_TYPE.LOGIN, SysLogConstants.SOURCE_TYPE.USER, user.getUserId(), null, null, null);
|
||||||
|
authUserService.unlockAccount(username, 0);
|
||||||
|
authUserService.clearCache(user.getUserId());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object login(@RequestBody LoginDto loginDto) throws Exception {
|
public Object login(@RequestBody LoginDto loginDto) throws Exception {
|
||||||
Map<String, Object> result = new HashMap<>();
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
@ -83,6 +83,7 @@ public class ShiroServiceImpl implements ShiroService {
|
|||||||
filterChainDefinitionMap.put("/api/auth/login", ANON);
|
filterChainDefinitionMap.put("/api/auth/login", ANON);
|
||||||
filterChainDefinitionMap.put("/api/auth/seizeLogin", ANON);
|
filterChainDefinitionMap.put("/api/auth/seizeLogin", ANON);
|
||||||
filterChainDefinitionMap.put("/api/auth/logout", ANON);
|
filterChainDefinitionMap.put("/api/auth/logout", ANON);
|
||||||
|
filterChainDefinitionMap.put("/api/auth/mobileLogin", ANON);
|
||||||
filterChainDefinitionMap.put("/api/auth/isPluginLoaded", ANON);
|
filterChainDefinitionMap.put("/api/auth/isPluginLoaded", ANON);
|
||||||
filterChainDefinitionMap.put("/system/requestTimeOut", ANON);
|
filterChainDefinitionMap.put("/system/requestTimeOut", ANON);
|
||||||
filterChainDefinitionMap.put("/api/auth/validateName", ANON);
|
filterChainDefinitionMap.put("/api/auth/validateName", ANON);
|
||||||
|
@ -80,7 +80,7 @@ public class XDingtalkServer {
|
|||||||
return dingtalkXpackService.getQrParam();
|
return dingtalkXpackService.getQrParam();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ModelAndView privateCallBack(String code, Boolean withoutLogin) {
|
private ModelAndView privateCallBack(String code, Boolean withoutLogin, Boolean isMobile) {
|
||||||
ModelAndView modelAndView = new ModelAndView("redirect:/");
|
ModelAndView modelAndView = new ModelAndView("redirect:/");
|
||||||
HttpServletResponse response = ServletUtils.response();
|
HttpServletResponse response = ServletUtils.response();
|
||||||
DingtalkXpackService dingtalkXpackService = null;
|
DingtalkXpackService dingtalkXpackService = null;
|
||||||
@ -109,7 +109,7 @@ public class XDingtalkServer {
|
|||||||
}
|
}
|
||||||
TokenInfo tokenInfo = TokenInfo.builder().userId(sysUserEntity.getUserId()).username(sysUserEntity.getUsername()).build();
|
TokenInfo tokenInfo = TokenInfo.builder().userId(sysUserEntity.getUserId()).username(sysUserEntity.getUsername()).build();
|
||||||
String realPwd = sysUserEntity.getPassword();
|
String realPwd = sysUserEntity.getPassword();
|
||||||
String token = JWTUtils.sign(tokenInfo, realPwd);
|
String token = JWTUtils.sign(tokenInfo, realPwd, !isMobile);
|
||||||
ServletUtils.setToken(token);
|
ServletUtils.setToken(token);
|
||||||
|
|
||||||
DeLogUtils.save(SysLogConstants.OPERATE_TYPE.LOGIN, SysLogConstants.SOURCE_TYPE.USER, sysUserEntity.getUserId(), null, null, null);
|
DeLogUtils.save(SysLogConstants.OPERATE_TYPE.LOGIN, SysLogConstants.SOURCE_TYPE.USER, sysUserEntity.getUserId(), null, null, null);
|
||||||
@ -144,13 +144,14 @@ public class XDingtalkServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/callBackWithoutLogin")
|
@GetMapping("/callBackWithoutLogin")
|
||||||
public ModelAndView callBackWithoutLogin(@RequestParam("code") String code) {
|
public ModelAndView callBackWithoutLogin(@RequestParam("code") String code, @RequestParam("mobile") String mobile) {
|
||||||
return privateCallBack(code, true);
|
boolean isMobile = StringUtils.equals("1", mobile);
|
||||||
|
return privateCallBack(code, true, isMobile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/callBack")
|
@GetMapping("/callBack")
|
||||||
public ModelAndView callBack(@RequestParam("code") String code, @RequestParam("state") String state) {
|
public ModelAndView callBack(@RequestParam("code") String code, @RequestParam("state") String state) {
|
||||||
return privateCallBack(code, false);
|
return privateCallBack(code, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindError(HttpServletResponse response, String url, String errorMsg) {
|
private void bindError(HttpServletResponse response, String url, String errorMsg) {
|
||||||
|
@ -92,11 +92,12 @@ public class XLarkServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/callBackWithoutLogin")
|
@GetMapping("/callBackWithoutLogin")
|
||||||
public ModelAndView callBackWithoutLogin(@RequestParam("code") String code) {
|
public ModelAndView callBackWithoutLogin(@RequestParam("code") String code, @RequestParam("mobile") String mobile) {
|
||||||
return privateCallBack(code, null, true);
|
boolean isMobile = StringUtils.equals("1", mobile);
|
||||||
|
return privateCallBack(code, null, true, isMobile);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ModelAndView privateCallBack(String code, String state, Boolean withoutLogin) {
|
private ModelAndView privateCallBack(String code, String state, Boolean withoutLogin, Boolean isMobile) {
|
||||||
ModelAndView modelAndView = new ModelAndView("redirect:/");
|
ModelAndView modelAndView = new ModelAndView("redirect:/");
|
||||||
HttpServletResponse response = ServletUtils.response();
|
HttpServletResponse response = ServletUtils.response();
|
||||||
LarkXpackService larkXpackService = null;
|
LarkXpackService larkXpackService = null;
|
||||||
@ -132,7 +133,7 @@ public class XLarkServer {
|
|||||||
}
|
}
|
||||||
TokenInfo tokenInfo = TokenInfo.builder().userId(sysUserEntity.getUserId()).username(sysUserEntity.getUsername()).build();
|
TokenInfo tokenInfo = TokenInfo.builder().userId(sysUserEntity.getUserId()).username(sysUserEntity.getUsername()).build();
|
||||||
String realPwd = sysUserEntity.getPassword();
|
String realPwd = sysUserEntity.getPassword();
|
||||||
String token = JWTUtils.sign(tokenInfo, realPwd);
|
String token = JWTUtils.sign(tokenInfo, realPwd, !isMobile);
|
||||||
ServletUtils.setToken(token);
|
ServletUtils.setToken(token);
|
||||||
|
|
||||||
DeLogUtils.save(SysLogConstants.OPERATE_TYPE.LOGIN, SysLogConstants.SOURCE_TYPE.USER, sysUserEntity.getUserId(), null, null, null);
|
DeLogUtils.save(SysLogConstants.OPERATE_TYPE.LOGIN, SysLogConstants.SOURCE_TYPE.USER, sysUserEntity.getUserId(), null, null, null);
|
||||||
@ -168,7 +169,7 @@ public class XLarkServer {
|
|||||||
|
|
||||||
@GetMapping("/callBack")
|
@GetMapping("/callBack")
|
||||||
public ModelAndView callBack(@RequestParam("code") String code, @RequestParam("state") String state) {
|
public ModelAndView callBack(@RequestParam("code") String code, @RequestParam("state") String state) {
|
||||||
return privateCallBack(code, state, false);
|
return privateCallBack(code, state, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindError(HttpServletResponse response, String url, String errorMsg) {
|
private void bindError(HttpServletResponse response, String url, String errorMsg) {
|
||||||
|
@ -2,7 +2,7 @@ import request from '@/common/js/request'
|
|||||||
|
|
||||||
export function login(data) {
|
export function login(data) {
|
||||||
return request({
|
return request({
|
||||||
url: '/api/auth/login',
|
url: '/api/auth/mobileLogin',
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data
|
data
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user