|
|
@@ -2,8 +2,12 @@ package com.roma.romaapi.controller;
|
|
|
|
|
|
|
|
|
import com.roma.romaapi.service.CaptchaService;
|
|
|
-import jakarta.servlet.http.HttpServletResponse;
|
|
|
+import com.roma.romaapi.utils.CustomResponse;
|
|
|
+import com.roma.romaapi.utils.UUIDUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
+import org.springframework.data.redis.core.ValueOperations;
|
|
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
@@ -11,13 +15,20 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
import java.io.IOException;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
@RestController
|
|
|
@CrossOrigin
|
|
|
public class ApiController {
|
|
|
|
|
|
+ @Value("${server.servlet.session.timeout}")
|
|
|
+ private Integer timeout;
|
|
|
@Autowired
|
|
|
CaptchaService captchaService;
|
|
|
+ @Autowired
|
|
|
+ private UUIDUtil uuidUtil;
|
|
|
+ @Autowired
|
|
|
+ private RedisTemplate<String, String> redisTemplate;
|
|
|
// 获取验证码
|
|
|
@RequestMapping("/login/verifyCode")
|
|
|
public Map<String, Object> loginVerifyCode() throws IOException {
|
|
|
@@ -27,9 +38,19 @@ public class ApiController {
|
|
|
// 登录系统
|
|
|
@RequestMapping("/api/login")
|
|
|
public Map login(){
|
|
|
- System.out.print("aaa");
|
|
|
- Map a = new HashMap();
|
|
|
- a.put("aa", "dsadsa");
|
|
|
- return a;
|
|
|
+
|
|
|
+ Map ret = new HashMap();
|
|
|
+ String key = uuidUtil.getUUID32();
|
|
|
+ ret.put("token", key);
|
|
|
+ return CustomResponse.formatResponse(ret);
|
|
|
+// //生成验证码对应的token 以token为key 验证码为value存在redis中
|
|
|
+// ValueOperations<String, String> valueOperations = redisTemplate.opsForValue();
|
|
|
+// valueOperations.set(key, key);
|
|
|
+// //设置验证码过期时间
|
|
|
+// redisTemplate.expire(key, timeout, TimeUnit.MINUTES);
|
|
|
+// Map<String, Object> map = new HashMap<>();
|
|
|
+// map.put("token", key);
|
|
|
+// map.put("expire", timeout);
|
|
|
+
|
|
|
}
|
|
|
}
|