|
@@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
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.ApiConstant;
|
|
|
import com.gis.common.constant.ConfigConstant;
|
|
|
import com.gis.common.util.*;
|
|
|
import com.gis.admin.entity.po.SysUserEntity;
|
|
@@ -61,38 +62,37 @@ public class LoginController {
|
|
|
// 超级管理员角色key
|
|
|
private static String ROLE_SYS_ADMIN = "sys_admin";
|
|
|
|
|
|
- final static String HOST = "http://127.0.0.1:8024/admin/authorize";
|
|
|
|
|
|
|
|
|
|
|
|
// 目前是24h
|
|
|
private static Integer TOKEN_EXPIRE = 1000 * 60 * 60 * 24;
|
|
|
|
|
|
- @ApiOperation("登录")
|
|
|
- @PostMapping(value = "/admin/login")
|
|
|
- public Result login(@Valid @RequestBody LoginDto param, String pwdEncrypt) {
|
|
|
- // 1.获取用户
|
|
|
- SysUserEntity entity = userService.findByUserName(param.getUserName());
|
|
|
- BaseRuntimeException.isNull(entity, null, "用户不存在");
|
|
|
-
|
|
|
- //校验密码
|
|
|
- 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, "密码错误");
|
|
|
- // 检查账号是否启用
|
|
|
- BaseRuntimeException.isTrue(entity.getIsEnabled() != 1, null, "此账号已停用:" + entity.getUserName());
|
|
|
-
|
|
|
- return createToken(entity, "loginCms");
|
|
|
-
|
|
|
- }
|
|
|
+// @ApiOperation("登录")
|
|
|
+// @PostMapping(value = "/admin/login")
|
|
|
+// public Result login(@Valid @RequestBody LoginDto param, String pwdEncrypt) {
|
|
|
+// // 1.获取用户
|
|
|
+// SysUserEntity entity = userService.findByUserName(param.getUserName());
|
|
|
+// BaseRuntimeException.isNull(entity, null, "用户不存在");
|
|
|
+//
|
|
|
+// //校验密码
|
|
|
+// 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, "密码错误");
|
|
|
+// // 检查账号是否启用
|
|
|
+// BaseRuntimeException.isTrue(entity.getIsEnabled() != 1, null, "此账号已停用:" + entity.getUserName());
|
|
|
+//
|
|
|
+// return createToken(entity, "loginCms");
|
|
|
+//
|
|
|
+// }
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -102,32 +102,31 @@ public class LoginController {
|
|
|
* @param pwdEncrypt 非必传
|
|
|
* @return
|
|
|
*/
|
|
|
-// @ApiOperation("授权登录")
|
|
|
-// @PostMapping(value = "/admin/login")
|
|
|
-// public Result login(@Valid @RequestBody LoginDto param, String pwdEncrypt) {
|
|
|
-// String api = HOST + "?pwdEncrypt=" + pwdEncrypt;
|
|
|
-// HashMap<Object, Object> querys = new HashMap<>();
|
|
|
-// querys.put("pwdEncrypt", pwdEncrypt);
|
|
|
-//
|
|
|
-// JSONObject json = new JSONObject();
|
|
|
-// json.put("userName", param.getUserName());
|
|
|
-// json.put("password", param.getPassword());
|
|
|
-// String s = HttpUtil.createPost(api)
|
|
|
-// .body(json.toJSONString(), "application/json;charset=UTF-8")
|
|
|
-// .execute().body();
|
|
|
-// log.info("授权返回值: {}", s);
|
|
|
-//
|
|
|
-// Result result = JSON.parseObject(s, Result.class);
|
|
|
-// if (result.getCode() != 0){
|
|
|
-// return result;
|
|
|
-// }
|
|
|
-//
|
|
|
-// SysUserEntity entity = JSON.parseObject(result.getData().toString(), SysUserEntity.class);
|
|
|
-//
|
|
|
-//
|
|
|
-// return createToken(entity, "loginCms");
|
|
|
-//
|
|
|
-// }
|
|
|
+ @ApiOperation("授权登录")
|
|
|
+ @PostMapping(value = "/admin/login")
|
|
|
+ public Result login(@Valid @RequestBody LoginDto param, String pwdEncrypt) {
|
|
|
+ String api = configConstant.ageUserHost + ApiConstant.AGE_USER_AUTHORIZE + "?pwdEncrypt=" + pwdEncrypt;
|
|
|
+ HashMap<Object, Object> querys = new HashMap<>();
|
|
|
+ querys.put("pwdEncrypt", pwdEncrypt);
|
|
|
+
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+ json.put("userName", param.getUserName());
|
|
|
+ json.put("password", param.getPassword());
|
|
|
+ String s = HttpUtil.createPost(api)
|
|
|
+ .body(json.toJSONString(), "application/json;charset=UTF-8")
|
|
|
+ .execute().body();
|
|
|
+ log.info("授权返回值: {}", s);
|
|
|
+
|
|
|
+ Result result = JSON.parseObject(s, Result.class);
|
|
|
+ if (result.getCode() != 0){
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ SysUserEntity entity = JSON.parseObject(result.getData().toString(), SysUserEntity.class);
|
|
|
+ userService.syncUserToLocal(entity);
|
|
|
+ return createToken(entity, "loginCms");
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
|
|
|
private Result createToken(SysUserEntity entity, String loginType){
|
|
@@ -158,7 +157,7 @@ public class LoginController {
|
|
|
// 保存操作日志
|
|
|
saveLog(userId, loginType);
|
|
|
|
|
|
- redisUtil.setEx(configConstant.redisPrefix + token, token, 23, TimeUnit.HOURS);
|
|
|
+ redisUtil.setEx(token, token, 23, TimeUnit.HOURS);
|
|
|
return Result.success(result);
|
|
|
}
|
|
|
|