|
|
@ -5,15 +5,15 @@ import com.qyft.gd.system.common.result.Result; |
|
|
|
import com.qyft.gd.system.common.result.ResultCode; |
|
|
|
import com.qyft.gd.system.common.utils.JwtUtil; |
|
|
|
import com.qyft.gd.system.model.entity.User; |
|
|
|
import com.qyft.gd.system.model.form.LoginForm; |
|
|
|
import com.qyft.gd.system.service.UserService; |
|
|
|
import io.swagger.v3.oas.annotations.Operation; |
|
|
|
import io.swagger.v3.oas.annotations.Parameter; |
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.web.bind.annotation.PostMapping; |
|
|
|
import org.springframework.web.bind.annotation.RequestBody; |
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
import org.springframework.web.bind.annotation.RequestParam; |
|
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
|
|
|
import java.util.Objects; |
|
|
@ -32,14 +32,11 @@ public class AuthController { |
|
|
|
|
|
|
|
@Operation(summary = "账号密码登录") |
|
|
|
@PostMapping("/login") |
|
|
|
public Result<String> login( |
|
|
|
@Parameter(description = "用户名", example = "admin") @RequestParam String username, |
|
|
|
@Parameter(description = "密码", example = "123456") @RequestParam String password |
|
|
|
) { |
|
|
|
public Result<String> login(@RequestBody LoginForm loginForm) { |
|
|
|
// 查找用户 |
|
|
|
User user = userService.findByUsername(username); |
|
|
|
if (user != null && !Objects.equals(user.getIsDeleted(), DeletedEnum.ENABLE.getValue()) && user.getPassword().equals(password)) { |
|
|
|
String token = JwtUtil.createJWE(user.getUsername()); |
|
|
|
User user = userService.findByUsername(loginForm.getUsername()); |
|
|
|
if (user != null && !Objects.equals(user.getIsDeleted(), DeletedEnum.ENABLE.getValue()) && user.getPassword().equals(loginForm.getPassword())) { |
|
|
|
String token = JwtUtil.createJWE(loginForm.getUsername()); |
|
|
|
return Result.success("Bearer " + token); |
|
|
|
} |
|
|
|
return Result.failed(ResultCode.USER_PASSWORD_ERROR); |
|
|
|