YiAi/YiAiQuickDeploy/dist/modules/verification/verification.service.js
2024-07-02 16:38:26 +08:00

1 line
7.9 KiB
JavaScript

'use strict';const _0x1b5df4=_0x3a43;(function(_0xd01be5,_0x1cdef3){const _0x5d85d9=_0x3a43,_0x9c92f1=_0xd01be5();while(!![]){try{const _0x2c132f=-parseInt(_0x5d85d9(0x121))/0x1+parseInt(_0x5d85d9(0x11e))/0x2+parseInt(_0x5d85d9(0x135))/0x3+parseInt(_0x5d85d9(0x12d))/0x4*(parseInt(_0x5d85d9(0x139))/0x5)+-parseInt(_0x5d85d9(0x147))/0x6*(parseInt(_0x5d85d9(0x10f))/0x7)+parseInt(_0x5d85d9(0x143))/0x8+parseInt(_0x5d85d9(0x130))/0x9*(parseInt(_0x5d85d9(0x11a))/0xa);if(_0x2c132f===_0x1cdef3)break;else _0x9c92f1['push'](_0x9c92f1['shift']());}catch(_0x54dfe5){_0x9c92f1['push'](_0x9c92f1['shift']());}}}(_0x36d6,0x9fb9c));function _0x3a43(_0x28368f,_0x143fcc){const _0x36d69c=_0x36d6();return _0x3a43=function(_0x3a43b9,_0x10077a){_0x3a43b9=_0x3a43b9-0x105;let _0x425f68=_0x36d69c[_0x3a43b9];return _0x425f68;},_0x3a43(_0x28368f,_0x143fcc);}var __decorate=this&&this['__decorate']||function(_0x2fdd33,_0x15202f,_0x4898ba,_0x373a18){const _0x78c730=_0x3a43;var _0x6b46a0=arguments[_0x78c730(0x107)],_0x200c8b=_0x6b46a0<0x3?_0x15202f:_0x373a18===null?_0x373a18=Object[_0x78c730(0x123)](_0x15202f,_0x4898ba):_0x373a18,_0x3fa162;if(typeof Reflect===_0x78c730(0x115)&&typeof Reflect['decorate']===_0x78c730(0x146))_0x200c8b=Reflect[_0x78c730(0x119)](_0x2fdd33,_0x15202f,_0x4898ba,_0x373a18);else{for(var _0x3e3c0d=_0x2fdd33[_0x78c730(0x107)]-0x1;_0x3e3c0d>=0x0;_0x3e3c0d--)if(_0x3fa162=_0x2fdd33[_0x3e3c0d])_0x200c8b=(_0x6b46a0<0x3?_0x3fa162(_0x200c8b):_0x6b46a0>0x3?_0x3fa162(_0x15202f,_0x4898ba,_0x200c8b):_0x3fa162(_0x15202f,_0x4898ba))||_0x200c8b;}return _0x6b46a0>0x3&&_0x200c8b&&Object['defineProperty'](_0x15202f,_0x4898ba,_0x200c8b),_0x200c8b;},__metadata=this&&this[_0x1b5df4(0x138)]||function(_0x169ea9,_0x1b422b){const _0x57493c=_0x1b5df4;if(typeof Reflect===_0x57493c(0x115)&&typeof Reflect[_0x57493c(0x125)]===_0x57493c(0x146))return Reflect['metadata'](_0x169ea9,_0x1b422b);},__param=this&&this['__param']||function(_0x13141f,_0x34e4a6){return function(_0x3d59fe,_0x21ea8a){_0x34e4a6(_0x3d59fe,_0x21ea8a,_0x13141f);};};Object['defineProperty'](exports,_0x1b5df4(0x10a),{'value':!![]}),exports['VerificationService']=void 0x0;function _0x36d6(){const _0x224d99=['design:paramtypes','metadata','verifycationEntity','https://dysmsapi.aliyuncs.com','VerificationService','createRandomCode','VerifycationEntity','BAD_REQUEST','data','20sagniA','Message','USED','9EREKJn','SendSms','当前验证码已被使用!','getTime','验证码错误','359226lURswt','Repository','findOne','__metadata','508445tAEoxd','图形验证码已过期、请重新输入!','update',':CAPTCHA:','getNamespace','图形验证码错误、请检查填写!','./verifycation.entity','request','verifyCaptcha','sendPhoneCode','8221560ZwTBzD','ceil','Injectable','function','258ntnMDp','HttpException','stringify','redisCacheService','length','createdAt','验证码发送失败!','__esModule','HttpStatus','@nestjs/common','RedisCacheService','getPhoneVerifyConfig','163604VIYUYz','DESC','@alicloud/pop-core','get','验证码已过期','expiresAt','object','globalConfigService','确实必要参数错误!','验证码不存在','decorate','464680UPTJlX','del','used','typeorm','1335078xquVqI','now','VerificationUseStatusEnum','710657biobmJ','createVerification','getOwnPropertyDescriptor'];_0x36d6=function(){return _0x224d99;};return _0x36d6();}const globalConfig_service_1=require('../globalConfig/globalConfig.service'),status_constant_1=require('../../common/constants/status.constant'),typeorm_1=require('@nestjs/typeorm'),typeorm_2=require(_0x1b5df4(0x11d)),verifycation_entity_1=require(_0x1b5df4(0x13f)),common_1=require(_0x1b5df4(0x10c)),utils_1=require('../../common/utils'),redisCache_service_1=require('../redisCache/redisCache.service'),Core=require(_0x1b5df4(0x111));let VerificationService=class VerificationService{constructor(_0x1fe17d,_0x758c3,_0x10e077){const _0x92619c=_0x1b5df4;this[_0x92619c(0x126)]=_0x1fe17d,this[_0x92619c(0x116)]=_0x758c3,this['redisCacheService']=_0x10e077;}async[_0x1b5df4(0x122)](_0x2c6169,_0x43c1d8,_0x506dd1=0x1e*0x3c){const _0x537440=_0x1b5df4,_0x5a9c12=await this['verifycationEntity'][_0x537440(0x137)]({'where':{'userId':_0x2c6169['id'],'type':_0x43c1d8},'order':{'createdAt':_0x537440(0x110)}});if(_0x5a9c12&&_0x5a9c12[_0x537440(0x108)][_0x537440(0x133)]()+0x1*0x3c*0x3e8>Date['now']()){const _0x2adfdd=Math[_0x537440(0x144)]((_0x5a9c12[_0x537440(0x108)][_0x537440(0x133)]()+0x1*0x3c*0x3e8-Date[_0x537440(0x11f)]())/0x3e8);throw new common_1[(_0x537440(0x148))](_0x2adfdd+'S内不得重新发送',common_1[_0x537440(0x10b)][_0x537440(0x12b)]);}const _0x20c9dc=(0x0,utils_1[_0x537440(0x129)])(),_0x47e440=new Date(Date['now']()+_0x506dd1*0x3e8),{id:_0x82e12,email:_0x5e4159}=_0x2c6169,_0x4feb7e={'userId':_0x82e12,'type':_0x43c1d8,'code':_0x20c9dc,'expiresAt':_0x47e440,'email':_0x5e4159};return await this[_0x537440(0x126)]['save'](_0x4feb7e);}async['verifyCode']({code:_0x193f86,id:_0x41fcf9},_0x4b7bd4){const _0x851ed3=_0x1b5df4,_0x3e2256=await this[_0x851ed3(0x126)][_0x851ed3(0x137)]({'where':{'id':_0x41fcf9,'type':_0x4b7bd4},'order':{'createdAt':'DESC'}});if(!_0x3e2256)throw new common_1['HttpException'](_0x851ed3(0x118),common_1[_0x851ed3(0x10b)][_0x851ed3(0x12b)]);if(_0x3e2256[_0x851ed3(0x11c)]===status_constant_1[_0x851ed3(0x120)][_0x851ed3(0x12f)])throw new common_1[(_0x851ed3(0x148))](_0x851ed3(0x132),common_1[_0x851ed3(0x10b)][_0x851ed3(0x12b)]);else _0x3e2256[_0x851ed3(0x11c)]=status_constant_1[_0x851ed3(0x120)][_0x851ed3(0x12f)],await this[_0x851ed3(0x126)][_0x851ed3(0x13b)]({'id':_0x41fcf9},_0x3e2256);if(Number(_0x3e2256['code'])!==Number(_0x193f86))throw new common_1[(_0x851ed3(0x148))](_0x851ed3(0x134),common_1[_0x851ed3(0x10b)][_0x851ed3(0x12b)]);if(_0x3e2256[_0x851ed3(0x114)]<new Date())throw new common_1[(_0x851ed3(0x148))](_0x851ed3(0x113),common_1[_0x851ed3(0x10b)][_0x851ed3(0x12b)]);return _0x3e2256;}async[_0x1b5df4(0x141)](_0xd0771){const _0x11071f=_0x1b5df4,{captchaId:_0x56a67c,captchaCode:_0x252162}=_0xd0771,_0x24adaa=await this[_0x11071f(0x116)][_0x11071f(0x13d)](),_0x35702a=_0x24adaa+_0x11071f(0x13c)+_0x56a67c,_0x49fce0=await this[_0x11071f(0x106)][_0x11071f(0x112)]({'key':_0x35702a});await this[_0x11071f(0x106)][_0x11071f(0x11b)]({'key':_0x35702a});if(!_0x49fce0)throw new common_1[(_0x11071f(0x148))](_0x11071f(0x13a),common_1[_0x11071f(0x10b)][_0x11071f(0x12b)]);if(!_0x49fce0||_0x49fce0!==_0x252162)throw new common_1[(_0x11071f(0x148))](_0x11071f(0x13e),common_1['HttpStatus']['BAD_REQUEST']);}async[_0x1b5df4(0x142)](_0x202b44){const _0x17503f=_0x1b5df4;var _0x71f14d;const {accessKeyId:_0x116edd,accessKeySecret:_0x44b4a3,SignName:_0xe5ab4e,TemplateCode:_0x34f956}=await this[_0x17503f(0x116)][_0x17503f(0x10e)](),{phone:_0x1344af,code:_0xad518b}=_0x202b44;if(!_0x1344af||!_0xad518b)throw new common_1[(_0x17503f(0x148))](_0x17503f(0x117),common_1[_0x17503f(0x10b)][_0x17503f(0x12b)]);const _0x3d5f19=new Core({'accessKeyId':_0x116edd,'accessKeySecret':_0x44b4a3,'endpoint':_0x17503f(0x127),'apiVersion':'2017-05-25'}),_0x321da7={'PhoneNumbers':_0x1344af,'SignName':_0xe5ab4e,'TemplateCode':_0x34f956,'TemplateParam':JSON[_0x17503f(0x105)]({'code':_0xad518b})},_0x5a54d5={'method':'POST','formatParams':![]};try{const _0x4a4482=await _0x3d5f19[_0x17503f(0x140)](_0x17503f(0x131),_0x321da7,_0x5a54d5);if(_0x4a4482['Code']==='OK')return!![];else throw new common_1[(_0x17503f(0x148))](_0x4a4482[_0x17503f(0x12e)]||_0x17503f(0x109),common_1[_0x17503f(0x10b)]['BAD_REQUEST']);}catch(_0x25ac17){throw new common_1[(_0x17503f(0x148))](((_0x71f14d=_0x25ac17===null||_0x25ac17===void 0x0?void 0x0:_0x25ac17[_0x17503f(0x12c)])===null||_0x71f14d===void 0x0?void 0x0:_0x71f14d[_0x17503f(0x12e)])||_0x17503f(0x109),common_1['HttpStatus']['BAD_REQUEST']);}}};VerificationService=__decorate([(0x0,common_1[_0x1b5df4(0x145)])(),__param(0x0,(0x0,typeorm_1['InjectRepository'])(verifycation_entity_1[_0x1b5df4(0x12a)])),__metadata(_0x1b5df4(0x124),[typeorm_2[_0x1b5df4(0x136)],globalConfig_service_1['GlobalConfigService'],redisCache_service_1[_0x1b5df4(0x10d)]])],VerificationService),exports[_0x1b5df4(0x128)]=VerificationService;