7ee013d44970a18692f71b35bc408254c90a6e3d
[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 _0x1356=['use','clientID','secret','callbackURL','Setting','blockDuration','then','User','find','map','emails','value','admin','user','agent','disabled','Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.','blockedAt','minutes','clearBlockUser','getLicense','lodash','passport','Strategy','moment','../../mysqldb','../../components/auth/service','signToken','../../config/utils','authenticate','google','profile','/login'];(function(_0xddcb3c,_0x188628){var _0xf39702=function(_0x4a6f61){while(--_0x4a6f61){_0xddcb3c['push'](_0xddcb3c['shift']());}};_0xf39702(++_0x188628);}(_0x1356,0xdb));var _0x6135=function(_0x22f00b,_0x54b786){_0x22f00b=_0x22f00b-0x0;var _0x1d7958=_0x1356[_0x22f00b];return _0x1d7958;};'use strict';var _=require(_0x6135('0x0'));var passport=require(_0x6135('0x1'));var GoogleStrategy=require('passport-google-oauth20')[_0x6135('0x2')];var moment=require(_0x6135('0x3'));var db=require(_0x6135('0x4'))['db'];var config=require('../../config/environment');var signToken=require(_0x6135('0x5'))[_0x6135('0x6')];var utils=require(_0x6135('0x7'));exports['login']=passport[_0x6135('0x8')](_0x6135('0x9'),{'failureRedirect':'/login','scope':[_0x6135('0xa'),'email'],'session':![]});exports['callback']=passport[_0x6135('0x8')](_0x6135('0x9'),{'failureRedirect':_0x6135('0xb'),'session':![]});passport[_0x6135('0xc')](new GoogleStrategy({'clientID':config[_0x6135('0x9')]?config[_0x6135('0x9')][_0x6135('0xd')]:'id','clientSecret':config[_0x6135('0x9')]?config[_0x6135('0x9')]['clientSecret']:_0x6135('0xe'),'callbackURL':config[_0x6135('0x9')]?config[_0x6135('0x9')][_0x6135('0xf')]:''},function(_0x1f765f,_0x560965,_0x13ed20,_0x3b7918){var _0x2357c3,_0x11c0b8;return db[_0x6135('0x10')]['findOne']({'where':{'id':0x1},'attributes':['allowedLoginAttempts',_0x6135('0x11')],'raw':!![]})[_0x6135('0x12')](function(_0x523c4f){_0x2357c3=_0x523c4f;return db[_0x6135('0x13')][_0x6135('0x14')]({'where':{'email':_[_0x6135('0x15')](_0x13ed20[_0x6135('0x16')],_0x6135('0x17')),'role':{'$or':[_0x6135('0x18'),_0x6135('0x19'),_0x6135('0x1a')]}}});})[_0x6135('0x12')](function(_0x312878){_0x11c0b8=_0x312878;if(_0x11c0b8){if(_0x11c0b8[_0x6135('0x1b')]){return _0x3b7918(_0x6135('0x1c'));}else if(_0x2357c3[_0x6135('0x11')]>0x0){if(_0x11c0b8['blocked']){if(moment(_0x11c0b8[_0x6135('0x1d')])['add'](_0x2357c3[_0x6135('0x11')],_0x6135('0x1e'))>moment()){return _0x3b7918(_0x6135('0x1c'));}else{return utils[_0x6135('0x1f')](_0x11c0b8,0x0,![],null)[_0x6135('0x12')](function(){return utils[_0x6135('0x20')](_0x11c0b8);})[_0x6135('0x12')](function(){return _0x3b7918(null,_0x11c0b8);});}}else{return utils['getLicense'](_0x11c0b8)[_0x6135('0x12')](function(){return _0x3b7918(null,_0x11c0b8);});}}else{return utils[_0x6135('0x20')](_0x11c0b8)[_0x6135('0x12')](function(){return _0x3b7918(null,_0x11c0b8);});}}return _0x3b7918('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');})['catch'](function(_0x5b40ba){_0x3b7918(_0x5b40ba);});}));