2e1d193441bf4721a5bb5f3ec6bd0a92278e2246
[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 _0x7d3e=['moment','../../config/environment','../../components/auth/service','../../config/utils','/login','email','callback','authenticate','google','use','clientID','clientSecret','findOne','allowedLoginAttempts','User','find','map','emails','value','then','Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.','blockDuration','blocked','blockedAt','add','minutes','getLicense','catch','lodash','passport','passport-google-oauth20'];(function(_0xca073c,_0x5030ae){var _0x5187f4=function(_0x2c4411){while(--_0x2c4411){_0xca073c['push'](_0xca073c['shift']());}};_0x5187f4(++_0x5030ae);}(_0x7d3e,0x152));var _0xe7d3=function(_0x3762cd,_0x43838a){_0x3762cd=_0x3762cd-0x0;var _0x29b8e9=_0x7d3e[_0x3762cd];return _0x29b8e9;};'use strict';var _=require(_0xe7d3('0x0'));var passport=require(_0xe7d3('0x1'));var GoogleStrategy=require(_0xe7d3('0x2'))['Strategy'];var moment=require(_0xe7d3('0x3'));var db=require('../../mysqldb')['db'];var config=require(_0xe7d3('0x4'));var signToken=require(_0xe7d3('0x5'))['signToken'];var utils=require(_0xe7d3('0x6'));exports['login']=passport['authenticate']('google',{'failureRedirect':_0xe7d3('0x7'),'scope':['profile',_0xe7d3('0x8')],'session':![]});exports[_0xe7d3('0x9')]=passport[_0xe7d3('0xa')](_0xe7d3('0xb'),{'failureRedirect':_0xe7d3('0x7'),'session':![]});passport[_0xe7d3('0xc')](new GoogleStrategy({'clientID':config[_0xe7d3('0xb')]?config[_0xe7d3('0xb')][_0xe7d3('0xd')]:'id','clientSecret':config['google']?config['google'][_0xe7d3('0xe')]:'secret','callbackURL':config[_0xe7d3('0xb')]?config['google']['callbackURL']:''},function(_0x968deb,_0x3a4f9e,_0x5abf1e,_0x432282){var _0x258d1c,_0xb6af64;return db['Setting'][_0xe7d3('0xf')]({'where':{'id':0x1},'attributes':[_0xe7d3('0x10'),'blockDuration'],'raw':!![]})['then'](function(_0x3ec48b){_0x258d1c=_0x3ec48b;return db[_0xe7d3('0x11')][_0xe7d3('0x12')]({'where':{'email':_[_0xe7d3('0x13')](_0x5abf1e[_0xe7d3('0x14')],_0xe7d3('0x15')),'role':{'$or':['admin','user','agent']}}});})[_0xe7d3('0x16')](function(_0x41b38b){_0xb6af64=_0x41b38b;if(_0xb6af64){if(_0xb6af64['disabled']){return _0x432282(_0xe7d3('0x17'));}else if(_0x258d1c[_0xe7d3('0x18')]>0x0){if(_0xb6af64[_0xe7d3('0x19')]){if(moment(_0xb6af64[_0xe7d3('0x1a')])[_0xe7d3('0x1b')](_0x258d1c[_0xe7d3('0x18')],_0xe7d3('0x1c'))>moment()){return _0x432282(_0xe7d3('0x17'));}else{return utils['clearBlockUser'](_0xb6af64,0x0,![],null)[_0xe7d3('0x16')](function(){return utils[_0xe7d3('0x1d')](_0xb6af64);})[_0xe7d3('0x16')](function(){return _0x432282(null,_0xb6af64);});}}else{return utils[_0xe7d3('0x1d')](_0xb6af64)[_0xe7d3('0x16')](function(){return _0x432282(null,_0xb6af64);});}}else{return utils[_0xe7d3('0x1d')](_0xb6af64)['then'](function(){return _0x432282(null,_0xb6af64);});}}return _0x432282(_0xe7d3('0x17'));})[_0xe7d3('0x1e')](function(_0x3462e2){_0x432282(_0x3462e2);});}));