Built motion from commit 85328c08.|2.5.50
[motion2.git] / server / components / auth / service.js
index 4e5f1a8..795aae7 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x573f=['hex','floor','now','HS512','../../mysqldb','../../config/environment','jsonwebtoken','express-jwt','composable-middleware','basic-auth','crypto','bluebird','role','fullname','name','internal','email','userpic','permissions','md5secret','voicePause','chatPause','mailPause','smsPause','openchannelPause','lastPauseAt','crudPermissions','allowmessenger','alias','phoneBarAutoAnswer','phoneBarAutoAnswerDelay','phoneBarEnableDtmfTone','phoneBarEnableSettings','phoneBarExpires','phoneBarPrefixRequired','phoneBarRemoteControlPort','hotdesk','interface','userProfileId','isChatInteractionAuthorized','use','user','ChatInteraction','params','closed','disposition','then','unmanaged','json','Unmanaged.','Forbidden.','catch','isAuthenticated','headers','authorization','startsWith','find','authenticate','pass','Wrong\x20credentials.','Bearer','status','Unknown\x20authorization\x20format','query','apikey','getUuid','User','sub','isEqual','apiKeyNonce','API\x20access\x20key\x20is\x20not\x20valid\x20anymore','User\x20not\x20found.','User\x20object\x20not\x20found.','../../config/license/util','getLicense','update','Forbidden','isMiddleware','signToken','setTokenCookie','It\x20looks\x20like\x20you\x20aren\x27t\x20logged\x20in,\x20please\x20try\x20again.','redirect','/dashboards/general','isNil','apiKeyIat','regenerateApiKey','Please\x20use\x20the\x20previous\x20API\x20access\x20key\x20to\x20generate\x20a\x20new\x20one','secret','secrets','payload','options','promisify','verify','session','randomBytes','toString'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x573f,0x64));var _0xf573=function(_0x1b1e6a,_0x2856a3){_0x1b1e6a=_0x1b1e6a-0x0;var _0x5eff52=_0x573f[_0x1b1e6a];return _0x5eff52;};'use strict';var db=require(_0xf573('0x0'))['db'];var config=require(_0xf573('0x1'));var hardwareConf=require('../../config/license/hardware');var _=require('lodash');var jwt=require(_0xf573('0x2'));var expressJwt=require(_0xf573('0x3'));var compose=require(_0xf573('0x4'));var basicAuth=require(_0xf573('0x5'));var crypto=require(_0xf573('0x6'));var BPromise=require(_0xf573('0x7'));var validateJwt=expressJwt({'secret':config['secrets']['session']});var userAttributes=['id',_0xf573('0x8'),_0xf573('0x9'),_0xf573('0xa'),_0xf573('0xb'),_0xf573('0xc'),_0xf573('0xd'),_0xf573('0xe'),_0xf573('0xf'),_0xf573('0x10'),_0xf573('0x11'),_0xf573('0x12'),'faxPause',_0xf573('0x13'),_0xf573('0x14'),'pauseType','showWebBar','lastLoginAt',_0xf573('0x15'),_0xf573('0x16'),_0xf573('0x17'),'passwordResetAt',_0xf573('0x18'),_0xf573('0x19'),_0xf573('0x1a'),'phoneBarDnd','phoneBarEnableRecording',_0xf573('0x1b'),_0xf573('0x1c'),_0xf573('0x1d'),_0xf573('0x1e'),'phoneBarRemoteControl',_0xf573('0x1f'),_0xf573('0x20'),_0xf573('0x21'),_0xf573('0x22')];exports[_0xf573('0x23')]=function(){return this['isAuthenticated'](!![])[_0xf573('0x24')](function(_0x46fefd,_0x34c59a,_0xbcd159){if(_0x46fefd[_0xf573('0x25')]){_0xbcd159();}else{return db[_0xf573('0x26')]['findOne']({'where':{'id':_0x46fefd[_0xf573('0x27')]['id']},'attributes':['id',_0xf573('0x28'),_0xf573('0x29')],'raw':!![]})[_0xf573('0x2a')](function(_0x183e1d){if(_0x183e1d&&_0x183e1d[_0xf573('0x28')]){return _0x34c59a['status'](_0x183e1d[_0xf573('0x29')]===_0xf573('0x2b')?0x195:0x193)[_0xf573('0x2c')]({'message':_0x183e1d[_0xf573('0x29')]===_0xf573('0x2b')?_0xf573('0x2d'):_0xf573('0x2e')});}else{_0xbcd159();}})[_0xf573('0x2f')](function(_0xbed0a6){_0xbcd159(_0xbed0a6);});}});};exports[_0xf573('0x30')]=function isAuthenticated(_0x299d9c){return compose()['use'](function(_0xb42a35,_0x4f27e4,_0xf7cc65){if(_0xb42a35[_0xf573('0x31')][_0xf573('0x32')]){if(_[_0xf573('0x33')](_0xb42a35[_0xf573('0x31')]['authorization'],'Basic')){var _0x490b67=basicAuth(_0xb42a35);db['User'][_0xf573('0x34')]({'where':{'name':_0x490b67[_0xf573('0xa')]}})[_0xf573('0x2a')](function(_0xf59eef){if(!_0xf59eef||!_0xf59eef[_0xf573('0x35')](_0x490b67[_0xf573('0x36')])){return _0x4f27e4['status'](0x191)[_0xf573('0x2c')]({'message':_0xf573('0x37')});}_0xb42a35[_0xf573('0x25')]={'id':_0xf59eef['id']};_0xf7cc65();})[_0xf573('0x2f')](function(_0x284330){_0xf7cc65(_0x284330);});}else if(_[_0xf573('0x33')](_0xb42a35[_0xf573('0x31')][_0xf573('0x32')],_0xf573('0x38'))){validateJwt(_0xb42a35,_0x4f27e4,_0xf7cc65);}else{if(_0x299d9c){_0xf7cc65();}else{return _0x4f27e4[_0xf573('0x39')](0x193)['json']({'message':_0xf573('0x3a')});}}}else if(_0xb42a35[_0xf573('0x3b')][_0xf573('0x3c')]){try{var _0x54e6fc={'audience':hardwareConf[_0xf573('0x3d')](),'issuer':hardwareConf[_0xf573('0x3d')]()};verifyJwt(_0xb42a35[_0xf573('0x3b')][_0xf573('0x3c')],_0x54e6fc)[_0xf573('0x2a')](function(_0x51b7a7){return db[_0xf573('0x3e')]['find']({'where':{'id':_0x51b7a7[_0xf573('0x3f')]}})[_0xf573('0x2a')](function(_0x1abf7f){if(!_0x1abf7f||!_[_0xf573('0x40')](_0x1abf7f[_0xf573('0x41')],_0x51b7a7['nonce'])){return _0x4f27e4[_0xf573('0x39')](0x191)[_0xf573('0x2c')]({'message':_0xf573('0x42')});}_0xb42a35[_0xf573('0x25')]={'id':_0x1abf7f['id']};_0xf7cc65();});})[_0xf573('0x2f')](function(){return _0x4f27e4[_0xf573('0x39')](0x191)[_0xf573('0x2c')]({'message':'Invalid\x20API\x20access\x20key'});});}catch(_0x367c8c){_0xf7cc65(_0x367c8c);}}else if(_0x299d9c){_0xf7cc65();}else{return _0x4f27e4[_0xf573('0x39')](0x193)[_0xf573('0x2c')]({'message':'Unknown\x20authorization\x20format'});}})['use'](function(_0x303c87,_0x2653c4,_0x55d1b7){if(_0x303c87['user']){db[_0xf573('0x3e')][_0xf573('0x34')]({'where':{'id':_0x303c87[_0xf573('0x25')]['id']},'attributes':userAttributes})[_0xf573('0x2a')](function(_0x288539){if(!_0x288539){return _0x2653c4[_0xf573('0x39')](0x194)[_0xf573('0x2c')]({'message':_0xf573('0x43')});}_0x303c87['user']=_0x288539;_0x55d1b7();})['catch'](function(_0x38fd2f){_0x55d1b7(_0x38fd2f);});}else if(_0x299d9c){_0x55d1b7();}else{return _0x2653c4[_0xf573('0x39')](0x194)[_0xf573('0x2c')]({'message':_0xf573('0x44')});}});};exports['canUpdate']=function canUpdate(){return compose()[_0xf573('0x24')](function(_0x36c262,_0x2e77ba,_0x146476){return require(_0xf573('0x45'))[_0xf573('0x46')]()['then'](function(_0x32320e){if(_0x32320e[_0xf573('0x47')]){_0x146476();}else{return _0x2e77ba['status'](0x193)[_0xf573('0x2c')]({'message':_0xf573('0x48')});}})['catch'](function(_0x378c89){_0x146476(_0x378c89);});});};exports['isMiddleware']=function(_0x355578,_0x2aec97,_0xd28e96){_0x355578[_0xf573('0x49')]=!![];return _0xd28e96();};exports[_0xf573('0x4a')]=function signToken(_0x1e2dfe){return signJwt(_0x1e2dfe);};exports[_0xf573('0x4b')]=function(_0x58f069,_0x12dd48){if(!_0x58f069[_0xf573('0x25')]){return _0x12dd48[_0xf573('0x39')](0x194)['json']({'message':_0xf573('0x4c')});}var _0x1fff35={'payload':{'id':_0x58f069['user']['id'],'role':_0x58f069['user'][_0xf573('0x8')]},'options':{'expiresIn':0x15180}};return signJwt(_0x1fff35)[_0xf573('0x2a')](function(_0xf8ea30){_0x12dd48['cookie']('motion.token',_0xf8ea30);_0x12dd48[_0xf573('0x4d')](_0xf573('0x4e'));})[_0xf573('0x2f')](function(_0xbb9402){return _0x12dd48['status'](0x1f4)['send'](_0xbb9402);});};exports['retrieveApiKey']=function(_0x739224){if(_['isNil'](_0x739224[_0xf573('0x41')])||_[_0xf573('0x4f')](_0x739224[_0xf573('0x50')])){return null;}else{return createJwt(_0x739224);}};exports['generateApiKey']=function(_0x535ebc){_0x535ebc[_0xf573('0x41')]=generateNonce();_0x535ebc[_0xf573('0x50')]=generateIssuedAt();return createJwt(_0x535ebc);};exports[_0xf573('0x51')]=function(_0x27358d,_0x4e5229){var _0x9f93b5=_0x27358d[_0xf573('0x3b')][_0xf573('0x3c')];if(_0x9f93b5){var _0x40c65a={'nonce':_0x4e5229[_0xf573('0x41')],'iat':_0x4e5229[_0xf573('0x50')],'audience':hardwareConf[_0xf573('0x3d')](),'issuer':hardwareConf[_0xf573('0x3d')]()};return verifyJwt(_0x9f93b5,_0x40c65a)[_0xf573('0x2a')](function(){return generateApiKey(_0x4e5229);});}else{throw{'message':_0xf573('0x52')};}};function signJwt(_0x1226d6){var _0x5e3c6f=BPromise['promisify'](jwt['sign'],{'context':jwt});var _0x30abde=_0x1226d6[_0xf573('0x53')]||config[_0xf573('0x54')]['session'];return new BPromise(function(_0x2fbb66,_0x171375){_0x5e3c6f(_0x1226d6[_0xf573('0x55')],_0x30abde,_0x1226d6[_0xf573('0x56')])[_0xf573('0x2a')](function(_0x482f22){_0x2fbb66(_0x482f22);})[_0xf573('0x2f')](function(_0x16f2e7){_0x171375(_0x16f2e7);});});}function verifyJwt(_0x24b389,_0x59a194,_0x12904d){var _0x3c0021=BPromise[_0xf573('0x57')](jwt[_0xf573('0x58')],{'context':jwt});var _0x582cab=_0x12904d||config[_0xf573('0x54')][_0xf573('0x59')];return new BPromise(function(_0x54df7b,_0x5f2a15){_0x3c0021(_0x24b389,_0x582cab,_0x59a194)[_0xf573('0x2a')](function(_0x2f816f){_0x54df7b(_0x2f816f);})[_0xf573('0x2f')](function(_0x3adf63){_0x5f2a15(_0x3adf63);});});}function generateNonce(){return crypto[_0xf573('0x5a')](0x10)[_0xf573('0x5b')](_0xf573('0x5c'));}function generateIssuedAt(){return Math[_0xf573('0x5d')](Date[_0xf573('0x5e')]()/0x3e8)['toString']();}function createJwt(_0x20637c){var _0x368e76={'payload':{'iat':_0x20637c[_0xf573('0x50')],'nonce':_0x20637c[_0xf573('0x41')]},'options':{'algorithm':_0xf573('0x5f'),'subject':_0x20637c['id'][_0xf573('0x5b')](),'issuer':hardwareConf[_0xf573('0x3d')](),'audience':hardwareConf[_0xf573('0x3d')]()}};return signJwt(_0x368e76)[_0xf573('0x2a')](function(_0x3ccbca){return{'iat':_0x20637c[_0xf573('0x50')],'nonce':_0x20637c[_0xf573('0x41')],'token':_0x3ccbca};});}
\ 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