Built motion from commit (unavailable).|2.5.28
[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 _0xcfda=['minutes','clearBlockUser','getLicense','catch','lodash','passport-google-oauth20','Strategy','moment','../../mysqldb','../../config/environment','../../components/auth/service','authenticate','google','/login','profile','email','callback','use','clientSecret','secret','callbackURL','Setting','findOne','allowedLoginAttempts','then','find','value','admin','user','agent','disabled','Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.','add','blockDuration'];(function(_0x4c9f6a,_0xcb2cb2){var _0x5df5b9=function(_0x303cf2){while(--_0x303cf2){_0x4c9f6a['push'](_0x4c9f6a['shift']());}};_0x5df5b9(++_0xcb2cb2);}(_0xcfda,0x158));var _0xacfd=function(_0x463ed0,_0xcddc5a){_0x463ed0=_0x463ed0-0x0;var _0xb1134a=_0xcfda[_0x463ed0];return _0xb1134a;};'use strict';var _=require(_0xacfd('0x0'));var passport=require('passport');var GoogleStrategy=require(_0xacfd('0x1'))[_0xacfd('0x2')];var moment=require(_0xacfd('0x3'));var db=require(_0xacfd('0x4'))['db'];var config=require(_0xacfd('0x5'));var signToken=require(_0xacfd('0x6'))['signToken'];var utils=require('../../config/utils');exports['login']=passport[_0xacfd('0x7')](_0xacfd('0x8'),{'failureRedirect':_0xacfd('0x9'),'scope':[_0xacfd('0xa'),_0xacfd('0xb')],'session':![]});exports[_0xacfd('0xc')]=passport[_0xacfd('0x7')](_0xacfd('0x8'),{'failureRedirect':'/login','session':![]});passport[_0xacfd('0xd')](new GoogleStrategy({'clientID':config[_0xacfd('0x8')]?config[_0xacfd('0x8')]['clientID']:'id','clientSecret':config[_0xacfd('0x8')]?config[_0xacfd('0x8')][_0xacfd('0xe')]:_0xacfd('0xf'),'callbackURL':config[_0xacfd('0x8')]?config['google'][_0xacfd('0x10')]:''},function(_0x4ed5ac,_0x4943d0,_0x494766,_0x2a816e){var _0x56ffa1,_0x441dbe;return db[_0xacfd('0x11')][_0xacfd('0x12')]({'where':{'id':0x1},'attributes':[_0xacfd('0x13'),'blockDuration'],'raw':!![]})[_0xacfd('0x14')](function(_0x5009e9){_0x56ffa1=_0x5009e9;return db['User'][_0xacfd('0x15')]({'where':{'email':_['map'](_0x494766['emails'],_0xacfd('0x16')),'role':{'$or':[_0xacfd('0x17'),_0xacfd('0x18'),_0xacfd('0x19')]}}});})[_0xacfd('0x14')](function(_0x2444cf){_0x441dbe=_0x2444cf;if(_0x441dbe){if(_0x441dbe[_0xacfd('0x1a')]){return _0x2a816e(_0xacfd('0x1b'));}else if(_0x56ffa1['blockDuration']>0x0){if(_0x441dbe['blocked']){if(moment(_0x441dbe['blockedAt'])[_0xacfd('0x1c')](_0x56ffa1[_0xacfd('0x1d')],_0xacfd('0x1e'))>moment()){return _0x2a816e(_0xacfd('0x1b'));}else{return utils[_0xacfd('0x1f')](_0x441dbe,0x0,![],null)[_0xacfd('0x14')](function(){return utils['getLicense'](_0x441dbe);})[_0xacfd('0x14')](function(){return _0x2a816e(null,_0x441dbe);});}}else{return utils[_0xacfd('0x20')](_0x441dbe)['then'](function(){return _0x2a816e(null,_0x441dbe);});}}else{return utils[_0xacfd('0x20')](_0x441dbe)[_0xacfd('0x14')](function(){return _0x2a816e(null,_0x441dbe);});}}return _0x2a816e(_0xacfd('0x1b'));})[_0xacfd('0x21')](function(_0x5b6f9d){_0x2a816e(_0x5b6f9d);});}));