AuthUserController.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. package com.sumbytes.helloblog.auth.controller;
  2. import com.sumbytes.common.annotation.Explain;
  3. import com.sumbytes.common.annotation.LoginRequired;
  4. import com.sumbytes.common.base.domain.Result;
  5. import com.sumbytes.common.util.FileUtil;
  6. import com.sumbytes.helloblog.auth.domain.vo.AuthUserSocialVO;
  7. import com.sumbytes.helloblog.auth.domain.vo.AuthUserVO;
  8. import com.sumbytes.helloblog.auth.service.AuthUserService;
  9. import com.sumbytes.helloblog.auth.service.AuthUserSocialService;
  10. import com.sumbytes.helloblog.auth.service.OauthService;
  11. import com.sumbytes.system.enums.RoleEnum;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.http.MediaType;
  14. import org.springframework.web.bind.annotation.*;
  15. @RestController
  16. @RequestMapping("/auth")
  17. public class AuthUserController {
  18. @Autowired
  19. private OauthService oauthService;
  20. @Autowired
  21. private AuthUserService authUserService;
  22. @Autowired
  23. private AuthUserSocialService authUserSocialService;
  24. @Explain("获取用户信息")
  25. @LoginRequired(role = RoleEnum.USER)
  26. @GetMapping("/user/v1/get")
  27. public Result getUserInfo(AuthUserVO authUserVO) {
  28. return authUserService.getUserInfo(authUserVO);
  29. }
  30. @Explain("删除用户")
  31. @DeleteMapping("/user/v1/{id}")
  32. @LoginRequired(role = RoleEnum.ADMIN)
  33. public Result deleteUser(@PathVariable Long id) {
  34. return authUserService.deleteUsers(id);
  35. }
  36. @Explain("更新用户状态")
  37. @LoginRequired(role = RoleEnum.ADMIN)
  38. @PutMapping("/status/v1/update")
  39. public Result saveAuthUserStatus(@RequestBody AuthUserVO authUserVO) {
  40. return authUserService.saveAuthUserStatus(authUserVO);
  41. }
  42. @Explain("获取用户列表")
  43. @LoginRequired
  44. @GetMapping("/user/v1/list")
  45. public Result getUserList(AuthUserVO authUserVO) {
  46. return authUserService.getUserList(authUserVO);
  47. }
  48. @Explain("获取github登录地址")
  49. @GetMapping("/github/v1/get")
  50. public Result oauthLoginByGithub() {
  51. return oauthService.oauthLoginByGithub();
  52. }
  53. @Explain("github登录回调接口")
  54. @RequestMapping("/github/v1/callback")
  55. @ResponseBody
  56. public String callback(String code, String state) { //gitHub登陆回调接口
  57. return oauthService.callback(code, state);
  58. }
  59. @Explain("保存用户信息")
  60. @PostMapping("/user/v1/login")
  61. public Result saveUserByGithub(@RequestBody AuthUserVO authUserVO) {
  62. return oauthService.saveUserByGithub(authUserVO);
  63. }
  64. @Explain("更新用户信息")
  65. @LoginRequired
  66. @PutMapping("/user/v1/update")
  67. public Result updateUser(@RequestBody AuthUserVO authUserVO) {
  68. return authUserService.updateUser(authUserVO);
  69. }
  70. @Explain("退出登录")
  71. @PostMapping("/auth/v1/logout")
  72. public Result logout() {
  73. return authUserService.logout();
  74. }
  75. @Explain("管理员头像地址")
  76. @RequestMapping(value = "/auth/v1/avatar", produces = MediaType.IMAGE_JPEG_VALUE)
  77. public byte[] getAvatar() {
  78. return FileUtil.tranToBytes(authUserService.getAvatar());
  79. }
  80. @Explain("获取管理员信息")
  81. @GetMapping("/master/v1/get")
  82. public Result getMasterUserInfo() {
  83. return authUserService.getMasterUserInfo();
  84. }
  85. @Explain("管理员登录")
  86. @PostMapping("/admin/v1/login")
  87. public Result adminLogin(@RequestBody AuthUserVO authUserVO) {
  88. return oauthService.login(authUserVO);
  89. }
  90. @Explain("管理员密码修改")
  91. @LoginRequired
  92. @PutMapping("/password/v1/update")
  93. public Result updatePassword(@RequestBody AuthUserVO authUserVO) {
  94. return oauthService.updatePassword(authUserVO);
  95. }
  96. @Explain("更新管理员信息")
  97. @LoginRequired
  98. @PutMapping("/admin/v1/update")
  99. public Result updateAdmin(@RequestBody AuthUserVO authUserVO) {
  100. return authUserService.updateAdmin(authUserVO);
  101. }
  102. @Explain("管理员注册,不存在管理员可以注册成功")
  103. @PostMapping("/admin/v1/register")
  104. public Result registerAdminByGithub(@RequestBody AuthUserVO authUserVO) {
  105. return oauthService.registerAdmin(authUserVO);
  106. }
  107. @GetMapping("/social/v1/{id}")
  108. public Result getSocial(@PathVariable("id") Long id) {
  109. return authUserSocialService.getSocial(id);
  110. }
  111. @GetMapping("/social/v1/socials")
  112. public Result getSocialEnableList(AuthUserSocialVO authUserSocialVO) {
  113. authUserSocialVO.setIsEnabled(1);
  114. return authUserSocialService.getSocialList(authUserSocialVO);
  115. }
  116. @GetMapping("/social/v1/info")
  117. public Result getSocialInfo() {
  118. return authUserSocialService.getSocialInfo();
  119. }
  120. }