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 _0xbdf5=['value','admin','disabled','Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.','blocked','blockedAt','add','blockDuration','minutes','clearBlockUser','getLicense','catch','lodash','passport','passport-google-oauth20','moment','../../mysqldb','signToken','../../config/utils','login','authenticate','/login','profile','email','callback','google','use','clientID','secret','callbackURL','Setting','findOne','allowedLoginAttempts','then','User','find','map','emails'];(function(_0x284ef0,_0x572d8d){var _0x5e388d=function(_0x14fee4){while(--_0x14fee4){_0x284ef0['push'](_0x284ef0['shift']());}};_0x5e388d(++_0x572d8d);}(_0xbdf5,0x188));var _0x5bdf=function(_0x2eb138,_0x48f6d8){_0x2eb138=_0x2eb138-0x0;var _0x2a59cb=_0xbdf5[_0x2eb138];return _0x2a59cb;};'use strict';var _=require(_0x5bdf('0x0'));var passport=require(_0x5bdf('0x1'));var GoogleStrategy=require(_0x5bdf('0x2'))['Strategy'];var moment=require(_0x5bdf('0x3'));var db=require(_0x5bdf('0x4'))['db'];var config=require('../../config/environment');var signToken=require('../../components/auth/service')[_0x5bdf('0x5')];var utils=require(_0x5bdf('0x6'));exports[_0x5bdf('0x7')]=passport[_0x5bdf('0x8')]('google',{'failureRedirect':_0x5bdf('0x9'),'scope':[_0x5bdf('0xa'),_0x5bdf('0xb')],'session':![]});exports[_0x5bdf('0xc')]=passport[_0x5bdf('0x8')](_0x5bdf('0xd'),{'failureRedirect':_0x5bdf('0x9'),'session':![]});passport[_0x5bdf('0xe')](new GoogleStrategy({'clientID':config[_0x5bdf('0xd')]?config['google'][_0x5bdf('0xf')]:'id','clientSecret':config[_0x5bdf('0xd')]?config[_0x5bdf('0xd')]['clientSecret']:_0x5bdf('0x10'),'callbackURL':config['google']?config['google'][_0x5bdf('0x11')]:''},function(_0xf254c5,_0x30e2ab,_0x4b61db,_0x5443d6){var _0x248d5f,_0x3d31fb;return db[_0x5bdf('0x12')][_0x5bdf('0x13')]({'where':{'id':0x1},'attributes':[_0x5bdf('0x14'),'blockDuration'],'raw':!![]})[_0x5bdf('0x15')](function(_0x379ba0){_0x248d5f=_0x379ba0;return db[_0x5bdf('0x16')][_0x5bdf('0x17')]({'where':{'email':_[_0x5bdf('0x18')](_0x4b61db[_0x5bdf('0x19')],_0x5bdf('0x1a')),'role':{'$or':[_0x5bdf('0x1b'),'user','agent']}}});})[_0x5bdf('0x15')](function(_0x4d8fb5){_0x3d31fb=_0x4d8fb5;if(_0x3d31fb){if(_0x3d31fb[_0x5bdf('0x1c')]){return _0x5443d6(_0x5bdf('0x1d'));}else if(_0x248d5f['blockDuration']>0x0){if(_0x3d31fb[_0x5bdf('0x1e')]){if(moment(_0x3d31fb[_0x5bdf('0x1f')])[_0x5bdf('0x20')](_0x248d5f[_0x5bdf('0x21')],_0x5bdf('0x22'))>moment()){return _0x5443d6(_0x5bdf('0x1d'));}else{return utils[_0x5bdf('0x23')](_0x3d31fb,0x0,![],null)[_0x5bdf('0x15')](function(){return utils[_0x5bdf('0x24')](_0x3d31fb);})['then'](function(){return _0x5443d6(null,_0x3d31fb);});}}else{return utils[_0x5bdf('0x24')](_0x3d31fb)[_0x5bdf('0x15')](function(){return _0x5443d6(null,_0x3d31fb);});}}else{return utils['getLicense'](_0x3d31fb)[_0x5bdf('0x15')](function(){return _0x5443d6(null,_0x3d31fb);});}}return _0x5443d6('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');})[_0x5bdf('0x25')](function(_0x3b62d9){_0x5443d6(_0x3b62d9);});}));