Built motion from commit (unavailable).|2.5.4
[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 _0xff77=['use','clientID','clientSecret','callbackURL','findOne','allowedLoginAttempts','then','find','value','admin','agent','disabled','Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.','blockDuration','blocked','add','minutes','clearBlockUser','getLicense','passport-google-oauth20','Strategy','../../config/environment','../../components/auth/service','signToken','login','google','email','callback','/login'];(function(_0x355c3b,_0xae147a){var _0xcf072=function(_0x37dea0){while(--_0x37dea0){_0x355c3b['push'](_0x355c3b['shift']());}};_0xcf072(++_0xae147a);}(_0xff77,0x1c6));var _0x7ff7=function(_0xbf806a,_0x138c27){_0xbf806a=_0xbf806a-0x0;var _0x2c8f13=_0xff77[_0xbf806a];return _0x2c8f13;};'use strict';var _=require('lodash');var passport=require('passport');var GoogleStrategy=require(_0x7ff7('0x0'))[_0x7ff7('0x1')];var moment=require('moment');var db=require('../../mysqldb')['db'];var config=require(_0x7ff7('0x2'));var signToken=require(_0x7ff7('0x3'))[_0x7ff7('0x4')];var utils=require('../../config/utils');exports[_0x7ff7('0x5')]=passport['authenticate'](_0x7ff7('0x6'),{'failureRedirect':'/login','scope':['profile',_0x7ff7('0x7')],'session':![]});exports[_0x7ff7('0x8')]=passport['authenticate']('google',{'failureRedirect':_0x7ff7('0x9'),'session':![]});passport[_0x7ff7('0xa')](new GoogleStrategy({'clientID':config[_0x7ff7('0x6')]?config['google'][_0x7ff7('0xb')]:'id','clientSecret':config[_0x7ff7('0x6')]?config[_0x7ff7('0x6')][_0x7ff7('0xc')]:'secret','callbackURL':config['google']?config['google'][_0x7ff7('0xd')]:''},function(_0x117be2,_0x2e79b0,_0x360439,_0x1b120e){var _0x57ed11,_0x24fbda;return db['Setting'][_0x7ff7('0xe')]({'where':{'id':0x1},'attributes':[_0x7ff7('0xf'),'blockDuration'],'raw':!![]})[_0x7ff7('0x10')](function(_0x53f307){_0x57ed11=_0x53f307;return db['User'][_0x7ff7('0x11')]({'where':{'email':_['map'](_0x360439['emails'],_0x7ff7('0x12')),'role':{'$or':[_0x7ff7('0x13'),'user',_0x7ff7('0x14')]}}});})[_0x7ff7('0x10')](function(_0x557cba){_0x24fbda=_0x557cba;if(_0x24fbda){if(_0x24fbda[_0x7ff7('0x15')]){return _0x1b120e(_0x7ff7('0x16'));}else if(_0x57ed11[_0x7ff7('0x17')]>0x0){if(_0x24fbda[_0x7ff7('0x18')]){if(moment(_0x24fbda['blockedAt'])[_0x7ff7('0x19')](_0x57ed11[_0x7ff7('0x17')],_0x7ff7('0x1a'))>moment()){return _0x1b120e(_0x7ff7('0x16'));}else{return utils[_0x7ff7('0x1b')](_0x24fbda,0x0,![],null)['then'](function(){return utils[_0x7ff7('0x1c')](_0x24fbda);})['then'](function(){return _0x1b120e(null,_0x24fbda);});}}else{return utils[_0x7ff7('0x1c')](_0x24fbda)[_0x7ff7('0x10')](function(){return _0x1b120e(null,_0x24fbda);});}}else{return utils[_0x7ff7('0x1c')](_0x24fbda)[_0x7ff7('0x10')](function(){return _0x1b120e(null,_0x24fbda);});}}return _0x1b120e(_0x7ff7('0x16'));})['catch'](function(_0x58e940){_0x1b120e(_0x58e940);});}));