mirror of
https://github.com/FatttSnake/Pinnacle-OA.git
synced 2026-04-05 15:01:23 +08:00
Fixed token to large error
This commit is contained in:
@@ -33,6 +33,12 @@ public class UserController {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@GetMapping("/info")
|
||||
@Operation(summary = "获取当前用户信息")
|
||||
public ResponseResult<User> getInfo() {
|
||||
return ResponseResult.databaseSelectSuccess(userService.getInfo());
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@PreAuthorize("hasAnyAuthority('system:user:all', 'system:user:add', 'system:user:modify')")
|
||||
@Operation(summary = "获取所有用户(权限管理相关)")
|
||||
|
||||
@@ -15,6 +15,8 @@ import java.util.List;
|
||||
*/
|
||||
public interface IUserService extends IService<User> {
|
||||
|
||||
User getInfo();
|
||||
|
||||
List<User> getAllUser();
|
||||
|
||||
User getUser(long id);
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.cfive.pinnacle.mapper.permission.MenuMapper;
|
||||
import com.cfive.pinnacle.mapper.permission.OperationMapper;
|
||||
import com.cfive.pinnacle.service.IUserService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.cfive.pinnacle.utils.WebUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -72,6 +73,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
||||
this.passwordEncoder = passwordEncoder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getInfo() {
|
||||
return WebUtil.getLoginUser().getUser();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<User> getAllUser() {
|
||||
List<User> users = userMapper.getAll();
|
||||
|
||||
@@ -5,8 +5,6 @@ import com.cfive.pinnacle.entity.permission.LoginUser;
|
||||
import com.cfive.pinnacle.service.permission.ILoginService;
|
||||
import com.cfive.pinnacle.utils.JwtUtil;
|
||||
import com.cfive.pinnacle.utils.RedisCache;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
@@ -43,13 +41,7 @@ public class LoginServiceImpl implements ILoginService {
|
||||
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
|
||||
loginUser.getUser().setPasswd("");
|
||||
String userId = loginUser.getUser().getId().toString();
|
||||
String jwt;
|
||||
try {
|
||||
jwt = JwtUtil.createJWT(new ObjectMapper().writeValueAsString(loginUser.getUser()));
|
||||
} catch (JsonProcessingException e) {
|
||||
jwt = JwtUtil.createJWT(userId);
|
||||
}
|
||||
|
||||
String jwt = JwtUtil.createJWT(userId);
|
||||
|
||||
HashMap<String, String> hashMap = new HashMap<>();
|
||||
hashMap.put("token", jwt);
|
||||
|
||||
@@ -223,13 +223,13 @@ export default {
|
||||
setLocalStorage('menuCollapsed', this.isCollapsed.toString())
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.username = getUsername()
|
||||
async mounted() {
|
||||
this.username = await getUsername()
|
||||
const allRoutes = _.cloneDeep(
|
||||
_.filter(_.get(this.$router, 'options.routes[0].children'), 'meta.title')
|
||||
)
|
||||
|
||||
const user = getUser()
|
||||
const user = await getUser()
|
||||
const menus = user.menus
|
||||
this.routes = allRoutes.filter((level1) => {
|
||||
if (level1.meta.requiresAuth) {
|
||||
|
||||
@@ -50,7 +50,7 @@ const router = createRouter({
|
||||
]
|
||||
})
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
if (to.matched.length === 0) {
|
||||
from.path !== '' ? next({ path: from.path }) : next('/')
|
||||
} else {
|
||||
@@ -64,7 +64,7 @@ router.beforeEach((to, from, next) => {
|
||||
next('/')
|
||||
} else {
|
||||
if (to.meta.requiresAuth === true) {
|
||||
const user = getUser()
|
||||
const user = await getUser()
|
||||
const menus = user.menus
|
||||
for (const menu of menus) {
|
||||
if (menu.url === '/') continue
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import type { Captcha } from './common'
|
||||
import { clearLocalStorage, getCaptcha, getLocalStorage, getToken } from './common'
|
||||
import { TOKEN_NAME } from '@/constants/Common.constants'
|
||||
import { clearLocalStorage, getCaptcha, getLocalStorage, setLocalStorage } from './common'
|
||||
import { DATABASE_SELECT_OK, TOKEN_NAME } from '@/constants/Common.constants'
|
||||
import request from '@/services'
|
||||
import jwtDecode, { type JwtPayload } from 'jwt-decode'
|
||||
import _ from 'lodash'
|
||||
|
||||
let captcha: Captcha
|
||||
@@ -21,20 +20,27 @@ function getLoginStatus(): boolean {
|
||||
return getLocalStorage(TOKEN_NAME) != null
|
||||
}
|
||||
|
||||
function getUser(): any {
|
||||
const token = getToken()
|
||||
|
||||
if (token === null) {
|
||||
logout()
|
||||
return ''
|
||||
async function getUser(): Promise<any> {
|
||||
if (getLocalStorage('userInfo') !== null) {
|
||||
return JSON.parse(getLocalStorage('userInfo') as string)
|
||||
}
|
||||
|
||||
const jwtPayload: JwtPayload = jwtDecode(token)
|
||||
return JSON.parse(jwtPayload.sub ?? '')
|
||||
return await requestUser()
|
||||
}
|
||||
|
||||
function getUsername(): string {
|
||||
const user = getUser()
|
||||
async function requestUser(): Promise<any> {
|
||||
let user
|
||||
await request.get('/user/info').then((res) => {
|
||||
const response = res.data
|
||||
if (response.code === DATABASE_SELECT_OK) {
|
||||
user = response.data
|
||||
setLocalStorage('userInfo', JSON.stringify(user))
|
||||
}
|
||||
})
|
||||
return user
|
||||
}
|
||||
|
||||
async function getUsername(): Promise<string> {
|
||||
const user = await getUser()
|
||||
|
||||
return user.staff != null
|
||||
? `${_.toString(user.staff.lastName)}${_.toString(user.staff.firstName)}`
|
||||
|
||||
Reference in New Issue
Block a user