|
|
@ -1,6 +1,7 @@ |
|
|
|
package com.iflytop.colortitration.app.controller; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.iflytop.colortitration.app.core.state.DeviceState; |
|
|
|
import com.iflytop.colortitration.app.model.dto.LoginDTO; |
|
|
|
import com.iflytop.colortitration.common.enums.EnableStatus; |
|
|
|
import com.iflytop.colortitration.common.model.entity.User; |
|
|
@ -25,15 +26,15 @@ import java.util.Objects; |
|
|
|
@RequiredArgsConstructor |
|
|
|
@Slf4j |
|
|
|
public class AuthController { |
|
|
|
|
|
|
|
private final UserService userService; |
|
|
|
private final DeviceState deviceState; |
|
|
|
|
|
|
|
@Operation(summary = "账号密码登录") |
|
|
|
@PostMapping("/login") |
|
|
|
public Result<User> login(@Valid @RequestBody LoginDTO loginDTO) { |
|
|
|
User user = userService.getOne(new LambdaQueryWrapper<>(User.class).eq(User::getUsername, loginDTO.getUsername())); |
|
|
|
if (user != null && !Objects.equals(user.getDeleted(), EnableStatus.ENABLE) && user.getPassword().equals(loginDTO.getPassword())) { |
|
|
|
userService.setCurrentUser(user); |
|
|
|
deviceState.setCurrentUser(user); |
|
|
|
user.setPassword(null); |
|
|
|
return Result.success(user); |
|
|
|
} |
|
|
@ -43,13 +44,13 @@ public class AuthController { |
|
|
|
@Operation(summary = "用户登出") |
|
|
|
@PostMapping("/logout") |
|
|
|
public Result<String> logout() { |
|
|
|
userService.setCurrentUser(null); |
|
|
|
deviceState.setCurrentUser(null); |
|
|
|
return Result.success(); |
|
|
|
} |
|
|
|
|
|
|
|
@Operation(summary = "获取当前登录用户") |
|
|
|
@GetMapping("/current") |
|
|
|
public Result<User> current() { |
|
|
|
return Result.success(userService.getCurrentUser()); |
|
|
|
return Result.success(deviceState.getCurrentUser()); |
|
|
|
} |
|
|
|
} |