Skip to content

Commit

Permalink
feat(server): add id verify (#1449)
Browse files Browse the repository at this point in the history
* chore(server): add interceptor logic

* feat(server): Add a global http interceptor

* chore

* refactor: add post http interceptor

* chore

* add handler and controller to http-interceptor

* add realname auth

* add id-card to userprofile

* chore

* chore
  • Loading branch information
HUAHUAI23 authored Aug 22, 2023
1 parent 4e3edb3 commit 924e0fa
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 1 deletion.
13 changes: 13 additions & 0 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"@types/passport-jwt": "^3.0.7",
"@types/passport-local": "^1.0.34",
"@types/supertest": "^2.0.11",
"@types/uuid": "^9.0.2",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"eslint": "^8.0.1",
Expand Down
4 changes: 3 additions & 1 deletion server/src/app.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ export class AppInterceptor implements NestInterceptor {
response.redirect(interceptorData.redirect.data)
return of(null)
}
throw new ForbiddenException("You don't have permission to access")
throw new ForbiddenException(
interceptorData.denyMessage || "You don't have permission to access",
)
}
}
1 change: 1 addition & 0 deletions server/src/interceptor/dto/http-interceptor.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ export class HttpInterceptorResponseDto {
action: HttpInterceptorAction
rewrite?: HttpInterceptorRewrite
redirect?: HttpInterceptorRedirect
denyMessage?: string
}
10 changes: 10 additions & 0 deletions server/src/interceptor/http-interceptor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ export class HttpInterceptorService {
data,
{ timeout: this.HTTP_INTERCEPTOR_TIMEOUT },
)
if (!response.data) {
return {
action: HttpInterceptorAction.DENY,
}
}
if (!response.data.action) {
return {
action: HttpInterceptorAction.DENY,
}
}
return response.data
} catch (error) {
if (error.code === 'ECONNABORTED') {
Expand Down
1 change: 1 addition & 0 deletions server/src/setting/entities/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export enum SettingKey {
SiteUrl = 'site_url',
SiteFooter = 'site_footer',
InvitationProfit = 'invitation_profit',
IdVerify = 'id_verify',

AIPilotApiUrl = 'ai_pilot_api_url',
}
Expand Down
13 changes: 13 additions & 0 deletions server/src/user/entities/user-profile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'
import { ObjectId } from 'mongodb'
class IdVerified {
@ApiProperty({ type: Boolean })
isVerified: boolean

@ApiProperty({ type: Number })
idVerifyFailedTimes: number
}

export class UserProfile {
@ApiProperty({ type: String })
Expand All @@ -17,6 +24,12 @@ export class UserProfile {
@ApiPropertyOptional()
name?: string

@ApiProperty({ type: IdVerified })
idVerified?: IdVerified

@ApiProperty()
idCard?: string

@ApiProperty()
createdAt: Date

Expand Down

0 comments on commit 924e0fa

Please sign in to comment.