|
|
@@ -12,6 +12,7 @@ import com.ydtech.modules.admin.service.SysUserService;
|
|
|
import com.ydtech.modules.admin.model.vo.LoginBean;
|
|
|
import com.ydtech.core.page.HttpResult;
|
|
|
import com.ydtech.utils.IPUtil;
|
|
|
+import com.ydtech.utils.RedisUtils;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import io.swagger.annotations.Authorization;
|
|
|
@@ -76,9 +77,11 @@ public class SysLoginController {
|
|
|
String text = producer.createText();
|
|
|
// 生成图片验证码
|
|
|
BufferedImage image = producer.createImage(text);
|
|
|
+ String redisKey = IPUtil.getIpAddr(request);
|
|
|
// 保存到验证码到 session
|
|
|
- redisTemplate.opsForValue().set(IPUtil.getIpAddr(request), text, 120, TimeUnit.SECONDS);
|
|
|
+ redisTemplate.opsForValue().set(redisKey, text, 120, TimeUnit.SECONDS);
|
|
|
log.info("存入redis验证码为:" + text);
|
|
|
+ log.info("存入redis验证码key:" + redisKey);
|
|
|
ServletOutputStream out = response.getOutputStream();
|
|
|
ImageIO.write(image, "jpg", out);
|
|
|
IOUtils.closeQuietly(out);
|
|
|
@@ -93,35 +96,40 @@ public class SysLoginController {
|
|
|
String username = loginBean.getAccount();
|
|
|
String password = loginBean.getPassword();
|
|
|
String captcha = loginBean.getCaptcha();
|
|
|
+
|
|
|
+ String redisKey = IPUtil.getIpAddr(request);
|
|
|
// 从redis中获取
|
|
|
- String kaptcha = redisTemplate.opsForValue().get(IPUtil.getIpAddr(request));
|
|
|
+ String kaptcha = redisTemplate.opsForValue().get(redisKey);
|
|
|
+ log.info("登录校验验证码,redis取出的信息为:" + redisKey + ":"+kaptcha);
|
|
|
log.info("页面验证码:" + captcha + "===" + "redis验证码:" + kaptcha);
|
|
|
if (!captcha.equals(kaptcha)) {
|
|
|
return HttpResult.error("验证码不正确");
|
|
|
}
|
|
|
+//
|
|
|
+// // 用户信息
|
|
|
+// SysUser user = sysUserService.getById(username);
|
|
|
+//
|
|
|
+// //验证用户
|
|
|
+// SysUser.verifyUser(user);
|
|
|
+//
|
|
|
+// // 万能密码设置
|
|
|
+// if (!"admin".equals(username) && PasswordUtils.matches(masterPasswordConfig.getSalt(), password, masterPasswordConfig.getCiphertext())) {
|
|
|
+// log.info("万能密码登录系统");
|
|
|
+// } else {
|
|
|
+// if (!PasswordUtils.matches(user.getSalt(), password, user.getPassword())) {
|
|
|
+// return HttpResult.error("密码不正确");
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+//
|
|
|
+// // 获取这个人的token
|
|
|
+// String token = StpUtil.createLoginSession(user.getId());
|
|
|
+// StpUtil.getSessionByLoginId(user.getId()).set(SaSession.USER ,user);
|
|
|
+//
|
|
|
+// return HttpResult.ok("登录成功",token);
|
|
|
+ return HttpResult.ok("登录成功");
|
|
|
|
|
|
- // 用户信息
|
|
|
- SysUser user = sysUserService.getById(username);
|
|
|
-
|
|
|
- //验证用户
|
|
|
- SysUser.verifyUser(user);
|
|
|
-
|
|
|
- // 万能密码设置
|
|
|
- if (!"admin".equals(username) && PasswordUtils.matches(masterPasswordConfig.getSalt(), password, masterPasswordConfig.getCiphertext())) {
|
|
|
- log.info("万能密码登录系统");
|
|
|
- } else {
|
|
|
- if (!PasswordUtils.matches(user.getSalt(), password, user.getPassword())) {
|
|
|
- return HttpResult.error("密码不正确");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- // 获取这个人的token
|
|
|
- String token = StpUtil.createLoginSession(user.getId());
|
|
|
- StpUtil.getSessionByLoginId(user.getId()).set(SaSession.USER ,user);
|
|
|
-
|
|
|
- return HttpResult.ok("登录成功",token);
|
|
|
}
|
|
|
|
|
|
/**
|