Built motion from commit 85328c08.|2.5.50
[motion2.git] / server / components / auth / service.js
index beaed73..795aae7 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x4110=['API\x20access\x20key\x20is\x20not\x20valid\x20anymore','disabled','Invalid\x20API\x20access\x20key','blockedAt','add','minutes','Unknown\x20authorization\x20format','User\x20not\x20found.','User\x20object\x20not\x20found.','canUpdate','getLicense','update','isMiddleware','signToken','setTokenCookie','It\x20looks\x20like\x20you\x20aren\x27t\x20logged\x20in,\x20please\x20try\x20again.','cookie','redirect','/dashboards/general','send','retrieveApiKey','isNil','generateApiKey','apiKeyIat','regenerateApiKey','query','apiKeyNonce','Please\x20use\x20the\x20previous\x20API\x20access\x20key\x20to\x20generate\x20a\x20new\x20one','validatePasswordPattern','test','validatePasswordHistory','decryptString','split','toLowerCase','format','The\x20password\x20must\x20be\x20different\x20from\x20the\x20last\x20one.\x20Please\x20choose\x20another\x20one.','Sequelize','ValidationError','updatePasswordsHistory','length','unshift','encryptString','promisify','sign','secret','secrets','session','payload','options','verify','randomBytes','hex','toString','../../mysqldb','../../config/environment','../../config/license/hardware','../../config/license/util','jsonwebtoken','express-jwt','composable-middleware','basic-auth','crypto','bluebird','moment','role','fullname','internal','userpic','md5secret','voicePause','chatPause','mailPause','faxPause','smsPause','allowmessenger','alias','phoneBarAutoAnswer','phoneBarAutoAnswerDelay','phoneBarDnd','phoneBarEnableRecording','phoneBarEnableDtmfTone','phoneBarEnableSettings','phoneBarExpires','phoneBarPrefixRequired','phoneBarRemoteControl','phoneBarRemoteControlPort','hotdesk','userProfileId','privacyEnabled','settingsEnabled','wssPort','downloadOmnichannelInteractions','downloadAttachments','isAuthenticated','use','user','closed','disposition','then','unmanaged','json','catch','authorization','startsWith','Basic','User','find','authenticate','pass','Wrong\x20credentials.','headers','status','apikey','getUuid','Setting','findOne','allowedLoginAttempts','blockDuration','isEqual'];(function(_0x514c15,_0x486901){var _0x16283e=function(_0x53b7d0){while(--_0x53b7d0){_0x514c15['push'](_0x514c15['shift']());}};_0x16283e(++_0x486901);}(_0x4110,0xac));var _0x0411=function(_0x5e29dc,_0x80e733){_0x5e29dc=_0x5e29dc-0x0;var _0x208b08=_0x4110[_0x5e29dc];return _0x208b08;};'use strict';var db=require(_0x0411('0x0'))['db'];var config=require(_0x0411('0x1'));var hardwareConf=require(_0x0411('0x2'));var licenseUtil=require(_0x0411('0x3'));var encryptor=require('../encryptor');var _=require('lodash');var jwt=require(_0x0411('0x4'));var expressJwt=require(_0x0411('0x5'));var compose=require(_0x0411('0x6'));var basicAuth=require(_0x0411('0x7'));var crypto=require(_0x0411('0x8'));var BPromise=require(_0x0411('0x9'));var util=require('util');var moment=require(_0x0411('0xa'));var validateJwt=expressJwt({'secret':config['secrets']['session']});var userAttributes=['id',_0x0411('0xb'),_0x0411('0xc'),'name',_0x0411('0xd'),'email',_0x0411('0xe'),'permissions',_0x0411('0xf'),_0x0411('0x10'),_0x0411('0x11'),_0x0411('0x12'),_0x0411('0x13'),_0x0411('0x14'),'openchannelPause','pauseType','showWebBar','lastLoginAt','lastPauseAt','crudPermissions',_0x0411('0x15'),'passwordResetAt',_0x0411('0x16'),_0x0411('0x17'),_0x0411('0x18'),_0x0411('0x19'),_0x0411('0x1a'),_0x0411('0x1b'),_0x0411('0x1c'),_0x0411('0x1d'),_0x0411('0x1e'),_0x0411('0x1f'),_0x0411('0x20'),_0x0411('0x21'),'interface',_0x0411('0x22'),_0x0411('0x23'),_0x0411('0x24'),_0x0411('0x25'),'downloadVoiceRecordings',_0x0411('0x26'),_0x0411('0x27')];exports['isChatInteractionAuthorized']=function(){return this[_0x0411('0x28')](!![])[_0x0411('0x29')](function(_0x46a1ce,_0x6a849a,_0x41b24d){if(_0x46a1ce[_0x0411('0x2a')]){_0x41b24d();}else{return db['ChatInteraction']['findOne']({'where':{'id':_0x46a1ce['params']['id']},'attributes':['id',_0x0411('0x2b'),_0x0411('0x2c')],'raw':!![]})[_0x0411('0x2d')](function(_0x2d83d1){if(_0x2d83d1&&_0x2d83d1['closed']){return _0x6a849a['status'](_0x2d83d1['disposition']===_0x0411('0x2e')?0x195:0x193)[_0x0411('0x2f')]({'message':_0x2d83d1[_0x0411('0x2c')]===_0x0411('0x2e')?'Unmanaged.':'Forbidden.'});}else{_0x41b24d();}})[_0x0411('0x30')](function(_0x36abd9){_0x41b24d(_0x36abd9);});}});};exports['isAuthenticated']=function isAuthenticated(_0x52f6bc){return compose()[_0x0411('0x29')](function(_0x9a0dd0,_0x2e47f4,_0x48b176){var _0x1ad432;if(_0x9a0dd0['headers'][_0x0411('0x31')]){if(_[_0x0411('0x32')](_0x9a0dd0['headers']['authorization'],_0x0411('0x33'))){var _0x3e6cb4=basicAuth(_0x9a0dd0);db[_0x0411('0x34')][_0x0411('0x35')]({'where':{'name':_0x3e6cb4['name']}})['then'](function(_0x167755){if(!_0x167755||!_0x167755[_0x0411('0x36')](_0x3e6cb4[_0x0411('0x37')])){return _0x2e47f4['status'](0x191)['json']({'message':_0x0411('0x38')});}_0x9a0dd0[_0x0411('0x2a')]={'id':_0x167755['id']};_0x48b176();})[_0x0411('0x30')](function(_0x3bc7bc){_0x48b176(_0x3bc7bc);});}else if(_[_0x0411('0x32')](_0x9a0dd0[_0x0411('0x39')][_0x0411('0x31')],'Bearer')){validateJwt(_0x9a0dd0,_0x2e47f4,_0x48b176);}else{if(_0x52f6bc){_0x48b176();}else{return _0x2e47f4[_0x0411('0x3a')](0x193)[_0x0411('0x2f')]({'message':'Unknown\x20authorization\x20format'});}}}else if(_0x9a0dd0['query'][_0x0411('0x3b')]){try{var _0x2d534d={'audience':hardwareConf[_0x0411('0x3c')](),'issuer':hardwareConf[_0x0411('0x3c')]()};verifyJwt(_0x9a0dd0['query'][_0x0411('0x3b')],_0x2d534d)['then'](function(_0x4e6785){return db[_0x0411('0x34')][_0x0411('0x35')]({'where':{'id':_0x4e6785['sub']}})[_0x0411('0x2d')](function(_0x4f24f6){_0x1ad432=_0x4f24f6;return db[_0x0411('0x3d')][_0x0411('0x3e')]({'where':{'id':0x1},'attributes':[_0x0411('0x3f'),_0x0411('0x40')],'raw':!![]});})['then'](function(_0x5322a8){if(!_0x1ad432||!_[_0x0411('0x41')](_0x1ad432['apiKeyNonce'],_0x4e6785['nonce'])){return _0x2e47f4[_0x0411('0x3a')](0x191)[_0x0411('0x2f')]({'message':_0x0411('0x42')});}if(_0x1ad432[_0x0411('0x43')]){return _0x2e47f4[_0x0411('0x3a')](0x191)[_0x0411('0x2f')]({'message':_0x0411('0x44')});}if(_0x1ad432['blocked']){if(_0x5322a8[_0x0411('0x40')]>0x0){if(moment(_0x1ad432[_0x0411('0x45')])[_0x0411('0x46')](_0x5322a8[_0x0411('0x40')],_0x0411('0x47'))>moment()){return _0x2e47f4['status'](0x191)[_0x0411('0x2f')]({'message':'Invalid\x20API\x20access\x20key'});}}else{return _0x2e47f4[_0x0411('0x3a')](0x191)[_0x0411('0x2f')]({'message':'Invalid\x20API\x20access\x20key'});}}_0x9a0dd0[_0x0411('0x2a')]={'id':_0x1ad432['id']};_0x48b176();});})['catch'](function(){return _0x2e47f4[_0x0411('0x3a')](0x191)[_0x0411('0x2f')]({'message':_0x0411('0x44')});});}catch(_0x51e095){_0x48b176(_0x51e095);}}else if(_0x52f6bc){_0x48b176();}else{return _0x2e47f4[_0x0411('0x3a')](0x193)[_0x0411('0x2f')]({'message':_0x0411('0x48')});}})[_0x0411('0x29')](function(_0x5b3dc7,_0x2f5094,_0x547e4a){if(_0x5b3dc7[_0x0411('0x2a')]){db[_0x0411('0x34')][_0x0411('0x35')]({'where':{'id':_0x5b3dc7['user']['id']},'attributes':userAttributes})['then'](function(_0x52fa3d){if(!_0x52fa3d){return _0x2f5094['status'](0x194)[_0x0411('0x2f')]({'message':_0x0411('0x49')});}_0x5b3dc7[_0x0411('0x2a')]=_0x52fa3d;_0x547e4a();})[_0x0411('0x30')](function(_0x15a096){_0x547e4a(_0x15a096);});}else if(_0x52f6bc){_0x547e4a();}else{return _0x2f5094[_0x0411('0x3a')](0x194)['json']({'message':_0x0411('0x4a')});}});};exports[_0x0411('0x4b')]=function canUpdate(){return compose()['use'](function(_0x35b6c8,_0x2f39e0,_0x1de5ec){return licenseUtil[_0x0411('0x4c')]()[_0x0411('0x2d')](function(_0x2eacf1){if(_0x2eacf1[_0x0411('0x4d')]){_0x1de5ec();}else{return _0x2f39e0[_0x0411('0x3a')](0x193)[_0x0411('0x2f')]({'message':'Forbidden'});}})[_0x0411('0x30')](function(_0x571cb3){_0x1de5ec(_0x571cb3);});});};exports['isMiddleware']=function(_0x3456b9,_0x3f372e,_0x5435ec){_0x3456b9[_0x0411('0x4e')]=!![];return _0x5435ec();};exports[_0x0411('0x4f')]=function signToken(_0x20c33a){return signJwt(_0x20c33a);};exports[_0x0411('0x50')]=function(_0x237041,_0x457fd8){if(!_0x237041[_0x0411('0x2a')]){return _0x457fd8[_0x0411('0x3a')](0x194)[_0x0411('0x2f')]({'message':_0x0411('0x51')});}var _0x2f73ff={'payload':{'id':_0x237041[_0x0411('0x2a')]['id'],'role':_0x237041[_0x0411('0x2a')][_0x0411('0xb')]},'options':{'expiresIn':0x15180}};return signJwt(_0x2f73ff)[_0x0411('0x2d')](function(_0x1de393){_0x457fd8[_0x0411('0x52')]('motion.token',_0x1de393);_0x457fd8[_0x0411('0x53')](_0x0411('0x54'));})['catch'](function(_0x441479){return _0x457fd8['status'](0x1f4)[_0x0411('0x55')](_0x441479);});};exports[_0x0411('0x56')]=function(_0x23fe6c){if(_['isNil'](_0x23fe6c['apiKeyNonce'])||_[_0x0411('0x57')](_0x23fe6c['apiKeyIat'])){return null;}else{return createJwt(_0x23fe6c);}};exports[_0x0411('0x58')]=function(_0x4fea7a){_0x4fea7a['apiKeyNonce']=generateNonce();_0x4fea7a[_0x0411('0x59')]=generateIssuedAt();return createJwt(_0x4fea7a);};exports[_0x0411('0x5a')]=function(_0x63a72b,_0xa1da0b){var _0x5041e2=_0x63a72b[_0x0411('0x5b')]['apikey'];if(_0x5041e2){var _0x1867d5={'nonce':_0xa1da0b[_0x0411('0x5c')],'iat':_0xa1da0b[_0x0411('0x59')],'audience':hardwareConf[_0x0411('0x3c')](),'issuer':hardwareConf[_0x0411('0x3c')]()};return verifyJwt(_0x5041e2,_0x1867d5)[_0x0411('0x2d')](function(){return generateApiKey(_0xa1da0b);});}else{throw{'message':_0x0411('0x5d')};}};exports[_0x0411('0x5e')]=function(_0x1139b2){var _0x11554b=new RegExp(/(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[?!@#\$%\^&\*~\-_=+[{\]\}])(?=.{8,})/);if(!_0x11554b[_0x0411('0x5f')](_0x1139b2))throw new db['Sequelize']['ValidationError']('The\x20password\x20must\x20be\x20at\x20least\x208\x20characters\x20long\x20and\x20have\x201\x20lowercase\x20character,\x201\x20uppercase\x20character,\x201\x20number\x20and\x201\x20special\x20character\x20~!@#$%^&-_=+[{]}.');return;};exports[_0x0411('0x60')]=function(_0x14fdc2,_0xf8209d,_0x4991a2){var _0x4460fb=encryptor[_0x0411('0x61')](_0xf8209d)[_0x0411('0x62')](',');for(var _0x120256=0x0;_0x120256<_0x4991a2;_0x120256++){if(!_0x4460fb[_0x120256])break;if(_0x14fdc2[_0x0411('0x63')]()===_0x4460fb[_0x120256]['toLowerCase']()){var _0x4d0a87=util[_0x0411('0x64')]('The\x20password\x20must\x20be\x20different\x20from\x20the\x20previous\x20%d\x20passwords.\x20Please\x20choose\x20another\x20one.',_0x4991a2);if(_0x4991a2===0x1){_0x4d0a87=_0x0411('0x65');}throw new db[(_0x0411('0x66'))][(_0x0411('0x67'))](_0x4d0a87);}}return;};exports[_0x0411('0x68')]=function(_0x2e5415,_0x21c589){var _0x4c49f7=_0x21c589?encryptor[_0x0411('0x61')](_0x21c589)[_0x0411('0x62')](','):[];if(_0x4c49f7[_0x0411('0x69')]===0x5){_0x4c49f7['splice'](-0x1,0x1);}_0x4c49f7[_0x0411('0x6a')](_0x2e5415);return encryptor[_0x0411('0x6b')](_0x4c49f7['join'](','));};function signJwt(_0x32e819){var _0x3bc4f3=BPromise[_0x0411('0x6c')](jwt[_0x0411('0x6d')],{'context':jwt});var _0x48e491=_0x32e819[_0x0411('0x6e')]||config[_0x0411('0x6f')][_0x0411('0x70')];return new BPromise(function(_0x2b5206,_0x4b32c1){_0x3bc4f3(_0x32e819[_0x0411('0x71')],_0x48e491,_0x32e819[_0x0411('0x72')])[_0x0411('0x2d')](function(_0x21328e){_0x2b5206(_0x21328e);})[_0x0411('0x30')](function(_0x12d1fa){_0x4b32c1(_0x12d1fa);});});}function verifyJwt(_0x3dcfd9,_0x1c0e0a,_0x2611b7){var _0x501b6d=BPromise['promisify'](jwt[_0x0411('0x73')],{'context':jwt});var _0xd68b90=_0x2611b7||config[_0x0411('0x6f')]['session'];return new BPromise(function(_0x31fda6,_0x5b2c90){_0x501b6d(_0x3dcfd9,_0xd68b90,_0x1c0e0a)['then'](function(_0x3a6cbb){_0x31fda6(_0x3a6cbb);})[_0x0411('0x30')](function(_0x24d4aa){_0x5b2c90(_0x24d4aa);});});}function generateNonce(){return crypto[_0x0411('0x74')](0x10)['toString'](_0x0411('0x75'));}function generateIssuedAt(){return Math['floor'](Date['now']()/0x3e8)['toString']();}function createJwt(_0x2c1bb7){var _0x2d0f7b={'payload':{'iat':_0x2c1bb7[_0x0411('0x59')],'nonce':_0x2c1bb7[_0x0411('0x5c')]},'options':{'algorithm':'HS512','subject':_0x2c1bb7['id'][_0x0411('0x76')](),'issuer':hardwareConf[_0x0411('0x3c')](),'audience':hardwareConf[_0x0411('0x3c')]()}};return signJwt(_0x2d0f7b)[_0x0411('0x2d')](function(_0x569a13){return{'iat':_0x2c1bb7[_0x0411('0x59')],'nonce':_0x2c1bb7[_0x0411('0x5c')],'token':_0x569a13};});}
\ No newline at end of file
+var _0x55ca=['It\x20looks\x20like\x20you\x20aren\x27t\x20logged\x20in,\x20please\x20try\x20again.','cookie','redirect','/dashboards/general','send','isNil','apiKeyIat','generateApiKey','regenerateApiKey','validatePasswordPattern','test','Sequelize','ValidationError','The\x20password\x20must\x20be\x20at\x20least\x208\x20characters\x20long\x20and\x20have\x201\x20lowercase\x20character,\x201\x20uppercase\x20character,\x201\x20number\x20and\x201\x20special\x20character\x20~!@#$%^&-_=+[{]}.','decryptString','split','toLowerCase','format','The\x20password\x20must\x20be\x20different\x20from\x20the\x20previous\x20%d\x20passwords.\x20Please\x20choose\x20another\x20one.','The\x20password\x20must\x20be\x20different\x20from\x20the\x20last\x20one.\x20Please\x20choose\x20another\x20one.','splice','unshift','encryptString','join','promisify','payload','options','session','randomBytes','toString','hex','floor','now','HS512','../../mysqldb','../../config/environment','lodash','jsonwebtoken','composable-middleware','basic-auth','crypto','bluebird','util','moment','secrets','role','fullname','internal','email','md5secret','voicePause','chatPause','mailPause','faxPause','smsPause','openchannelPause','pauseType','showWebBar','lastLoginAt','allowmessenger','phoneBarAutoAnswerDelay','phoneBarDnd','phoneBarEnableRecording','phoneBarEnableDtmfTone','phoneBarEnableSettings','phoneBarExpires','phoneBarRemoteControl','phoneBarRemoteControlPort','hotdesk','interface','userProfileId','privacyEnabled','settingsEnabled','wssPort','downloadVoiceRecordings','downloadAttachments','ignorePauseForPreviewCalls','selectRecallMeCampaign','chatAutoanswer','chatAutoanswerDelay','emailAutoanswer','smsAutoanswerDelay','openchannelAutoanswer','openchannelAutoanswerDelay','faxAutoanswerDelay','whatsappAutoanswer','isChatInteractionAuthorized','isAuthenticated','use','user','closed','then','status','disposition','unmanaged','json','Unmanaged.','Forbidden.','headers','authorization','startsWith','User','find','name','authenticate','pass','Wrong\x20credentials.','catch','query','apikey','getUuid','Setting','allowedLoginAttempts','isEqual','apiKeyNonce','nonce','API\x20access\x20key\x20is\x20not\x20valid\x20anymore','blockDuration','add','Invalid\x20API\x20access\x20key','Unknown\x20authorization\x20format','User\x20not\x20found.','canUpdate','update','isWebrtcLicence','getLicense','webrtc','Forbidden','isMiddleware','signToken'];(function(_0x172555,_0x4f04fe){var _0x5edc24=function(_0x436fe3){while(--_0x436fe3){_0x172555['push'](_0x172555['shift']());}};_0x5edc24(++_0x4f04fe);}(_0x55ca,0x126));var _0xa55c=function(_0x466f51,_0x1393ed){_0x466f51=_0x466f51-0x0;var _0x2db305=_0x55ca[_0x466f51];return _0x2db305;};'use strict';var db=require(_0xa55c('0x0'))['db'];var config=require(_0xa55c('0x1'));var hardwareConf=require('../../config/license/hardware');var licenseUtil=require('../../config/license/util');var encryptor=require('../encryptor');var _=require(_0xa55c('0x2'));var jwt=require(_0xa55c('0x3'));var expressJwt=require('express-jwt');var compose=require(_0xa55c('0x4'));var basicAuth=require(_0xa55c('0x5'));var crypto=require(_0xa55c('0x6'));var BPromise=require(_0xa55c('0x7'));var util=require(_0xa55c('0x8'));var moment=require(_0xa55c('0x9'));var validateJwt=expressJwt({'secret':config[_0xa55c('0xa')]['session']});var userAttributes=['id',_0xa55c('0xb'),_0xa55c('0xc'),'name',_0xa55c('0xd'),_0xa55c('0xe'),'userpic','permissions',_0xa55c('0xf'),_0xa55c('0x10'),_0xa55c('0x11'),_0xa55c('0x12'),_0xa55c('0x13'),_0xa55c('0x14'),_0xa55c('0x15'),_0xa55c('0x16'),_0xa55c('0x17'),_0xa55c('0x18'),'lastPauseAt','crudPermissions',_0xa55c('0x19'),'passwordResetAt','alias','phoneBarAutoAnswer',_0xa55c('0x1a'),_0xa55c('0x1b'),_0xa55c('0x1c'),_0xa55c('0x1d'),_0xa55c('0x1e'),_0xa55c('0x1f'),'phoneBarPrefixRequired',_0xa55c('0x20'),_0xa55c('0x21'),_0xa55c('0x22'),_0xa55c('0x23'),_0xa55c('0x24'),_0xa55c('0x25'),_0xa55c('0x26'),_0xa55c('0x27'),_0xa55c('0x28'),'downloadOmnichannelInteractions',_0xa55c('0x29'),_0xa55c('0x2a'),_0xa55c('0x2b'),_0xa55c('0x2c'),_0xa55c('0x2d'),_0xa55c('0x2e'),'emailAutoanswerDelay','smsAutoanswer',_0xa55c('0x2f'),_0xa55c('0x30'),_0xa55c('0x31'),'faxAutoanswer',_0xa55c('0x32'),_0xa55c('0x33'),'whatsappAutoanswerDelay'];exports[_0xa55c('0x34')]=function(){return this[_0xa55c('0x35')](!![])[_0xa55c('0x36')](function(_0x1965f1,_0x234372,_0x49ed04){if(_0x1965f1[_0xa55c('0x37')]){_0x49ed04();}else{return db['ChatInteraction']['findOne']({'where':{'id':_0x1965f1['params']['id']},'attributes':['id',_0xa55c('0x38'),'disposition'],'raw':!![]})[_0xa55c('0x39')](function(_0x190757){if(_0x190757&&_0x190757[_0xa55c('0x38')]){return _0x234372[_0xa55c('0x3a')](_0x190757[_0xa55c('0x3b')]===_0xa55c('0x3c')?0x195:0x193)[_0xa55c('0x3d')]({'message':_0x190757[_0xa55c('0x3b')]===_0xa55c('0x3c')?_0xa55c('0x3e'):_0xa55c('0x3f')});}else{_0x49ed04();}})['catch'](function(_0x430d55){_0x49ed04(_0x430d55);});}});};exports[_0xa55c('0x35')]=function isAuthenticated(_0x1c9f6b){return compose()[_0xa55c('0x36')](function(_0x5d940d,_0x1377b0,_0x22f6b6){var _0x1b8388;if(_0x5d940d[_0xa55c('0x40')][_0xa55c('0x41')]){if(_[_0xa55c('0x42')](_0x5d940d['headers'][_0xa55c('0x41')],'Basic')){var _0x35c9c2=basicAuth(_0x5d940d);db[_0xa55c('0x43')][_0xa55c('0x44')]({'where':{'name':_0x35c9c2[_0xa55c('0x45')]}})['then'](function(_0x3d28fb){if(!_0x3d28fb||!_0x3d28fb[_0xa55c('0x46')](_0x35c9c2[_0xa55c('0x47')])){return _0x1377b0[_0xa55c('0x3a')](0x191)[_0xa55c('0x3d')]({'message':_0xa55c('0x48')});}_0x5d940d[_0xa55c('0x37')]={'id':_0x3d28fb['id']};_0x22f6b6();})[_0xa55c('0x49')](function(_0x2808e9){_0x22f6b6(_0x2808e9);});}else if(_[_0xa55c('0x42')](_0x5d940d[_0xa55c('0x40')]['authorization'],'Bearer')){validateJwt(_0x5d940d,_0x1377b0,_0x22f6b6);}else{if(_0x1c9f6b){_0x22f6b6();}else{return _0x1377b0[_0xa55c('0x3a')](0x193)[_0xa55c('0x3d')]({'message':'Unknown\x20authorization\x20format'});}}}else if(_0x5d940d[_0xa55c('0x4a')][_0xa55c('0x4b')]){try{var _0x2e9623={'audience':hardwareConf[_0xa55c('0x4c')](),'issuer':hardwareConf[_0xa55c('0x4c')]()};verifyJwt(_0x5d940d[_0xa55c('0x4a')][_0xa55c('0x4b')],_0x2e9623)[_0xa55c('0x39')](function(_0x3959e3){return db['User']['find']({'where':{'id':_0x3959e3['sub']}})[_0xa55c('0x39')](function(_0x18e00e){_0x1b8388=_0x18e00e;return db[_0xa55c('0x4d')]['findOne']({'where':{'id':0x1},'attributes':[_0xa55c('0x4e'),'blockDuration'],'raw':!![]});})[_0xa55c('0x39')](function(_0x4ad813){if(!_0x1b8388||!_[_0xa55c('0x4f')](_0x1b8388[_0xa55c('0x50')],_0x3959e3[_0xa55c('0x51')])){return _0x1377b0['status'](0x191)[_0xa55c('0x3d')]({'message':_0xa55c('0x52')});}if(_0x1b8388['disabled']){return _0x1377b0[_0xa55c('0x3a')](0x191)[_0xa55c('0x3d')]({'message':'Invalid\x20API\x20access\x20key'});}if(_0x1b8388['blocked']){if(_0x4ad813[_0xa55c('0x53')]>0x0){if(moment(_0x1b8388['blockedAt'])[_0xa55c('0x54')](_0x4ad813[_0xa55c('0x53')],'minutes')>moment()){return _0x1377b0['status'](0x191)['json']({'message':'Invalid\x20API\x20access\x20key'});}}else{return _0x1377b0[_0xa55c('0x3a')](0x191)[_0xa55c('0x3d')]({'message':_0xa55c('0x55')});}}_0x5d940d[_0xa55c('0x37')]={'id':_0x1b8388['id']};_0x22f6b6();});})[_0xa55c('0x49')](function(){return _0x1377b0['status'](0x191)[_0xa55c('0x3d')]({'message':_0xa55c('0x55')});});}catch(_0x77d623){_0x22f6b6(_0x77d623);}}else if(_0x1c9f6b){_0x22f6b6();}else{return _0x1377b0[_0xa55c('0x3a')](0x193)[_0xa55c('0x3d')]({'message':_0xa55c('0x56')});}})['use'](function(_0x386e34,_0x5ee63d,_0x57a972){if(_0x386e34[_0xa55c('0x37')]){db[_0xa55c('0x43')]['find']({'where':{'id':_0x386e34[_0xa55c('0x37')]['id']},'attributes':userAttributes})['then'](function(_0x5f25f7){if(!_0x5f25f7){return _0x5ee63d[_0xa55c('0x3a')](0x194)[_0xa55c('0x3d')]({'message':_0xa55c('0x57')});}_0x386e34['user']=_0x5f25f7;_0x57a972();})[_0xa55c('0x49')](function(_0xd5a006){_0x57a972(_0xd5a006);});}else if(_0x1c9f6b){_0x57a972();}else{return _0x5ee63d['status'](0x194)[_0xa55c('0x3d')]({'message':'User\x20object\x20not\x20found.'});}});};exports[_0xa55c('0x58')]=function canUpdate(){return compose()[_0xa55c('0x36')](function(_0x5be43f,_0x66d1de,_0x1dae70){return licenseUtil['getLicense']()[_0xa55c('0x39')](function(_0x187e09){if(_0x187e09[_0xa55c('0x59')]){_0x1dae70();}else{return _0x66d1de['status'](0x193)[_0xa55c('0x3d')]({'message':'Forbidden'});}})[_0xa55c('0x49')](function(_0x3a8af4){_0x1dae70(_0x3a8af4);});});};exports[_0xa55c('0x5a')]=function isWebrtcLicence(){return compose()['use'](function(_0x41eab1,_0x106adb,_0x592429){return licenseUtil[_0xa55c('0x5b')]()[_0xa55c('0x39')](function(_0x5d5cf6){if(_0x5d5cf6[_0xa55c('0x5c')]){_0x592429();}else{return _0x106adb[_0xa55c('0x3a')](0x193)['json']({'message':_0xa55c('0x5d')});}})[_0xa55c('0x49')](function(_0x219a68){_0x592429(_0x219a68);});});};exports[_0xa55c('0x5e')]=function(_0x564cb3,_0x143989,_0x58a7ea){_0x564cb3[_0xa55c('0x5e')]=!![];return _0x58a7ea();};exports[_0xa55c('0x5f')]=function signToken(_0x194a79){return signJwt(_0x194a79);};exports['setTokenCookie']=function(_0x39bd3d,_0x250b00){if(!_0x39bd3d['user']){return _0x250b00[_0xa55c('0x3a')](0x194)[_0xa55c('0x3d')]({'message':_0xa55c('0x60')});}var _0xcd78c5={'payload':{'id':_0x39bd3d[_0xa55c('0x37')]['id'],'role':_0x39bd3d[_0xa55c('0x37')][_0xa55c('0xb')]},'options':{'expiresIn':0x15180}};return signJwt(_0xcd78c5)[_0xa55c('0x39')](function(_0x3c147b){_0x250b00[_0xa55c('0x61')]('motion.token',_0x3c147b);_0x250b00[_0xa55c('0x62')](_0xa55c('0x63'));})[_0xa55c('0x49')](function(_0x4f73b6){return _0x250b00[_0xa55c('0x3a')](0x1f4)[_0xa55c('0x64')](_0x4f73b6);});};exports['retrieveApiKey']=function(_0x21b760){if(_['isNil'](_0x21b760[_0xa55c('0x50')])||_[_0xa55c('0x65')](_0x21b760[_0xa55c('0x66')])){return null;}else{return createJwt(_0x21b760);}};exports[_0xa55c('0x67')]=function(_0x2ecf79){_0x2ecf79['apiKeyNonce']=generateNonce();_0x2ecf79[_0xa55c('0x66')]=generateIssuedAt();return createJwt(_0x2ecf79);};exports[_0xa55c('0x68')]=function(_0x4b85cc,_0x3929a6){var _0x2291e0=_0x4b85cc[_0xa55c('0x4a')][_0xa55c('0x4b')];if(_0x2291e0){var _0x50176b={'nonce':_0x3929a6['apiKeyNonce'],'iat':_0x3929a6[_0xa55c('0x66')],'audience':hardwareConf[_0xa55c('0x4c')](),'issuer':hardwareConf[_0xa55c('0x4c')]()};return verifyJwt(_0x2291e0,_0x50176b)[_0xa55c('0x39')](function(){return generateApiKey(_0x3929a6);});}else{throw{'message':'Please\x20use\x20the\x20previous\x20API\x20access\x20key\x20to\x20generate\x20a\x20new\x20one'};}};exports[_0xa55c('0x69')]=function(_0x5ce463){var _0x2742e4=new RegExp(/(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[?!@#\$%\^&\*~\-_=+[{\]\}])(?=.{8,})/);if(!_0x2742e4[_0xa55c('0x6a')](_0x5ce463))throw new db[(_0xa55c('0x6b'))][(_0xa55c('0x6c'))](_0xa55c('0x6d'));return;};exports['validatePasswordHistory']=function(_0x1cb73b,_0x54f776,_0x23f67f){var _0x157afe=encryptor[_0xa55c('0x6e')](_0x54f776)[_0xa55c('0x6f')](',');for(var _0x19aaf5=0x0;_0x19aaf5<_0x23f67f;_0x19aaf5++){if(!_0x157afe[_0x19aaf5])break;if(_0x1cb73b[_0xa55c('0x70')]()===_0x157afe[_0x19aaf5][_0xa55c('0x70')]()){var _0x53e2be=util[_0xa55c('0x71')](_0xa55c('0x72'),_0x23f67f);if(_0x23f67f===0x1){_0x53e2be=_0xa55c('0x73');}throw new db[(_0xa55c('0x6b'))][(_0xa55c('0x6c'))](_0x53e2be);}}return;};exports['updatePasswordsHistory']=function(_0xa72718,_0x3cd40d){var _0x28bac4=_0x3cd40d?encryptor[_0xa55c('0x6e')](_0x3cd40d)[_0xa55c('0x6f')](','):[];if(_0x28bac4['length']===0x5){_0x28bac4[_0xa55c('0x74')](-0x1,0x1);}_0x28bac4[_0xa55c('0x75')](_0xa72718);return encryptor[_0xa55c('0x76')](_0x28bac4[_0xa55c('0x77')](','));};function signJwt(_0x3ba56d){var _0x480dfc=BPromise[_0xa55c('0x78')](jwt['sign'],{'context':jwt});var _0x2e482a=_0x3ba56d['secret']||config[_0xa55c('0xa')]['session'];return new BPromise(function(_0x34edc5,_0x1333da){_0x480dfc(_0x3ba56d[_0xa55c('0x79')],_0x2e482a,_0x3ba56d[_0xa55c('0x7a')])[_0xa55c('0x39')](function(_0x3a5a52){_0x34edc5(_0x3a5a52);})[_0xa55c('0x49')](function(_0x2f2226){_0x1333da(_0x2f2226);});});}function verifyJwt(_0x14b515,_0x1acf50,_0x51c736){var _0x150a07=BPromise[_0xa55c('0x78')](jwt['verify'],{'context':jwt});var _0x18b928=_0x51c736||config[_0xa55c('0xa')][_0xa55c('0x7b')];return new BPromise(function(_0x9fe234,_0x1b8b06){_0x150a07(_0x14b515,_0x18b928,_0x1acf50)[_0xa55c('0x39')](function(_0x3cef1f){_0x9fe234(_0x3cef1f);})[_0xa55c('0x49')](function(_0x47de0a){_0x1b8b06(_0x47de0a);});});}function generateNonce(){return crypto[_0xa55c('0x7c')](0x10)[_0xa55c('0x7d')](_0xa55c('0x7e'));}function generateIssuedAt(){return Math[_0xa55c('0x7f')](Date[_0xa55c('0x80')]()/0x3e8)[_0xa55c('0x7d')]();}function createJwt(_0x2f1237){var _0x4249c1={'payload':{'iat':_0x2f1237[_0xa55c('0x66')],'nonce':_0x2f1237['apiKeyNonce']},'options':{'algorithm':_0xa55c('0x81'),'subject':_0x2f1237['id'][_0xa55c('0x7d')](),'issuer':hardwareConf[_0xa55c('0x4c')](),'audience':hardwareConf[_0xa55c('0x4c')]()}};return signJwt(_0x4249c1)[_0xa55c('0x39')](function(_0x10e711){return{'iat':_0x2f1237[_0xa55c('0x66')],'nonce':_0x2f1237[_0xa55c('0x50')],'token':_0x10e711};});}
\ No newline at end of file