|
@@ -2,50 +2,50 @@ package com.example.onlinejudge.controller;
|
|
|
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
import cn.dev33.satoken.util.SaResult;
|
|
import cn.dev33.satoken.util.SaResult;
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
|
+import com.alibaba.druid.util.StringUtils;
|
|
|
|
+import com.example.onlinejudge.model.dto.user.UserLoginRequest;
|
|
import com.example.onlinejudge.model.entity.result.Result;
|
|
import com.example.onlinejudge.model.entity.result.Result;
|
|
|
|
+import com.example.onlinejudge.model.entity.result.ResultCode;
|
|
import com.example.onlinejudge.service.UserService;
|
|
import com.example.onlinejudge.service.UserService;
|
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
-/**
|
|
|
|
- * 用户Controller层
|
|
|
|
- */
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+
|
|
|
|
+
|
|
@Controller
|
|
@Controller
|
|
@RequestMapping("/api/user")
|
|
@RequestMapping("/api/user")
|
|
public class UserController {
|
|
public class UserController {
|
|
- @Autowired
|
|
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
private UserService userService;
|
|
private UserService userService;
|
|
|
|
|
|
- /**
|
|
|
|
- * 登录
|
|
|
|
- *
|
|
|
|
- * @param username 用户名
|
|
|
|
- * @param password 用户密码
|
|
|
|
- * @return 用户bean
|
|
|
|
- */
|
|
|
|
- @PostMapping("/login/{username}/{password}")
|
|
|
|
|
|
+ @ApiOperation(value = "用户登录")
|
|
|
|
+ @PostMapping("/login")
|
|
@ResponseBody
|
|
@ResponseBody
|
|
- public Result login(@PathVariable("username") String username,
|
|
|
|
- @PathVariable("password") String password) {
|
|
|
|
|
|
+ public Result login(@RequestBody UserLoginRequest userLoginRequest) {
|
|
|
|
+ if(userLoginRequest == null) {
|
|
|
|
+ return Result.error(ResultCode.PARAM_IS_INVALID.getCode(),ResultCode.PARAM_IS_INVALID.getMessage());
|
|
|
|
+ }
|
|
|
|
+ String username = userLoginRequest.getUserName();
|
|
|
|
+ String password = userLoginRequest.getPassword();
|
|
|
|
+ if(StrUtil.isBlank(username) || StrUtil.isBlank(password)) {
|
|
|
|
+ return Result.error(ResultCode.PARAM_IS_BLANK.getCode(),ResultCode.PARAM_IS_BLANK.getMessage());
|
|
|
|
+ }
|
|
return userService.login(username, password);
|
|
return userService.login(username, password);
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * 测试是否登录
|
|
|
|
- *
|
|
|
|
- * @return 字符串
|
|
|
|
- */
|
|
|
|
|
|
+ @ApiOperation(value = "判断用户是否登录")
|
|
@GetMapping("/isLogin")
|
|
@GetMapping("/isLogin")
|
|
@ResponseBody
|
|
@ResponseBody
|
|
public String isLogin() {
|
|
public String isLogin() {
|
|
return "当前会话登录了";
|
|
return "当前会话登录了";
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * 测试注销
|
|
|
|
- * @return LinkedHashMap
|
|
|
|
- */
|
|
|
|
|
|
+ @ApiOperation(value = "用户登出")
|
|
@GetMapping("/logout")
|
|
@GetMapping("/logout")
|
|
@ResponseBody
|
|
@ResponseBody
|
|
public Result logout() {
|
|
public Result logout() {
|