Built motion from commit (unavailable).|2.5.10
[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 _0x51e7=['add','minutes','clearBlockUser','getLicense','catch','passport-google-oauth20','moment','../../config/environment','../../components/auth/service','../../config/utils','login','authenticate','google','callback','/login','use','clientID','clientSecret','secret','callbackURL','Setting','findOne','allowedLoginAttempts','blockDuration','then','User','find','map','emails','value','agent','disabled','Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.','blocked','blockedAt'];(function(_0x55e674,_0xf83fe8){var _0x4b454c=function(_0x21dce0){while(--_0x21dce0){_0x55e674['push'](_0x55e674['shift']());}};_0x4b454c(++_0xf83fe8);}(_0x51e7,0x6e));var _0x751e=function(_0xaca365,_0x39c012){_0xaca365=_0xaca365-0x0;var _0x1bfbb6=_0x51e7[_0xaca365];return _0x1bfbb6;};'use strict';var _=require('lodash');var passport=require('passport');var GoogleStrategy=require(_0x751e('0x0'))['Strategy'];var moment=require(_0x751e('0x1'));var db=require('../../mysqldb')['db'];var config=require(_0x751e('0x2'));var signToken=require(_0x751e('0x3'))['signToken'];var utils=require(_0x751e('0x4'));exports[_0x751e('0x5')]=passport[_0x751e('0x6')](_0x751e('0x7'),{'failureRedirect':'/login','scope':['profile','email'],'session':![]});exports[_0x751e('0x8')]=passport[_0x751e('0x6')](_0x751e('0x7'),{'failureRedirect':_0x751e('0x9'),'session':![]});passport[_0x751e('0xa')](new GoogleStrategy({'clientID':config[_0x751e('0x7')]?config[_0x751e('0x7')][_0x751e('0xb')]:'id','clientSecret':config['google']?config[_0x751e('0x7')][_0x751e('0xc')]:_0x751e('0xd'),'callbackURL':config[_0x751e('0x7')]?config['google'][_0x751e('0xe')]:''},function(_0x3c430f,_0x469464,_0x4ae2fe,_0x23f054){var _0x562b54,_0x40866c;return db[_0x751e('0xf')][_0x751e('0x10')]({'where':{'id':0x1},'attributes':[_0x751e('0x11'),_0x751e('0x12')],'raw':!![]})[_0x751e('0x13')](function(_0x1aa7bd){_0x562b54=_0x1aa7bd;return db[_0x751e('0x14')][_0x751e('0x15')]({'where':{'email':_[_0x751e('0x16')](_0x4ae2fe[_0x751e('0x17')],_0x751e('0x18')),'role':{'$or':['admin','user',_0x751e('0x19')]}}});})['then'](function(_0xe662ed){_0x40866c=_0xe662ed;if(_0x40866c){if(_0x40866c[_0x751e('0x1a')]){return _0x23f054(_0x751e('0x1b'));}else if(_0x562b54[_0x751e('0x12')]>0x0){if(_0x40866c[_0x751e('0x1c')]){if(moment(_0x40866c[_0x751e('0x1d')])[_0x751e('0x1e')](_0x562b54['blockDuration'],_0x751e('0x1f'))>moment()){return _0x23f054(_0x751e('0x1b'));}else{return utils[_0x751e('0x20')](_0x40866c,0x0,![],null)['then'](function(){return utils[_0x751e('0x21')](_0x40866c);})['then'](function(){return _0x23f054(null,_0x40866c);});}}else{return utils['getLicense'](_0x40866c)[_0x751e('0x13')](function(){return _0x23f054(null,_0x40866c);});}}else{return utils[_0x751e('0x21')](_0x40866c)[_0x751e('0x13')](function(){return _0x23f054(null,_0x40866c);});}}return _0x23f054(_0x751e('0x1b'));})[_0x751e('0x22')](function(_0x182209){_0x23f054(_0x182209);});}));