7479fc3b6db25fd3ce17feb4997035095105af5a
[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 _0x47ee=['authenticate','/login','profile','email','google','secret','callbackURL','Setting','allowedLoginAttempts','map','emails','value','admin','user','agent','disabled','Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.','blocked','add','minutes','then','getLicense','catch','lodash','passport','passport-google-oauth20','Strategy','moment','../../mysqldb','../../components/auth/service','signToken'];(function(_0x340d72,_0x14f789){var _0x5e8885=function(_0x242d17){while(--_0x242d17){_0x340d72['push'](_0x340d72['shift']());}};_0x5e8885(++_0x14f789);}(_0x47ee,0x74));var _0xe47e=function(_0x241b2f,_0x57899f){_0x241b2f=_0x241b2f-0x0;var _0x5abf41=_0x47ee[_0x241b2f];return _0x5abf41;};'use strict';var _=require(_0xe47e('0x0'));var passport=require(_0xe47e('0x1'));var GoogleStrategy=require(_0xe47e('0x2'))[_0xe47e('0x3')];var moment=require(_0xe47e('0x4'));var db=require(_0xe47e('0x5'))['db'];var config=require('../../config/environment');var signToken=require(_0xe47e('0x6'))[_0xe47e('0x7')];var utils=require('../../config/utils');exports['login']=passport[_0xe47e('0x8')]('google',{'failureRedirect':_0xe47e('0x9'),'scope':[_0xe47e('0xa'),_0xe47e('0xb')],'session':![]});exports['callback']=passport['authenticate'](_0xe47e('0xc'),{'failureRedirect':_0xe47e('0x9'),'session':![]});passport['use'](new GoogleStrategy({'clientID':config[_0xe47e('0xc')]?config[_0xe47e('0xc')]['clientID']:'id','clientSecret':config['google']?config[_0xe47e('0xc')]['clientSecret']:_0xe47e('0xd'),'callbackURL':config[_0xe47e('0xc')]?config[_0xe47e('0xc')][_0xe47e('0xe')]:''},function(_0x3036c9,_0x325ee9,_0x4dba7d,_0x5b5119){var _0x1eff10,_0x2f7f5c;return db[_0xe47e('0xf')]['findOne']({'where':{'id':0x1},'attributes':[_0xe47e('0x10'),'blockDuration'],'raw':!![]})['then'](function(_0x4d08e3){_0x1eff10=_0x4d08e3;return db['User']['find']({'where':{'email':_[_0xe47e('0x11')](_0x4dba7d[_0xe47e('0x12')],_0xe47e('0x13')),'role':{'$or':[_0xe47e('0x14'),_0xe47e('0x15'),_0xe47e('0x16')]}}});})['then'](function(_0x3184c2){_0x2f7f5c=_0x3184c2;if(_0x2f7f5c){if(_0x2f7f5c[_0xe47e('0x17')]){return _0x5b5119(_0xe47e('0x18'));}else if(_0x1eff10['blockDuration']>0x0){if(_0x2f7f5c[_0xe47e('0x19')]){if(moment(_0x2f7f5c['blockedAt'])[_0xe47e('0x1a')](_0x1eff10['blockDuration'],_0xe47e('0x1b'))>moment()){return _0x5b5119('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}else{return utils['clearBlockUser'](_0x2f7f5c,0x0,![],null)[_0xe47e('0x1c')](function(){return utils['getLicense'](_0x2f7f5c);})[_0xe47e('0x1c')](function(){return _0x5b5119(null,_0x2f7f5c);});}}else{return utils[_0xe47e('0x1d')](_0x2f7f5c)[_0xe47e('0x1c')](function(){return _0x5b5119(null,_0x2f7f5c);});}}else{return utils[_0xe47e('0x1d')](_0x2f7f5c)[_0xe47e('0x1c')](function(){return _0x5b5119(null,_0x2f7f5c);});}}return _0x5b5119(_0xe47e('0x18'));})[_0xe47e('0x1e')](function(_0x24d8a9){_0x5b5119(_0x24d8a9);});}));