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

1 line
15 KiB
JavaScript

'use strict';const _0x367faf=_0xf0c1;function _0xf0c1(_0x5cf201,_0x1a91a4){const _0x4fc894=_0x4fc8();return _0xf0c1=function(_0xf0c1b,_0x4e671a){_0xf0c1b=_0xf0c1b-0xb6;let _0x5616b0=_0x4fc894[_0xf0c1b];return _0x5616b0;},_0xf0c1(_0x5cf201,_0x1a91a4);}(function(_0x20bb12,_0x30da39){const _0x5bef79=_0xf0c1,_0xe085fe=_0x20bb12();while(!![]){try{const _0x1508d3=parseInt(_0x5bef79(0xba))/0x1+-parseInt(_0x5bef79(0x133))/0x2*(parseInt(_0x5bef79(0xdb))/0x3)+-parseInt(_0x5bef79(0x11c))/0x4*(parseInt(_0x5bef79(0xfe))/0x5)+parseInt(_0x5bef79(0xe1))/0x6*(-parseInt(_0x5bef79(0x114))/0x7)+-parseInt(_0x5bef79(0x12c))/0x8*(-parseInt(_0x5bef79(0x11b))/0x9)+-parseInt(_0x5bef79(0x10d))/0xa+-parseInt(_0x5bef79(0xef))/0xb*(-parseInt(_0x5bef79(0xe5))/0xc);if(_0x1508d3===_0x30da39)break;else _0xe085fe['push'](_0xe085fe['shift']());}catch(_0x6b68b8){_0xe085fe['push'](_0xe085fe['shift']());}}}(_0x4fc8,0x756d1));function _0x4fc8(){const _0x5d41fd=['typeorm','3726cHGAgh','8WMZpKZ','design:paramtypes','Registration','MailerService','log','redisCacheService','user','toString','&registerFailEmailTitle=','onModuleInit','registerSuccessEmaileAppend','userId','&username=',':PHONECODE:','hashSync','updatePassByOther','1560tHfNjd','registerSuccessEmailTitle','UserStatusEnum','账户已被激活过','internal','forEach','configKey','11698TppHDF','object','验证码类型错误','密码修改成功','updatePassword','register','../user/user.service','ipAddress','HttpStatus','/api/auth/registerError?message=','getUserInfo','registerSuccessEmailTeamName','jwtService','getUserStatus','@nestjs/jwt','decorate','set','837531PzzrAC','&registerFailEmailTeamName=','&email=','__decorate','UserStatusErrMsg','#fff','registerFailEmailTeamName','sendPhoneCode','getNamespace','../redisCache/redisCache.service','IPv4','../userBalance/userBalance.service','userService','sign','VerificationEnum','createRandomUid','avatar','text','&registerSuccessEmailTeamName=','admin','registerByPhone','defineProperty','createMathExpr','verifyUserCredentials','redirect','getConfigs','&registerSuccessEmailTitle=','UserService','@nestjs/typeorm','无权此操作!','../globalConfig/config.entity','oldPassword','../../common/utils','183YPOABH','@nestjs/common','loginByOpenId','127.0.0.1','mailerService','HttpException','6RmxdTI','captcha','UserBalanceService','JwtService','36YPQrxD','__param','getClientIp','createUserAndVerifycation','metadata','globalConfigService','/api/auth/registerSuccess?id=','qureyUserInfoByInviteCode','verifyUserPassword','ttl','4670545Ttndgs','svg-captcha','非法操作、请联系管理员!','ACTIVE','get','verificationService','getOwnPropertyDescriptor','updateUserPassword','BAD_REQUEST','ConfigEntity','AuthService','function','@nine.com','秒内不得重复发送短信!','verifyCaptcha','1871755EoCBuh','../../common/constants/user.constant','Repository','password','addBalanceToNewUser','../globalConfig/globalConfig.service','RedisCacheService','createTokenFromFingerprint','saveToken','验证码填写错误、请重新输入!','padStart','验证码已过期、请重新发送!','savaLoginIp','registerFailEmailTitle','verifyUserRegisterByPhone','4699450OUjOYJ','userBalanceService','error:\x20','data','networkInterfaces','length','验证码发送成功、请填写验证码完成注册!','949431lMwfnW','Injectable','userDefautlAvatar','family','visitor','address'];_0x4fc8=function(){return _0x5d41fd;};return _0x4fc8();}var __decorate=this&&this[_0x367faf(0xbd)]||function(_0x550b38,_0x29a67f,_0x44b640,_0x50b03f){const _0x40d043=_0x367faf;var _0x407f33=arguments[_0x40d043(0x112)],_0x596176=_0x407f33<0x3?_0x29a67f:_0x50b03f===null?_0x50b03f=Object[_0x40d043(0xf5)](_0x29a67f,_0x44b640):_0x50b03f,_0x90b0d7;if(typeof Reflect===_0x40d043(0x134)&&typeof Reflect[_0x40d043(0xb8)]===_0x40d043(0xfa))_0x596176=Reflect[_0x40d043(0xb8)](_0x550b38,_0x29a67f,_0x44b640,_0x50b03f);else{for(var _0x2e2701=_0x550b38[_0x40d043(0x112)]-0x1;_0x2e2701>=0x0;_0x2e2701--)if(_0x90b0d7=_0x550b38[_0x2e2701])_0x596176=(_0x407f33<0x3?_0x90b0d7(_0x596176):_0x407f33>0x3?_0x90b0d7(_0x29a67f,_0x44b640,_0x596176):_0x90b0d7(_0x29a67f,_0x44b640))||_0x596176;}return _0x407f33>0x3&&_0x596176&&Object[_0x40d043(0xcf)](_0x29a67f,_0x44b640,_0x596176),_0x596176;},__metadata=this&&this['__metadata']||function(_0x48446c,_0x37ea02){const _0x558ff3=_0x367faf;if(typeof Reflect===_0x558ff3(0x134)&&typeof Reflect[_0x558ff3(0xe9)]===_0x558ff3(0xfa))return Reflect[_0x558ff3(0xe9)](_0x48446c,_0x37ea02);},__param=this&&this[_0x367faf(0xe6)]||function(_0x3122e0,_0x4d8096){return function(_0x18f503,_0x435a21){_0x4d8096(_0x18f503,_0x435a21,_0x3122e0);};};Object[_0x367faf(0xcf)](exports,'__esModule',{'value':!![]}),exports[_0x367faf(0xf9)]=void 0x0;const globalConfig_service_1=require(_0x367faf(0x103)),verification_constant_1=require('../../common/constants/verification.constant'),verification_service_1=require('../verification/verification.service'),common_1=require(_0x367faf(0xdc)),jwt_1=require(_0x367faf(0xb7)),user_service_1=require(_0x367faf(0x139)),mailer_service_1=require('../mailer/mailer.service'),user_constant_1=require(_0x367faf(0xff)),userBalance_service_1=require(_0x367faf(0xc5)),config_entity_1=require(_0x367faf(0xd8)),typeorm_1=require(_0x367faf(0x11a)),typeorm_2=require(_0x367faf(0xd6)),utils_1=require(_0x367faf(0xda)),os=require('os'),redisCache_service_1=require(_0x367faf(0xc3)),svgCaptcha=require(_0x367faf(0xf0)),bcrypt=require('bcryptjs');let AuthService=class AuthService{constructor(_0x204c2d,_0x528c39,_0x19bba5,_0x15be0f,_0x45e780,_0x21d462,_0x5e960c,_0x496644){const _0x3d10ea=_0x367faf;this['configEntity']=_0x204c2d,this['userService']=_0x528c39,this[_0x3d10ea(0x13f)]=_0x19bba5,this[_0x3d10ea(0xdf)]=_0x15be0f,this[_0x3d10ea(0xf4)]=_0x45e780,this[_0x3d10ea(0x10e)]=_0x21d462,this[_0x3d10ea(0x121)]=_0x5e960c,this[_0x3d10ea(0xea)]=_0x496644;}async[_0x367faf(0x125)](){this['getIp']();}async[_0x367faf(0x138)](_0x3aba1a,_0x534080){const _0x1539f2=_0x367faf;await this[_0x1539f2(0xf4)][_0x1539f2(0xfd)](_0x3aba1a);const _0x579d1a=await this[_0x1539f2(0xc6)][_0x1539f2(0xe8)](_0x3aba1a,_0x534080),{username:_0x37f38a,email:_0x46b5c3,client:_0x5da51a,id:_0x46d2da}=_0x579d1a,_0x462313={'username':_0x37f38a,'email':_0x46b5c3,'id':_0x46d2da};return _0x5da51a&&(_0x462313['client']=_0x5da51a),_0x462313;}async[_0x367faf(0xce)](_0xfea65a,_0x406eb4){const _0x42b192=_0x367faf,{username:_0x4334bd,password:_0x53e1ab,phone:_0x3e13f7,phoneCode:_0x2622d7,invitedBy:_0x473cd6}=_0xfea65a;await this[_0x42b192(0xc6)][_0x42b192(0x10c)](_0xfea65a);const _0x1aa4c5=await this[_0x42b192(0xea)]['getNamespace'](),_0x2b9d7e=_0x1aa4c5+':PHONECODE:'+_0x3e13f7,_0x2441e3=await this[_0x42b192(0x121)][_0x42b192(0xf3)]({'key':_0x2b9d7e});if(!_0x2441e3)throw new common_1['HttpException'](_0x42b192(0x109),common_1[_0x42b192(0x13b)][_0x42b192(0xf7)]);if(_0x2622d7!==_0x2441e3)throw new common_1[(_0x42b192(0xe0))](_0x42b192(0x107),common_1['HttpStatus'][_0x42b192(0xf7)]);const _0x48ee51=(0x0,utils_1[_0x42b192(0xc9)])()+_0x42b192(0xfb),_0x573a8d={'username':_0x4334bd,'password':_0x53e1ab,'phone':_0x3e13f7,'invitedBy':_0x473cd6,'email':_0x48ee51,'status':user_constant_1[_0x42b192(0x12e)][_0x42b192(0xf2)]},_0x565677=await this[_0x42b192(0xea)][_0x42b192(0xd3)]([_0x42b192(0x116)]);_0x573a8d[_0x42b192(0xca)]=_0x565677;const _0x25b86f=bcrypt[_0x42b192(0x12a)](_0x53e1ab,0xa);_0x573a8d[_0x42b192(0x101)]=_0x25b86f;const _0x6c849d=await this['userService']['createUser'](_0x573a8d);let _0x4bc0fa;_0x473cd6&&(_0x4bc0fa=await this['userService'][_0x42b192(0xec)](_0x473cd6));await this['userBalanceService'][_0x42b192(0x102)](_0x6c849d['id'],_0x4bc0fa===null||_0x4bc0fa===void 0x0?void 0x0:_0x4bc0fa['id']);return;}async['login'](_0x4d457e,_0x3ea64a){const _0x5cb6c8=_0x367faf,_0x176cd6=await this[_0x5cb6c8(0xc6)][_0x5cb6c8(0xd1)](_0x4d457e),{username:_0x5c4231,id:_0x37e191,email:_0x41c74c,role:_0x212e41,openId:_0x1e2f60,client:_0x3df714}=_0x176cd6,_0x243071=(0x0,utils_1[_0x5cb6c8(0xe7)])(_0x3ea64a);await this[_0x5cb6c8(0xc6)][_0x5cb6c8(0x10a)](_0x37e191,_0x243071);const _0x352fc1=await this[_0x5cb6c8(0x13f)]['sign']({'username':_0x5c4231,'id':_0x37e191,'email':_0x41c74c,'role':_0x212e41,'openId':_0x1e2f60,'client':_0x3df714});return await this['redisCacheService'][_0x5cb6c8(0x106)](_0x37e191,_0x352fc1),_0x352fc1;}async['loginByPhone'](_0x20d5ba,_0x1a1c09){const _0x129296=_0x367faf,_0x2b3b29=await this['userService'][_0x129296(0xd1)](_0x20d5ba),{username:_0x11be62,id:_0x57c332,email:_0x4699d6,role:_0x1d50aa,openId:_0x5e21e4,client:_0x4afebb}=_0x2b3b29,_0x688de5=(0x0,utils_1[_0x129296(0xe7)])(_0x1a1c09);await this[_0x129296(0xc6)][_0x129296(0x10a)](_0x57c332,_0x688de5);const {phone:_0xd3b299}=_0x20d5ba,_0x19e167=await this[_0x129296(0x13f)][_0x129296(0xc7)]({'username':_0x11be62,'id':_0x57c332,'email':_0x4699d6,'role':_0x1d50aa,'openId':_0x5e21e4,'client':_0x4afebb,'phone':_0xd3b299});return await this[_0x129296(0x121)]['saveToken'](_0x57c332,_0x19e167),_0x19e167;}async[_0x367faf(0xdd)](_0x44096d,_0x437fe6){const _0x26b1d7=_0x367faf,{status:_0x1d333c}=_0x44096d;if(_0x1d333c!==user_constant_1['UserStatusEnum']['ACTIVE'])throw new common_1[(_0x26b1d7(0xe0))](user_constant_1[_0x26b1d7(0xbe)][_0x1d333c],common_1['HttpStatus']['BAD_REQUEST']);const {username:_0x44f64c,id:_0x5dc90b,email:_0x205cf8,role:_0x243f1b,openId:_0x508b26,client:_0x276a6f}=_0x44096d,_0x214a45=(0x0,utils_1['getClientIp'])(_0x437fe6);await this['userService'][_0x26b1d7(0x10a)](_0x5dc90b,_0x214a45);const _0x129508=await this[_0x26b1d7(0x13f)]['sign']({'username':_0x44f64c,'id':_0x5dc90b,'email':_0x205cf8,'role':_0x243f1b,'openId':_0x508b26,'client':_0x276a6f});return await this['redisCacheService'][_0x26b1d7(0x106)](_0x5dc90b,_0x129508),_0x129508;}async['getInfo'](_0xd53a2b){const _0xa10601=_0x367faf,{id:_0x1bd425}=_0xd53a2b[_0xa10601(0x122)];return await this['userService'][_0xa10601(0x13d)](_0x1bd425);}async['activateAccount'](_0x3512e6,_0x1eb588){const _0x2d1b42=_0x367faf,_0x39e1e5=await this['configEntity']['find']({'where':{'configKey':(0x0,typeorm_1['In'])([_0x2d1b42(0x12d),_0x2d1b42(0x13e),_0x2d1b42(0x126),_0x2d1b42(0x10b),'registerFailEmailTeamName'])}}),_0x44f68e=_0x39e1e5['reduce']((_0x208515,_0x7851fd)=>{const _0x32949a=_0x2d1b42;return _0x208515[_0x7851fd[_0x32949a(0x132)]]=_0x7851fd['configVal'],_0x208515;},{});try{const _0x35e2e4=await this[_0x2d1b42(0xf4)]['verifyCode'](_0x3512e6,verification_constant_1[_0x2d1b42(0xc8)][_0x2d1b42(0x11e)]),{type:_0x4e29c3,userId:_0x7c8e0a}=_0x35e2e4;if(_0x4e29c3!==verification_constant_1['VerificationEnum'][_0x2d1b42(0x11e)])throw new common_1[(_0x2d1b42(0xe0))](_0x2d1b42(0x135),common_1['HttpStatus'][_0x2d1b42(0xf7)]);const _0x41ad78=await this[_0x2d1b42(0xc6)][_0x2d1b42(0xb6)](_0x7c8e0a);if(_0x41ad78===user_constant_1['UserStatusEnum'][_0x2d1b42(0xf2)])throw new common_1[(_0x2d1b42(0xe0))](_0x2d1b42(0x12f),common_1[_0x2d1b42(0x13b)][_0x2d1b42(0xf7)]);await this['userService']['updateUserStatus'](_0x35e2e4[_0x2d1b42(0x127)],user_constant_1[_0x2d1b42(0x12e)][_0x2d1b42(0xf2)]);const _0xa4b5cc=await this[_0x2d1b42(0xc6)]['queryUserInfoById'](_0x35e2e4['userId']),{username:_0x34c06f,email:_0x573bca,id:_0xd535c5,invitedBy:_0x2bbe8b}=_0xa4b5cc;let _0x108680;_0x2bbe8b&&(_0x108680=await this[_0x2d1b42(0xc6)][_0x2d1b42(0xec)](_0x2bbe8b)),await this['userBalanceService'][_0x2d1b42(0x102)](_0xd535c5,_0x108680===null||_0x108680===void 0x0?void 0x0:_0x108680['id']),_0x1eb588[_0x2d1b42(0xd2)](_0x2d1b42(0xeb)+_0xd535c5[_0x2d1b42(0x123)]()[_0x2d1b42(0x108)](0x4,'0')+_0x2d1b42(0x128)+_0x34c06f+_0x2d1b42(0xbc)+_0x573bca+_0x2d1b42(0xd4)+_0x44f68e[_0x2d1b42(0x12d)]+_0x2d1b42(0xcc)+_0x44f68e['registerSuccessEmailTeamName']+'&registerSuccessEmaileAppend='+_0x44f68e[_0x2d1b42(0x126)]);}catch(_0x36f5f1){console[_0x2d1b42(0x120)](_0x2d1b42(0x10f),_0x36f5f1);const _0x30d3bb=_0x36f5f1['response'];_0x1eb588[_0x2d1b42(0xd2)](_0x2d1b42(0x13c)+_0x30d3bb+_0x2d1b42(0x124)+_0x44f68e[_0x2d1b42(0x10b)]+_0x2d1b42(0xbb)+_0x44f68e[_0x2d1b42(0xc0)]);}}async[_0x367faf(0x137)](_0x41e977,_0x52cd84){const _0x397dd7=_0x367faf,{id:_0xb576e9,client:_0x227134,role:_0x60cfe9}=_0x41e977[_0x397dd7(0x122)];if(_0x227134&&Number(_0x227134)>0x0)throw new common_1[(_0x397dd7(0xe0))]('无权此操作、请联系管理员!',common_1['HttpStatus'][_0x397dd7(0xf7)]);if(_0x60cfe9===_0x397dd7(0xcd))throw new common_1[(_0x397dd7(0xe0))](_0x397dd7(0xf1),common_1[_0x397dd7(0x13b)][_0x397dd7(0xf7)]);const _0xe7d7a2=await this[_0x397dd7(0xc6)][_0x397dd7(0xed)](_0xb576e9,_0x52cd84[_0x397dd7(0xd9)]);if(!_0xe7d7a2)throw new common_1[(_0x397dd7(0xe0))]('旧密码错误、请检查提交',common_1['HttpStatus'][_0x397dd7(0xf7)]);return this[_0x397dd7(0xc6)][_0x397dd7(0xf6)](_0xb576e9,_0x52cd84[_0x397dd7(0x101)]),_0x397dd7(0x136);}async[_0x367faf(0x12b)](_0x2c6b6f,_0x1e9a2d){const _0x5c14ae=_0x367faf,{id:_0x90b66,client:_0x3c7c04}=_0x2c6b6f[_0x5c14ae(0x122)];if(!_0x3c7c04)throw new common_1[(_0x5c14ae(0xe0))](_0x5c14ae(0xd7),common_1['HttpStatus']['BAD_REQUEST']);return this[_0x5c14ae(0xc6)][_0x5c14ae(0xf6)](_0x90b66,_0x1e9a2d[_0x5c14ae(0x101)]),_0x5c14ae(0x136);}['getIp'](){const _0x419661=_0x367faf;let _0x1614fa;const _0x29ce30=os[_0x419661(0x111)]();Object['keys'](_0x29ce30)[_0x419661(0x131)](_0x4e0bcb=>{const _0x34c4c9=_0x419661,_0x132ca5=_0x29ce30[_0x4e0bcb];for(let _0x3fe4f7=0x0;_0x3fe4f7<_0x132ca5['length'];_0x3fe4f7++){const _0x3cddb0=_0x132ca5[_0x3fe4f7];if(_0x3cddb0[_0x34c4c9(0x117)]===_0x34c4c9(0xc4)&&_0x3cddb0['address']!==_0x34c4c9(0xde)&&!_0x3cddb0[_0x34c4c9(0x130)]){_0x1614fa=_0x3cddb0[_0x34c4c9(0x119)];break;}}}),this[_0x419661(0x13a)]=_0x1614fa;}async[_0x367faf(0xe2)](_0x3a3b53){const _0x342227=_0x367faf,_0x134462=await this[_0x342227(0xea)][_0x342227(0xc2)](),{color:color=_0x342227(0xbf)}=_0x3a3b53,_0x4da7a0=svgCaptcha[_0x342227(0xd0)]({'background':color,'height':0x22,'width':0x78,'noise':0x3}),_0x36e4e6=_0x4da7a0[_0x342227(0xcb)],_0x24632d=(0x0,utils_1[_0x342227(0xc9)])(),_0x2be2fa=_0x134462+':CAPTCHA:'+_0x24632d;return await this[_0x342227(0x121)][_0x342227(0xb9)]({'key':_0x2be2fa,'val':_0x4da7a0['text']},0x5*0x3c),{'svgCode':_0x4da7a0[_0x342227(0x110)],'code':_0x24632d};}async[_0x367faf(0xc1)](_0x2d9011){const _0x26ad80=_0x367faf;await this[_0x26ad80(0xf4)][_0x26ad80(0xfd)](_0x2d9011);const {phone:_0x2db628}=_0x2d9011,_0x446fb0=await this[_0x26ad80(0xea)][_0x26ad80(0xc2)](),_0x3934de=_0x446fb0+_0x26ad80(0x129)+_0x2db628,_0x3cf53c=await this[_0x26ad80(0x121)][_0x26ad80(0xee)](_0x3934de);if(_0x3cf53c&&_0x3cf53c>0x0)throw new common_1[(_0x26ad80(0xe0))](_0x3cf53c+_0x26ad80(0xfc),common_1[_0x26ad80(0x13b)][_0x26ad80(0xf7)]);const _0x39aa64=(0x0,utils_1['createRandomCode'])(),_0x5914ec={'phone':_0x2db628,'code':_0x39aa64};return await this[_0x26ad80(0xf4)][_0x26ad80(0xc1)](_0x5914ec),await this[_0x26ad80(0x121)]['set']({'key':_0x3934de,'val':_0x39aa64},0x1*0x3c),_0x26ad80(0x113);}[_0x367faf(0x105)](_0x33018e){const _0x1dd494=_0x367faf,_0x262797=this[_0x1dd494(0x13f)][_0x1dd494(0xc7)]({'username':'游客'+_0x33018e,'id':_0x33018e,'email':_0x33018e+_0x1dd494(0xfb),'role':_0x1dd494(0x118),'openId':null,'client':null});return _0x262797;}};AuthService=__decorate([(0x0,common_1[_0x367faf(0x115)])(),__param(0x0,(0x0,typeorm_2['InjectRepository'])(config_entity_1[_0x367faf(0xf8)])),__metadata(_0x367faf(0x11d),[typeorm_1[_0x367faf(0x100)],user_service_1[_0x367faf(0xd5)],jwt_1[_0x367faf(0xe4)],mailer_service_1[_0x367faf(0x11f)],verification_service_1['VerificationService'],userBalance_service_1[_0x367faf(0xe3)],redisCache_service_1[_0x367faf(0x104)],globalConfig_service_1['GlobalConfigService']])],AuthService),exports[_0x367faf(0xf9)]=AuthService;