|
@@ -1,6 +1,7 @@
|
|
|
package com.gis.web.controller;
|
|
|
|
|
|
import com.gis.common.constant.TypeCode;
|
|
|
+import com.gis.common.util.Base64Converter;
|
|
|
import com.gis.common.util.PasswordUtils;
|
|
|
import com.gis.common.util.Result;
|
|
|
import com.gis.domain.po.LogEntity;
|
|
@@ -23,6 +24,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
import springfox.documentation.annotations.ApiIgnore;
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
+import javax.validation.constraints.NotBlank;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
@@ -48,14 +50,11 @@ public class IndexController extends BaseController {
|
|
|
private SysUserService userService;
|
|
|
|
|
|
@Autowired
|
|
|
- private SysRoleService sysRoleService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
private RedisTemplate<String, String> redisTemplate;
|
|
|
|
|
|
- @ApiOperation("登录")
|
|
|
+ @ApiOperation(value = "登录", notes = "密码密文")
|
|
|
@PostMapping(value = "admin/login")
|
|
|
- public Result login(@Valid @RequestBody LoginRequest param) throws Exception {
|
|
|
+ public Result login(@Valid @RequestBody LoginRequest param) {
|
|
|
|
|
|
// 1.获取用户
|
|
|
SysUserEntity userEntity = userService.findByUserName(param.getUserName());
|
|
@@ -63,8 +62,12 @@ public class IndexController extends BaseController {
|
|
|
log.error("用户不存在");
|
|
|
return Result.failure(5100,"用户不存在或密码错误");
|
|
|
}
|
|
|
+
|
|
|
+ // 解密密码
|
|
|
+ String password = Base64Converter.decodePassword(param.getPassword());
|
|
|
+
|
|
|
// 验证密码,解密出来是明文密码,在跟输入密码比较
|
|
|
- boolean decryptName = PasswordUtils.decrypt(userEntity.getPassword(), param.getPassword(), PasswordUtils.getStaticSalt());
|
|
|
+ boolean decryptName = PasswordUtils.decrypt(userEntity.getPassword(), password, PasswordUtils.getStaticSalt());
|
|
|
if (!decryptName) {
|
|
|
log.error("密码错误");
|
|
|
return Result.failure(5100,"用户不存在或密码错误");
|
|
@@ -110,7 +113,6 @@ public class IndexController extends BaseController {
|
|
|
|
|
|
}
|
|
|
|
|
|
- @ApiOperation("退出")
|
|
|
@GetMapping("admin/logout")
|
|
|
public Result logout() {
|
|
|
String token = getToken();
|
|
@@ -130,5 +132,63 @@ public class IndexController extends BaseController {
|
|
|
|
|
|
|
|
|
|
|
|
+ @ApiOperation(value = "测试登录", notes = "密码用明文")
|
|
|
+ @PostMapping(value = "admin/testLogin")
|
|
|
+ public Result testLogin(@Valid @RequestBody LoginRequest param) {
|
|
|
+
|
|
|
+ // 1.获取用户
|
|
|
+ SysUserEntity userEntity = userService.findByUserName(param.getUserName());
|
|
|
+ if (userEntity == null){
|
|
|
+ log.error("用户不存在");
|
|
|
+ return Result.failure(5100,"用户不存在或密码错误");
|
|
|
+ }
|
|
|
+ // 验证密码,解密出来是明文密码,在跟输入密码比较
|
|
|
+ boolean decryptName = PasswordUtils.decrypt(userEntity.getPassword(), param.getPassword(), PasswordUtils.getStaticSalt());
|
|
|
+ if (!decryptName) {
|
|
|
+ log.error("密码错误");
|
|
|
+ return Result.failure(5100,"用户不存在或密码错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查账号是否启用, 状态 0:启用 1:停用 2:注销
|
|
|
+ if (userEntity.getStatus() == 1) {
|
|
|
+ log.error("账号已停用: {}", userEntity.getUserName());
|
|
|
+ return Result.failure(5101, "账号已停用");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (userEntity.getStatus() == 2) {
|
|
|
+ log.error("账号已注销: {}", userEntity.getUserName());
|
|
|
+ return Result.failure(5102, "账号已注销");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 创建新token
|
|
|
+ HashMap<String, Object> tokenMap = new HashMap<>();
|
|
|
+ tokenMap.put("userName", userEntity.getUserName());
|
|
|
+ tokenMap.put("id", userEntity.getId());
|
|
|
+ tokenMap.put("roleId", userEntity.getRoleId());
|
|
|
+
|
|
|
+ // 创建新token
|
|
|
+ String token = JwtUtil.createJWT(TOKEN_EXPIRE, tokenMap);
|
|
|
+
|
|
|
+ HashMap<String, Object> result = new HashMap<>();
|
|
|
+ result.put("user", userEntity);
|
|
|
+ result.put("token", token);
|
|
|
+
|
|
|
+ // 保存操作日志
|
|
|
+ saveLog(new LogEntity(userEntity.getId(),"登录管理","用户登录"));
|
|
|
+
|
|
|
+ // 更新到 redis, 有效期24h, 旧token无效, 做单用户登录
|
|
|
+ redisTemplate.opsForValue().set(TypeCode.REDIS_LOGIN_TOKEN + token, token, Long.parseLong("23"), TimeUnit.HOURS);
|
|
|
+
|
|
|
+ return Result.success(result);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ String str = "一二三四五六七八九十";
|
|
|
+ System.out.println(str.length());
|
|
|
+ }
|
|
|
|
|
|
}
|