图形验证码重置处理

This commit is contained in:
mashuai 2024-06-11 16:25:22 +08:00
parent 338d1e6a20
commit 15feec4e84
3 changed files with 15 additions and 11 deletions

View File

@ -67,6 +67,18 @@ public class TokenController {
*/ */
@PostMapping("login") @PostMapping("login")
public R<?> login(@RequestBody LoginBody form) throws Exception { public R<?> login(@RequestBody LoginBody form) throws Exception {
//优先校验图形验证码
String uuid = form.getUuid();
Object cacheObject = redisService.getCacheObject(CacheConstants.CAPTCHA_CODE_KEY + uuid);
String captcha = cacheObject == null ? null : cacheObject.toString();
// 获取后立即删除图形验证码缓存
redisService.deleteObject(CacheConstants.CAPTCHA_CODE_KEY + uuid);
if (StringUtils.isBlank(captcha)) {
throw new ServiceException("图形验证码失效,请重新刷新获取");
}
if (form.getCode() != null && !form.getCode().equals(captcha)) {
throw new ServiceException("图形验证码错误");
}
//根据用户名查询用户信息 //根据用户名查询用户信息
LoginUser user = sysLoginService.selectByName(form.getUsername()); LoginUser user = sysLoginService.selectByName(form.getUsername());
//获取查询的用户手机号 //获取查询的用户手机号
@ -84,26 +96,18 @@ public class TokenController {
throw new ServiceException("短信验证码错误", 500); throw new ServiceException("短信验证码错误", 500);
} }
} }
String uuid = form.getUuid();
String decryptedData = RsaUtil.decryptByPrivateKey(form.getPassword(), privateKey); String decryptedData = RsaUtil.decryptByPrivateKey(form.getPassword(), privateKey);
Object cacheObject = redisService.getCacheObject(CacheConstants.CAPTCHA_CODE_KEY + uuid);
String captcha = cacheObject == null ? null : cacheObject.toString();
// 获取后立即删除图形验证码缓存
redisService.deleteObject(CacheConstants.CAPTCHA_CODE_KEY + uuid);
// 用户登录 // 用户登录
LoginUser userInfo = sysLoginService.login(form.getUsername(), decryptedData); LoginUser userInfo = sysLoginService.login(form.getUsername(), decryptedData);
if (decryptedData.equals(USER_PASSWORD)) { if (decryptedData.equals(USER_PASSWORD)) {
userInfo.setCode(1); userInfo.setCode(1);
} }
if (StringUtils.isBlank(captcha)) {
return R.fail("图形验证码超时,请重新刷新");
}
if (form.getCode() != null && form.getCode().equals(captcha)) { if (form.getCode() != null && form.getCode().equals(captcha)) {
redisService.deleteObject("code_" + phone); redisService.deleteObject("code_" + phone);
// 获取登录token // 获取登录token
return R.ok(tokenService.createToken(userInfo)); return R.ok(tokenService.createToken(userInfo));
} else { } else {
return R.fail("图形验证码错误"); return R.fail("登录失败,请联系管理员!");
} }
} }

View File

@ -89,7 +89,7 @@ public class SysProfileController extends BaseController {
* 重置密码 * 重置密码
*/ */
@Log(title = "个人信息", businessType = BusinessType.UPDATE) @Log(title = "个人信息", businessType = BusinessType.UPDATE)
@PutMapping("/updatePwd") @PutMapping("/update")
public AjaxResult updatePwd(String actionCode, String handleCode) throws Exception { public AjaxResult updatePwd(String actionCode, String handleCode) throws Exception {
//对新老密码进行解密 //对新老密码进行解密
String oldDecrypt = RsaUtil.decryptByPrivateKey(actionCode, Constants.privateKey); String oldDecrypt = RsaUtil.decryptByPrivateKey(actionCode, Constants.privateKey);

View File

@ -260,7 +260,7 @@ public class SysUserController extends BaseController {
*/ */
@RequiresPermissions("system:user:edit") @RequiresPermissions("system:user:edit")
@Log(title = "用户管理", businessType = BusinessType.UPDATE) @Log(title = "用户管理", businessType = BusinessType.UPDATE)
@PutMapping("/resetPwd") @PutMapping("/reset")
public AjaxResult resetPwd(@RequestBody SysUser user) throws Exception { public AjaxResult resetPwd(@RequestBody SysUser user) throws Exception {
//对密码进行解密 //对密码进行解密
String decrypt = RsaUtil.decryptByPrivateKey(user.getPassword(), Constants.privateKey); String decrypt = RsaUtil.decryptByPrivateKey(user.getPassword(), Constants.privateKey);