43 lines
1.6 KiB
Java
43 lines
1.6 KiB
Java
package com.guo.learningprogresstracker.controller;
|
|
|
|
import com.guo.learningprogresstracker.entity.CommonResult;
|
|
import com.guo.learningprogresstracker.dto.request.LoginBody;
|
|
import com.guo.learningprogresstracker.exception.AppException;
|
|
import com.guo.learningprogresstracker.service.LoginService;
|
|
import com.guo.learningprogresstracker.service.UserService;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
/**
|
|
* @author guo
|
|
*/
|
|
@CrossOrigin
|
|
@RestController
|
|
@RequiredArgsConstructor
|
|
public class LoginController {
|
|
|
|
private final LoginService loginService;
|
|
private final UserService userServiceImpl;
|
|
|
|
@Operation(summary = "登录API")
|
|
@PostMapping("/login")
|
|
public CommonResult<String> login(@RequestBody LoginBody loginBody) throws AppException {
|
|
String userId = userServiceImpl.authenticate(loginBody.getUsername(), loginBody.getPassword());
|
|
String token = loginService.login(userId);
|
|
//todo 参数传递未加密
|
|
return CommonResult.success("登录成功!", token);
|
|
}
|
|
|
|
@Operation(summary = "退出登录API-功能未完成")
|
|
@PostMapping("/loingOut")
|
|
public CommonResult<Void> loingOut(@RequestBody LoginBody loginBody) throws AppException {
|
|
//todo loginOut 退出登录API
|
|
// loginService.loginOut();
|
|
return CommonResult.success("已登出");
|
|
}
|
|
} |