Built motion from commit 85328c08.|2.5.50
[motion2.git] / server / components / auth / service.js
index 8a11426..795aae7 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xff01=['Wrong\x20credentials.','startsWith','Unknown\x20authorization\x20format','query','apikey','getUuid','sub','Setting','findOne','allowedLoginAttempts','blockDuration','isEqual','nonce','API\x20access\x20key\x20is\x20not\x20valid\x20anymore','disabled','Invalid\x20API\x20access\x20key','blockedAt','minutes','user','User\x20not\x20found.','User\x20object\x20not\x20found.','getLicense','isMiddleware','signToken','setTokenCookie','cookie','motion.token','send','retrieveApiKey','isNil','apiKeyIat','generateApiKey','apiKeyNonce','regenerateApiKey','Please\x20use\x20the\x20previous\x20API\x20access\x20key\x20to\x20generate\x20a\x20new\x20one','validatePasswordPattern','test','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~!@#$%^&-_=+[{]}.','validatePasswordHistory','decryptString','split','toLowerCase','The\x20password\x20must\x20be\x20different\x20from\x20the\x20previous\x20%d\x20passwords.\x20Please\x20choose\x20another\x20one.','Sequelize','updatePasswordsHistory','length','splice','unshift','encryptString','promisify','sign','secret','secrets','session','payload','options','verify','randomBytes','floor','now','toString','HS512','../../mysqldb','../../config/environment','../../config/license/util','lodash','jsonwebtoken','express-jwt','basic-auth','bluebird','moment','role','fullname','internal','email','userpic','permissions','md5secret','chatPause','faxPause','smsPause','openchannelPause','pauseType','showWebBar','lastLoginAt','lastPauseAt','crudPermissions','allowmessenger','passwordResetAt','phoneBarAutoAnswer','phoneBarAutoAnswerDelay','phoneBarDnd','phoneBarEnableRecording','phoneBarEnableSettings','phoneBarExpires','phoneBarRemoteControl','phoneBarRemoteControlPort','hotdesk','privacyEnabled','settingsEnabled','isAuthenticated','use','params','closed','disposition','status','unmanaged','json','Unmanaged.','Forbidden.','catch','headers','authorization','Basic','User','find','name','then','pass'];(function(_0x5f4e06,_0x36042a){var _0x4617f6=function(_0x561fd0){while(--_0x561fd0){_0x5f4e06['push'](_0x5f4e06['shift']());}};_0x4617f6(++_0x36042a);}(_0xff01,0xb7));var _0x1ff0=function(_0x14aa74,_0x846e4d){_0x14aa74=_0x14aa74-0x0;var _0xd383f1=_0xff01[_0x14aa74];return _0xd383f1;};'use strict';var db=require(_0x1ff0('0x0'))['db'];var config=require(_0x1ff0('0x1'));var hardwareConf=require('../../config/license/hardware');var licenseUtil=require(_0x1ff0('0x2'));var encryptor=require('../encryptor');var _=require(_0x1ff0('0x3'));var jwt=require(_0x1ff0('0x4'));var expressJwt=require(_0x1ff0('0x5'));var compose=require('composable-middleware');var basicAuth=require(_0x1ff0('0x6'));var crypto=require('crypto');var BPromise=require(_0x1ff0('0x7'));var util=require('util');var moment=require(_0x1ff0('0x8'));var validateJwt=expressJwt({'secret':config['secrets']['session']});var userAttributes=['id',_0x1ff0('0x9'),_0x1ff0('0xa'),'name',_0x1ff0('0xb'),_0x1ff0('0xc'),_0x1ff0('0xd'),_0x1ff0('0xe'),_0x1ff0('0xf'),'voicePause',_0x1ff0('0x10'),'mailPause',_0x1ff0('0x11'),_0x1ff0('0x12'),_0x1ff0('0x13'),_0x1ff0('0x14'),_0x1ff0('0x15'),_0x1ff0('0x16'),_0x1ff0('0x17'),_0x1ff0('0x18'),_0x1ff0('0x19'),_0x1ff0('0x1a'),'alias',_0x1ff0('0x1b'),_0x1ff0('0x1c'),_0x1ff0('0x1d'),_0x1ff0('0x1e'),'phoneBarEnableDtmfTone',_0x1ff0('0x1f'),_0x1ff0('0x20'),'phoneBarPrefixRequired',_0x1ff0('0x21'),_0x1ff0('0x22'),_0x1ff0('0x23'),'interface','userProfileId',_0x1ff0('0x24'),_0x1ff0('0x25')];exports['isChatInteractionAuthorized']=function(){return this[_0x1ff0('0x26')](!![])[_0x1ff0('0x27')](function(_0x2b3199,_0x12ed82,_0x580215){if(_0x2b3199['user']){_0x580215();}else{return db['ChatInteraction']['findOne']({'where':{'id':_0x2b3199[_0x1ff0('0x28')]['id']},'attributes':['id',_0x1ff0('0x29'),_0x1ff0('0x2a')],'raw':!![]})['then'](function(_0x34cc1d){if(_0x34cc1d&&_0x34cc1d[_0x1ff0('0x29')]){return _0x12ed82[_0x1ff0('0x2b')](_0x34cc1d[_0x1ff0('0x2a')]===_0x1ff0('0x2c')?0x195:0x193)[_0x1ff0('0x2d')]({'message':_0x34cc1d[_0x1ff0('0x2a')]===_0x1ff0('0x2c')?_0x1ff0('0x2e'):_0x1ff0('0x2f')});}else{_0x580215();}})[_0x1ff0('0x30')](function(_0x4dcd52){_0x580215(_0x4dcd52);});}});};exports[_0x1ff0('0x26')]=function isAuthenticated(_0x525579){return compose()[_0x1ff0('0x27')](function(_0x54d6e1,_0x459844,_0x2b1045){var _0x3c9e6e;if(_0x54d6e1[_0x1ff0('0x31')][_0x1ff0('0x32')]){if(_['startsWith'](_0x54d6e1[_0x1ff0('0x31')][_0x1ff0('0x32')],_0x1ff0('0x33'))){var _0x5d6212=basicAuth(_0x54d6e1);db[_0x1ff0('0x34')][_0x1ff0('0x35')]({'where':{'name':_0x5d6212[_0x1ff0('0x36')]}})[_0x1ff0('0x37')](function(_0x203d4d){if(!_0x203d4d||!_0x203d4d['authenticate'](_0x5d6212[_0x1ff0('0x38')])){return _0x459844[_0x1ff0('0x2b')](0x191)[_0x1ff0('0x2d')]({'message':_0x1ff0('0x39')});}_0x54d6e1['user']={'id':_0x203d4d['id']};_0x2b1045();})[_0x1ff0('0x30')](function(_0x50c306){_0x2b1045(_0x50c306);});}else if(_[_0x1ff0('0x3a')](_0x54d6e1[_0x1ff0('0x31')]['authorization'],'Bearer')){validateJwt(_0x54d6e1,_0x459844,_0x2b1045);}else{if(_0x525579){_0x2b1045();}else{return _0x459844['status'](0x193)['json']({'message':_0x1ff0('0x3b')});}}}else if(_0x54d6e1[_0x1ff0('0x3c')][_0x1ff0('0x3d')]){try{var _0x579c2c={'audience':hardwareConf[_0x1ff0('0x3e')](),'issuer':hardwareConf[_0x1ff0('0x3e')]()};verifyJwt(_0x54d6e1['query'][_0x1ff0('0x3d')],_0x579c2c)[_0x1ff0('0x37')](function(_0x1a6bed){return db[_0x1ff0('0x34')]['find']({'where':{'id':_0x1a6bed[_0x1ff0('0x3f')]}})['then'](function(_0x3d4749){_0x3c9e6e=_0x3d4749;return db[_0x1ff0('0x40')][_0x1ff0('0x41')]({'where':{'id':0x1},'attributes':[_0x1ff0('0x42'),_0x1ff0('0x43')],'raw':!![]});})[_0x1ff0('0x37')](function(_0x3fbadb){if(!_0x3c9e6e||!_[_0x1ff0('0x44')](_0x3c9e6e['apiKeyNonce'],_0x1a6bed[_0x1ff0('0x45')])){return _0x459844['status'](0x191)[_0x1ff0('0x2d')]({'message':_0x1ff0('0x46')});}if(_0x3c9e6e[_0x1ff0('0x47')]){return _0x459844['status'](0x191)['json']({'message':_0x1ff0('0x48')});}if(_0x3c9e6e['blocked']){if(_0x3fbadb[_0x1ff0('0x43')]>0x0){if(moment(_0x3c9e6e[_0x1ff0('0x49')])['add'](_0x3fbadb[_0x1ff0('0x43')],_0x1ff0('0x4a'))>moment()){return _0x459844[_0x1ff0('0x2b')](0x191)[_0x1ff0('0x2d')]({'message':_0x1ff0('0x48')});}}else{return _0x459844[_0x1ff0('0x2b')](0x191)['json']({'message':_0x1ff0('0x48')});}}_0x54d6e1[_0x1ff0('0x4b')]={'id':_0x3c9e6e['id']};_0x2b1045();});})[_0x1ff0('0x30')](function(){return _0x459844['status'](0x191)['json']({'message':_0x1ff0('0x48')});});}catch(_0x5ca72c){_0x2b1045(_0x5ca72c);}}else if(_0x525579){_0x2b1045();}else{return _0x459844[_0x1ff0('0x2b')](0x193)[_0x1ff0('0x2d')]({'message':'Unknown\x20authorization\x20format'});}})['use'](function(_0x3a4703,_0x2b54ad,_0x570f9a){if(_0x3a4703[_0x1ff0('0x4b')]){db['User'][_0x1ff0('0x35')]({'where':{'id':_0x3a4703['user']['id']},'attributes':userAttributes})['then'](function(_0x5241d8){if(!_0x5241d8){return _0x2b54ad[_0x1ff0('0x2b')](0x194)['json']({'message':_0x1ff0('0x4c')});}_0x3a4703[_0x1ff0('0x4b')]=_0x5241d8;_0x570f9a();})['catch'](function(_0x413e46){_0x570f9a(_0x413e46);});}else if(_0x525579){_0x570f9a();}else{return _0x2b54ad[_0x1ff0('0x2b')](0x194)[_0x1ff0('0x2d')]({'message':_0x1ff0('0x4d')});}});};exports['canUpdate']=function canUpdate(){return compose()[_0x1ff0('0x27')](function(_0x467bee,_0x403a62,_0x36ba09){return licenseUtil[_0x1ff0('0x4e')]()[_0x1ff0('0x37')](function(_0xf24b77){if(_0xf24b77['update']){_0x36ba09();}else{return _0x403a62[_0x1ff0('0x2b')](0x193)['json']({'message':'Forbidden'});}})[_0x1ff0('0x30')](function(_0x2d70f7){_0x36ba09(_0x2d70f7);});});};exports[_0x1ff0('0x4f')]=function(_0x48d927,_0x389929,_0x284d8f){_0x48d927[_0x1ff0('0x4f')]=!![];return _0x284d8f();};exports[_0x1ff0('0x50')]=function signToken(_0x15dd24){return signJwt(_0x15dd24);};exports[_0x1ff0('0x51')]=function(_0x5bb192,_0x4d5c04){if(!_0x5bb192[_0x1ff0('0x4b')]){return _0x4d5c04[_0x1ff0('0x2b')](0x194)[_0x1ff0('0x2d')]({'message':'It\x20looks\x20like\x20you\x20aren\x27t\x20logged\x20in,\x20please\x20try\x20again.'});}var _0x2320c7={'payload':{'id':_0x5bb192[_0x1ff0('0x4b')]['id'],'role':_0x5bb192[_0x1ff0('0x4b')][_0x1ff0('0x9')]},'options':{'expiresIn':0x15180}};return signJwt(_0x2320c7)[_0x1ff0('0x37')](function(_0x4e3a01){_0x4d5c04[_0x1ff0('0x52')](_0x1ff0('0x53'),_0x4e3a01);_0x4d5c04['redirect']('/dashboards/general');})['catch'](function(_0x2e9742){return _0x4d5c04[_0x1ff0('0x2b')](0x1f4)[_0x1ff0('0x54')](_0x2e9742);});};exports[_0x1ff0('0x55')]=function(_0x36013b){if(_['isNil'](_0x36013b['apiKeyNonce'])||_[_0x1ff0('0x56')](_0x36013b[_0x1ff0('0x57')])){return null;}else{return createJwt(_0x36013b);}};exports[_0x1ff0('0x58')]=function(_0x4a381e){_0x4a381e[_0x1ff0('0x59')]=generateNonce();_0x4a381e[_0x1ff0('0x57')]=generateIssuedAt();return createJwt(_0x4a381e);};exports[_0x1ff0('0x5a')]=function(_0x37aad9,_0x3c68cd){var _0x543cf5=_0x37aad9[_0x1ff0('0x3c')][_0x1ff0('0x3d')];if(_0x543cf5){var _0x386f62={'nonce':_0x3c68cd[_0x1ff0('0x59')],'iat':_0x3c68cd[_0x1ff0('0x57')],'audience':hardwareConf['getUuid'](),'issuer':hardwareConf[_0x1ff0('0x3e')]()};return verifyJwt(_0x543cf5,_0x386f62)[_0x1ff0('0x37')](function(){return generateApiKey(_0x3c68cd);});}else{throw{'message':_0x1ff0('0x5b')};}};exports[_0x1ff0('0x5c')]=function(_0x329aeb){var _0x455246=new RegExp(/(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[?!@#\$%\^&\*~\-_=+[{\]\}])(?=.{8,})/);if(!_0x455246[_0x1ff0('0x5d')](_0x329aeb))throw new db['Sequelize'][(_0x1ff0('0x5e'))](_0x1ff0('0x5f'));return;};exports[_0x1ff0('0x60')]=function(_0x11dc1b,_0x41b7f9,_0x2c76ac){var _0x3370ac=encryptor[_0x1ff0('0x61')](_0x41b7f9)[_0x1ff0('0x62')](',');for(var _0x3fc329=0x0;_0x3fc329<_0x2c76ac;_0x3fc329++){if(!_0x3370ac[_0x3fc329])break;if(_0x11dc1b[_0x1ff0('0x63')]()===_0x3370ac[_0x3fc329][_0x1ff0('0x63')]()){var _0x30f3cc=util['format'](_0x1ff0('0x64'),_0x2c76ac);if(_0x2c76ac===0x1){_0x30f3cc='The\x20password\x20must\x20be\x20different\x20from\x20the\x20last\x20one.\x20Please\x20choose\x20another\x20one.';}throw new db[(_0x1ff0('0x65'))][(_0x1ff0('0x5e'))](_0x30f3cc);}}return;};exports[_0x1ff0('0x66')]=function(_0x19f92b,_0x377af6){var _0x2249e3=_0x377af6?encryptor[_0x1ff0('0x61')](_0x377af6)[_0x1ff0('0x62')](','):[];if(_0x2249e3[_0x1ff0('0x67')]===0x5){_0x2249e3[_0x1ff0('0x68')](-0x1,0x1);}_0x2249e3[_0x1ff0('0x69')](_0x19f92b);return encryptor[_0x1ff0('0x6a')](_0x2249e3['join'](','));};function signJwt(_0x6a5108){var _0x38e9cc=BPromise[_0x1ff0('0x6b')](jwt[_0x1ff0('0x6c')],{'context':jwt});var _0x212078=_0x6a5108[_0x1ff0('0x6d')]||config[_0x1ff0('0x6e')][_0x1ff0('0x6f')];return new BPromise(function(_0x1bc613,_0x49c286){_0x38e9cc(_0x6a5108[_0x1ff0('0x70')],_0x212078,_0x6a5108[_0x1ff0('0x71')])[_0x1ff0('0x37')](function(_0x6b403){_0x1bc613(_0x6b403);})[_0x1ff0('0x30')](function(_0xc22df1){_0x49c286(_0xc22df1);});});}function verifyJwt(_0x357c87,_0x3c4e34,_0x2fc027){var _0x4285ea=BPromise[_0x1ff0('0x6b')](jwt[_0x1ff0('0x72')],{'context':jwt});var _0x21cd38=_0x2fc027||config['secrets'][_0x1ff0('0x6f')];return new BPromise(function(_0x14fd28,_0x276d1c){_0x4285ea(_0x357c87,_0x21cd38,_0x3c4e34)['then'](function(_0x4c16f2){_0x14fd28(_0x4c16f2);})[_0x1ff0('0x30')](function(_0x1ae947){_0x276d1c(_0x1ae947);});});}function generateNonce(){return crypto[_0x1ff0('0x73')](0x10)['toString']('hex');}function generateIssuedAt(){return Math[_0x1ff0('0x74')](Date[_0x1ff0('0x75')]()/0x3e8)[_0x1ff0('0x76')]();}function createJwt(_0x1ae35e){var _0x50165a={'payload':{'iat':_0x1ae35e['apiKeyIat'],'nonce':_0x1ae35e[_0x1ff0('0x59')]},'options':{'algorithm':_0x1ff0('0x77'),'subject':_0x1ae35e['id'][_0x1ff0('0x76')](),'issuer':hardwareConf[_0x1ff0('0x3e')](),'audience':hardwareConf[_0x1ff0('0x3e')]()}};return signJwt(_0x50165a)[_0x1ff0('0x37')](function(_0x1ad41e){return{'iat':_0x1ae35e[_0x1ff0('0x57')],'nonce':_0x1ae35e[_0x1ff0('0x59')],'token':_0x1ad41e};});}
\ 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