|
@@ -1,6 +1,9 @@
|
|
package com.hb.proj.auth.controller;
|
|
package com.hb.proj.auth.controller;
|
|
|
|
|
|
|
|
+import java.util.UUID;
|
|
|
|
+
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
@@ -8,9 +11,8 @@ import org.springframework.web.bind.annotation.RestController;
|
|
import com.hb.proj.allconfig.AccessToken;
|
|
import com.hb.proj.allconfig.AccessToken;
|
|
import com.hb.proj.allconfig.CacheConfig;
|
|
import com.hb.proj.allconfig.CacheConfig;
|
|
import com.hb.proj.allconfig.SysLog;
|
|
import com.hb.proj.allconfig.SysLog;
|
|
-import com.hb.proj.auth.service.User;
|
|
|
|
-import com.hb.proj.auth.service.UserService;
|
|
|
|
-import com.hb.proj.utils.RequestParams;
|
|
|
|
|
|
+import com.hb.proj.model.User;
|
|
|
|
+import com.hb.proj.sys.service.UserService;
|
|
import com.hb.proj.utils.RespVO;
|
|
import com.hb.proj.utils.RespVO;
|
|
import com.hb.proj.utils.RespVOBuilder;
|
|
import com.hb.proj.utils.RespVOBuilder;
|
|
|
|
|
|
@@ -21,10 +23,15 @@ import jakarta.validation.constraints.NotBlank;
|
|
*/
|
|
*/
|
|
|
|
|
|
@RestController
|
|
@RestController
|
|
-@RequestMapping("/api/login")
|
|
|
|
|
|
+@RequestMapping("/login")
|
|
@Validated
|
|
@Validated
|
|
public class LoginController {
|
|
public class LoginController {
|
|
|
|
|
|
|
|
+ @Value("${sys.admin.account}")
|
|
|
|
+ private String adminAccount;
|
|
|
|
+
|
|
|
|
+ @Value("${sys.admin.pwd}")
|
|
|
|
+ private String adminPwd;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private UserService userService;
|
|
private UserService userService;
|
|
@@ -39,39 +46,29 @@ public class LoginController {
|
|
@RequestMapping("/check")
|
|
@RequestMapping("/check")
|
|
@SysLog("用户{arg0}登录系统")
|
|
@SysLog("用户{arg0}登录系统")
|
|
public RespVO<AccessToken> check(@NotBlank(message = "账号不能为空") String loginId,@NotBlank(message = "密码不能为空") String pwd){
|
|
public RespVO<AccessToken> check(@NotBlank(message = "账号不能为空") String loginId,@NotBlank(message = "密码不能为空") String pwd){
|
|
- User us=userService.getByLoginId(loginId);
|
|
|
|
- if(us==null||!pwd.equals(us.getPwd())) {
|
|
|
|
- return RespVOBuilder.error("账号或密码错误");
|
|
|
|
|
|
+ boolean isAdmin=loginId.equalsIgnoreCase(adminAccount);
|
|
|
|
+ AccessToken token=null;
|
|
|
|
+
|
|
|
|
+ if(isAdmin) {
|
|
|
|
+ if(!pwd.equals(adminPwd)) {
|
|
|
|
+ return RespVOBuilder.error("账号或密码错误");
|
|
|
|
+ }
|
|
|
|
+ token=new AccessToken(UUID.randomUUID().toString().replace("-", ""),isAdmin);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ User us=userService.getByLoginId(loginId);
|
|
|
|
+ if(us==null||!pwd.equals(us.getPwd())) {
|
|
|
|
+ return RespVOBuilder.error("账号或密码错误");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ token=new AccessToken(us.getUserId(),isAdmin);
|
|
}
|
|
}
|
|
|
|
|
|
- AccessToken token=new AccessToken(us.getUserId());
|
|
|
|
|
|
|
|
CacheConfig.put(token);
|
|
CacheConfig.put(token);
|
|
|
|
|
|
-
|
|
|
|
return RespVOBuilder.ok(token);
|
|
return RespVOBuilder.ok(token);
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * 获得单个用户数据.
|
|
|
|
- * @apiNote <p>通过指定的用户编号获取数据<br>
|
|
|
|
- * 用户编号不能为空
|
|
|
|
- * @param id 用户编号
|
|
|
|
- * @param params 其它参数
|
|
|
|
- * @return 用户数据json
|
|
|
|
- */
|
|
|
|
- @RequestMapping("/get")
|
|
|
|
- RespVO<User> getUser(@NotBlank(message = "用户编号【id】不能为空") String id,RequestParams params) {
|
|
|
|
- return RespVOBuilder.ok(userService.getUs(id));
|
|
|
|
- }
|
|
|
|
|
|
|
|
- @RequestMapping("/update")
|
|
|
|
- @SysLog("更新用户{arg0}的姓名为{arg1}")
|
|
|
|
- RespVO<String> updateUser(@NotBlank(message = "用户编号编号【id】不能为空") String id,String name) {
|
|
|
|
- User us=new User();
|
|
|
|
- us.setNickname(name);
|
|
|
|
- us.setUserId(id);
|
|
|
|
- boolean rst=userService.updateUser(us);
|
|
|
|
- return rst?RespVOBuilder.ok():RespVOBuilder.error("未找到数据");
|
|
|
|
- }
|
|
|
|
}
|
|
}
|