Built motion from commit f651e4b0a7312c0adceb5e57d6684a801a3aaf0d. Version 3.0.0...
[motion-next.git] / server / api / user / user.model.js
1 const a650_0x47ae=['CDR(type)=%s','internal','User','utf8','exports','%s%s','Authenticate','_XCALLY_MIXMONITOR_FORMAT=%s','sequelize','priority','extensionMonitor','updatePassword','VoiceExtension','gsm','prefix','record','context','sha1','toString','Hangup','options','pbkdf2','recordingFormat','./user.attributes','define','Set','prototype','bulkCreate','function','md5secret','concat','_XCALLY_MIXMONITOR_UNIQUEID=${UNIQUEID}','name','length','lodash','local','password','CDR(type)=internal','utf8_bin','join','base64','randomBytes','wav','defaults','ChanSpy','Dial','makeSaltAsync','${UNIQUEID}.%s,ab','MixMonitor','crypto','includes','md5','catch','destroy','chanspy','provider','then','system','changed','encryptPassword','Invalid\x20password','authenticate','SIP/%s,,tTxX','push','merge','google','salt','Missing\x20Callback','updateMd5Password','resolve','from-sip','format'];(function(_0x3ff2a2,_0x47aea0){const _0x55177a=function(_0x447f0a){while(--_0x447f0a){_0x3ff2a2['push'](_0x3ff2a2['shift']());}};_0x55177a(++_0x47aea0);}(a650_0x47ae,0x120));const a650_0x5517=function(_0x3ff2a2,_0x47aea0){_0x3ff2a2=_0x3ff2a2-0x0;let _0x55177a=a650_0x47ae[_0x3ff2a2];return _0x55177a;};const _0x5e3c4b=a650_0x5517;'use strict';const _=require(_0x5e3c4b('0x22')),util=require('util'),crypto=require(_0x5e3c4b('0x31')),md5=require(_0x5e3c4b('0x33')),sequelize=require(_0x5e3c4b('0x8')),{Op}=sequelize,attributes=require(_0x5e3c4b('0x17')),addUserApplication=function(_0x447f0a,_0x326e2d){const _0x22c546=_0x5e3c4b,_0x42c35b=[_0x22c546('0x2a'),'WAV',_0x22c546('0xd')],_0x914795={'context':_0x447f0a[_0x22c546('0x10')]||_0x22c546('0x46'),'exten':_0x326e2d,'type':_0x22c546('0x39'),'isApp':![],'UserId':_0x447f0a['id']},_0x531fed=[{'app':_0x22c546('0x19'),'appdata':_0x22c546('0x25')}];_0x447f0a[_0x22c546('0xa')]&&_[_0x22c546('0x32')](_0x42c35b,_0x447f0a[_0x22c546('0xa')])?(_0x531fed[_0x22c546('0x3f')]({'app':_0x22c546('0x19'),'appdata':_0x22c546('0x1f')}),_0x531fed[_0x22c546('0x3f')]({'app':_0x22c546('0x19'),'appdata':util[_0x22c546('0x47')](_0x22c546('0x7'),_0x447f0a[_0x22c546('0xa')])}),_0x531fed[_0x22c546('0x3f')]({'app':_0x22c546('0x2d'),'appdata':util['format']('SIP/%s,,tTxXU(xcally-mixmonitor-context)',_0x447f0a[_0x22c546('0x20')])})):_0x531fed['push']({'app':'Dial','appdata':util[_0x22c546('0x47')](_0x22c546('0x3e'),_0x447f0a['name'])});_0x531fed[_0x22c546('0x3f')]({'app':_0x22c546('0x13')});for(let _0x2ee38e=0x0;_0x2ee38e<_0x531fed['length'];_0x2ee38e++){_0x531fed[_0x2ee38e][_0x22c546('0x9')]=_0x2ee38e+0x1,_0x531fed[_0x2ee38e]=_[_0x22c546('0x2b')](_0x531fed[_0x2ee38e],_0x914795);}return _0x531fed;},addChanSpyApplications=function(_0x2d6757,_0x571f6f,_0x2fc4a9){const _0x5f2e21=_0x5e3c4b,_0x9c8d70={'context':_0x2d6757['context']||_0x5f2e21('0x46'),'type':'system','isApp':![],'UserId':_0x2d6757['id']},_0x112835=[];for(let _0x2800b6=0x0,_0xc23749=0x1;_0x2800b6<_0x2fc4a9[_0x5f2e21('0x21')];_0x2800b6++,_0xc23749=0x1){const _0x6d29f3={'exten':util['format'](_0x5f2e21('0x5'),_0x2fc4a9[_0x2800b6][_0x5f2e21('0xe')],_0x571f6f),'ChanSpyId':_0x2fc4a9[_0x2800b6]['id']};_0x112835[_0x5f2e21('0x3f')](_[_0x5f2e21('0x40')]({'app':_0x5f2e21('0x19'),'appdata':util[_0x5f2e21('0x47')](_0x5f2e21('0x0'),'chanspy'),'priority':_0xc23749++},_0x9c8d70,_0x6d29f3)),_0x2fc4a9[_0x2800b6][_0x5f2e21('0xf')]&&_0x112835['push'](_[_0x5f2e21('0x40')]({'app':_0x5f2e21('0x30'),'appdata':util['format'](_0x5f2e21('0x2f'),_0x2fc4a9[_0x2800b6][_0x5f2e21('0x16')]),'priority':_0xc23749++},_0x9c8d70,_0x6d29f3)),_0x2fc4a9[_0x2800b6]['auth']&&_0x112835[_0x5f2e21('0x3f')](_['merge']({'app':_0x5f2e21('0x6'),'appdata':_0x2fc4a9[_0x2800b6][_0x5f2e21('0x24')],'priority':_0xc23749++},_0x9c8d70,_0x6d29f3)),_0x112835['push'](_[_0x5f2e21('0x40')]({'app':_0x5f2e21('0x2c'),'appdata':util['format']('SIP/%s,%s',_0x2d6757[_0x5f2e21('0x20')],_0x2fc4a9[_0x2800b6]['options']?_0x2fc4a9[_0x2800b6][_0x5f2e21('0x14')][_0x5f2e21('0x27')](''):''),'priority':_0xc23749++},_0x9c8d70,_0x6d29f3)),_0x2fc4a9[_0x2800b6][_0x5f2e21('0xf')]&&_0x112835['push'](_[_0x5f2e21('0x40')]({'app':'StopMixMonitor','priority':_0xc23749++},_0x9c8d70,_0x6d29f3));}return _0x112835;},getChanSpy=function(_0x33c36e,_0x3f65e6){return new Promise(function(_0x1d4938,_0x55c5d3){const _0xea4cc8=a650_0x5517;return _0x33c36e['VoiceChanSpy']['findAll']()[_0xea4cc8('0x38')](function(_0x3bbb45){const _0x1120c9=_0xea4cc8;if(_0x3bbb45){let _0x2cc660=addChanSpyApplications(_0x3f65e6,_0x3f65e6[_0x1120c9('0x1')],_0x3bbb45);return _0x3f65e6[_0x1120c9('0x1')]!=_0x3f65e6[_0x1120c9('0x20')]&&(_0x2cc660=_0x2cc660[_0x1120c9('0x1e')](addChanSpyApplications(_0x3f65e6,_0x3f65e6[_0x1120c9('0x20')],_0x3bbb45))),_0x1d4938(_0x2cc660);}return _0x1d4938([]);})[_0xea4cc8('0x34')](function(_0xf98eaa){_0x55c5d3(_0xf98eaa);});});},authTypes=[_0x5e3c4b('0x41'),_0x5e3c4b('0x23')];module[_0x5e3c4b('0x4')]=function(_0x473452){const _0x3aee57=_0x5e3c4b,_0x1a4463=_0x473452['models'],_0x34f44d=_0x473452[_0x3aee57('0x18')](_0x3aee57('0x2'),attributes,{'tableName':'users','paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'beforeCreate':function(_0x51a80d){return _0x51a80d['updateMd5Password'](),_0x51a80d['updatePassword']();},'beforeUpdate':function(_0x533f4f){const _0x4507a0=_0x3aee57;return _0x533f4f[_0x4507a0('0x3a')]('password')?(_0x533f4f[_0x4507a0('0x44')](),_0x533f4f[_0x4507a0('0xb')]()):Promise[_0x4507a0('0x45')]();},'afterCreate':function(_0x55119b){const _0x5cf562=_0x3aee57;let _0x14213e=addUserApplication(_0x55119b,_0x55119b[_0x5cf562('0x1')]);return _0x55119b[_0x5cf562('0x1')]!=_0x55119b[_0x5cf562('0x20')]&&(_0x14213e=_0x14213e[_0x5cf562('0x1e')](addUserApplication(_0x55119b,_0x55119b[_0x5cf562('0x20')]))),_0x1a4463[_0x5cf562('0xc')][_0x5cf562('0x1b')](_0x14213e)[_0x5cf562('0x38')](function(){const _0x398876=_0x5cf562;if(_0x55119b[_0x398876('0x36')])return getChanSpy(_0x1a4463,_0x55119b);})['then'](function(_0x26037f){const _0x1e6772=_0x5cf562;return _0x26037f&&_0x26037f[_0x1e6772('0x21')]?_0x1a4463[_0x1e6772('0xc')][_0x1e6772('0x1b')](_0x26037f):null;})[_0x5cf562('0x34')](function(_0x3fac5b){return _0x3fac5b;});},'afterUpdate':function(_0x4873c0){const _0xbc2625=_0x3aee57;return Promise[_0xbc2625('0x45')]()['then'](function(){const _0x3d8583=_0xbc2625;if(_0x4873c0['changed']('chanspy')||_0x4873c0[_0x3d8583('0x3a')](_0x3d8583('0x10')))return _0x1a4463[_0x3d8583('0xc')][_0x3d8583('0x35')]({'where':{'UserId':_0x4873c0['id'],'type':_0x3d8583('0x39'),'ChanSpyId':{[Op['ne']]:null}}})['then'](function(){const _0x2eb794=_0x3d8583;if(_0x4873c0['chanspy'])return getChanSpy(_0x1a4463,_0x4873c0)[_0x2eb794('0x38')](function(_0x2cccbc){const _0x5261b2=_0x2eb794;if(_0x2cccbc&&_0x2cccbc[_0x5261b2('0x21')])return _0x1a4463['VoiceExtension'][_0x5261b2('0x1b')](_0x2cccbc);});});})[_0xbc2625('0x38')](function(){const _0x4f3d67=_0xbc2625;return _0x4873c0[_0x4f3d67('0x3a')](_0x4f3d67('0xa'))||_0x4873c0[_0x4f3d67('0x3a')](_0x4f3d67('0x10'))?_0x1a4463[_0x4f3d67('0xc')][_0x4f3d67('0x35')]({'where':{'UserId':_0x4873c0['id'],'type':_0x4f3d67('0x39'),'ChanSpyId':null}})[_0x4f3d67('0x38')](function(){const _0x52068a=_0x4f3d67;let _0x2938d0=addUserApplication(_0x4873c0,_0x4873c0[_0x52068a('0x1')]);return _0x4873c0['internal']!=_0x4873c0[_0x52068a('0x20')]&&(_0x2938d0=_0x2938d0['concat'](addUserApplication(_0x4873c0,_0x4873c0[_0x52068a('0x20')]))),_0x1a4463[_0x52068a('0xc')][_0x52068a('0x1b')](_0x2938d0);}):null;})[_0xbc2625('0x34')](function(_0x536b70){return _0x536b70;});},'afterDestroy':function(_0x1286ac){const _0x4dbdf4=_0x3aee57;return _0x1a4463[_0x4dbdf4('0xc')]['destroy']({'where':{'UserId':_0x1286ac['id'],'type':_0x4dbdf4('0x39')}});}},'charset':_0x3aee57('0x3'),'collate':_0x3aee57('0x26')});return _0x34f44d[_0x3aee57('0x1a')][_0x3aee57('0x3d')]=function(_0x1e0ffd,_0x42e4d6){const _0x14d048=_0x3aee57;if(!_0x42e4d6)return this['password']===this[_0x14d048('0x3b')](_0x1e0ffd);const _0x12b71f=this;this['encryptPassword'](_0x1e0ffd,function(_0xb2e28e,_0x48a4d1){const _0x280d5f=_0x14d048;_0xb2e28e&&_0x42e4d6(_0xb2e28e),_0x12b71f[_0x280d5f('0x24')]===_0x48a4d1?_0x42e4d6(null,!![]):_0x42e4d6(null,![]);});},_0x34f44d[_0x3aee57('0x1a')]['makeSalt']=function(_0x12c93c,_0x183b68){const _0x19fa40=_0x3aee57,_0x574271=0x10;if(typeof arguments[0x0]===_0x19fa40('0x1c'))_0x183b68=arguments[0x0],_0x12c93c=_0x574271;else{if(typeof arguments[0x1]==='function')_0x183b68=arguments[0x1];else throw new Error(_0x19fa40('0x43'));}return!_0x12c93c&&(_0x12c93c=_0x574271),crypto[_0x19fa40('0x29')](_0x12c93c,function(_0x12df09,_0x3744a9){const _0x2ed5d2=_0x19fa40;return _0x12df09&&_0x183b68(_0x12df09),_0x183b68(null,_0x3744a9[_0x2ed5d2('0x12')](_0x2ed5d2('0x28')));});},_0x34f44d['prototype'][_0x3aee57('0x2e')]=async function(_0x181dbe=0x10){return new Promise((_0x344c91,_0x567dcd)=>{const _0x24fadc=a650_0x5517;crypto[_0x24fadc('0x29')](_0x181dbe,function(_0x2dfade,_0x569226){const _0x2aa55a=_0x24fadc;return _0x2dfade&&_0x567dcd(_0x2dfade),_0x344c91(_0x569226[_0x2aa55a('0x12')](_0x2aa55a('0x28')));});});},_0x34f44d[_0x3aee57('0x1a')][_0x3aee57('0x3b')]=function(_0x1c14d2,_0x5a98b3){const _0x3126ff=_0x3aee57;if(!_0x1c14d2||!this[_0x3126ff('0x42')])return _0x5a98b3?_0x5a98b3(null):null;const _0xe540ec=0x2710,_0x130c0f=0x40,_0xca264c=Buffer['from'](this[_0x3126ff('0x42')],_0x3126ff('0x28'));if(!_0x5a98b3)return crypto['pbkdf2Sync'](_0x1c14d2,_0xca264c,_0xe540ec,_0x130c0f,_0x3126ff('0x11'))[_0x3126ff('0x12')](_0x3126ff('0x28'));return crypto[_0x3126ff('0x15')](_0x1c14d2,_0xca264c,_0xe540ec,_0x130c0f,_0x3126ff('0x11'),function(_0x50a703,_0x7d6b26){const _0x30f85d=_0x3126ff;return _0x50a703&&_0x5a98b3(_0x50a703),_0x5a98b3(null,_0x7d6b26[_0x30f85d('0x12')](_0x30f85d('0x28')));});},_0x34f44d[_0x3aee57('0x1a')][_0x3aee57('0xb')]=async function(){const _0x50b752=_0x3aee57;if(!this[_0x50b752('0x24')])return null;if(!_['isEmpty'](this[_0x50b752('0x24')])&&authTypes['indexOf'](this[_0x50b752('0x37')])===-0x1)throw new Error(_0x50b752('0x3c'));return this[_0x50b752('0x42')]=await this[_0x50b752('0x2e')](),new Promise((_0x1796dd,_0x166533)=>{const _0x32f537=_0x50b752;this[_0x32f537('0x3b')](this[_0x32f537('0x24')],(_0x12656b,_0x5e3ab8)=>{const _0x272840=_0x32f537;_0x12656b?_0x166533(_0x12656b):(this[_0x272840('0x24')]=_0x5e3ab8,_0x1796dd());});});},_0x34f44d[_0x3aee57('0x1a')]['updateMd5Password']=function(){const _0x162db5=_0x3aee57;this[_0x162db5('0x1d')]=md5(this[_0x162db5('0x20')]+':asterisk:'+this['password']);},_0x34f44d;};