|
|
@@ -1,9 +1,10 @@
|
|
|
package com.roma.romaapi.service;
|
|
|
|
|
|
import com.roma.romaapi.dao.ApiDao;
|
|
|
+import com.roma.romaapi.utils.JWTUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
-import org.springframework.data.redis.core.ValueOperations;
|
|
|
+import com.roma.romaapi.utils.SecurityUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
@@ -17,6 +18,10 @@ public class ApiService {
|
|
|
private RedisTemplate<String, String> redisTemplate;
|
|
|
@Autowired
|
|
|
private ApiDao apiDao;
|
|
|
+ @Autowired
|
|
|
+ SecurityUtils securityUtils;
|
|
|
+ @Autowired
|
|
|
+ JWTUtil jwtUtil;
|
|
|
// 登录方法
|
|
|
public Map<String, Object> login(Map<String, String[]> maps) {
|
|
|
// 请求参数,获取验证码,验证码token,用户名,密码
|
|
|
@@ -28,23 +33,32 @@ public class ApiService {
|
|
|
if(!Boolean.TRUE.equals(redisTemplate.hasKey(captchaToken)) || captchaTokenValue!=captcha){
|
|
|
// 验证码验证失败
|
|
|
}
|
|
|
+// String aa = securityUtils.encodePassword(password); // 加密密码
|
|
|
// 判断是否存在此用户,用户密码是否正确
|
|
|
Map UserInfo = apiDao.adminInfoQueryForMap(userName);
|
|
|
if(UserInfo.containsKey("sysErrorCode")) {
|
|
|
// 如果没查到用户信息,则报错
|
|
|
+ return UserInfo;
|
|
|
}
|
|
|
- Object userPassword = UserInfo.get("admin_password");
|
|
|
- String stringPassword = userPassword.toString();
|
|
|
-
|
|
|
- if(!password.equals(stringPassword)) {
|
|
|
+ Object adminPassword = UserInfo.get("admin_password");
|
|
|
+ String stringAdminPassword = adminPassword.toString();
|
|
|
+ // 校验密码是否正确
|
|
|
+ if(!securityUtils.matchesPassword(password,stringAdminPassword)) {
|
|
|
// 校验密码是否正确 密码不正确,返回错误
|
|
|
+ System.out.println("密码校验错误");
|
|
|
}
|
|
|
|
|
|
-// System.out.println(password);
|
|
|
- System.out.println(captcha);
|
|
|
-// System.out.println(captchaToken);
|
|
|
+ // 通过密码,验证码校验,发放token
|
|
|
+ Map<String, Object> jwtInfo = new HashMap<>();
|
|
|
+ Object userId = UserInfo.get("id");
|
|
|
+ String stringUserId = userId.toString();
|
|
|
+ jwtInfo.put("id", stringUserId);
|
|
|
+ jwtInfo.put("loginTime", System.currentTimeMillis()/1000+"");
|
|
|
+ jwtInfo.put("name", userName);
|
|
|
+ String jwtToken = jwtUtil.getToken(jwtInfo);
|
|
|
+ System.out.println("jwt---token==="+jwtToken);
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
- map.put("token", 1);
|
|
|
+ map.put("loginToken", jwtToken);
|
|
|
|
|
|
return map;
|
|
|
}
|