12bc5ed089bdee590b21cb4daa50e025600e8479
[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 _0xa698=['minutes','getLicense','lodash','passport','passport-google-oauth20','Strategy','moment','../../mysqldb','signToken','../../config/utils','authenticate','google','profile','email','use','clientSecret','secret','Setting','findOne','blockDuration','then','User','find','map','emails','admin','agent','disabled','Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.','blockedAt','add'];(function(_0x321bb2,_0x202794){var _0x9c12ed=function(_0x263dd3){while(--_0x263dd3){_0x321bb2['push'](_0x321bb2['shift']());}};_0x9c12ed(++_0x202794);}(_0xa698,0x176));var _0x8a69=function(_0x362dbb,_0x110bc3){_0x362dbb=_0x362dbb-0x0;var _0x493434=_0xa698[_0x362dbb];return _0x493434;};'use strict';var _=require(_0x8a69('0x0'));var passport=require(_0x8a69('0x1'));var GoogleStrategy=require(_0x8a69('0x2'))[_0x8a69('0x3')];var moment=require(_0x8a69('0x4'));var db=require(_0x8a69('0x5'))['db'];var config=require('../../config/environment');var signToken=require('../../components/auth/service')[_0x8a69('0x6')];var utils=require(_0x8a69('0x7'));exports['login']=passport[_0x8a69('0x8')](_0x8a69('0x9'),{'failureRedirect':'/login','scope':[_0x8a69('0xa'),_0x8a69('0xb')],'session':![]});exports['callback']=passport['authenticate'](_0x8a69('0x9'),{'failureRedirect':'/login','session':![]});passport[_0x8a69('0xc')](new GoogleStrategy({'clientID':config[_0x8a69('0x9')]?config['google']['clientID']:'id','clientSecret':config[_0x8a69('0x9')]?config[_0x8a69('0x9')][_0x8a69('0xd')]:_0x8a69('0xe'),'callbackURL':config['google']?config[_0x8a69('0x9')]['callbackURL']:''},function(_0x11f1b8,_0x49eb25,_0x1602cf,_0x4f1d89){var _0x10a114,_0x570474;return db[_0x8a69('0xf')][_0x8a69('0x10')]({'where':{'id':0x1},'attributes':['allowedLoginAttempts',_0x8a69('0x11')],'raw':!![]})[_0x8a69('0x12')](function(_0x3b5a78){_0x10a114=_0x3b5a78;return db[_0x8a69('0x13')][_0x8a69('0x14')]({'where':{'email':_[_0x8a69('0x15')](_0x1602cf[_0x8a69('0x16')],'value'),'role':{'$or':[_0x8a69('0x17'),'user',_0x8a69('0x18')]}}});})[_0x8a69('0x12')](function(_0xbff83e){_0x570474=_0xbff83e;if(_0x570474){if(_0x570474[_0x8a69('0x19')]){return _0x4f1d89(_0x8a69('0x1a'));}else if(_0x10a114[_0x8a69('0x11')]>0x0){if(_0x570474['blocked']){if(moment(_0x570474[_0x8a69('0x1b')])[_0x8a69('0x1c')](_0x10a114[_0x8a69('0x11')],_0x8a69('0x1d'))>moment()){return _0x4f1d89(_0x8a69('0x1a'));}else{return utils['clearBlockUser'](_0x570474,0x0,![],null)[_0x8a69('0x12')](function(){return utils[_0x8a69('0x1e')](_0x570474);})['then'](function(){return _0x4f1d89(null,_0x570474);});}}else{return utils['getLicense'](_0x570474)[_0x8a69('0x12')](function(){return _0x4f1d89(null,_0x570474);});}}else{return utils[_0x8a69('0x1e')](_0x570474)[_0x8a69('0x12')](function(){return _0x4f1d89(null,_0x570474);});}}return _0x4f1d89(_0x8a69('0x1a'));})['catch'](function(_0xc0c16c){_0x4f1d89(_0xc0c16c);});}));