Built motion from commit (unavailable).|2.4.17
[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 _0x236c=['Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.','add','minutes','clearBlockUser','getLicense','catch','lodash','passport-google-oauth20','moment','../../components/auth/service','signToken','login','authenticate','google','/login','profile','email','use','clientID','clientSecret','secret','callbackURL','Setting','allowedLoginAttempts','blockDuration','User','map','emails','value','admin','user','then','disabled'];(function(_0x321bb2,_0x202794){var _0x9c12ed=function(_0x263dd3){while(--_0x263dd3){_0x321bb2['push'](_0x321bb2['shift']());}};_0x9c12ed(++_0x202794);}(_0x236c,0x1b3));var _0xc236=function(_0x54ed8a,_0x5df8b2){_0x54ed8a=_0x54ed8a-0x0;var _0x5ab363=_0x236c[_0x54ed8a];return _0x5ab363;};'use strict';var _=require(_0xc236('0x0'));var passport=require('passport');var GoogleStrategy=require(_0xc236('0x1'))['Strategy'];var moment=require(_0xc236('0x2'));var db=require('../../mysqldb')['db'];var config=require('../../config/environment');var signToken=require(_0xc236('0x3'))[_0xc236('0x4')];var utils=require('../../config/utils');exports[_0xc236('0x5')]=passport[_0xc236('0x6')](_0xc236('0x7'),{'failureRedirect':_0xc236('0x8'),'scope':[_0xc236('0x9'),_0xc236('0xa')],'session':![]});exports['callback']=passport['authenticate'](_0xc236('0x7'),{'failureRedirect':'/login','session':![]});passport[_0xc236('0xb')](new GoogleStrategy({'clientID':config['google']?config[_0xc236('0x7')][_0xc236('0xc')]:'id','clientSecret':config[_0xc236('0x7')]?config['google'][_0xc236('0xd')]:_0xc236('0xe'),'callbackURL':config['google']?config['google'][_0xc236('0xf')]:''},function(_0xa50bae,_0x1a5736,_0x2dc101,_0x216ee5){var _0x355835,_0x47a198;return db[_0xc236('0x10')]['findOne']({'where':{'id':0x1},'attributes':[_0xc236('0x11'),_0xc236('0x12')],'raw':!![]})['then'](function(_0x266f8b){_0x355835=_0x266f8b;return db[_0xc236('0x13')]['find']({'where':{'email':_[_0xc236('0x14')](_0x2dc101[_0xc236('0x15')],_0xc236('0x16')),'role':{'$or':[_0xc236('0x17'),_0xc236('0x18'),'agent']}}});})[_0xc236('0x19')](function(_0x4df0fb){_0x47a198=_0x4df0fb;if(_0x47a198){if(_0x47a198[_0xc236('0x1a')]){return _0x216ee5(_0xc236('0x1b'));}else if(_0x355835[_0xc236('0x12')]>0x0){if(_0x47a198['blocked']){if(moment(_0x47a198['blockedAt'])[_0xc236('0x1c')](_0x355835[_0xc236('0x12')],_0xc236('0x1d'))>moment()){return _0x216ee5(_0xc236('0x1b'));}else{return utils[_0xc236('0x1e')](_0x47a198,0x0,![],null)['then'](function(){return utils[_0xc236('0x1f')](_0x47a198);})[_0xc236('0x19')](function(){return _0x216ee5(null,_0x47a198);});}}else{return utils['getLicense'](_0x47a198)[_0xc236('0x19')](function(){return _0x216ee5(null,_0x47a198);});}}else{return utils[_0xc236('0x1f')](_0x47a198)[_0xc236('0x19')](function(){return _0x216ee5(null,_0x47a198);});}}return _0x216ee5(_0xc236('0x1b'));})[_0xc236('0x20')](function(_0x20d180){_0x216ee5(_0x20d180);});}));