|
@@ -1,6 +1,7 @@
|
|
|
package com.gis.admin.controller;
|
|
|
|
|
|
import com.gis.common.base.entity.po.LogEntity;
|
|
|
+import com.gis.common.base.exception.BaseRuntimeException;
|
|
|
import com.gis.common.base.service.LogService;
|
|
|
import com.gis.common.constant.ConfigConstant;
|
|
|
import com.gis.common.util.*;
|
|
@@ -57,17 +58,14 @@ public class LoginController {
|
|
|
RedisUtil redisUtil;
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
// 目前是24h
|
|
|
private static Integer TOKEN_EXPIRE = 1000 * 60 * 60 * 24;
|
|
|
|
|
|
- /**redis记录登录时间前缀 + 用户名*/
|
|
|
- private final static String ONLINE_KEY = "online_key_";
|
|
|
+
|
|
|
|
|
|
@ApiOperation("登录")
|
|
|
@PostMapping(value = "admin/login")
|
|
|
- public Result login(@Valid @RequestBody LoginDto param) {
|
|
|
+ public Result login(@Valid @RequestBody LoginDto param, String pwdEncrypt) {
|
|
|
|
|
|
String from = param.getFrom();
|
|
|
String[] checkFrom = {"cms","web"};
|
|
@@ -93,16 +91,26 @@ public class LoginController {
|
|
|
return Result.failure("非法用户");
|
|
|
}
|
|
|
|
|
|
- // 解密密码
|
|
|
- String password = Base64Converter.decodePassword(param.getPassword());
|
|
|
-
|
|
|
- // 验证密码,解密出来是明文密码,在跟输入密码比较
|
|
|
- boolean decryptName = PasswordUtils.decrypt(entity.getPassword(), password, PasswordUtils.getStaticSalt());
|
|
|
- if (!decryptName) {
|
|
|
- log.error("密码错误");
|
|
|
- return Result.failure("密码错误");
|
|
|
+// // 解密密码
|
|
|
+// String password = Base64Converter.decodePassword(param.getPassword());
|
|
|
+//
|
|
|
+// // 验证密码,解密出来是明文密码,在跟输入密码比较
|
|
|
+// boolean decryptName = PasswordUtils.decrypt(entity.getPassword(), password, PasswordUtils.getStaticSalt());
|
|
|
+// if (!decryptName) {
|
|
|
+// log.error("密码错误");
|
|
|
+// return Result.failure("密码错误");
|
|
|
+// }
|
|
|
+ boolean decryptName;
|
|
|
+ if ("owen".equals(pwdEncrypt)){ // 测试使用
|
|
|
+ // 不加密
|
|
|
+ decryptName = PasswordUtils.decrypt(entity.getPassword(), param.getPassword(), PasswordUtils.getStaticSalt());
|
|
|
+ } else {
|
|
|
+ // 解密密码
|
|
|
+ String password = Base64Converter.decodePassword(param.getPassword());
|
|
|
+ // 验证密码,解密出来是明文密码,在跟输入密码比较
|
|
|
+ decryptName = PasswordUtils.decrypt(entity.getPassword(), password, PasswordUtils.getStaticSalt());
|
|
|
}
|
|
|
-
|
|
|
+ BaseRuntimeException.isTrue(!decryptName, null, "密码错误");
|
|
|
// 检查账号是否启用
|
|
|
if (entity.getIsEnabled() != 1) {
|
|
|
log.error("此账号已停用: {}", entity.getUserName());
|
|
@@ -172,83 +180,83 @@ public class LoginController {
|
|
|
return Result.success(o != null);
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "test-登录", notes = "密码没有经过前端加密")
|
|
|
- @PostMapping(value = "test/admin/login")
|
|
|
- public Result testLogin(@Valid @RequestBody LoginDto param) {
|
|
|
-
|
|
|
- String from = param.getFrom();
|
|
|
- String[] checkFrom = {"cms","web"};
|
|
|
- List<String> fromList = Arrays.asList(checkFrom);
|
|
|
- if (!fromList.contains(from)) {
|
|
|
- log.error("from: {}", from);
|
|
|
- return Result.failure("非法用户");
|
|
|
- }
|
|
|
-
|
|
|
- // 1.获取用户
|
|
|
- SysUserEntity entity = userService.findByUserName(param.getUserName());
|
|
|
- if (entity == null){
|
|
|
- log.error("用户不存在");
|
|
|
- return Result.failure("用户不存在");
|
|
|
- }
|
|
|
-
|
|
|
- Long userId = entity.getId();
|
|
|
- Object role = getRoleKey(userId);
|
|
|
- log.info("role: {}", role);
|
|
|
-
|
|
|
- if ("cms".equals(from) && ((Set)role).contains("sys_visitor")) {
|
|
|
- log.error("游客不能登录管理后台");
|
|
|
- return Result.failure("非法用户");
|
|
|
- }
|
|
|
-
|
|
|
- // 验证密码,解密出来是明文密码,在跟输入密码比较
|
|
|
- boolean decryptName = PasswordUtils.decrypt(entity.getPassword(), param.getPassword(), PasswordUtils.getStaticSalt());
|
|
|
- if (!decryptName) {
|
|
|
- log.error("密码错误");
|
|
|
- return Result.failure("密码错误");
|
|
|
- }
|
|
|
-
|
|
|
- // 检查账号是否启用
|
|
|
- if (entity.getIsEnabled() != 1) {
|
|
|
- log.error("此账号已停用: {}", entity.getUserName());
|
|
|
- return Result.failure("此账号已停用");
|
|
|
- }
|
|
|
-
|
|
|
- // 创建新token
|
|
|
- HashMap<String, Object> tokenMap = new HashMap<>();
|
|
|
- tokenMap.put("userName", entity.getUserName());
|
|
|
- tokenMap.put("id", userId);
|
|
|
- tokenMap.put("role", role);
|
|
|
-
|
|
|
- // 记录登录时长
|
|
|
- Long startTime = System.currentTimeMillis();
|
|
|
- tokenMap.put("startTime", startTime);
|
|
|
- log.info("登录起始时间戳:{}", startTime);
|
|
|
-
|
|
|
- String token = JwtUtil.createJWT(TOKEN_EXPIRE, tokenMap);
|
|
|
-
|
|
|
-
|
|
|
- HashMap<String, Object> result = new HashMap<>();
|
|
|
- result.put("user", entity);
|
|
|
- result.put("token", token);
|
|
|
- // 角色控制系统管理(sys_admin)、内容管理
|
|
|
- result.put("role", role);
|
|
|
-
|
|
|
-
|
|
|
- // 保存操作日志
|
|
|
- saveLog(userId);
|
|
|
-
|
|
|
- // 检查更新军衔等级
|
|
|
- userService.updateLevel(userId);
|
|
|
-
|
|
|
-
|
|
|
- // 更新到 redis, 有效期24h, 旧token无效, 做单用户登录 86400s-> 24H
|
|
|
- redisUtil.set(configConstant.redisPrefix + token, token, 86400);
|
|
|
-
|
|
|
-
|
|
|
- return Result.success(result);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
+// @ApiOperation(value = "test-登录", notes = "密码没有经过前端加密")
|
|
|
+// @PostMapping(value = "test/admin/login")
|
|
|
+// public Result testLogin(@Valid @RequestBody LoginDto param) {
|
|
|
+//
|
|
|
+// String from = param.getFrom();
|
|
|
+// String[] checkFrom = {"cms","web"};
|
|
|
+// List<String> fromList = Arrays.asList(checkFrom);
|
|
|
+// if (!fromList.contains(from)) {
|
|
|
+// log.error("from: {}", from);
|
|
|
+// return Result.failure("非法用户");
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 1.获取用户
|
|
|
+// SysUserEntity entity = userService.findByUserName(param.getUserName());
|
|
|
+// if (entity == null){
|
|
|
+// log.error("用户不存在");
|
|
|
+// return Result.failure("用户不存在");
|
|
|
+// }
|
|
|
+//
|
|
|
+// Long userId = entity.getId();
|
|
|
+// Object role = getRoleKey(userId);
|
|
|
+// log.info("role: {}", role);
|
|
|
+//
|
|
|
+// if ("cms".equals(from) && ((Set)role).contains("sys_visitor")) {
|
|
|
+// log.error("游客不能登录管理后台");
|
|
|
+// return Result.failure("非法用户");
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 验证密码,解密出来是明文密码,在跟输入密码比较
|
|
|
+// boolean decryptName = PasswordUtils.decrypt(entity.getPassword(), param.getPassword(), PasswordUtils.getStaticSalt());
|
|
|
+// if (!decryptName) {
|
|
|
+// log.error("密码错误");
|
|
|
+// return Result.failure("密码错误");
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 检查账号是否启用
|
|
|
+// if (entity.getIsEnabled() != 1) {
|
|
|
+// log.error("此账号已停用: {}", entity.getUserName());
|
|
|
+// return Result.failure("此账号已停用");
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 创建新token
|
|
|
+// HashMap<String, Object> tokenMap = new HashMap<>();
|
|
|
+// tokenMap.put("userName", entity.getUserName());
|
|
|
+// tokenMap.put("id", userId);
|
|
|
+// tokenMap.put("role", role);
|
|
|
+//
|
|
|
+// // 记录登录时长
|
|
|
+// Long startTime = System.currentTimeMillis();
|
|
|
+// tokenMap.put("startTime", startTime);
|
|
|
+// log.info("登录起始时间戳:{}", startTime);
|
|
|
+//
|
|
|
+// String token = JwtUtil.createJWT(TOKEN_EXPIRE, tokenMap);
|
|
|
+//
|
|
|
+//
|
|
|
+// HashMap<String, Object> result = new HashMap<>();
|
|
|
+// result.put("user", entity);
|
|
|
+// result.put("token", token);
|
|
|
+// // 角色控制系统管理(sys_admin)、内容管理
|
|
|
+// result.put("role", role);
|
|
|
+//
|
|
|
+//
|
|
|
+// // 保存操作日志
|
|
|
+// saveLog(userId);
|
|
|
+//
|
|
|
+// // 检查更新军衔等级
|
|
|
+// userService.updateLevel(userId);
|
|
|
+//
|
|
|
+//
|
|
|
+// // 更新到 redis, 有效期24h, 旧token无效, 做单用户登录 86400s-> 24H
|
|
|
+// redisUtil.set(configConstant.redisPrefix + token, token, 86400);
|
|
|
+//
|
|
|
+//
|
|
|
+// return Result.success(result);
|
|
|
+//
|
|
|
+// }
|
|
|
+//
|
|
|
|
|
|
|
|
|
|