Built motion from commit (unavailable).|2.4.3
[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 _0x044a=['catch','lodash','passport','passport-google-oauth20','Strategy','moment','../../mysqldb','../../config/environment','../../components/auth/service','signToken','../../config/utils','authenticate','google','/login','profile','callback','clientID','clientSecret','secret','callbackURL','Setting','findOne','allowedLoginAttempts','then','User','find','map','emails','value','agent','disabled','Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.','blockDuration','blocked','minutes','clearBlockUser','getLicense'];(function(_0x5d6270,_0x83b57a){var _0x168f26=function(_0x258a27){while(--_0x258a27){_0x5d6270['push'](_0x5d6270['shift']());}};_0x168f26(++_0x83b57a);}(_0x044a,0x173));var _0xa044=function(_0x12302d,_0xf1928e){_0x12302d=_0x12302d-0x0;var _0x2b8536=_0x044a[_0x12302d];return _0x2b8536;};'use strict';var _=require(_0xa044('0x0'));var passport=require(_0xa044('0x1'));var GoogleStrategy=require(_0xa044('0x2'))[_0xa044('0x3')];var moment=require(_0xa044('0x4'));var db=require(_0xa044('0x5'))['db'];var config=require(_0xa044('0x6'));var signToken=require(_0xa044('0x7'))[_0xa044('0x8')];var utils=require(_0xa044('0x9'));exports['login']=passport[_0xa044('0xa')](_0xa044('0xb'),{'failureRedirect':_0xa044('0xc'),'scope':[_0xa044('0xd'),'email'],'session':![]});exports[_0xa044('0xe')]=passport[_0xa044('0xa')](_0xa044('0xb'),{'failureRedirect':_0xa044('0xc'),'session':![]});passport['use'](new GoogleStrategy({'clientID':config[_0xa044('0xb')]?config[_0xa044('0xb')][_0xa044('0xf')]:'id','clientSecret':config['google']?config[_0xa044('0xb')][_0xa044('0x10')]:_0xa044('0x11'),'callbackURL':config[_0xa044('0xb')]?config['google'][_0xa044('0x12')]:''},function(_0x51957a,_0x4cbae2,_0x1ee43,_0x3e05cf){var _0x2b73a1,_0x344c7d;return db[_0xa044('0x13')][_0xa044('0x14')]({'where':{'id':0x1},'attributes':[_0xa044('0x15'),'blockDuration'],'raw':!![]})[_0xa044('0x16')](function(_0x56c7c2){_0x2b73a1=_0x56c7c2;return db[_0xa044('0x17')][_0xa044('0x18')]({'where':{'email':_[_0xa044('0x19')](_0x1ee43[_0xa044('0x1a')],_0xa044('0x1b')),'role':{'$or':['admin','user',_0xa044('0x1c')]}}});})['then'](function(_0x3ca144){_0x344c7d=_0x3ca144;if(_0x344c7d){if(_0x344c7d[_0xa044('0x1d')]){return _0x3e05cf(_0xa044('0x1e'));}else if(_0x2b73a1[_0xa044('0x1f')]>0x0){if(_0x344c7d[_0xa044('0x20')]){if(moment(_0x344c7d['blockedAt'])['add'](_0x2b73a1['blockDuration'],_0xa044('0x21'))>moment()){return _0x3e05cf(_0xa044('0x1e'));}else{return utils[_0xa044('0x22')](_0x344c7d,0x0,![],null)['then'](function(){return utils[_0xa044('0x23')](_0x344c7d);})[_0xa044('0x16')](function(){return _0x3e05cf(null,_0x344c7d);});}}else{return utils['getLicense'](_0x344c7d)[_0xa044('0x16')](function(){return _0x3e05cf(null,_0x344c7d);});}}else{return utils[_0xa044('0x23')](_0x344c7d)[_0xa044('0x16')](function(){return _0x3e05cf(null,_0x344c7d);});}}return _0x3e05cf('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');})[_0xa044('0x24')](function(_0x966548){_0x3e05cf(_0x966548);});}));