|
@@ -3,10 +3,17 @@ package com.pj.project4sp.admin4login;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
|
+import cn.hutool.cache.CacheUtil;
|
|
|
+import cn.hutool.cache.impl.TimedCache;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.crypto.asymmetric.KeyType;
|
|
|
+import cn.hutool.crypto.asymmetric.RSA;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.pj.current.satoken.AuthConst;
|
|
|
import com.pj.utils.cache.RedisUtil;
|
|
|
+import com.wf.captcha.ArithmeticCaptcha;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
@@ -20,6 +27,10 @@ import com.pj.utils.so.SoMap;
|
|
|
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.UUID;
|
|
|
+
|
|
|
/**
|
|
|
* admin账号相关的接口
|
|
|
* @author kong
|
|
@@ -39,15 +50,49 @@ public class SpAccAdminController {
|
|
|
|
|
|
/** 账号、密码登录 */
|
|
|
@RequestMapping("doLogin")
|
|
|
- AjaxJson doLogin(String key, String password) {
|
|
|
+ AjaxJson doLogin(String key, String password, String code, String verCode) {
|
|
|
// 1、验证参数
|
|
|
if(NbUtil.isOneNull(key, password)) {
|
|
|
return AjaxJson.getError("请提供key与password参数");
|
|
|
}
|
|
|
+ if (NbUtil.isOneNull(verCode, code)) {
|
|
|
+ return AjaxJson.getError("请输入验证码");
|
|
|
+ }
|
|
|
+ String cacheCode = RedisUtil.get(code);
|
|
|
+ if (NbUtil.isNull(cacheCode)) {
|
|
|
+ return AjaxJson.getError("验证码已过期");
|
|
|
+ }
|
|
|
+ RSA rsa = KEY_CACHE.get(code);
|
|
|
+ if (rsa==null){
|
|
|
+ return AjaxJson.getError("请重新刷新登录");
|
|
|
+ }
|
|
|
+ if (!StrUtil.equals(cacheCode.toUpperCase(), verCode.toUpperCase())) {
|
|
|
+ return AjaxJson.getError("验证码不正确");
|
|
|
+ }
|
|
|
+
|
|
|
+ password=rsa.decryptStr(password, KeyType.PrivateKey);
|
|
|
+ RedisUtil.del(code);
|
|
|
+ KEY_CACHE.remove(code);
|
|
|
return spAccAdminService.doLogin(key, password);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+ private TimedCache<String, RSA> KEY_CACHE = CacheUtil.newTimedCache(60000);
|
|
|
+ @PostMapping("captcha")
|
|
|
+ public AjaxJson render() {
|
|
|
+ ArithmeticCaptcha captcha = new ArithmeticCaptcha(130, 48);
|
|
|
+ String key = UUID.randomUUID().toString();
|
|
|
+ String verCode = captcha.text().toLowerCase(); // 获取验证码的字符
|
|
|
+ RedisUtil.setBySECONDS(key, verCode, 60);
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put("key", key);
|
|
|
+ map.put("image", captcha.toBase64());
|
|
|
+ RSA rsa = new RSA();
|
|
|
+ String publicKeyBase64Key = rsa.getPublicKeyBase64();
|
|
|
+ KEY_CACHE.put(key, rsa);
|
|
|
+ map.put("pKey", publicKeyBase64Key);
|
|
|
+ return AjaxJson.getSuccessData(map);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/** 退出登录 */
|
|
|
@RequestMapping("doExit")
|
|
|
AjaxJson doExit() {
|