21f28f256fdd202f26a6d3ffa5622e46b2bfb237
[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 _0x26ed=['callback','google','/login','clientID','clientSecret','secret','callbackURL','findOne','allowedLoginAttempts','blockDuration','then','find','emails','value','admin','user','agent','disabled','Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.','add','minutes','clearBlockUser','getLicense','catch','passport','passport-google-oauth20','Strategy','moment','../../mysqldb','../../components/auth/service','signToken','../../config/utils','login','authenticate','profile','email'];(function(_0x59ee6f,_0x450239){var _0x4c0979=function(_0x565e92){while(--_0x565e92){_0x59ee6f['push'](_0x59ee6f['shift']());}};_0x4c0979(++_0x450239);}(_0x26ed,0x1ec));var _0xd26e=function(_0x1ee0a1,_0x51058e){_0x1ee0a1=_0x1ee0a1-0x0;var _0x1d2d5b=_0x26ed[_0x1ee0a1];return _0x1d2d5b;};'use strict';var _=require('lodash');var passport=require(_0xd26e('0x0'));var GoogleStrategy=require(_0xd26e('0x1'))[_0xd26e('0x2')];var moment=require(_0xd26e('0x3'));var db=require(_0xd26e('0x4'))['db'];var config=require('../../config/environment');var signToken=require(_0xd26e('0x5'))[_0xd26e('0x6')];var utils=require(_0xd26e('0x7'));exports[_0xd26e('0x8')]=passport[_0xd26e('0x9')]('google',{'failureRedirect':'/login','scope':[_0xd26e('0xa'),_0xd26e('0xb')],'session':![]});exports[_0xd26e('0xc')]=passport[_0xd26e('0x9')](_0xd26e('0xd'),{'failureRedirect':_0xd26e('0xe'),'session':![]});passport['use'](new GoogleStrategy({'clientID':config[_0xd26e('0xd')]?config[_0xd26e('0xd')][_0xd26e('0xf')]:'id','clientSecret':config[_0xd26e('0xd')]?config['google'][_0xd26e('0x10')]:_0xd26e('0x11'),'callbackURL':config['google']?config['google'][_0xd26e('0x12')]:''},function(_0x1e728d,_0x163c54,_0x274679,_0x1e8412){var _0x59fda8,_0x54f6d4;return db['Setting'][_0xd26e('0x13')]({'where':{'id':0x1},'attributes':[_0xd26e('0x14'),_0xd26e('0x15')],'raw':!![]})[_0xd26e('0x16')](function(_0x24383e){_0x59fda8=_0x24383e;return db['User'][_0xd26e('0x17')]({'where':{'email':_['map'](_0x274679[_0xd26e('0x18')],_0xd26e('0x19')),'role':{'$or':[_0xd26e('0x1a'),_0xd26e('0x1b'),_0xd26e('0x1c')]}}});})['then'](function(_0x247c55){_0x54f6d4=_0x247c55;if(_0x54f6d4){if(_0x54f6d4[_0xd26e('0x1d')]){return _0x1e8412(_0xd26e('0x1e'));}else if(_0x59fda8[_0xd26e('0x15')]>0x0){if(_0x54f6d4['blocked']){if(moment(_0x54f6d4['blockedAt'])[_0xd26e('0x1f')](_0x59fda8[_0xd26e('0x15')],_0xd26e('0x20'))>moment()){return _0x1e8412(_0xd26e('0x1e'));}else{return utils[_0xd26e('0x21')](_0x54f6d4,0x0,![],null)[_0xd26e('0x16')](function(){return utils[_0xd26e('0x22')](_0x54f6d4);})[_0xd26e('0x16')](function(){return _0x1e8412(null,_0x54f6d4);});}}else{return utils[_0xd26e('0x22')](_0x54f6d4)['then'](function(){return _0x1e8412(null,_0x54f6d4);});}}else{return utils[_0xd26e('0x22')](_0x54f6d4)[_0xd26e('0x16')](function(){return _0x1e8412(null,_0x54f6d4);});}}return _0x1e8412(_0xd26e('0x1e'));})[_0xd26e('0x23')](function(_0x35d142){_0x1e8412(_0x35d142);});}));