Built motion from commit 19a84241.|2.5.34
[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 _0x0dcf=['Strategy','moment','../../mysqldb','../../config/environment','signToken','../../config/utils','authenticate','/login','google','use','secret','callbackURL','findOne','blockDuration','then','User','find','map','emails','value','admin','user','disabled','Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.','blocked','blockedAt','add','minutes','getLicense','lodash','passport'];(function(_0x16bd8d,_0x5285b1){var _0x32dc3f=function(_0x20badf){while(--_0x20badf){_0x16bd8d['push'](_0x16bd8d['shift']());}};_0x32dc3f(++_0x5285b1);}(_0x0dcf,0x191));var _0xf0dc=function(_0x358a32,_0x2f05c5){_0x358a32=_0x358a32-0x0;var _0x2e11ff=_0x0dcf[_0x358a32];return _0x2e11ff;};'use strict';var _=require(_0xf0dc('0x0'));var passport=require(_0xf0dc('0x1'));var GoogleStrategy=require('passport-google-oauth20')[_0xf0dc('0x2')];var moment=require(_0xf0dc('0x3'));var db=require(_0xf0dc('0x4'))['db'];var config=require(_0xf0dc('0x5'));var signToken=require('../../components/auth/service')[_0xf0dc('0x6')];var utils=require(_0xf0dc('0x7'));exports['login']=passport[_0xf0dc('0x8')]('google',{'failureRedirect':_0xf0dc('0x9'),'scope':['profile','email'],'session':![]});exports['callback']=passport[_0xf0dc('0x8')](_0xf0dc('0xa'),{'failureRedirect':_0xf0dc('0x9'),'session':![]});passport[_0xf0dc('0xb')](new GoogleStrategy({'clientID':config[_0xf0dc('0xa')]?config[_0xf0dc('0xa')]['clientID']:'id','clientSecret':config['google']?config[_0xf0dc('0xa')]['clientSecret']:_0xf0dc('0xc'),'callbackURL':config[_0xf0dc('0xa')]?config[_0xf0dc('0xa')][_0xf0dc('0xd')]:''},function(_0x16e7da,_0x3a19dd,_0x514b5c,_0x18a391){var _0x54e703,_0x1707f8;return db['Setting'][_0xf0dc('0xe')]({'where':{'id':0x1},'attributes':['allowedLoginAttempts',_0xf0dc('0xf')],'raw':!![]})[_0xf0dc('0x10')](function(_0x24604f){_0x54e703=_0x24604f;return db[_0xf0dc('0x11')][_0xf0dc('0x12')]({'where':{'email':_[_0xf0dc('0x13')](_0x514b5c[_0xf0dc('0x14')],_0xf0dc('0x15')),'role':{'$or':[_0xf0dc('0x16'),_0xf0dc('0x17'),'agent']}}});})[_0xf0dc('0x10')](function(_0xcf6fd2){_0x1707f8=_0xcf6fd2;if(_0x1707f8){if(_0x1707f8[_0xf0dc('0x18')]){return _0x18a391(_0xf0dc('0x19'));}else if(_0x54e703['blockDuration']>0x0){if(_0x1707f8[_0xf0dc('0x1a')]){if(moment(_0x1707f8[_0xf0dc('0x1b')])[_0xf0dc('0x1c')](_0x54e703[_0xf0dc('0xf')],_0xf0dc('0x1d'))>moment()){return _0x18a391('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}else{return utils['clearBlockUser'](_0x1707f8,0x0,![],null)[_0xf0dc('0x10')](function(){return utils[_0xf0dc('0x1e')](_0x1707f8);})['then'](function(){return _0x18a391(null,_0x1707f8);});}}else{return utils['getLicense'](_0x1707f8)[_0xf0dc('0x10')](function(){return _0x18a391(null,_0x1707f8);});}}else{return utils[_0xf0dc('0x1e')](_0x1707f8)[_0xf0dc('0x10')](function(){return _0x18a391(null,_0x1707f8);});}}return _0x18a391(_0xf0dc('0x19'));})['catch'](function(_0x3a4770){_0x18a391(_0x3a4770);});}));