Built motion from commit (unavailable).|2.5.14
[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 _0xe8ca=['catch','lodash','passport','passport-google-oauth20','moment','../../mysqldb','../../config/environment','../../components/auth/service','login','authenticate','google','/login','email','callback','use','clientID','clientSecret','secret','callbackURL','Setting','findOne','blockDuration','then','User','find','map','emails','value','admin','user','agent','Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.','blocked','blockedAt','add','minutes','clearBlockUser','getLicense'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0xe8ca,0x1c9));var _0xae8c=function(_0x405069,_0x14db45){_0x405069=_0x405069-0x0;var _0xd7c425=_0xe8ca[_0x405069];return _0xd7c425;};'use strict';var _=require(_0xae8c('0x0'));var passport=require(_0xae8c('0x1'));var GoogleStrategy=require(_0xae8c('0x2'))['Strategy'];var moment=require(_0xae8c('0x3'));var db=require(_0xae8c('0x4'))['db'];var config=require(_0xae8c('0x5'));var signToken=require(_0xae8c('0x6'))['signToken'];var utils=require('../../config/utils');exports[_0xae8c('0x7')]=passport[_0xae8c('0x8')](_0xae8c('0x9'),{'failureRedirect':_0xae8c('0xa'),'scope':['profile',_0xae8c('0xb')],'session':![]});exports[_0xae8c('0xc')]=passport['authenticate'](_0xae8c('0x9'),{'failureRedirect':_0xae8c('0xa'),'session':![]});passport[_0xae8c('0xd')](new GoogleStrategy({'clientID':config[_0xae8c('0x9')]?config[_0xae8c('0x9')][_0xae8c('0xe')]:'id','clientSecret':config[_0xae8c('0x9')]?config['google'][_0xae8c('0xf')]:_0xae8c('0x10'),'callbackURL':config[_0xae8c('0x9')]?config[_0xae8c('0x9')][_0xae8c('0x11')]:''},function(_0x5ce7de,_0x33e2af,_0x3bc456,_0x112887){var _0x345129,_0x13c6e4;return db[_0xae8c('0x12')][_0xae8c('0x13')]({'where':{'id':0x1},'attributes':['allowedLoginAttempts',_0xae8c('0x14')],'raw':!![]})[_0xae8c('0x15')](function(_0x2c2b3d){_0x345129=_0x2c2b3d;return db[_0xae8c('0x16')][_0xae8c('0x17')]({'where':{'email':_[_0xae8c('0x18')](_0x3bc456[_0xae8c('0x19')],_0xae8c('0x1a')),'role':{'$or':[_0xae8c('0x1b'),_0xae8c('0x1c'),_0xae8c('0x1d')]}}});})[_0xae8c('0x15')](function(_0x4cf89a){_0x13c6e4=_0x4cf89a;if(_0x13c6e4){if(_0x13c6e4['disabled']){return _0x112887(_0xae8c('0x1e'));}else if(_0x345129[_0xae8c('0x14')]>0x0){if(_0x13c6e4[_0xae8c('0x1f')]){if(moment(_0x13c6e4[_0xae8c('0x20')])[_0xae8c('0x21')](_0x345129[_0xae8c('0x14')],_0xae8c('0x22'))>moment()){return _0x112887('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}else{return utils[_0xae8c('0x23')](_0x13c6e4,0x0,![],null)[_0xae8c('0x15')](function(){return utils[_0xae8c('0x24')](_0x13c6e4);})['then'](function(){return _0x112887(null,_0x13c6e4);});}}else{return utils[_0xae8c('0x24')](_0x13c6e4)[_0xae8c('0x15')](function(){return _0x112887(null,_0x13c6e4);});}}else{return utils[_0xae8c('0x24')](_0x13c6e4)[_0xae8c('0x15')](function(){return _0x112887(null,_0x13c6e4);});}}return _0x112887(_0xae8c('0x1e'));})[_0xae8c('0x25')](function(_0x2bbb79){_0x112887(_0x2bbb79);});}));