YiAi/YiAiQuickDeploy/dist/modules/verification/verification.service.js

1 line
8.0 KiB
JavaScript

'use strict';const _0x28dd5c=_0x2944;(function(_0x989b24,_0x53764a){const _0x510e49=_0x2944,_0x41f24d=_0x989b24();while(!![]){try{const _0x202bc3=-parseInt(_0x510e49(0x111))/0x1+parseInt(_0x510e49(0x138))/0x2+parseInt(_0x510e49(0x120))/0x3*(-parseInt(_0x510e49(0xfd))/0x4)+parseInt(_0x510e49(0x107))/0x5*(parseInt(_0x510e49(0x106))/0x6)+parseInt(_0x510e49(0x102))/0x7+parseInt(_0x510e49(0x136))/0x8+parseInt(_0x510e49(0x114))/0x9;if(_0x202bc3===_0x53764a)break;else _0x41f24d['push'](_0x41f24d['shift']());}catch(_0x46b237){_0x41f24d['push'](_0x41f24d['shift']());}}}(_0x45d2,0x690f4));function _0x2944(_0x4e9e70,_0x5b13bf){const _0x45d2d1=_0x45d2();return _0x2944=function(_0x2944d4,_0x162035){_0x2944d4=_0x2944d4-0xf2;let _0xdbec76=_0x45d2d1[_0x2944d4];return _0xdbec76;},_0x2944(_0x4e9e70,_0x5b13bf);}var __decorate=this&&this[_0x28dd5c(0xfb)]||function(_0x367da8,_0x57a6cc,_0x9e5f9d,_0x17df74){const _0x46547b=_0x28dd5c;var _0xa7db80=arguments[_0x46547b(0x121)],_0x14340b=_0xa7db80<0x3?_0x57a6cc:_0x17df74===null?_0x17df74=Object[_0x46547b(0x11d)](_0x57a6cc,_0x9e5f9d):_0x17df74,_0x2567b8;if(typeof Reflect===_0x46547b(0x113)&&typeof Reflect[_0x46547b(0x12f)]===_0x46547b(0xf4))_0x14340b=Reflect[_0x46547b(0x12f)](_0x367da8,_0x57a6cc,_0x9e5f9d,_0x17df74);else{for(var _0x40e716=_0x367da8['length']-0x1;_0x40e716>=0x0;_0x40e716--)if(_0x2567b8=_0x367da8[_0x40e716])_0x14340b=(_0xa7db80<0x3?_0x2567b8(_0x14340b):_0xa7db80>0x3?_0x2567b8(_0x57a6cc,_0x9e5f9d,_0x14340b):_0x2567b8(_0x57a6cc,_0x9e5f9d))||_0x14340b;}return _0xa7db80>0x3&&_0x14340b&&Object[_0x46547b(0x12a)](_0x57a6cc,_0x9e5f9d,_0x14340b),_0x14340b;},__metadata=this&&this[_0x28dd5c(0xf8)]||function(_0xff0560,_0x461949){const _0x4bdd6e=_0x28dd5c;if(typeof Reflect==='object'&&typeof Reflect[_0x4bdd6e(0xf9)]===_0x4bdd6e(0xf4))return Reflect[_0x4bdd6e(0xf9)](_0xff0560,_0x461949);},__param=this&&this[_0x28dd5c(0x12d)]||function(_0x43d761,_0x44f4e4){return function(_0x467047,_0x534d1f){_0x44f4e4(_0x467047,_0x534d1f,_0x43d761);};};Object[_0x28dd5c(0x12a)](exports,_0x28dd5c(0xff),{'value':!![]}),exports[_0x28dd5c(0x109)]=void 0x0;const globalConfig_service_1=require(_0x28dd5c(0x124)),status_constant_1=require(_0x28dd5c(0x131)),typeorm_1=require(_0x28dd5c(0x135)),typeorm_2=require('typeorm'),verifycation_entity_1=require(_0x28dd5c(0x122)),common_1=require(_0x28dd5c(0xf6)),utils_1=require(_0x28dd5c(0xfe)),redisCache_service_1=require(_0x28dd5c(0xf5)),Core=require(_0x28dd5c(0x108));let VerificationService=class VerificationService{constructor(_0x5ce4e3,_0x586c4d,_0x50fe7e){const _0x47e30a=_0x28dd5c;this[_0x47e30a(0x115)]=_0x5ce4e3,this[_0x47e30a(0x101)]=_0x586c4d,this[_0x47e30a(0xfc)]=_0x50fe7e;}async['createVerification'](_0x20f26c,_0xfb7592,_0x42ddf1=0x1e*0x3c){const _0x197248=_0x28dd5c,_0x67f681=await this[_0x197248(0x115)][_0x197248(0x10c)]({'where':{'userId':_0x20f26c['id'],'type':_0xfb7592},'order':{'createdAt':'DESC'}});if(_0x67f681&&_0x67f681[_0x197248(0x11a)][_0x197248(0x105)]()+0x1*0x3c*0x3e8>Date[_0x197248(0x128)]()){const _0x141b1d=Math[_0x197248(0x116)]((_0x67f681[_0x197248(0x11a)][_0x197248(0x105)]()+0x1*0x3c*0x3e8-Date[_0x197248(0x128)]())/0x3e8);throw new common_1[(_0x197248(0xfa))](_0x141b1d+_0x197248(0xf7),common_1['HttpStatus']['BAD_REQUEST']);}const _0x4281fa=(0x0,utils_1[_0x197248(0x117)])(),_0x46fb3b=new Date(Date[_0x197248(0x128)]()+_0x42ddf1*0x3e8),{id:_0x424e27,email:_0x316489}=_0x20f26c,_0x58ecca={'userId':_0x424e27,'type':_0xfb7592,'code':_0x4281fa,'expiresAt':_0x46fb3b,'email':_0x316489};return await this['verifycationEntity'][_0x197248(0x125)](_0x58ecca);}async[_0x28dd5c(0x11b)]({code:_0x24c8c0,id:_0x5b022f},_0xb7f657){const _0x37d73f=_0x28dd5c,_0x7b61b1=await this[_0x37d73f(0x115)][_0x37d73f(0x10c)]({'where':{'id':_0x5b022f,'type':_0xb7f657},'order':{'createdAt':'DESC'}});if(!_0x7b61b1)throw new common_1[(_0x37d73f(0xfa))](_0x37d73f(0x12b),common_1[_0x37d73f(0x11c)][_0x37d73f(0x100)]);if(_0x7b61b1[_0x37d73f(0x132)]===status_constant_1[_0x37d73f(0x11e)][_0x37d73f(0x134)])throw new common_1[(_0x37d73f(0xfa))](_0x37d73f(0x103),common_1[_0x37d73f(0x11c)][_0x37d73f(0x100)]);else _0x7b61b1[_0x37d73f(0x132)]=status_constant_1[_0x37d73f(0x11e)][_0x37d73f(0x134)],await this[_0x37d73f(0x115)][_0x37d73f(0x104)]({'id':_0x5b022f},_0x7b61b1);if(Number(_0x7b61b1[_0x37d73f(0x12e)])!==Number(_0x24c8c0))throw new common_1[(_0x37d73f(0xfa))](_0x37d73f(0x10e),common_1['HttpStatus']['BAD_REQUEST']);if(_0x7b61b1[_0x37d73f(0x10b)]<new Date())throw new common_1[(_0x37d73f(0xfa))]('验证码已过期',common_1[_0x37d73f(0x11c)][_0x37d73f(0x100)]);return _0x7b61b1;}async['verifyCaptcha'](_0x4e6d01){const _0x4200b1=_0x28dd5c,{captchaId:_0x50fb35,captchaCode:_0x226318}=_0x4e6d01,_0x16f9f7=await this[_0x4200b1(0x101)][_0x4200b1(0x10a)](),_0x5a7c25=_0x16f9f7+_0x4200b1(0xf3)+_0x50fb35,_0x58e364=await this[_0x4200b1(0xfc)]['get']({'key':_0x5a7c25});await this['redisCacheService'][_0x4200b1(0x133)]({'key':_0x5a7c25});if(!_0x58e364)throw new common_1[(_0x4200b1(0xfa))]('图形验证码已过期、请重新输入!',common_1[_0x4200b1(0x11c)][_0x4200b1(0x100)]);if(!_0x58e364||_0x58e364!==_0x226318)throw new common_1[(_0x4200b1(0xfa))]('图形验证码错误、请检查填写!',common_1[_0x4200b1(0x11c)][_0x4200b1(0x100)]);}async[_0x28dd5c(0x118)](_0x409952){const _0x37e73e=_0x28dd5c;var _0x3dc0ff;const {accessKeyId:_0x22522d,accessKeySecret:_0x513b02,SignName:_0x46b19b,TemplateCode:_0x29672f}=await this[_0x37e73e(0x101)][_0x37e73e(0x12c)](),{phone:_0xe05817,code:_0x3a0c03}=_0x409952;if(!_0xe05817||!_0x3a0c03)throw new common_1[(_0x37e73e(0xfa))](_0x37e73e(0x127),common_1[_0x37e73e(0x11c)][_0x37e73e(0x100)]);const _0x58d972=new Core({'accessKeyId':_0x22522d,'accessKeySecret':_0x513b02,'endpoint':_0x37e73e(0x130),'apiVersion':_0x37e73e(0x139)}),_0x5777a2={'PhoneNumbers':_0xe05817,'SignName':_0x46b19b,'TemplateCode':_0x29672f,'TemplateParam':JSON[_0x37e73e(0x126)]({'code':_0x3a0c03})},_0x4a4ab7={'method':'POST','formatParams':![]};try{const _0x37d05d=await _0x58d972['request']('SendSms',_0x5777a2,_0x4a4ab7);if(_0x37d05d[_0x37e73e(0x10f)]==='OK')return!![];else throw new common_1[(_0x37e73e(0xfa))](_0x37d05d[_0x37e73e(0x129)]||_0x37e73e(0x123),common_1[_0x37e73e(0x11c)][_0x37e73e(0x100)]);}catch(_0x1fe33e){throw new common_1[(_0x37e73e(0xfa))](((_0x3dc0ff=_0x1fe33e===null||_0x1fe33e===void 0x0?void 0x0:_0x1fe33e[_0x37e73e(0x119)])===null||_0x3dc0ff===void 0x0?void 0x0:_0x3dc0ff[_0x37e73e(0x129)])||'验证码发送失败!',common_1['HttpStatus'][_0x37e73e(0x100)]);}}};VerificationService=__decorate([(0x0,common_1[_0x28dd5c(0x110)])(),__param(0x0,(0x0,typeorm_1[_0x28dd5c(0xf2)])(verifycation_entity_1[_0x28dd5c(0x137)])),__metadata(_0x28dd5c(0x11f),[typeorm_2[_0x28dd5c(0x10d)],globalConfig_service_1['GlobalConfigService'],redisCache_service_1[_0x28dd5c(0x112)]])],VerificationService),exports[_0x28dd5c(0x109)]=VerificationService;function _0x45d2(){const _0x2ce143=['2268432qpJIaw','verifycationEntity','ceil','createRandomCode','sendPhoneCode','data','createdAt','verifyCode','HttpStatus','getOwnPropertyDescriptor','VerificationUseStatusEnum','design:paramtypes','593247KryZRr','length','./verifycation.entity','验证码发送失败!','../globalConfig/globalConfig.service','save','stringify','确实必要参数错误!','now','Message','defineProperty','验证码不存在','getPhoneVerifyConfig','__param','code','decorate','https://dysmsapi.aliyuncs.com','../../common/constants/status.constant','used','del','USED','@nestjs/typeorm','3069200ohYziI','VerifycationEntity','9880LXDlLW','2017-05-25','InjectRepository',':CAPTCHA:','function','../redisCache/redisCache.service','@nestjs/common','S内不得重新发送','__metadata','metadata','HttpException','__decorate','redisCacheService','12jfOrep','../../common/utils','__esModule','BAD_REQUEST','globalConfigService','3899511ppsoNj','当前验证码已被使用!','update','getTime','1161264YboJnh','5EmSDyR','@alicloud/pop-core','VerificationService','getNamespace','expiresAt','findOne','Repository','验证码错误','Code','Injectable','367684GDMVKK','RedisCacheService','object'];_0x45d2=function(){return _0x2ce143;};return _0x45d2();}