|
@@ -0,0 +1,55 @@
|
|
|
|
+package cn.fastfun.controller.api;
|
|
|
|
+
|
|
|
|
+import cn.fastfun.controller.param.LoginParam;
|
|
|
|
+import cn.fastfun.service.UtilService;
|
|
|
|
+import cn.fastfun.service.entity.SysUser;
|
|
|
|
+import com.bridge.dto.ApiDTO;
|
|
|
|
+import com.bridge.service.JpaService;
|
|
|
|
+import io.swagger.annotations.Api;
|
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.util.DigestUtils;
|
|
|
|
+import org.springframework.validation.BindingResult;
|
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
|
+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;
|
|
|
|
+
|
|
|
|
+@Api(tags = {"1.1 系统登录"})
|
|
|
|
+@RestController
|
|
|
|
+@RequestMapping("/api/user")
|
|
|
|
+public class UserController {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ JpaService<SysUser, String> sysUserService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ UtilService utilService;
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "账号登录")
|
|
|
|
+ @PostMapping("login")
|
|
|
|
+ public ApiDTO login(@Validated @RequestBody LoginParam param, BindingResult result) {
|
|
|
|
+ // 效验字段
|
|
|
|
+ if (result.hasErrors())
|
|
|
|
+ return ApiDTO.error(result);
|
|
|
|
+ return utilService.login(param.getUserName(), DigestUtils.md5DigestAsHex(param.getUserPass().getBytes()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "账号注销")
|
|
|
|
+ @PostMapping("logout")
|
|
|
|
+ public ApiDTO logout() {
|
|
|
|
+ try {
|
|
|
|
+ utilService.clearLoginUser(utilService.getUserId());
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ return ApiDTO.ok(null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "获取账号信息")
|
|
|
|
+ @PostMapping("info")
|
|
|
|
+ public ApiDTO getUser() {
|
|
|
|
+ return ApiDTO.ok("获取用户信息", utilService.getUser());
|
|
|
|
+ }
|
|
|
|
+}
|