Skip to content

Commit 3f92f2e

Browse files
committed
增加userAuth===3为超级管理员
1 parent 349e12c commit 3f92f2e

File tree

7 files changed

+21
-13
lines changed

7 files changed

+21
-13
lines changed

src/article/article.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export class ArticleService {
163163
}
164164

165165
// 检查权限:只有文章作者和管理员可以修改
166-
const isAdmin = user.userAuth === 2;
166+
const isAdmin = user.userAuth === 2 || user.userAuth === 3;
167167
const isAuthor = article.userId === userId;
168168

169169
if (!isAdmin && !isAuthor) {
@@ -205,7 +205,7 @@ export class ArticleService {
205205
}
206206

207207
// 检查权限:只有文章作者和管理员可以删除
208-
const isAdmin = user.userAuth === 2;
208+
const isAdmin = user.userAuth === 2 || user.userAuth === 3;
209209
const isAuthor = article.userId === userId;
210210

211211
if (!isAdmin && !isAuthor) {

src/auth/auth.service.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { UsercenterService } from './../usercenter/usercenter.service';
2-
import { Injectable, UnauthorizedException, NotFoundException, BadRequestException } from '@nestjs/common';
2+
import {
3+
Injectable,
4+
UnauthorizedException,
5+
NotFoundException,
6+
BadRequestException,
7+
} from '@nestjs/common';
38
import { JwtService } from '@nestjs/jwt';
49

510
@Injectable()
@@ -46,7 +51,7 @@ export class AuthService {
4651
if (!refresh_token || typeof refresh_token !== 'string') {
4752
throw new BadRequestException('无效的refresh_token格式');
4853
}
49-
54+
5055
// 验证token
5156
const decoded = await this.jwtService.verifyAsync(refresh_token);
5257

@@ -68,7 +73,10 @@ export class AuthService {
6873
return { refresh_token: newRefresh_token, access_token };
6974
} catch (error) {
7075
// 区分不同类型的错误
71-
if (error instanceof BadRequestException || error instanceof NotFoundException) {
76+
if (
77+
error instanceof BadRequestException ||
78+
error instanceof NotFoundException
79+
) {
7280
throw error; // 重新抛出原始错误
7381
}
7482
// JWT相关错误统一处理为401未授权

src/auth/guards/admin.guard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class AdminGuard implements CanActivate {
2727
const userInfo = await this.usercenterService.findOne(user.sub);
2828

2929
// 检查用户是否具有管理员权限 (userAuth === 2)
30-
if (userInfo.userAuth !== 2) {
30+
if (userInfo.userAuth !== 2 || userInfo.userAuth !== 3 ) {
3131
throw new ForbiddenException('需要管理员权限');
3232
}
3333

src/recruitment/recruitment.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ export class RecruitmentService {
170170
}
171171

172172
// 检查权限:只有管理员可以修改
173-
const isAdmin = user.userAuth === 2;
173+
const isAdmin = user.userAuth === 2 || user.userAuth === 3;
174174

175175
if (!isAdmin) {
176176
throw new ForbiddenException(
@@ -214,7 +214,7 @@ export class RecruitmentService {
214214
}
215215

216216
// 检查权限:只有管理员可以删除
217-
const isAdmin = user.userAuth === 2;
217+
const isAdmin = user.userAuth === 2 || user.userAuth === 3;
218218

219219
if (!isAdmin) {
220220
throw new ForbiddenException(

src/resume-template/resume-template.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class ResumeTemplateService {
3333
if (!user) {
3434
throw new NotFoundException(`用户ID ${id} 不存在`);
3535
}
36-
if (user.userAuth !== 2) {
36+
if (user.userAuth !== 2 || user.userAuth !== 3) {
3737
throw new NotFoundException(`用户无权限创建简历模板`);
3838
}
3939
const ResumeTemplate = this.resumeTemplateRepository.create({

src/usercenter/entities/usercenter.entity.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class UserEntity {
6767
type: 'int',
6868
name: 'user_auth',
6969
nullable: false,
70-
default: 1, // 默认值为 1(普通用户),2(管理员)
70+
default: 1, // 默认值为 1(普通用户),2(管理员),3(超级管理员)
7171
})
7272
userAuth: number; // 用户权限
7373

@@ -127,7 +127,7 @@ export class UserEntity {
127127
@Column({
128128
type: 'varchar',
129129
name: 'avatar',
130-
default: ''
130+
default: '',
131131
})
132132
avatar: string; // 头像
133133

src/usercenter/usercenter.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
Injectable,
44
InternalServerErrorException,
55
NotFoundException,
6-
ConflictException
6+
ConflictException,
77
} from '@nestjs/common';
88
import { CreateUsercenterDto } from './dto/create-usercenter.dto';
99
import { UpdateUsercenterDto } from './dto/update-usercenter.dto';
@@ -17,7 +17,7 @@ export class UsercenterService {
1717
constructor(
1818
@InjectRepository(UserEntity)
1919
private readonly userRepository: Repository<UserEntity>,
20-
) { }
20+
) {}
2121
async createUser(createUsercenterDto: CreateUsercenterDto) {
2222
// 验证密码是否匹配
2323
if (

0 commit comments

Comments
 (0)