Built motion from commit 522ec06.|0.0.85
[motion.git] / server / auth / auth.service.js
1 var _0x2bcc=["\x75\x73\x65\x20\x73\x74\x72\x69\x63\x74","\x70\x61\x73\x73\x70\x6F\x72\x74","\x2E\x2E\x2F\x63\x6F\x6E\x66\x69\x67\x2F\x65\x6E\x76\x69\x72\x6F\x6E\x6D\x65\x6E\x74","\x6A\x73\x6F\x6E\x77\x65\x62\x74\x6F\x6B\x65\x6E","\x65\x78\x70\x72\x65\x73\x73\x2D\x6A\x77\x74","\x63\x6F\x6D\x70\x6F\x73\x61\x62\x6C\x65\x2D\x6D\x69\x64\x64\x6C\x65\x77\x61\x72\x65","\x55\x73\x65\x72","\x2E\x2E\x2F\x6D\x6F\x64\x65\x6C\x73","\x4C\x69\x73\x74","\x73\x65\x63\x72\x65\x74","\x73\x65\x73\x73\x69\x6F\x6E","\x63\x61\x74\x63\x68","\x73\x65\x6E\x64\x53\x74\x61\x74\x75\x73","\x75\x73\x65\x72","\x74\x68\x65\x6E","\x69\x64","\x66\x69\x6E\x64\x42\x79\x49\x64","\x75\x73\x65","\x71\x75\x65\x72\x79","\x61\x63\x63\x65\x73\x73\x5F\x74\x6F\x6B\x65\x6E","\x68\x61\x73\x4F\x77\x6E\x50\x72\x6F\x70\x65\x72\x74\x79","\x61\x75\x74\x68\x6F\x72\x69\x7A\x61\x74\x69\x6F\x6E","\x68\x65\x61\x64\x65\x72\x73","\x42\x65\x61\x72\x65\x72\x20","\x52\x65\x71\x75\x69\x72\x65\x64\x20\x72\x6F\x6C\x65\x20\x6E\x65\x65\x64\x73\x20\x74\x6F\x20\x62\x65\x20\x73\x65\x74","\x72\x6F\x6C\x65","\x69\x6E\x64\x65\x78\x4F\x66","\x75\x73\x65\x72\x52\x6F\x6C\x65\x73","\x31\x64","\x73\x69\x67\x6E","\x53\x6F\x6D\x65\x74\x68\x69\x6E\x67\x20\x77\x65\x6E\x74\x20\x77\x72\x6F\x6E\x67\x2C\x20\x70\x6C\x65\x61\x73\x65\x20\x74\x72\x79\x20\x61\x67\x61\x69\x6E\x2E","\x6A\x73\x6F\x6E","\x74\x6F\x6B\x65\x6E","\x73\x74\x72\x69\x6E\x67\x69\x66\x79","\x63\x6F\x6F\x6B\x69\x65","\x2F","\x72\x65\x64\x69\x72\x65\x63\x74","\x69\x73\x41\x75\x74\x68\x65\x6E\x74\x69\x63\x61\x74\x65\x64","\x68\x61\x73\x52\x6F\x6C\x65","\x73\x69\x67\x6E\x54\x6F\x6B\x65\x6E","\x73\x65\x74\x54\x6F\x6B\x65\x6E\x43\x6F\x6F\x6B\x69\x65"];_0x2bcc[0];var passport=require(_0x2bcc[1]);var config=require(_0x2bcc[2]);var jwt=require(_0x2bcc[3]);var expressJwt=require(_0x2bcc[4]);var compose=require(_0x2bcc[5]);var User=require(_0x2bcc[7])[_0x2bcc[6]];var List=require(_0x2bcc[7])[_0x2bcc[8]];var validateJwt=expressJwt({secret:config[_0x2bcc[10]][_0x2bcc[9]]});function isAuthenticated(){return compose()[_0x2bcc[17]](function(_0x42a3xa,_0x42a3xb,_0x42a3xc){if(_0x42a3xa[_0x2bcc[18]]&&_0x42a3xa[_0x2bcc[18]][_0x2bcc[20]](_0x2bcc[19])){_0x42a3xa[_0x2bcc[22]][_0x2bcc[21]]=_0x2bcc[23]+_0x42a3xa[_0x2bcc[18]][_0x2bcc[19]]};validateJwt(_0x42a3xa,_0x42a3xb,_0x42a3xc)})[_0x2bcc[17]](function(_0x42a3xa,_0x42a3xb,_0x42a3xc){User[_0x2bcc[16]](_0x42a3xa[_0x2bcc[13]][_0x2bcc[15]],{include:[{model:List}]})[_0x2bcc[14]](function(_0x42a3xe){if(!_0x42a3xe){return _0x42a3xb[_0x2bcc[12]](401)};_0x42a3xa[_0x2bcc[13]]=_0x42a3xe;return _0x42a3xc()})[_0x2bcc[11]](function(_0x42a3xd){return _0x42a3xc(_0x42a3xd)})})}function hasRole(_0x42a3x10){if(!_0x42a3x10){throw  new Error(_0x2bcc[24])};return compose()[_0x2bcc[17]](isAuthenticated())[_0x2bcc[17]](function _0x42a3x11(_0x42a3xa,_0x42a3xb,_0x42a3xc){if(config[_0x2bcc[27]][_0x2bcc[26]](_0x42a3xa[_0x2bcc[13]][_0x2bcc[25]])>=config[_0x2bcc[27]][_0x2bcc[26]](_0x42a3x10)){return _0x42a3xc()}else {return _0x42a3xb[_0x2bcc[12]](403)}})}function signToken(_0x42a3x13,_0x42a3x14,_0x42a3x15){var _0x42a3x16=60*24*365*5;if(!_0x42a3x15){_0x42a3x16=_0x2bcc[28]};return jwt[_0x2bcc[29]]({id:_0x42a3x13},config[_0x2bcc[10]][_0x2bcc[9]],{expiresIn:_0x42a3x16})}function setTokenCookie(_0x42a3xa,_0x42a3xb){if(!_0x42a3xa[_0x2bcc[13]]){return _0x42a3xb[_0x2bcc[31]](404,{message:_0x2bcc[30]})};var _0x42a3x18=signToken(_0x42a3xa[_0x2bcc[13]][_0x2bcc[15]],_0x42a3xa[_0x2bcc[13]][_0x2bcc[25]]);_0x42a3xb[_0x2bcc[34]](_0x2bcc[32],JSON[_0x2bcc[33]](_0x42a3x18));_0x42a3xb[_0x2bcc[36]](_0x2bcc[35])}exports[_0x2bcc[37]]=isAuthenticated;exports[_0x2bcc[38]]=hasRole;exports[_0x2bcc[39]]=signToken;exports[_0x2bcc[40]]=setTokenCookie