From eef2cf00bea4bd21e05006fef0c8c8c01a2bc67f Mon Sep 17 00:00:00 2001 From: moec42frf <3378620026@qq.com> Date: Sun, 30 Apr 2023 09:23:54 +0800 Subject: [PATCH] ADD file via upload --- .../org/sang/controller/UserController.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 blogserver/src/main/java/org/sang/controller/UserController.java diff --git a/blogserver/src/main/java/org/sang/controller/UserController.java b/blogserver/src/main/java/org/sang/controller/UserController.java new file mode 100644 index 0000000..d55c61d --- /dev/null +++ b/blogserver/src/main/java/org/sang/controller/UserController.java @@ -0,0 +1,53 @@ +package org.sang.controller; + +import org.sang.bean.RespBean; +import org.sang.service.UserService; +import org.sang.utils.Util; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +public class UserController { + + @Autowired + UserService userService; + + @RequestMapping("/currentUserName") + public String currentUserName() { + return Util.getCurrentUser().getNickname(); + } + + @RequestMapping("/currentUserId") + public Long currentUserId() { + return Util.getCurrentUser().getId(); + } + + @RequestMapping("/currentUserEmail") + public String currentUserEmail() { + return Util.getCurrentUser().getEmail(); + } + + @RequestMapping("/isAdmin") + public Boolean isAdmin() { + List authorities = Util.getCurrentUser().getAuthorities(); + for (GrantedAuthority authority : authorities) { + if (authority.getAuthority().contains("超级管理员")) { + return true; + } + } + return false; + } + + @RequestMapping(value = "/updateUserEmail",method = RequestMethod.PUT) + public RespBean updateUserEmail(String email) { + if (userService.updateUserEmail(email) == 1) { + return new RespBean("success", "开启成功!"); + } + return new RespBean("error", "开启失败!"); + } +}