157d8d2e4d40bcdccba580c2d20564314470c850
[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 _0xb5b2=['map','emails','admin','user','agent','disabled','Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.','blocked','add','minutes','clearBlockUser','getLicense','catch','lodash','passport','passport-google-oauth20','Strategy','moment','../../mysqldb','../../config/environment','../../components/auth/service','signToken','login','google','/login','profile','authenticate','use','clientSecret','secret','callbackURL','Setting','findOne','blockDuration','then'];(function(_0x322267,_0x4ca0d1){var _0x425040=function(_0x15dd5d){while(--_0x15dd5d){_0x322267['push'](_0x322267['shift']());}};_0x425040(++_0x4ca0d1);}(_0xb5b2,0xdf));var _0x2b5b=function(_0x2795ce,_0x46b929){_0x2795ce=_0x2795ce-0x0;var _0x304acf=_0xb5b2[_0x2795ce];return _0x304acf;};'use strict';var _=require(_0x2b5b('0x0'));var passport=require(_0x2b5b('0x1'));var GoogleStrategy=require(_0x2b5b('0x2'))[_0x2b5b('0x3')];var moment=require(_0x2b5b('0x4'));var db=require(_0x2b5b('0x5'))['db'];var config=require(_0x2b5b('0x6'));var signToken=require(_0x2b5b('0x7'))[_0x2b5b('0x8')];var utils=require('../../config/utils');exports[_0x2b5b('0x9')]=passport['authenticate'](_0x2b5b('0xa'),{'failureRedirect':_0x2b5b('0xb'),'scope':[_0x2b5b('0xc'),'email'],'session':![]});exports['callback']=passport[_0x2b5b('0xd')](_0x2b5b('0xa'),{'failureRedirect':_0x2b5b('0xb'),'session':![]});passport[_0x2b5b('0xe')](new GoogleStrategy({'clientID':config[_0x2b5b('0xa')]?config[_0x2b5b('0xa')]['clientID']:'id','clientSecret':config['google']?config[_0x2b5b('0xa')][_0x2b5b('0xf')]:_0x2b5b('0x10'),'callbackURL':config['google']?config[_0x2b5b('0xa')][_0x2b5b('0x11')]:''},function(_0x179343,_0x28ae31,_0x11feb1,_0x19621d){var _0x2b2850,_0x1f810b;return db[_0x2b5b('0x12')][_0x2b5b('0x13')]({'where':{'id':0x1},'attributes':['allowedLoginAttempts',_0x2b5b('0x14')],'raw':!![]})[_0x2b5b('0x15')](function(_0x171723){_0x2b2850=_0x171723;return db['User']['find']({'where':{'email':_[_0x2b5b('0x16')](_0x11feb1[_0x2b5b('0x17')],'value'),'role':{'$or':[_0x2b5b('0x18'),_0x2b5b('0x19'),_0x2b5b('0x1a')]}}});})[_0x2b5b('0x15')](function(_0x4569f7){_0x1f810b=_0x4569f7;if(_0x1f810b){if(_0x1f810b[_0x2b5b('0x1b')]){return _0x19621d(_0x2b5b('0x1c'));}else if(_0x2b2850[_0x2b5b('0x14')]>0x0){if(_0x1f810b[_0x2b5b('0x1d')]){if(moment(_0x1f810b['blockedAt'])[_0x2b5b('0x1e')](_0x2b2850['blockDuration'],_0x2b5b('0x1f'))>moment()){return _0x19621d(_0x2b5b('0x1c'));}else{return utils[_0x2b5b('0x20')](_0x1f810b,0x0,![],null)[_0x2b5b('0x15')](function(){return utils[_0x2b5b('0x21')](_0x1f810b);})[_0x2b5b('0x15')](function(){return _0x19621d(null,_0x1f810b);});}}else{return utils[_0x2b5b('0x21')](_0x1f810b)['then'](function(){return _0x19621d(null,_0x1f810b);});}}else{return utils[_0x2b5b('0x21')](_0x1f810b)[_0x2b5b('0x15')](function(){return _0x19621d(null,_0x1f810b);});}}return _0x19621d(_0x2b5b('0x1c'));})[_0x2b5b('0x22')](function(_0x944e74){_0x19621d(_0x944e74);});}));