57625c82d21682c5a2aee119b2944693685f4f2b
[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 _0xd7b8=['../../config/environment','signToken','../../config/utils','login','authenticate','/login','email','callback','google','use','clientID','clientSecret','Setting','findOne','allowedLoginAttempts','blockDuration','find','map','emails','value','admin','user','agent','then','add','Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.','clearBlockUser','getLicense','catch','lodash','passport','passport-google-oauth20','Strategy','moment','../../mysqldb'];(function(_0x432682,_0x253044){var _0x463d05=function(_0xa73403){while(--_0xa73403){_0x432682['push'](_0x432682['shift']());}};_0x463d05(++_0x253044);}(_0xd7b8,0x1e4));var _0x8d7b=function(_0x1834b3,_0x5d7607){_0x1834b3=_0x1834b3-0x0;var _0x396b1c=_0xd7b8[_0x1834b3];return _0x396b1c;};'use strict';var _=require(_0x8d7b('0x0'));var passport=require(_0x8d7b('0x1'));var GoogleStrategy=require(_0x8d7b('0x2'))[_0x8d7b('0x3')];var moment=require(_0x8d7b('0x4'));var db=require(_0x8d7b('0x5'))['db'];var config=require(_0x8d7b('0x6'));var signToken=require('../../components/auth/service')[_0x8d7b('0x7')];var utils=require(_0x8d7b('0x8'));exports[_0x8d7b('0x9')]=passport[_0x8d7b('0xa')]('google',{'failureRedirect':_0x8d7b('0xb'),'scope':['profile',_0x8d7b('0xc')],'session':![]});exports[_0x8d7b('0xd')]=passport[_0x8d7b('0xa')](_0x8d7b('0xe'),{'failureRedirect':_0x8d7b('0xb'),'session':![]});passport[_0x8d7b('0xf')](new GoogleStrategy({'clientID':config[_0x8d7b('0xe')]?config['google'][_0x8d7b('0x10')]:'id','clientSecret':config[_0x8d7b('0xe')]?config[_0x8d7b('0xe')][_0x8d7b('0x11')]:'secret','callbackURL':config[_0x8d7b('0xe')]?config[_0x8d7b('0xe')]['callbackURL']:''},function(_0x29d009,_0x1ea06b,_0x596968,_0x142d88){var _0x3ce3e8,_0x4a6b74;return db[_0x8d7b('0x12')][_0x8d7b('0x13')]({'where':{'id':0x1},'attributes':[_0x8d7b('0x14'),_0x8d7b('0x15')],'raw':!![]})['then'](function(_0x39e4ba){_0x3ce3e8=_0x39e4ba;return db['User'][_0x8d7b('0x16')]({'where':{'email':_[_0x8d7b('0x17')](_0x596968[_0x8d7b('0x18')],_0x8d7b('0x19')),'role':{'$or':[_0x8d7b('0x1a'),_0x8d7b('0x1b'),_0x8d7b('0x1c')]}}});})[_0x8d7b('0x1d')](function(_0x231242){_0x4a6b74=_0x231242;if(_0x4a6b74){if(_0x4a6b74['disabled']){return _0x142d88('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}else if(_0x3ce3e8[_0x8d7b('0x15')]>0x0){if(_0x4a6b74['blocked']){if(moment(_0x4a6b74['blockedAt'])[_0x8d7b('0x1e')](_0x3ce3e8[_0x8d7b('0x15')],'minutes')>moment()){return _0x142d88(_0x8d7b('0x1f'));}else{return utils[_0x8d7b('0x20')](_0x4a6b74,0x0,![],null)[_0x8d7b('0x1d')](function(){return utils[_0x8d7b('0x21')](_0x4a6b74);})[_0x8d7b('0x1d')](function(){return _0x142d88(null,_0x4a6b74);});}}else{return utils[_0x8d7b('0x21')](_0x4a6b74)[_0x8d7b('0x1d')](function(){return _0x142d88(null,_0x4a6b74);});}}else{return utils[_0x8d7b('0x21')](_0x4a6b74)[_0x8d7b('0x1d')](function(){return _0x142d88(null,_0x4a6b74);});}}return _0x142d88(_0x8d7b('0x1f'));})[_0x8d7b('0x22')](function(_0xac93){_0x142d88(_0xac93);});}));