YiAi/YiAiQuickDeploy/dist/modules/auth/auth.service.js
2024-02-06 13:43:30 +08:00

1 line
15 KiB
JavaScript

'use strict';const _0x45e8dc=_0x3960;(function(_0x3ecab1,_0x54ac57){const _0x216d62=_0x3960,_0x48352b=_0x3ecab1();while(!![]){try{const _0x192387=parseInt(_0x216d62(0x174))/0x1+parseInt(_0x216d62(0x193))/0x2+parseInt(_0x216d62(0x192))/0x3*(-parseInt(_0x216d62(0x190))/0x4)+-parseInt(_0x216d62(0x181))/0x5+parseInt(_0x216d62(0x18b))/0x6*(-parseInt(_0x216d62(0x1da))/0x7)+parseInt(_0x216d62(0x1d3))/0x8*(parseInt(_0x216d62(0x1ef))/0x9)+parseInt(_0x216d62(0x16b))/0xa;if(_0x192387===_0x54ac57)break;else _0x48352b['push'](_0x48352b['shift']());}catch(_0x4ed7d1){_0x48352b['push'](_0x48352b['shift']());}}}(_0x2eb0,0x4b63c));function _0x2eb0(){const _0x1d391e=['@nine.com','ttl','HttpException','svg-captcha','defineProperty','2191SvKRRb','userService','configVal','sendPhoneCode','data','AuthService','@nestjs/jwt','redisCacheService','../mailer/mailer.service','verifyUserRegisterByPhone','redirect','VerificationService','registerSuccessEmailTitle','log','verifyUserPassword','metadata','../globalConfig/config.entity','typeorm','forEach','UserStatusEnum','address','18vsshgO','updateUserPassword','captcha','mailerService','8556910zqRxDw','HttpStatus','createTokenFromFingerprint','networkInterfaces','decorate','set','error:\x20','@nestjs/common','@nestjs/typeorm','279349HBgtmV','UserStatusErrMsg','UserBalanceService','response','IPv4','globalConfigService','client','getIp','oldPassword','&username=','getUserStatus','registerByPhone','__decorate','2755555hACbhq','无权此操作!','UserService',':CAPTCHA:','&registerSuccessEmaileAppend=','configKey','../user/user.service','userBalanceService','keys','internal','8406SiLapb','createUser','text','/api/auth/registerSuccess?id=','toString','7788xgGdOk','register','111QbPIOl','137918FPJJBF','../../common/constants/verification.constant','MailerService','find','../../common/constants/user.constant','qureyUserInfoByInviteCode','&registerFailEmailTeamName=','#fff','Repository','user','../globalConfig/globalConfig.service',':PHONECODE:','createRandomCode','userId','object','registerSuccessEmaileAppend','visitor','createRandomUid','design:paramtypes','验证码类型错误','login','密码修改成功','updatePassByOther','registerFailEmailTeamName','验证码已过期、请重新发送!','updatePassword','addBalanceToNewUser','registerFailEmailTitle','length','GlobalConfigService','验证码填写错误、请重新输入!','getNamespace','../verification/verification.service','Injectable','family','password','getClientIp','__metadata','padStart','userDefautlAvatar','127.0.0.1','&email=','ACTIVE','无权此操作、请联系管理员!','__param','../redisCache/redisCache.service','updateUserStatus','function','verificationService','VerificationEnum','RedisCacheService','sign','createUserAndVerifycation','admin','jwtService','InjectRepository','savaLoginIp','BAD_REQUEST','Registration','verifyUserCredentials','verifyCode','avatar','ConfigEntity','&registerSuccessEmailTitle=','665840zEKUqu','getUserInfo'];_0x2eb0=function(){return _0x1d391e;};return _0x2eb0();}var __decorate=this&&this[_0x45e8dc(0x180)]||function(_0x5877cc,_0x296bbd,_0xa1d7ab,_0x50a792){const _0x46feb7=_0x45e8dc;var _0x1a0d96=arguments[_0x46feb7(0x1af)],_0x52dea3=_0x1a0d96<0x3?_0x296bbd:_0x50a792===null?_0x50a792=Object['getOwnPropertyDescriptor'](_0x296bbd,_0xa1d7ab):_0x50a792,_0x2f0f37;if(typeof Reflect===_0x46feb7(0x1a1)&&typeof Reflect[_0x46feb7(0x16f)]===_0x46feb7(0x1c2))_0x52dea3=Reflect[_0x46feb7(0x16f)](_0x5877cc,_0x296bbd,_0xa1d7ab,_0x50a792);else{for(var _0x2e2315=_0x5877cc['length']-0x1;_0x2e2315>=0x0;_0x2e2315--)if(_0x2f0f37=_0x5877cc[_0x2e2315])_0x52dea3=(_0x1a0d96<0x3?_0x2f0f37(_0x52dea3):_0x1a0d96>0x3?_0x2f0f37(_0x296bbd,_0xa1d7ab,_0x52dea3):_0x2f0f37(_0x296bbd,_0xa1d7ab))||_0x52dea3;}return _0x1a0d96>0x3&&_0x52dea3&&Object[_0x46feb7(0x1d9)](_0x296bbd,_0xa1d7ab,_0x52dea3),_0x52dea3;},__metadata=this&&this[_0x45e8dc(0x1b8)]||function(_0x3b14b1,_0x5d0530){const _0x5b09aa=_0x45e8dc;if(typeof Reflect===_0x5b09aa(0x1a1)&&typeof Reflect[_0x5b09aa(0x1e9)]===_0x5b09aa(0x1c2))return Reflect['metadata'](_0x3b14b1,_0x5d0530);},__param=this&&this[_0x45e8dc(0x1bf)]||function(_0x2ef3c6,_0x329f62){return function(_0x28aed1,_0x339074){_0x329f62(_0x28aed1,_0x339074,_0x2ef3c6);};};function _0x3960(_0x2df4ed,_0x2b777d){const _0x2eb010=_0x2eb0();return _0x3960=function(_0x396038,_0x4b3fd2){_0x396038=_0x396038-0x16a;let _0x5c1da8=_0x2eb010[_0x396038];return _0x5c1da8;},_0x3960(_0x2df4ed,_0x2b777d);}Object[_0x45e8dc(0x1d9)](exports,'__esModule',{'value':!![]}),exports[_0x45e8dc(0x1df)]=void 0x0;const globalConfig_service_1=require(_0x45e8dc(0x19d)),verification_constant_1=require(_0x45e8dc(0x194)),verification_service_1=require(_0x45e8dc(0x1b3)),common_1=require(_0x45e8dc(0x172)),jwt_1=require(_0x45e8dc(0x1e0)),user_service_1=require(_0x45e8dc(0x187)),mailer_service_1=require(_0x45e8dc(0x1e2)),user_constant_1=require(_0x45e8dc(0x197)),userBalance_service_1=require('../userBalance/userBalance.service'),config_entity_1=require(_0x45e8dc(0x1ea)),typeorm_1=require(_0x45e8dc(0x1eb)),typeorm_2=require(_0x45e8dc(0x173)),utils_1=require('../../common/utils'),os=require('os'),redisCache_service_1=require(_0x45e8dc(0x1c0)),svgCaptcha=require(_0x45e8dc(0x1d8)),bcrypt=require('bcryptjs');let AuthService=class AuthService{constructor(_0x170030,_0x1f3d94,_0x3fb88f,_0x5d06be,_0x4264f2,_0x2db828,_0x87d63,_0x31f963){const _0x390a02=_0x45e8dc;this['configEntity']=_0x170030,this[_0x390a02(0x1db)]=_0x1f3d94,this[_0x390a02(0x1c9)]=_0x3fb88f,this[_0x390a02(0x16a)]=_0x5d06be,this[_0x390a02(0x1c3)]=_0x4264f2,this[_0x390a02(0x188)]=_0x2db828,this[_0x390a02(0x1e1)]=_0x87d63,this[_0x390a02(0x179)]=_0x31f963;}async['onModuleInit'](){this['getIp']();}async[_0x45e8dc(0x191)](_0xc394bc,_0x117e12){const _0x9598ea=_0x45e8dc;await this['verificationService']['verifyCaptcha'](_0xc394bc);const _0x1becad=await this[_0x9598ea(0x1db)][_0x9598ea(0x1c7)](_0xc394bc,_0x117e12),{username:_0xa68da4,email:_0x3b6029,client:_0x260519,id:_0x424b21}=_0x1becad,_0x1900b8={'username':_0xa68da4,'email':_0x3b6029,'id':_0x424b21};return _0x260519&&(_0x1900b8[_0x9598ea(0x17a)]=_0x260519),_0x1900b8;}async[_0x45e8dc(0x17f)](_0x4fb100,_0x1a8618){const _0x5c69d4=_0x45e8dc,{username:_0x957232,password:_0x20c658,phone:_0x2febc3,phoneCode:_0x3a71dc,invitedBy:_0x4b0fb5}=_0x4fb100;await this[_0x5c69d4(0x1db)][_0x5c69d4(0x1e3)](_0x4fb100);const _0x31c3d3=await this[_0x5c69d4(0x179)][_0x5c69d4(0x1b2)](),_0x4e3df5=_0x31c3d3+_0x5c69d4(0x19e)+_0x2febc3,_0x4eaed3=await this[_0x5c69d4(0x1e1)]['get']({'key':_0x4e3df5});if(!_0x4eaed3)throw new common_1[(_0x5c69d4(0x1d7))](_0x5c69d4(0x1ab),common_1[_0x5c69d4(0x16c)]['BAD_REQUEST']);if(_0x3a71dc!==_0x4eaed3)throw new common_1['HttpException'](_0x5c69d4(0x1b1),common_1[_0x5c69d4(0x16c)][_0x5c69d4(0x1cc)]);const _0x2c1ef1=(0x0,utils_1[_0x5c69d4(0x1a4)])()+_0x5c69d4(0x1d5),_0x2dce55={'username':_0x957232,'password':_0x20c658,'phone':_0x2febc3,'invitedBy':_0x4b0fb5,'email':_0x2c1ef1,'status':user_constant_1[_0x5c69d4(0x1ed)][_0x5c69d4(0x1bd)]},_0x519498=await this[_0x5c69d4(0x179)]['getConfigs']([_0x5c69d4(0x1ba)]);_0x2dce55[_0x5c69d4(0x1d0)]=_0x519498;const _0x553bb7=bcrypt['hashSync'](_0x20c658,0xa);_0x2dce55[_0x5c69d4(0x1b6)]=_0x553bb7;const _0x12bc44=await this[_0x5c69d4(0x1db)][_0x5c69d4(0x18c)](_0x2dce55);let _0x44b88c;_0x4b0fb5&&(_0x44b88c=await this[_0x5c69d4(0x1db)][_0x5c69d4(0x198)](_0x4b0fb5));await this['userBalanceService']['addBalanceToNewUser'](_0x12bc44['id'],_0x44b88c===null||_0x44b88c===void 0x0?void 0x0:_0x44b88c['id']);return;}async[_0x45e8dc(0x1a7)](_0x4b0b75,_0x4cb9b1){const _0x54efa8=_0x45e8dc,_0x4d87e8=await this['userService']['verifyUserCredentials'](_0x4b0b75),{username:_0x3eb2fd,id:_0x236dbe,email:_0x135c36,role:_0x37fdcb,openId:_0x517224,client:_0x190dff}=_0x4d87e8,_0x4d173f=(0x0,utils_1[_0x54efa8(0x1b7)])(_0x4cb9b1);await this['userService'][_0x54efa8(0x1cb)](_0x236dbe,_0x4d173f);const _0x448c28=await this[_0x54efa8(0x1c9)]['sign']({'username':_0x3eb2fd,'id':_0x236dbe,'email':_0x135c36,'role':_0x37fdcb,'openId':_0x517224,'client':_0x190dff});return await this[_0x54efa8(0x1e1)]['saveToken'](_0x236dbe,_0x448c28),_0x448c28;}async['loginByPhone'](_0xdd7762,_0x7b4420){const _0x1f7a79=_0x45e8dc,_0x17f3d9=await this[_0x1f7a79(0x1db)][_0x1f7a79(0x1ce)](_0xdd7762),{username:_0xf74cd6,id:_0x1905a7,email:_0x6ad8f7,role:_0x3ee5d0,openId:_0xf61774,client:_0x423329}=_0x17f3d9,_0x479e34=(0x0,utils_1[_0x1f7a79(0x1b7)])(_0x7b4420);await this[_0x1f7a79(0x1db)][_0x1f7a79(0x1cb)](_0x1905a7,_0x479e34);const {phone:_0x40f014}=_0xdd7762,_0x3a0d5f=await this['jwtService'][_0x1f7a79(0x1c6)]({'username':_0xf74cd6,'id':_0x1905a7,'email':_0x6ad8f7,'role':_0x3ee5d0,'openId':_0xf61774,'client':_0x423329,'phone':_0x40f014});return await this['redisCacheService']['saveToken'](_0x1905a7,_0x3a0d5f),_0x3a0d5f;}async['loginByOpenId'](_0x31d9cd,_0x27c2a7){const _0x4346ed=_0x45e8dc,{status:_0x52a9cc}=_0x31d9cd;if(_0x52a9cc!==user_constant_1[_0x4346ed(0x1ed)][_0x4346ed(0x1bd)])throw new common_1[(_0x4346ed(0x1d7))](user_constant_1[_0x4346ed(0x175)][_0x52a9cc],common_1[_0x4346ed(0x16c)][_0x4346ed(0x1cc)]);const {username:_0x4da548,id:_0x4cbf1d,email:_0x224134,role:_0x5af507,openId:_0x8a5a0,client:_0x2862d2}=_0x31d9cd,_0x2c0508=(0x0,utils_1[_0x4346ed(0x1b7)])(_0x27c2a7);await this[_0x4346ed(0x1db)][_0x4346ed(0x1cb)](_0x4cbf1d,_0x2c0508);const _0x1ed554=await this['jwtService']['sign']({'username':_0x4da548,'id':_0x4cbf1d,'email':_0x224134,'role':_0x5af507,'openId':_0x8a5a0,'client':_0x2862d2});return await this[_0x4346ed(0x1e1)]['saveToken'](_0x4cbf1d,_0x1ed554),_0x1ed554;}async['getInfo'](_0x26ee3b){const _0xa1ee53=_0x45e8dc,{id:_0x3c3487}=_0x26ee3b[_0xa1ee53(0x19c)];return await this[_0xa1ee53(0x1db)][_0xa1ee53(0x1d4)](_0x3c3487);}async['activateAccount'](_0x2b2859,_0x4af581){const _0x2cc0fe=_0x45e8dc,_0x4e849c=await this['configEntity'][_0x2cc0fe(0x196)]({'where':{'configKey':(0x0,typeorm_1['In'])([_0x2cc0fe(0x1e6),'registerSuccessEmailTeamName',_0x2cc0fe(0x1a2),_0x2cc0fe(0x1ae),_0x2cc0fe(0x1aa)])}}),_0x5e73b9=_0x4e849c['reduce']((_0x21ab8f,_0x13017e)=>{const _0xc0e304=_0x2cc0fe;return _0x21ab8f[_0x13017e[_0xc0e304(0x186)]]=_0x13017e[_0xc0e304(0x1dc)],_0x21ab8f;},{});try{const _0x1faad3=await this[_0x2cc0fe(0x1c3)][_0x2cc0fe(0x1cf)](_0x2b2859,verification_constant_1[_0x2cc0fe(0x1c4)][_0x2cc0fe(0x1cd)]),{type:_0x4efe71,userId:_0x3dfedc}=_0x1faad3;if(_0x4efe71!==verification_constant_1[_0x2cc0fe(0x1c4)][_0x2cc0fe(0x1cd)])throw new common_1[(_0x2cc0fe(0x1d7))](_0x2cc0fe(0x1a6),common_1[_0x2cc0fe(0x16c)][_0x2cc0fe(0x1cc)]);const _0x26e9e5=await this[_0x2cc0fe(0x1db)][_0x2cc0fe(0x17e)](_0x3dfedc);if(_0x26e9e5===user_constant_1[_0x2cc0fe(0x1ed)]['ACTIVE'])throw new common_1[(_0x2cc0fe(0x1d7))]('账户已被激活过',common_1[_0x2cc0fe(0x16c)]['BAD_REQUEST']);await this[_0x2cc0fe(0x1db)][_0x2cc0fe(0x1c1)](_0x1faad3['userId'],user_constant_1[_0x2cc0fe(0x1ed)][_0x2cc0fe(0x1bd)]);const _0x2d531d=await this[_0x2cc0fe(0x1db)]['queryUserInfoById'](_0x1faad3[_0x2cc0fe(0x1a0)]),{username:_0x178bf3,email:_0x3307b7,id:_0x52fd8f,invitedBy:_0x4f6893}=_0x2d531d;let _0x4ed0f0;_0x4f6893&&(_0x4ed0f0=await this[_0x2cc0fe(0x1db)][_0x2cc0fe(0x198)](_0x4f6893)),await this[_0x2cc0fe(0x188)][_0x2cc0fe(0x1ad)](_0x52fd8f,_0x4ed0f0===null||_0x4ed0f0===void 0x0?void 0x0:_0x4ed0f0['id']),_0x4af581[_0x2cc0fe(0x1e4)](_0x2cc0fe(0x18e)+_0x52fd8f[_0x2cc0fe(0x18f)]()[_0x2cc0fe(0x1b9)](0x4,'0')+_0x2cc0fe(0x17d)+_0x178bf3+_0x2cc0fe(0x1bc)+_0x3307b7+_0x2cc0fe(0x1d2)+_0x5e73b9[_0x2cc0fe(0x1e6)]+'&registerSuccessEmailTeamName='+_0x5e73b9['registerSuccessEmailTeamName']+_0x2cc0fe(0x185)+_0x5e73b9[_0x2cc0fe(0x1a2)]);}catch(_0x3dc634){console[_0x2cc0fe(0x1e7)](_0x2cc0fe(0x171),_0x3dc634);const _0x25e26d=_0x3dc634[_0x2cc0fe(0x177)];_0x4af581['redirect']('/api/auth/registerError?message='+_0x25e26d+'&registerFailEmailTitle='+_0x5e73b9['registerFailEmailTitle']+_0x2cc0fe(0x199)+_0x5e73b9[_0x2cc0fe(0x1aa)]);}}async[_0x45e8dc(0x1ac)](_0x434c40,_0x31a571){const _0x52514e=_0x45e8dc,{id:_0x1a3521,client:_0x4666eb,role:_0x36c898}=_0x434c40[_0x52514e(0x19c)];if(_0x4666eb&&Number(_0x4666eb)>0x0)throw new common_1[(_0x52514e(0x1d7))](_0x52514e(0x1be),common_1[_0x52514e(0x16c)][_0x52514e(0x1cc)]);if(_0x36c898===_0x52514e(0x1c8))throw new common_1[(_0x52514e(0x1d7))]('非法操作、请联系管理员!',common_1[_0x52514e(0x16c)][_0x52514e(0x1cc)]);const _0x2d4dde=await this[_0x52514e(0x1db)][_0x52514e(0x1e8)](_0x1a3521,_0x31a571[_0x52514e(0x17c)]);if(!_0x2d4dde)throw new common_1[(_0x52514e(0x1d7))]('旧密码错误、请检查提交',common_1[_0x52514e(0x16c)]['BAD_REQUEST']);return this[_0x52514e(0x1db)][_0x52514e(0x1f0)](_0x1a3521,_0x31a571[_0x52514e(0x1b6)]),_0x52514e(0x1a8);}async[_0x45e8dc(0x1a9)](_0x3a57e5,_0x38909c){const _0x346883=_0x45e8dc,{id:_0x25433d,client:_0x339bf7}=_0x3a57e5[_0x346883(0x19c)];if(!_0x339bf7)throw new common_1['HttpException'](_0x346883(0x182),common_1['HttpStatus'][_0x346883(0x1cc)]);return this[_0x346883(0x1db)][_0x346883(0x1f0)](_0x25433d,_0x38909c[_0x346883(0x1b6)]),_0x346883(0x1a8);}[_0x45e8dc(0x17b)](){const _0x4e54cb=_0x45e8dc;let _0x5e65d0;const _0x50daa3=os[_0x4e54cb(0x16e)]();Object[_0x4e54cb(0x189)](_0x50daa3)[_0x4e54cb(0x1ec)](_0x21ba12=>{const _0x5c378d=_0x4e54cb,_0x3989a3=_0x50daa3[_0x21ba12];for(let _0x4a21ce=0x0;_0x4a21ce<_0x3989a3[_0x5c378d(0x1af)];_0x4a21ce++){const _0xcf2503=_0x3989a3[_0x4a21ce];if(_0xcf2503[_0x5c378d(0x1b5)]===_0x5c378d(0x178)&&_0xcf2503[_0x5c378d(0x1ee)]!==_0x5c378d(0x1bb)&&!_0xcf2503[_0x5c378d(0x18a)]){_0x5e65d0=_0xcf2503['address'];break;}}}),this['ipAddress']=_0x5e65d0;}async[_0x45e8dc(0x1f1)](_0x13d689){const _0xde1851=_0x45e8dc,_0xbe328f=await this[_0xde1851(0x179)][_0xde1851(0x1b2)](),{color:color=_0xde1851(0x19a)}=_0x13d689,_0x4c4fdc=svgCaptcha['createMathExpr']({'background':color,'height':0x22,'width':0x78,'noise':0x3}),_0x22ca6e=_0x4c4fdc[_0xde1851(0x18d)],_0x3102b3=(0x0,utils_1['createRandomUid'])(),_0x2bc8c7=_0xbe328f+_0xde1851(0x184)+_0x3102b3;return await this[_0xde1851(0x1e1)]['set']({'key':_0x2bc8c7,'val':_0x4c4fdc[_0xde1851(0x18d)]},0x5*0x3c),{'svgCode':_0x4c4fdc[_0xde1851(0x1de)],'code':_0x3102b3};}async[_0x45e8dc(0x1dd)](_0x484a7d){const _0x240f35=_0x45e8dc;await this[_0x240f35(0x1c3)]['verifyCaptcha'](_0x484a7d);const {phone:_0x5458ef}=_0x484a7d,_0x564e0b=await this[_0x240f35(0x179)]['getNamespace'](),_0xb1de0=_0x564e0b+_0x240f35(0x19e)+_0x5458ef,_0x34e269=await this[_0x240f35(0x1e1)][_0x240f35(0x1d6)](_0xb1de0);if(_0x34e269&&_0x34e269>0x0)throw new common_1[(_0x240f35(0x1d7))](_0x34e269+'秒内不得重复发送短信!',common_1[_0x240f35(0x16c)][_0x240f35(0x1cc)]);const _0x5a7627=(0x0,utils_1[_0x240f35(0x19f)])(),_0x4a20b3={'phone':_0x5458ef,'code':_0x5a7627};return await this[_0x240f35(0x1c3)]['sendPhoneCode'](_0x4a20b3),await this[_0x240f35(0x1e1)][_0x240f35(0x170)]({'key':_0xb1de0,'val':_0x5a7627},0x1*0x3c),'验证码发送成功、请填写验证码完成注册!';}[_0x45e8dc(0x16d)](_0xd9656a){const _0x491779=_0x45e8dc,_0x29809e=this['jwtService'][_0x491779(0x1c6)]({'username':'游客'+_0xd9656a,'id':_0xd9656a,'email':_0xd9656a+'@nine.com','role':_0x491779(0x1a3),'openId':null,'client':null});return _0x29809e;}};AuthService=__decorate([(0x0,common_1[_0x45e8dc(0x1b4)])(),__param(0x0,(0x0,typeorm_2[_0x45e8dc(0x1ca)])(config_entity_1[_0x45e8dc(0x1d1)])),__metadata(_0x45e8dc(0x1a5),[typeorm_1[_0x45e8dc(0x19b)],user_service_1[_0x45e8dc(0x183)],jwt_1['JwtService'],mailer_service_1[_0x45e8dc(0x195)],verification_service_1[_0x45e8dc(0x1e5)],userBalance_service_1[_0x45e8dc(0x176)],redisCache_service_1[_0x45e8dc(0x1c5)],globalConfig_service_1[_0x45e8dc(0x1b0)]])],AuthService),exports[_0x45e8dc(0x1df)]=AuthService;