1.fix autologin issue

main
Gary 1 year ago
parent 390ddcde05
commit 247bcce796

@ -89,7 +89,8 @@ public class OperationAspect {
String ip = getIpAddr(request);
ip = ip.replace(":", "");
String redisKey = fullMethodName + ip;
Integer cuCount = (Integer) redisUtils.get(redisKey);
Object count=redisUtils.get(redisKey);
Integer cuCount= null==count?0:Integer.valueOf((String)count);
if (cuCount != null && cuCount > threshold - 1) {
throw new BizException(StatusCode.REQUEST_TOO_FREQUENCY);
}

@ -90,7 +90,7 @@ public class UserController {
return Result.success(map);
}
@ApiOperation(value = "2.登录/注册后返回token")
@ApiOperation(value = "2.登录/注册",notes="成功后返回用户信息和token")
@PostMapping("/appLogin/{mobile}/{mobileCheckCode}")
@GlobalInterceptor
public Result appLogin( @PathVariable @VerifyParam(required=true,regex=VerifyRegexEnum.MOBILE)String mobile,
@ -135,7 +135,7 @@ public class UserController {
*/
@ApiOperation(value = "1.发送短信验证码", notes = "有效期15分钟一个手机号一天最多发50次请求")
@PostMapping("/sendsms/{mobile}")
@GlobalInterceptor(checkLogin = true, frequencyType = RequestFrequencyTypeEnum.DAY, requestFrequencyThreshold = 50)
@GlobalInterceptor(frequencyType = RequestFrequencyTypeEnum.DAY, requestFrequencyThreshold = 50)
public Result<Void> sendSms(@PathVariable @VerifyParam(required=true,regex=VerifyRegexEnum.MOBILE)String mobile) {
userService.sendSms(mobile);
return Result.success();
@ -144,17 +144,17 @@ public class UserController {
/**
* token
*/
@ApiOperation(value = "5.token 续期,有效期7天")
@PostMapping("/autoLogin/{token}")
@ApiOperation(value = "5.token续期", notes = "有效期7天")
@PostMapping("/autoLogin")
@GlobalInterceptor
public Result<String> autoLogin(@PathVariable @VerifyParam(required = true) String token) {
public Result<String> autoLogin(@RequestHeader(value = "token", required = false) String token) {
return Result.success(userService.autoLogin(token));
}
/**
*
*/
@ApiOperation(value = "4.三次短信验证失败后获取图形验证码有效期10分钟")
@ApiOperation(value="4.获取图形验证码", notes = "4.三次短信验证失败后获取图形验证码有效期10分钟")
@GetMapping("/imageCheckCode/{mobile}")
@GlobalInterceptor
public void imageCheckCode(HttpServletResponse response,
@ -179,18 +179,15 @@ public class UserController {
) {
// 得到缓存中的验证码
String redisImageCheckCodeKey=Constants.REDIS_KEY_IMAGE_CHECK_CODE+mobile;
try {
String redisImageCheckCode = (String) redisTemplate.opsForValue().get(redisImageCheckCodeKey);
if (StringTools.isEmpty(redisImageCheckCode)) {
return Result.failed(StatusCode.USER_IMAGE_VERIFICATION_CODE_EXPIRED);
}
if (!redisImageCheckCode.equals(imageCheckCode)) {
if (!redisImageCheckCode.equalsIgnoreCase(imageCheckCode)) {
return Result.failed(StatusCode.USER_IMAGE_VERIFICATION_CODE_MISMATCH);
}
return appLogin(mobile,mobileCheckCode);
}finally {
redisTemplate.delete(redisImageCheckCodeKey);
}
return appLogin(mobile,mobileCheckCode);
}
/*

@ -33,6 +33,7 @@ import com.luoo.user.util.NickNameUtil;
import api.Result;
import api.StatusCode;
import dto.UserLoginDto;
import io.jsonwebtoken.Claims;
import util.JwtUtil;
@ -288,15 +289,13 @@ public class UserService {
public String autoLogin(String token) {
try {
Claims claims = jwtUtil.parseJWT(token);
String userId = claims.getId();
if(Constants.TOKEN_ROLE_APP_USER.equals((String) claims.get(Constants.TOKEN_ROLE))){
User user = userDao.findById(userId).orElse(null);
UserLoginDto userLoginDto=jwtUtil.getUserLoginDto(token);
if(Constants.TOKEN_ROLE_APP_USER.equals(userLoginDto.getRoles())){
User user = userDao.findById(userLoginDto.getUserId()).get();
user.setLastdate(new Date());
userDao.save(user);
}
return jwtUtil.createJWT(userId, claims.getSubject(), Constants.TOKEN_ROLE_APP_USER);
return jwtUtil.createJWT(userLoginDto.getUserId(), userLoginDto.getNickName(), userLoginDto.getRoles());
} catch (Exception e) {
return null;
}

Loading…
Cancel
Save