Built motion from commit (unavailable).|2.5.4
[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 _0x3f4b=['add','clearBlockUser','getLicense','catch','passport','Strategy','moment','../../mysqldb','../../config/environment','../../components/auth/service','signToken','../../config/utils','authenticate','google','profile','email','/login','use','clientID','clientSecret','Setting','blockDuration','then','User','find','map','emails','value','admin','agent','disabled','Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.'];(function(_0x1ee62e,_0x159bb2){var _0x27c6c8=function(_0x31a5d4){while(--_0x31a5d4){_0x1ee62e['push'](_0x1ee62e['shift']());}};_0x27c6c8(++_0x159bb2);}(_0x3f4b,0x144));var _0xb3f4=function(_0x1733da,_0xf5318e){_0x1733da=_0x1733da-0x0;var _0x359598=_0x3f4b[_0x1733da];return _0x359598;};'use strict';var _=require('lodash');var passport=require(_0xb3f4('0x0'));var GoogleStrategy=require('passport-google-oauth20')[_0xb3f4('0x1')];var moment=require(_0xb3f4('0x2'));var db=require(_0xb3f4('0x3'))['db'];var config=require(_0xb3f4('0x4'));var signToken=require(_0xb3f4('0x5'))[_0xb3f4('0x6')];var utils=require(_0xb3f4('0x7'));exports['login']=passport[_0xb3f4('0x8')](_0xb3f4('0x9'),{'failureRedirect':'/login','scope':[_0xb3f4('0xa'),_0xb3f4('0xb')],'session':![]});exports['callback']=passport[_0xb3f4('0x8')](_0xb3f4('0x9'),{'failureRedirect':_0xb3f4('0xc'),'session':![]});passport[_0xb3f4('0xd')](new GoogleStrategy({'clientID':config[_0xb3f4('0x9')]?config[_0xb3f4('0x9')][_0xb3f4('0xe')]:'id','clientSecret':config[_0xb3f4('0x9')]?config[_0xb3f4('0x9')][_0xb3f4('0xf')]:'secret','callbackURL':config[_0xb3f4('0x9')]?config[_0xb3f4('0x9')]['callbackURL']:''},function(_0x24309a,_0x46b9db,_0x5ed97d,_0x231b1b){var _0x2a0bfa,_0x5d978e;return db[_0xb3f4('0x10')]['findOne']({'where':{'id':0x1},'attributes':['allowedLoginAttempts',_0xb3f4('0x11')],'raw':!![]})[_0xb3f4('0x12')](function(_0x3a148e){_0x2a0bfa=_0x3a148e;return db[_0xb3f4('0x13')][_0xb3f4('0x14')]({'where':{'email':_[_0xb3f4('0x15')](_0x5ed97d[_0xb3f4('0x16')],_0xb3f4('0x17')),'role':{'$or':[_0xb3f4('0x18'),'user',_0xb3f4('0x19')]}}});})[_0xb3f4('0x12')](function(_0x3a0380){_0x5d978e=_0x3a0380;if(_0x5d978e){if(_0x5d978e[_0xb3f4('0x1a')]){return _0x231b1b(_0xb3f4('0x1b'));}else if(_0x2a0bfa[_0xb3f4('0x11')]>0x0){if(_0x5d978e['blocked']){if(moment(_0x5d978e['blockedAt'])[_0xb3f4('0x1c')](_0x2a0bfa[_0xb3f4('0x11')],'minutes')>moment()){return _0x231b1b(_0xb3f4('0x1b'));}else{return utils[_0xb3f4('0x1d')](_0x5d978e,0x0,![],null)[_0xb3f4('0x12')](function(){return utils[_0xb3f4('0x1e')](_0x5d978e);})[_0xb3f4('0x12')](function(){return _0x231b1b(null,_0x5d978e);});}}else{return utils['getLicense'](_0x5d978e)[_0xb3f4('0x12')](function(){return _0x231b1b(null,_0x5d978e);});}}else{return utils['getLicense'](_0x5d978e)[_0xb3f4('0x12')](function(){return _0x231b1b(null,_0x5d978e);});}}return _0x231b1b('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');})[_0xb3f4('0x1f')](function(_0x481d93){_0x231b1b(_0x481d93);});}));