mirror of
https://github.com/vastxie/99AI.git
synced 2025-11-11 19:23:42 +08:00
v4.1.0
This commit is contained in:
27
AIWebQuickDeploy/dist/modules/verification/dto/verifyCode.dto.js
vendored
Normal file
27
AIWebQuickDeploy/dist/modules/verification/dto/verifyCode.dto.js
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.VerifyCodeDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class VerifyCodeDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '1', description: '验证码下发id' }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '缺少必要参数!' }),
|
||||
__metadata("design:type", Number)
|
||||
], VerifyCodeDto.prototype, "id", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '15366754', description: '验证码' }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '验证码不能为空!' }),
|
||||
__metadata("design:type", Number)
|
||||
], VerifyCodeDto.prototype, "code", void 0);
|
||||
exports.VerifyCodeDto = VerifyCodeDto;
|
||||
23
AIWebQuickDeploy/dist/modules/verification/verification.module.js
vendored
Normal file
23
AIWebQuickDeploy/dist/modules/verification/verification.module.js
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.VerificationModule = void 0;
|
||||
const typeorm_1 = require("@nestjs/typeorm");
|
||||
const common_1 = require("@nestjs/common");
|
||||
const verification_service_1 = require("./verification.service");
|
||||
const verifycation_entity_1 = require("./verifycation.entity");
|
||||
const redisCache_service_1 = require("../redisCache/redisCache.service");
|
||||
let VerificationModule = class VerificationModule {
|
||||
};
|
||||
VerificationModule = __decorate([
|
||||
(0, common_1.Module)({
|
||||
imports: [typeorm_1.TypeOrmModule.forFeature([verifycation_entity_1.VerifycationEntity])],
|
||||
providers: [redisCache_service_1.RedisCacheService, verification_service_1.VerificationService],
|
||||
})
|
||||
], VerificationModule);
|
||||
exports.VerificationModule = VerificationModule;
|
||||
150
AIWebQuickDeploy/dist/modules/verification/verification.service.js
vendored
Normal file
150
AIWebQuickDeploy/dist/modules/verification/verification.service.js
vendored
Normal file
@@ -0,0 +1,150 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.VerificationService = void 0;
|
||||
const utils_1 = require("../../common/utils");
|
||||
const globalConfig_service_1 = require("../globalConfig/globalConfig.service");
|
||||
const common_1 = require("@nestjs/common");
|
||||
const typeorm_1 = require("@nestjs/typeorm");
|
||||
const typeorm_2 = require("typeorm");
|
||||
const redisCache_service_1 = require("../redisCache/redisCache.service");
|
||||
const status_constant_1 = require("./../../common/constants/status.constant");
|
||||
const verifycation_entity_1 = require("./verifycation.entity");
|
||||
const Core = require("@alicloud/pop-core");
|
||||
const axios_1 = require("axios");
|
||||
let VerificationService = class VerificationService {
|
||||
constructor(verifycationEntity, globalConfigService, redisCacheService) {
|
||||
this.verifycationEntity = verifycationEntity;
|
||||
this.globalConfigService = globalConfigService;
|
||||
this.redisCacheService = redisCacheService;
|
||||
}
|
||||
async createVerification(user, type, expir = 30 * 60) {
|
||||
const historyVerify = await this.verifycationEntity.findOne({
|
||||
where: { userId: user.id, type },
|
||||
order: { createdAt: 'DESC' },
|
||||
});
|
||||
if (historyVerify &&
|
||||
historyVerify.createdAt.getTime() + 1 * 60 * 1000 > Date.now()) {
|
||||
const diffS = Math.ceil((historyVerify.createdAt.getTime() + 1 * 60 * 1000 - Date.now()) / 1000);
|
||||
throw new common_1.HttpException(`${diffS}S内不得重新发送`, common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const code = (0, utils_1.createRandomCode)();
|
||||
const expiresAt = new Date(Date.now() + expir * 1000);
|
||||
const { id, email } = user;
|
||||
const verifycation = { userId: id, type, code, expiresAt, email };
|
||||
return await this.verifycationEntity.save(verifycation);
|
||||
}
|
||||
async verifyCode({ code, id }, type) {
|
||||
const v = await this.verifycationEntity.findOne({
|
||||
where: { id, type },
|
||||
order: { createdAt: 'DESC' },
|
||||
});
|
||||
if (!v) {
|
||||
throw new common_1.HttpException('验证码不存在', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (v.used === status_constant_1.VerificationUseStatusEnum.USED) {
|
||||
throw new common_1.HttpException('当前验证码已被使用!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
else {
|
||||
v.used = status_constant_1.VerificationUseStatusEnum.USED;
|
||||
await this.verifycationEntity.update({ id }, v);
|
||||
}
|
||||
if (Number(v.code) !== Number(code)) {
|
||||
throw new common_1.HttpException('验证码错误', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (v.expiresAt < new Date()) {
|
||||
throw new common_1.HttpException('验证码已过期', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
async sendPhoneCode(messageInfo) {
|
||||
var _a;
|
||||
const { accessKeyId, accessKeySecret, SignName, TemplateCode } = await this.globalConfigService.getPhoneVerifyConfig();
|
||||
console.log('Received messageInfo:', messageInfo);
|
||||
const { phone, code } = messageInfo;
|
||||
if (!phone || !code) {
|
||||
throw new common_1.HttpException('确实必要参数错误!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const client = new Core({
|
||||
accessKeyId,
|
||||
accessKeySecret,
|
||||
endpoint: 'https://dysmsapi.aliyuncs.com',
|
||||
apiVersion: '2017-05-25',
|
||||
});
|
||||
const params = {
|
||||
PhoneNumbers: phone,
|
||||
SignName,
|
||||
TemplateCode,
|
||||
TemplateParam: JSON.stringify({ code }),
|
||||
};
|
||||
const requestOption = { method: 'POST', formatParams: false };
|
||||
try {
|
||||
const response = await client.request('SendSms', params, requestOption);
|
||||
if (response.Code === 'OK') {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
throw new common_1.HttpException(response.Message || '验证码发送失败!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
throw new common_1.HttpException(((_a = error === null || error === void 0 ? void 0 : error.data) === null || _a === void 0 ? void 0 : _a.Message) || '验证码发送失败!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
async verifyIdentity(identityInfo) {
|
||||
const appCode = await this.globalConfigService.getConfigs(['appCode']);
|
||||
const { name, idCard } = identityInfo;
|
||||
if (!name || !idCard) {
|
||||
throw new common_1.HttpException('缺少必要参数!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
common_1.Logger.debug(`Received identityInfo: ${name}, ${idCard}`);
|
||||
const apiUrl = 'https://eid.shumaidata.com/eid/check';
|
||||
const headers = {
|
||||
Authorization: `APPCODE ${appCode}`,
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
};
|
||||
const params = new URLSearchParams({
|
||||
name: name,
|
||||
idcard: idCard,
|
||||
});
|
||||
try {
|
||||
const response = await axios_1.default.post(apiUrl, params, { headers });
|
||||
const responseString = JSON.stringify(response.data);
|
||||
common_1.Logger.debug(`Received response: ${responseString}`);
|
||||
switch (response.data.result.res) {
|
||||
case '1':
|
||||
return true;
|
||||
case '2':
|
||||
common_1.Logger.log('验证不一致', 'VerificationService');
|
||||
case '3':
|
||||
common_1.Logger.log('实名认证异常', 'VerificationService');
|
||||
default:
|
||||
common_1.Logger.log('未知的认证结果', 'VerificationService');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`Error: ${error.message}`, error.stack, 'Verification');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
VerificationService = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__param(0, (0, typeorm_1.InjectRepository)(verifycation_entity_1.VerifycationEntity)),
|
||||
__metadata("design:paramtypes", [typeorm_2.Repository,
|
||||
globalConfig_service_1.GlobalConfigService,
|
||||
redisCache_service_1.RedisCacheService])
|
||||
], VerificationService);
|
||||
exports.VerificationService = VerificationService;
|
||||
44
AIWebQuickDeploy/dist/modules/verification/verifycation.entity.js
vendored
Normal file
44
AIWebQuickDeploy/dist/modules/verification/verifycation.entity.js
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.VerifycationEntity = void 0;
|
||||
const typeorm_1 = require("typeorm");
|
||||
const baseEntity_1 = require("../../common/entity/baseEntity");
|
||||
let VerifycationEntity = class VerifycationEntity extends baseEntity_1.BaseEntity {
|
||||
};
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '用户id' }),
|
||||
__metadata("design:type", Number)
|
||||
], VerifycationEntity.prototype, "userId", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ nullable: false, comment: '验证类型' }),
|
||||
__metadata("design:type", Number)
|
||||
], VerifycationEntity.prototype, "type", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ nullable: false, comment: '验证码' }),
|
||||
__metadata("design:type", Number)
|
||||
], VerifycationEntity.prototype, "code", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '过期时间' }),
|
||||
__metadata("design:type", Date)
|
||||
], VerifycationEntity.prototype, "expiresAt", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ length: 64, nullable: false, comment: '发送的邮箱' }),
|
||||
__metadata("design:type", String)
|
||||
], VerifycationEntity.prototype, "email", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ default: 0, nullable: false, comment: '是否已经使用了' }),
|
||||
__metadata("design:type", Number)
|
||||
], VerifycationEntity.prototype, "used", void 0);
|
||||
VerifycationEntity = __decorate([
|
||||
(0, typeorm_1.Entity)({ name: 'verifycation' })
|
||||
], VerifycationEntity);
|
||||
exports.VerifycationEntity = VerifycationEntity;
|
||||
Reference in New Issue
Block a user