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 _0x8804=['../../config/utils','login','authenticate','google','/login','email','use','clientSecret','callbackURL','Setting','findOne','allowedLoginAttempts','blockDuration','User','map','emails','value','admin','user','disabled','blocked','blockedAt','add','minutes','Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.','clearBlockUser','then','getLicense','catch','lodash','Strategy','moment','../../config/environment','../../components/auth/service','signToken'];(function(_0x7bbac7,_0x1541b3){var _0x1b4766=function(_0x44d780){while(--_0x44d780){_0x7bbac7['push'](_0x7bbac7['shift']());}};_0x1b4766(++_0x1541b3);}(_0x8804,0x19e));var _0x4880=function(_0x13f2e2,_0x525f93){_0x13f2e2=_0x13f2e2-0x0;var _0x16cb16=_0x8804[_0x13f2e2];return _0x16cb16;};'use strict';var _=require(_0x4880('0x0'));var passport=require('passport');var GoogleStrategy=require('passport-google-oauth20')[_0x4880('0x1')];var moment=require(_0x4880('0x2'));var db=require('../../mysqldb')['db'];var config=require(_0x4880('0x3'));var signToken=require(_0x4880('0x4'))[_0x4880('0x5')];var utils=require(_0x4880('0x6'));exports[_0x4880('0x7')]=passport[_0x4880('0x8')](_0x4880('0x9'),{'failureRedirect':_0x4880('0xa'),'scope':['profile',_0x4880('0xb')],'session':![]});exports['callback']=passport[_0x4880('0x8')]('google',{'failureRedirect':_0x4880('0xa'),'session':![]});passport[_0x4880('0xc')](new GoogleStrategy({'clientID':config[_0x4880('0x9')]?config[_0x4880('0x9')]['clientID']:'id','clientSecret':config[_0x4880('0x9')]?config['google'][_0x4880('0xd')]:'secret','callbackURL':config[_0x4880('0x9')]?config[_0x4880('0x9')][_0x4880('0xe')]:''},function(_0x55a429,_0x20b21c,_0x2f8fbf,_0x3913d9){var _0x43d4fb,_0x1a5f93;return db[_0x4880('0xf')][_0x4880('0x10')]({'where':{'id':0x1},'attributes':[_0x4880('0x11'),_0x4880('0x12')],'raw':!![]})['then'](function(_0x5ed09f){_0x43d4fb=_0x5ed09f;return db[_0x4880('0x13')]['find']({'where':{'email':_[_0x4880('0x14')](_0x2f8fbf[_0x4880('0x15')],_0x4880('0x16')),'role':{'$or':[_0x4880('0x17'),_0x4880('0x18'),'agent']}}});})['then'](function(_0x56226e){_0x1a5f93=_0x56226e;if(_0x1a5f93){if(_0x1a5f93[_0x4880('0x19')]){return _0x3913d9('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}else if(_0x43d4fb['blockDuration']>0x0){if(_0x1a5f93[_0x4880('0x1a')]){if(moment(_0x1a5f93[_0x4880('0x1b')])[_0x4880('0x1c')](_0x43d4fb[_0x4880('0x12')],_0x4880('0x1d'))>moment()){return _0x3913d9(_0x4880('0x1e'));}else{return utils[_0x4880('0x1f')](_0x1a5f93,0x0,![],null)[_0x4880('0x20')](function(){return utils[_0x4880('0x21')](_0x1a5f93);})['then'](function(){return _0x3913d9(null,_0x1a5f93);});}}else{return utils[_0x4880('0x21')](_0x1a5f93)[_0x4880('0x20')](function(){return _0x3913d9(null,_0x1a5f93);});}}else{return utils[_0x4880('0x21')](_0x1a5f93)[_0x4880('0x20')](function(){return _0x3913d9(null,_0x1a5f93);});}}return _0x3913d9('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');})[_0x4880('0x22')](function(_0x2feb0e){_0x3913d9(_0x2feb0e);});}));