forked from RyanGoodwill/backend
添加jwt支持
This commit is contained in:
parent
57b75e4813
commit
442eaf2479
@ -4,6 +4,7 @@ package org.cmh.backend.authentication.controller;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.cmh.backend.Utils.JwtUtil;
|
||||
import org.cmh.backend.authentication.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@ -45,7 +46,7 @@ class AuthenticationController {
|
||||
boolean isValidUser = userService.loginUser(loginRequest.getUsername(), loginRequest.getPassword());
|
||||
|
||||
if (isValidUser) {
|
||||
return new ResponseEntity<>(new LoginResponse("登录成功", loginRequest.getUsername()), HttpStatus.OK);
|
||||
return new ResponseEntity<>(new LoginResponse("登录成功", JwtUtil.generateToken(loginRequest.getUsername())), HttpStatus.OK);
|
||||
} else {
|
||||
return new ResponseEntity<>(new LoginResponse("用户名或密码错误", ""), HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
@ -84,5 +85,5 @@ class LoginRequest {
|
||||
@AllArgsConstructor
|
||||
class LoginResponse {
|
||||
private String message;
|
||||
private String username;
|
||||
private String jwt;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user