Built motion from commit (unavailable).|2.4.4
[motion2.git] / server / api / authGoogle / authGoogle.controller.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x30bc=['../../mysqldb','../../config/environment','../../components/auth/service','signToken','../../config/utils','login','authenticate','google','/login','email','callback','use','clientID','clientSecret','secret','callbackURL','Setting','allowedLoginAttempts','User','map','emails','value','admin','agent','then','disabled','Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.','blockDuration','blockedAt','add','minutes','clearBlockUser','getLicense','lodash','passport','passport-google-oauth20','moment'];(function(_0x15797a,_0x16274f){var _0x3e2618=function(_0x2b6e99){while(--_0x2b6e99){_0x15797a['push'](_0x15797a['shift']());}};_0x3e2618(++_0x16274f);}(_0x30bc,0x149));var _0xc30b=function(_0x36856f,_0x98b59e){_0x36856f=_0x36856f-0x0;var _0x43ac52=_0x30bc[_0x36856f];return _0x43ac52;};'use strict';var _=require(_0xc30b('0x0'));var passport=require(_0xc30b('0x1'));var GoogleStrategy=require(_0xc30b('0x2'))['Strategy'];var moment=require(_0xc30b('0x3'));var db=require(_0xc30b('0x4'))['db'];var config=require(_0xc30b('0x5'));var signToken=require(_0xc30b('0x6'))[_0xc30b('0x7')];var utils=require(_0xc30b('0x8'));exports[_0xc30b('0x9')]=passport[_0xc30b('0xa')](_0xc30b('0xb'),{'failureRedirect':_0xc30b('0xc'),'scope':['profile',_0xc30b('0xd')],'session':![]});exports[_0xc30b('0xe')]=passport[_0xc30b('0xa')](_0xc30b('0xb'),{'failureRedirect':'/login','session':![]});passport[_0xc30b('0xf')](new GoogleStrategy({'clientID':config['google']?config[_0xc30b('0xb')][_0xc30b('0x10')]:'id','clientSecret':config['google']?config['google'][_0xc30b('0x11')]:_0xc30b('0x12'),'callbackURL':config[_0xc30b('0xb')]?config[_0xc30b('0xb')][_0xc30b('0x13')]:''},function(_0x41210d,_0x597c8d,_0x32f7f0,_0x3e155a){var _0x4d72a2,_0x15b529;return db[_0xc30b('0x14')]['findOne']({'where':{'id':0x1},'attributes':[_0xc30b('0x15'),'blockDuration'],'raw':!![]})['then'](function(_0x4d7725){_0x4d72a2=_0x4d7725;return db[_0xc30b('0x16')]['find']({'where':{'email':_[_0xc30b('0x17')](_0x32f7f0[_0xc30b('0x18')],_0xc30b('0x19')),'role':{'$or':[_0xc30b('0x1a'),'user',_0xc30b('0x1b')]}}});})[_0xc30b('0x1c')](function(_0x1cd5de){_0x15b529=_0x1cd5de;if(_0x15b529){if(_0x15b529[_0xc30b('0x1d')]){return _0x3e155a(_0xc30b('0x1e'));}else if(_0x4d72a2[_0xc30b('0x1f')]>0x0){if(_0x15b529['blocked']){if(moment(_0x15b529[_0xc30b('0x20')])[_0xc30b('0x21')](_0x4d72a2[_0xc30b('0x1f')],_0xc30b('0x22'))>moment()){return _0x3e155a(_0xc30b('0x1e'));}else{return utils[_0xc30b('0x23')](_0x15b529,0x0,![],null)[_0xc30b('0x1c')](function(){return utils['getLicense'](_0x15b529);})[_0xc30b('0x1c')](function(){return _0x3e155a(null,_0x15b529);});}}else{return utils['getLicense'](_0x15b529)[_0xc30b('0x1c')](function(){return _0x3e155a(null,_0x15b529);});}}else{return utils[_0xc30b('0x24')](_0x15b529)[_0xc30b('0x1c')](function(){return _0x3e155a(null,_0x15b529);});}}return _0x3e155a(_0xc30b('0x1e'));})['catch'](function(_0x1ed77f){_0x3e155a(_0x1ed77f);});}));