移动端token策略处理
This commit is contained in:
parent
a40363f3e5
commit
035de35c26
|
|
@ -59,6 +59,19 @@ public class LoginUser implements Serializable
|
|||
*/
|
||||
private SysUser sysUser;
|
||||
|
||||
/**
|
||||
* 登录方式 移动端:mobile 电脑端:pc
|
||||
*/
|
||||
private String loginMethod;
|
||||
|
||||
public String getLoginMethod() {
|
||||
return loginMethod;
|
||||
}
|
||||
|
||||
public void setLoginMethod(String loginMethod) {
|
||||
this.loginMethod = loginMethod;
|
||||
}
|
||||
|
||||
public String getToken()
|
||||
{
|
||||
return token;
|
||||
|
|
|
|||
|
|
@ -79,7 +79,12 @@ public class TokenController {
|
|||
public R<?> loginApp(@RequestBody LoginBody form) {
|
||||
// 用户登录
|
||||
LoginUser userInfo = sysLoginService.login(form.getUsername(), form.getPassword());
|
||||
if (userInfo != null) {
|
||||
userInfo.setLoginMethod("mobile");
|
||||
return R.ok(tokenService.createToken(userInfo));
|
||||
} else {
|
||||
return R.fail("登录信息为空,请重试");
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("sendCode")
|
||||
|
|
@ -93,6 +98,7 @@ public class TokenController {
|
|||
// 校验验证码
|
||||
LoginUser loginUser = sysLoginService.loginCode(form.getPhone(), form.getCode());
|
||||
if (StringUtils.isNotNull(loginUser)) {
|
||||
loginUser.setLoginMethod("mobile");
|
||||
// 创建token
|
||||
Map<String, Object> tokenMap = tokenService.createToken(loginUser);
|
||||
return R.ok(tokenService.createToken(loginUser));
|
||||
|
|
|
|||
|
|
@ -12,6 +12,11 @@ public class CacheConstants
|
|||
*/
|
||||
public final static long EXPIRATION = 720;
|
||||
|
||||
/**
|
||||
* 移动端缓存有效期,48小时
|
||||
*/
|
||||
public final static long EXPIRATION_MOBILE = 2880;
|
||||
|
||||
/**
|
||||
* 缓存刷新时间,默认120(分钟)
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -39,6 +39,8 @@ public class TokenService
|
|||
|
||||
private final static long EXPIRE_TIME = CacheConstants.EXPIRATION;
|
||||
|
||||
private final static long EXPIRATION_MOBILE = CacheConstants.EXPIRATION_MOBILE;
|
||||
|
||||
private final static String ACCESS_TOKEN = CacheConstants.LOGIN_TOKEN_KEY;
|
||||
|
||||
private final static Long MILLIS_MINUTE_TEN = CacheConstants.REFRESH_TIME * MILLIS_MINUTE;
|
||||
|
|
@ -66,7 +68,11 @@ public class TokenService
|
|||
// 接口返回信息
|
||||
Map<String, Object> rspMap = new HashMap<String, Object>(16);
|
||||
rspMap.put("access_token", JwtUtils.createToken(claimsMap));
|
||||
if (loginUser.getLoginMethod() != null && "mobile".equals(loginUser.getLoginMethod())) {
|
||||
rspMap.put("expires_in", EXPIRATION_MOBILE);
|
||||
} else {
|
||||
rspMap.put("expires_in", EXPIRE_TIME);
|
||||
}
|
||||
//密码置空后返回
|
||||
loginUser.getSysUser().setPassword("");
|
||||
rspMap.put("login_user", loginUser);
|
||||
|
|
@ -74,6 +80,7 @@ public class TokenService
|
|||
return rspMap;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户身份信息
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue