eb0d325c531af85a527849c58c5b03d0e385b2d5
[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 _0x181f=['/login','profile','email','use','clientID','clientSecret','callbackURL','Setting','findOne','allowedLoginAttempts','blockDuration','then','map','emails','user','disabled','Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.','blocked','add','getLicense','catch','lodash','passport','passport-google-oauth20','moment','../../config/environment','../../components/auth/service','signToken','login','authenticate','google'];(function(_0xfda361,_0xbbbe96){var _0x1495ea=function(_0x5cc7f7){while(--_0x5cc7f7){_0xfda361['push'](_0xfda361['shift']());}};_0x1495ea(++_0xbbbe96);}(_0x181f,0x1e6));var _0xf181=function(_0x513ac6,_0x2cef0f){_0x513ac6=_0x513ac6-0x0;var _0x162c0e=_0x181f[_0x513ac6];return _0x162c0e;};'use strict';var _=require(_0xf181('0x0'));var passport=require(_0xf181('0x1'));var GoogleStrategy=require(_0xf181('0x2'))['Strategy'];var moment=require(_0xf181('0x3'));var db=require('../../mysqldb')['db'];var config=require(_0xf181('0x4'));var signToken=require(_0xf181('0x5'))[_0xf181('0x6')];var utils=require('../../config/utils');exports[_0xf181('0x7')]=passport[_0xf181('0x8')](_0xf181('0x9'),{'failureRedirect':_0xf181('0xa'),'scope':[_0xf181('0xb'),_0xf181('0xc')],'session':![]});exports['callback']=passport[_0xf181('0x8')]('google',{'failureRedirect':_0xf181('0xa'),'session':![]});passport[_0xf181('0xd')](new GoogleStrategy({'clientID':config[_0xf181('0x9')]?config[_0xf181('0x9')][_0xf181('0xe')]:'id','clientSecret':config[_0xf181('0x9')]?config[_0xf181('0x9')][_0xf181('0xf')]:'secret','callbackURL':config[_0xf181('0x9')]?config[_0xf181('0x9')][_0xf181('0x10')]:''},function(_0x2ea39a,_0x3bd206,_0x13bd2a,_0x2f32f6){var _0x33c5ba,_0x5066da;return db[_0xf181('0x11')][_0xf181('0x12')]({'where':{'id':0x1},'attributes':[_0xf181('0x13'),_0xf181('0x14')],'raw':!![]})[_0xf181('0x15')](function(_0xb652d1){_0x33c5ba=_0xb652d1;return db['User']['find']({'where':{'email':_[_0xf181('0x16')](_0x13bd2a[_0xf181('0x17')],'value'),'role':{'$or':['admin',_0xf181('0x18'),'agent']}}});})[_0xf181('0x15')](function(_0x15945c){_0x5066da=_0x15945c;if(_0x5066da){if(_0x5066da[_0xf181('0x19')]){return _0x2f32f6(_0xf181('0x1a'));}else if(_0x33c5ba[_0xf181('0x14')]>0x0){if(_0x5066da[_0xf181('0x1b')]){if(moment(_0x5066da['blockedAt'])[_0xf181('0x1c')](_0x33c5ba[_0xf181('0x14')],'minutes')>moment()){return _0x2f32f6(_0xf181('0x1a'));}else{return utils['clearBlockUser'](_0x5066da,0x0,![],null)[_0xf181('0x15')](function(){return utils[_0xf181('0x1d')](_0x5066da);})[_0xf181('0x15')](function(){return _0x2f32f6(null,_0x5066da);});}}else{return utils[_0xf181('0x1d')](_0x5066da)['then'](function(){return _0x2f32f6(null,_0x5066da);});}}else{return utils[_0xf181('0x1d')](_0x5066da)['then'](function(){return _0x2f32f6(null,_0x5066da);});}}return _0x2f32f6(_0xf181('0x1a'));})[_0xf181('0x1e')](function(_0x14bb49){_0x2f32f6(_0x14bb49);});}));