b6a9ee9251c8b3c3c7381d1a5e5cd44201d84e78
[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 _0x59e0=['User','admin','user','then','disabled','Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.','blockDuration','blockedAt','clearBlockUser','getLicense','passport','passport-google-oauth20','Strategy','moment','signToken','login','authenticate','google','/login','profile','email','callback','use','clientID','clientSecret','secret','callbackURL','allowedLoginAttempts'];(function(_0x3a062d,_0x503f80){var _0x2c5410=function(_0x1a5d54){while(--_0x1a5d54){_0x3a062d['push'](_0x3a062d['shift']());}};_0x2c5410(++_0x503f80);}(_0x59e0,0x1e6));var _0x059e=function(_0x61ed56,_0x4d394a){_0x61ed56=_0x61ed56-0x0;var _0x224ba8=_0x59e0[_0x61ed56];return _0x224ba8;};'use strict';var _=require('lodash');var passport=require(_0x059e('0x0'));var GoogleStrategy=require(_0x059e('0x1'))[_0x059e('0x2')];var moment=require(_0x059e('0x3'));var db=require('../../mysqldb')['db'];var config=require('../../config/environment');var signToken=require('../../components/auth/service')[_0x059e('0x4')];var utils=require('../../config/utils');exports[_0x059e('0x5')]=passport[_0x059e('0x6')](_0x059e('0x7'),{'failureRedirect':_0x059e('0x8'),'scope':[_0x059e('0x9'),_0x059e('0xa')],'session':![]});exports[_0x059e('0xb')]=passport[_0x059e('0x6')](_0x059e('0x7'),{'failureRedirect':'/login','session':![]});passport[_0x059e('0xc')](new GoogleStrategy({'clientID':config[_0x059e('0x7')]?config[_0x059e('0x7')][_0x059e('0xd')]:'id','clientSecret':config[_0x059e('0x7')]?config['google'][_0x059e('0xe')]:_0x059e('0xf'),'callbackURL':config[_0x059e('0x7')]?config['google'][_0x059e('0x10')]:''},function(_0x288e0c,_0x48f1df,_0x414ff7,_0x3adcc9){var _0x49679a,_0x416eb7;return db['Setting']['findOne']({'where':{'id':0x1},'attributes':[_0x059e('0x11'),'blockDuration'],'raw':!![]})['then'](function(_0x9adcac){_0x49679a=_0x9adcac;return db[_0x059e('0x12')]['find']({'where':{'email':_['map'](_0x414ff7['emails'],'value'),'role':{'$or':[_0x059e('0x13'),_0x059e('0x14'),'agent']}}});})[_0x059e('0x15')](function(_0x362262){_0x416eb7=_0x362262;if(_0x416eb7){if(_0x416eb7[_0x059e('0x16')]){return _0x3adcc9(_0x059e('0x17'));}else if(_0x49679a[_0x059e('0x18')]>0x0){if(_0x416eb7['blocked']){if(moment(_0x416eb7[_0x059e('0x19')])['add'](_0x49679a['blockDuration'],'minutes')>moment()){return _0x3adcc9(_0x059e('0x17'));}else{return utils[_0x059e('0x1a')](_0x416eb7,0x0,![],null)['then'](function(){return utils[_0x059e('0x1b')](_0x416eb7);})[_0x059e('0x15')](function(){return _0x3adcc9(null,_0x416eb7);});}}else{return utils[_0x059e('0x1b')](_0x416eb7)[_0x059e('0x15')](function(){return _0x3adcc9(null,_0x416eb7);});}}else{return utils['getLicense'](_0x416eb7)[_0x059e('0x15')](function(){return _0x3adcc9(null,_0x416eb7);});}}return _0x3adcc9(_0x059e('0x17'));})['catch'](function(_0x5aab7d){_0x3adcc9(_0x5aab7d);});}));