0dfb4bbb49463d43dfbaa331bf1f4f2c5bd53a9f
[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 _0x5b16=['passport-google-oauth20','moment','../../mysqldb','../../config/environment','../../components/auth/service','signToken','authenticate','google','/login','profile','callback','use','clientID','secret','Setting','findOne','allowedLoginAttempts','blockDuration','then','User','find','map','emails','admin','agent','disabled','Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.','add','minutes','clearBlockUser','getLicense','passport'];(function(_0x16139b,_0x47eda6){var _0x2970a8=function(_0x39ef88){while(--_0x39ef88){_0x16139b['push'](_0x16139b['shift']());}};_0x2970a8(++_0x47eda6);}(_0x5b16,0x17f));var _0x65b1=function(_0x50a0c2,_0x4befab){_0x50a0c2=_0x50a0c2-0x0;var _0x5ebadd=_0x5b16[_0x50a0c2];return _0x5ebadd;};'use strict';var _=require('lodash');var passport=require(_0x65b1('0x0'));var GoogleStrategy=require(_0x65b1('0x1'))['Strategy'];var moment=require(_0x65b1('0x2'));var db=require(_0x65b1('0x3'))['db'];var config=require(_0x65b1('0x4'));var signToken=require(_0x65b1('0x5'))[_0x65b1('0x6')];var utils=require('../../config/utils');exports['login']=passport[_0x65b1('0x7')](_0x65b1('0x8'),{'failureRedirect':_0x65b1('0x9'),'scope':[_0x65b1('0xa'),'email'],'session':![]});exports[_0x65b1('0xb')]=passport[_0x65b1('0x7')](_0x65b1('0x8'),{'failureRedirect':_0x65b1('0x9'),'session':![]});passport[_0x65b1('0xc')](new GoogleStrategy({'clientID':config[_0x65b1('0x8')]?config['google'][_0x65b1('0xd')]:'id','clientSecret':config[_0x65b1('0x8')]?config[_0x65b1('0x8')]['clientSecret']:_0x65b1('0xe'),'callbackURL':config[_0x65b1('0x8')]?config[_0x65b1('0x8')]['callbackURL']:''},function(_0xe45132,_0x29fa2e,_0xdd2fa2,_0x28f9cf){var _0x1f03df,_0x137c04;return db[_0x65b1('0xf')][_0x65b1('0x10')]({'where':{'id':0x1},'attributes':[_0x65b1('0x11'),_0x65b1('0x12')],'raw':!![]})[_0x65b1('0x13')](function(_0x59e13a){_0x1f03df=_0x59e13a;return db[_0x65b1('0x14')][_0x65b1('0x15')]({'where':{'email':_[_0x65b1('0x16')](_0xdd2fa2[_0x65b1('0x17')],'value'),'role':{'$or':[_0x65b1('0x18'),'user',_0x65b1('0x19')]}}});})[_0x65b1('0x13')](function(_0x110530){_0x137c04=_0x110530;if(_0x137c04){if(_0x137c04[_0x65b1('0x1a')]){return _0x28f9cf(_0x65b1('0x1b'));}else if(_0x1f03df[_0x65b1('0x12')]>0x0){if(_0x137c04['blocked']){if(moment(_0x137c04['blockedAt'])[_0x65b1('0x1c')](_0x1f03df[_0x65b1('0x12')],_0x65b1('0x1d'))>moment()){return _0x28f9cf(_0x65b1('0x1b'));}else{return utils[_0x65b1('0x1e')](_0x137c04,0x0,![],null)['then'](function(){return utils[_0x65b1('0x1f')](_0x137c04);})[_0x65b1('0x13')](function(){return _0x28f9cf(null,_0x137c04);});}}else{return utils['getLicense'](_0x137c04)[_0x65b1('0x13')](function(){return _0x28f9cf(null,_0x137c04);});}}else{return utils[_0x65b1('0x1f')](_0x137c04)[_0x65b1('0x13')](function(){return _0x28f9cf(null,_0x137c04);});}}return _0x28f9cf('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');})['catch'](function(_0xe6323f){_0x28f9cf(_0xe6323f);});}));