From 924e0fa6eee9b3fa259208f66a275fe86405c778 Mon Sep 17 00:00:00 2001 From: limbo <43649186+HUAHUAI23@users.noreply.github.com> Date: Tue, 22 Aug 2023 15:28:17 +0800 Subject: [PATCH] feat(server): add id verify (#1449) * 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 --- server/package-lock.json | 13 +++++++++++++ server/package.json | 1 + server/src/app.interceptor.ts | 4 +++- server/src/interceptor/dto/http-interceptor.dto.ts | 1 + server/src/interceptor/http-interceptor.service.ts | 10 ++++++++++ server/src/setting/entities/setting.ts | 1 + server/src/user/entities/user-profile.ts | 13 +++++++++++++ 7 files changed, 42 insertions(+), 1 deletion(-) diff --git a/server/package-lock.json b/server/package-lock.json index 6d088d4fda..3807258ac2 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -69,6 +69,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", @@ -5861,6 +5862,12 @@ "@types/superagent": "*" } }, + "node_modules/@types/uuid": { + "version": "9.0.2", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-9.0.2.tgz", + "integrity": "sha512-kNnC1GFBLuhImSnV7w4njQkUiJi0ZXUycu1rUaouPqiKlXkh77JKgdRnTAp1x5eBwcIwbtI+3otwzuIDEuDoxQ==", + "dev": true + }, "node_modules/@types/validator": { "version": "13.7.12", "resolved": "https://registry.npmjs.org/@types/validator/-/validator-13.7.12.tgz", @@ -20228,6 +20235,12 @@ "@types/superagent": "*" } }, + "@types/uuid": { + "version": "9.0.2", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-9.0.2.tgz", + "integrity": "sha512-kNnC1GFBLuhImSnV7w4njQkUiJi0ZXUycu1rUaouPqiKlXkh77JKgdRnTAp1x5eBwcIwbtI+3otwzuIDEuDoxQ==", + "dev": true + }, "@types/validator": { "version": "13.7.12", "resolved": "https://registry.npmjs.org/@types/validator/-/validator-13.7.12.tgz", diff --git a/server/package.json b/server/package.json index 5a3c036ed4..1627b772cc 100644 --- a/server/package.json +++ b/server/package.json @@ -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", diff --git a/server/src/app.interceptor.ts b/server/src/app.interceptor.ts index 4786ffc9f3..aada501da3 100644 --- a/server/src/app.interceptor.ts +++ b/server/src/app.interceptor.ts @@ -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", + ) } } diff --git a/server/src/interceptor/dto/http-interceptor.dto.ts b/server/src/interceptor/dto/http-interceptor.dto.ts index 9aa5f01a6a..886cc43cb5 100644 --- a/server/src/interceptor/dto/http-interceptor.dto.ts +++ b/server/src/interceptor/dto/http-interceptor.dto.ts @@ -14,4 +14,5 @@ export class HttpInterceptorResponseDto { action: HttpInterceptorAction rewrite?: HttpInterceptorRewrite redirect?: HttpInterceptorRedirect + denyMessage?: string } diff --git a/server/src/interceptor/http-interceptor.service.ts b/server/src/interceptor/http-interceptor.service.ts index fe479b1c0f..e3a9ca961f 100644 --- a/server/src/interceptor/http-interceptor.service.ts +++ b/server/src/interceptor/http-interceptor.service.ts @@ -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') { diff --git a/server/src/setting/entities/setting.ts b/server/src/setting/entities/setting.ts index 757c7c64cf..70de8159d2 100644 --- a/server/src/setting/entities/setting.ts +++ b/server/src/setting/entities/setting.ts @@ -11,6 +11,7 @@ export enum SettingKey { SiteUrl = 'site_url', SiteFooter = 'site_footer', InvitationProfit = 'invitation_profit', + IdVerify = 'id_verify', AIPilotApiUrl = 'ai_pilot_api_url', } diff --git a/server/src/user/entities/user-profile.ts b/server/src/user/entities/user-profile.ts index 6887a4cb32..d7cdf390d7 100644 --- a/server/src/user/entities/user-profile.ts +++ b/server/src/user/entities/user-profile.ts @@ -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 }) @@ -17,6 +24,12 @@ export class UserProfile { @ApiPropertyOptional() name?: string + @ApiProperty({ type: IdVerified }) + idVerified?: IdVerified + + @ApiProperty() + idCard?: string + @ApiProperty() createdAt: Date