Built motion from commit (unavailable).|2.4.15
[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 _0xbea9=['google','/login','profile','email','callback','clientID','clientSecret','secret','Setting','findOne','find','emails','value','admin','user','agent','then','disabled','Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.','blockDuration','blocked','blockedAt','add','clearBlockUser','getLicense','catch','lodash','passport','passport-google-oauth20','Strategy','moment','../../mysqldb','../../config/environment','signToken','../../config/utils','login','authenticate'];(function(_0x1407d1,_0x4cc88c){var _0x4e6cbe=function(_0x40b958){while(--_0x40b958){_0x1407d1['push'](_0x1407d1['shift']());}};_0x4e6cbe(++_0x4cc88c);}(_0xbea9,0x89));var _0x9bea=function(_0xa464c9,_0x7c86d8){_0xa464c9=_0xa464c9-0x0;var _0x3d73c4=_0xbea9[_0xa464c9];return _0x3d73c4;};'use strict';var _=require(_0x9bea('0x0'));var passport=require(_0x9bea('0x1'));var GoogleStrategy=require(_0x9bea('0x2'))[_0x9bea('0x3')];var moment=require(_0x9bea('0x4'));var db=require(_0x9bea('0x5'))['db'];var config=require(_0x9bea('0x6'));var signToken=require('../../components/auth/service')[_0x9bea('0x7')];var utils=require(_0x9bea('0x8'));exports[_0x9bea('0x9')]=passport[_0x9bea('0xa')](_0x9bea('0xb'),{'failureRedirect':_0x9bea('0xc'),'scope':[_0x9bea('0xd'),_0x9bea('0xe')],'session':![]});exports[_0x9bea('0xf')]=passport[_0x9bea('0xa')]('google',{'failureRedirect':_0x9bea('0xc'),'session':![]});passport['use'](new GoogleStrategy({'clientID':config[_0x9bea('0xb')]?config[_0x9bea('0xb')][_0x9bea('0x10')]:'id','clientSecret':config[_0x9bea('0xb')]?config[_0x9bea('0xb')][_0x9bea('0x11')]:_0x9bea('0x12'),'callbackURL':config[_0x9bea('0xb')]?config[_0x9bea('0xb')]['callbackURL']:''},function(_0x5c55b4,_0x318b00,_0x420372,_0x5b9073){var _0xa2ba8b,_0x282d78;return db[_0x9bea('0x13')][_0x9bea('0x14')]({'where':{'id':0x1},'attributes':['allowedLoginAttempts','blockDuration'],'raw':!![]})['then'](function(_0x35c2be){_0xa2ba8b=_0x35c2be;return db['User'][_0x9bea('0x15')]({'where':{'email':_['map'](_0x420372[_0x9bea('0x16')],_0x9bea('0x17')),'role':{'$or':[_0x9bea('0x18'),_0x9bea('0x19'),_0x9bea('0x1a')]}}});})[_0x9bea('0x1b')](function(_0x3875be){_0x282d78=_0x3875be;if(_0x282d78){if(_0x282d78[_0x9bea('0x1c')]){return _0x5b9073(_0x9bea('0x1d'));}else if(_0xa2ba8b[_0x9bea('0x1e')]>0x0){if(_0x282d78[_0x9bea('0x1f')]){if(moment(_0x282d78[_0x9bea('0x20')])[_0x9bea('0x21')](_0xa2ba8b[_0x9bea('0x1e')],'minutes')>moment()){return _0x5b9073(_0x9bea('0x1d'));}else{return utils[_0x9bea('0x22')](_0x282d78,0x0,![],null)[_0x9bea('0x1b')](function(){return utils[_0x9bea('0x23')](_0x282d78);})[_0x9bea('0x1b')](function(){return _0x5b9073(null,_0x282d78);});}}else{return utils[_0x9bea('0x23')](_0x282d78)[_0x9bea('0x1b')](function(){return _0x5b9073(null,_0x282d78);});}}else{return utils['getLicense'](_0x282d78)[_0x9bea('0x1b')](function(){return _0x5b9073(null,_0x282d78);});}}return _0x5b9073(_0x9bea('0x1d'));})[_0x9bea('0x24')](function(_0x4239f0){_0x5b9073(_0x4239f0);});}));