123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- package com.sumbytes.helloblog.auth.controller;
- import com.sumbytes.common.annotation.Explain;
- import com.sumbytes.common.annotation.LoginRequired;
- import com.sumbytes.common.base.domain.Result;
- import com.sumbytes.common.util.FileUtil;
- import com.sumbytes.helloblog.auth.domain.vo.AuthUserSocialVO;
- import com.sumbytes.helloblog.auth.domain.vo.AuthUserVO;
- import com.sumbytes.helloblog.auth.service.AuthUserService;
- import com.sumbytes.helloblog.auth.service.AuthUserSocialService;
- import com.sumbytes.helloblog.auth.service.OauthService;
- import com.sumbytes.system.enums.RoleEnum;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.http.MediaType;
- import org.springframework.web.bind.annotation.*;
- @RestController
- @RequestMapping("/auth")
- public class AuthUserController {
- @Autowired
- private OauthService oauthService;
- @Autowired
- private AuthUserService authUserService;
- @Autowired
- private AuthUserSocialService authUserSocialService;
- @Explain("获取用户信息")
- @LoginRequired(role = RoleEnum.USER)
- @GetMapping("/user/v1/get")
- public Result getUserInfo(AuthUserVO authUserVO) {
- return authUserService.getUserInfo(authUserVO);
- }
- @Explain("删除用户")
- @DeleteMapping("/user/v1/{id}")
- @LoginRequired(role = RoleEnum.ADMIN)
- public Result deleteUser(@PathVariable Long id) {
- return authUserService.deleteUsers(id);
- }
- @Explain("更新用户状态")
- @LoginRequired(role = RoleEnum.ADMIN)
- @PutMapping("/status/v1/update")
- public Result saveAuthUserStatus(@RequestBody AuthUserVO authUserVO) {
- return authUserService.saveAuthUserStatus(authUserVO);
- }
- @Explain("获取用户列表")
- @LoginRequired
- @GetMapping("/user/v1/list")
- public Result getUserList(AuthUserVO authUserVO) {
- return authUserService.getUserList(authUserVO);
- }
- @Explain("获取github登录地址")
- @GetMapping("/github/v1/get")
- public Result oauthLoginByGithub() {
- return oauthService.oauthLoginByGithub();
- }
- @Explain("github登录回调接口")
- @RequestMapping("/github/v1/callback")
- @ResponseBody
- public String callback(String code, String state) { //gitHub登陆回调接口
- return oauthService.callback(code, state);
- }
- @Explain("保存用户信息")
- @PostMapping("/user/v1/login")
- public Result saveUserByGithub(@RequestBody AuthUserVO authUserVO) {
- return oauthService.saveUserByGithub(authUserVO);
- }
- @Explain("更新用户信息")
- @LoginRequired
- @PutMapping("/user/v1/update")
- public Result updateUser(@RequestBody AuthUserVO authUserVO) {
- return authUserService.updateUser(authUserVO);
- }
- @Explain("退出登录")
- @PostMapping("/auth/v1/logout")
- public Result logout() {
- return authUserService.logout();
- }
- @Explain("管理员头像地址")
- @RequestMapping(value = "/auth/v1/avatar", produces = MediaType.IMAGE_JPEG_VALUE)
- public byte[] getAvatar() {
- return FileUtil.tranToBytes(authUserService.getAvatar());
- }
- @Explain("获取管理员信息")
- @GetMapping("/master/v1/get")
- public Result getMasterUserInfo() {
- return authUserService.getMasterUserInfo();
- }
- @Explain("管理员登录")
- @PostMapping("/admin/v1/login")
- public Result adminLogin(@RequestBody AuthUserVO authUserVO) {
- return oauthService.login(authUserVO);
- }
- @Explain("管理员密码修改")
- @LoginRequired
- @PutMapping("/password/v1/update")
- public Result updatePassword(@RequestBody AuthUserVO authUserVO) {
- return oauthService.updatePassword(authUserVO);
- }
- @Explain("更新管理员信息")
- @LoginRequired
- @PutMapping("/admin/v1/update")
- public Result updateAdmin(@RequestBody AuthUserVO authUserVO) {
- return authUserService.updateAdmin(authUserVO);
- }
- @Explain("管理员注册,不存在管理员可以注册成功")
- @PostMapping("/admin/v1/register")
- public Result registerAdminByGithub(@RequestBody AuthUserVO authUserVO) {
- return oauthService.registerAdmin(authUserVO);
- }
- @GetMapping("/social/v1/{id}")
- public Result getSocial(@PathVariable("id") Long id) {
- return authUserSocialService.getSocial(id);
- }
- @GetMapping("/social/v1/socials")
- public Result getSocialEnableList(AuthUserSocialVO authUserSocialVO) {
- authUserSocialVO.setIsEnabled(1);
- return authUserSocialService.getSocialList(authUserSocialVO);
- }
- @GetMapping("/social/v1/info")
- public Result getSocialInfo() {
- return authUserSocialService.getSocialInfo();
- }
- }
|