CatchTheLettersBackend/src/main/java/com/example/catchTheLetters/controller/AuthController.java

54 lines
1.6 KiB
Java
Raw Normal View History

package com.example.catchTheLetters.controller;
import com.example.catchTheLetters.entity.LoginDto;
2024-04-09 13:49:20 +00:00
import com.example.catchTheLetters.entity.RegisterDto;
import com.example.catchTheLetters.entity.User;
import com.example.catchTheLetters.service.AuthService;
import com.example.catchTheLetters.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
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.RestController;
/**
* 认证控制器
* @author spyn
*/
@RestController
@Slf4j
@Api(tags = "认证API")
@RequestMapping("/auth")
public class AuthController {
@Resource
private AuthService authService;
@ApiOperation(value = "用户登录")
@PostMapping("/login")
public R<String> login(@RequestBody LoginDto loginDto) {
return R.ok(authService.login(loginDto));
}
@ApiOperation(value = "用户注销")
@PostMapping("/logout")
public R logout(String token) {
return authService.logout(token) ? R.ok() : R.fail();
}
@ApiOperation(value = "验证token")
@PostMapping("/verify")
public R<User> verify(String token) {
return R.ok(authService.verify(token));
}
2024-04-09 13:49:20 +00:00
@ApiOperation(value = "用户注册")
@PostMapping("/register")
public R<String> register(@RequestBody RegisterDto registerDto) {
return R.ok(authService.register(registerDto));
}
}