|
|
@@ -0,0 +1,51 @@
|
|
|
+package com.roma.romaapi.service;
|
|
|
+
|
|
|
+import com.roma.romaapi.dao.ApiDao;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
+import org.springframework.data.redis.core.ValueOperations;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class ApiService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RedisTemplate<String, String> redisTemplate;
|
|
|
+ @Autowired
|
|
|
+ private ApiDao apiDao;
|
|
|
+ // 登录方法
|
|
|
+ public Map<String, Object> login(Map<String, String[]> maps) {
|
|
|
+ // 请求参数,获取验证码,验证码token,用户名,密码
|
|
|
+ String userName = maps.get("api_name")[0]; // 用户名
|
|
|
+ String password = maps.get("api_password")[0]; // 密码
|
|
|
+ String captcha = maps.get("api_captcha")[0]; // 用户输入验证码
|
|
|
+ String captchaToken = maps.get("captchaToken")[0]; // 验证码token,获取验证码的值
|
|
|
+ String captchaTokenValue = redisTemplate.opsForValue().get(captchaToken); // 缓存中验证码的值
|
|
|
+ if(!Boolean.TRUE.equals(redisTemplate.hasKey(captchaToken)) || captchaTokenValue!=captcha){
|
|
|
+ // 验证码验证失败
|
|
|
+ }
|
|
|
+ // 判断是否存在此用户,用户密码是否正确
|
|
|
+ Map UserInfo = apiDao.adminInfoQueryForMap(userName);
|
|
|
+ if(UserInfo.containsKey("sysErrorCode")) {
|
|
|
+ // 如果没查到用户信息,则报错
|
|
|
+ }
|
|
|
+ Object userPassword = UserInfo.get("admin_password");
|
|
|
+ String stringPassword = userPassword.toString();
|
|
|
+
|
|
|
+ if(!password.equals(stringPassword)) {
|
|
|
+ // 校验密码是否正确 密码不正确,返回错误
|
|
|
+ }
|
|
|
+
|
|
|
+// System.out.println(password);
|
|
|
+ System.out.println(captcha);
|
|
|
+// System.out.println(captchaToken);
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("token", 1);
|
|
|
+
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+}
|