mirror of
https://github.com/suyiiyii/SIMS.git
synced 2025-06-03 12:56:10 +08:00
816
This commit is contained in:
parent
0820b9b651
commit
c8ea250769
@ -42,6 +42,10 @@ public class JwtInterceptor implements HandlerInterceptor {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// request.setAttribute();
|
||||
// request.getAttribute()
|
||||
|
||||
// 执行认证
|
||||
if (StrUtil.isBlank(token)) {
|
||||
//权限错误
|
||||
|
@ -10,36 +10,40 @@ import lombok.NoArgsConstructor;
|
||||
* @Date 2024/8/10 21:18
|
||||
* @PackageName:top.suyiiyii.sims.common
|
||||
* @ClassName: Result
|
||||
* @Description: TODO
|
||||
* @Description: 泛型结果对象
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class Result {
|
||||
public class Result<T> { // 添加类型参数 T
|
||||
|
||||
public static final String CODE_SUCCESS = "200";
|
||||
public static final String CODE_AUTH_ERROR = "401";
|
||||
public static final String CODE_SYS_ERROR = "500";
|
||||
|
||||
public static final String CODE_SUCCESS="200";
|
||||
public static final String CODE_AUTH_ERROR="401";
|
||||
public static final String CODE_SYS_ERROR="500";
|
||||
private String code;
|
||||
|
||||
private String msg;
|
||||
private Object data;
|
||||
public static Result success(){
|
||||
return new Result(CODE_SUCCESS,"success",null);
|
||||
}
|
||||
public static Result success(Object data){
|
||||
return new Result(CODE_SUCCESS,"success",data);
|
||||
}
|
||||
public static Result error(String msg) {
|
||||
return new Result(CODE_SYS_ERROR, msg, null);
|
||||
private T data; // 将 Object 改为 T
|
||||
|
||||
public static <T> Result<T> success() { // 添加类型参数 T 并指定返回类型
|
||||
return new Result<>(CODE_SUCCESS, "success", null);
|
||||
}
|
||||
|
||||
public static Result error(String code,String msg){
|
||||
return new Result(code,msg,null);
|
||||
public static <T> Result<T> success(T data) { // 添加类型参数 T 并指定返回类型
|
||||
return new Result<>(CODE_SUCCESS, "success", data);
|
||||
}
|
||||
public static Result authError(String msg){
|
||||
return new Result(CODE_AUTH_ERROR,"系统错误",null);
|
||||
|
||||
public static <T> Result<T> error(String msg) { // 添加类型参数 T 并指定返回类型
|
||||
return new Result<>(CODE_SYS_ERROR, msg, null);
|
||||
}
|
||||
|
||||
public static <T> Result<T> error(String code, String msg) { // 添加类型参数 T 并指定返回类型
|
||||
return new Result<>(code, msg, null);
|
||||
}
|
||||
|
||||
public static <T> Result<T> authError(String msg) { // 添加类型参数 T 并指定返回类型
|
||||
return new Result<>(CODE_AUTH_ERROR, "认证错误", null);
|
||||
}
|
||||
}
|
||||
|
@ -34,21 +34,15 @@ public class AdminController {
|
||||
List<User> userList = roleService.findAllUsersWithRoles();
|
||||
return Result.success(userList);
|
||||
}
|
||||
|
||||
@GetMapping("/selectAll")
|
||||
public Result selectAll() {
|
||||
List<User> users = userService.selectAll();
|
||||
return Result.success(users);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @author: tortoise
|
||||
* @date: 2024/8/15 16:27
|
||||
* @Description: TODO 查看所有成员的信息(姓名,学号,年级,组别,担任角色)
|
||||
* @param
|
||||
* @return: top.suyiiyii.sims.common.Result
|
||||
*/
|
||||
@GetMapping("/findAllUsers")
|
||||
public Result findAllUsers() {
|
||||
List<UserVO> userList = userService.findAllUsers();
|
||||
request.setAttribute();lUsers();
|
||||
return Result.success(userList);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package top.suyiiyii.sims.controller;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.Data;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import top.suyiiyii.sims.common.AuthAccess;
|
||||
@ -37,17 +38,29 @@ public class UserController {
|
||||
}
|
||||
|
||||
@PostMapping("/login")
|
||||
public Result login(@RequestBody User user){
|
||||
if(StrUtil.isBlank(user.getUsername())||StrUtil.isBlank(user.getPassword())){
|
||||
public Result login(LoginRequest request){
|
||||
|
||||
if(StrUtil.isBlank(request.getUsername())||StrUtil.isBlank(request.getPassword())){
|
||||
|
||||
return Result.error("用户名或密码不能为空");
|
||||
}
|
||||
user =userService.login(user);
|
||||
|
||||
User user = userService.login(request.getUsername(), request.getPassword());
|
||||
|
||||
return Result.success(user);
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class LoginRequest{
|
||||
public String username;
|
||||
public String password;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class LoginResponse{
|
||||
public String token;
|
||||
}
|
||||
|
||||
@PostMapping("/register")
|
||||
public Result register(@RequestBody User user){
|
||||
if(StrUtil.isBlank(user.getUsername())||StrUtil.isBlank(user.getPassword())){
|
||||
|
@ -19,6 +19,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.function.ToDoubleBiFunction;
|
||||
|
||||
/**
|
||||
* @Author tortoise
|
||||
@ -56,13 +57,13 @@ public class UserService {
|
||||
public List<User> selectAll() {
|
||||
return userMapper.selectAll();
|
||||
}
|
||||
|
||||
public User login(User user) {
|
||||
User dbUser = userMapper.selectByUserName(user.getUsername());
|
||||
//TODO:返回一个DTO,用户基本信息
|
||||
public User login(String username, String password) {
|
||||
User dbUser = userMapper.selectByUserName(username);
|
||||
if (dbUser == null) {
|
||||
throw new ServiceException("账号不存在");
|
||||
}
|
||||
if (!dbUser.getPassword().equals(user.getPassword())) {
|
||||
if (!dbUser.getPassword().equals(password)) {
|
||||
throw new ServiceException("密码或用户名错误");
|
||||
}
|
||||
HashSet<Permissions> permissionsSet = new HashSet<>();
|
||||
|
Loading…
x
Reference in New Issue
Block a user