Built motion from commit 3e059bc2.|2.5.32
[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 _0x146b=['blockedAt','minutes','clearBlockUser','getLicense','then','catch','lodash','passport','Strategy','../../mysqldb','../../config/environment','../../components/auth/service','signToken','../../config/utils','login','google','email','authenticate','/login','use','clientID','clientSecret','secret','findOne','allowedLoginAttempts','blockDuration','User','emails','value','admin','agent','disabled','Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.','blocked'];(function(_0x595a27,_0x36a37a){var _0x5233d9=function(_0x4fbca7){while(--_0x4fbca7){_0x595a27['push'](_0x595a27['shift']());}};_0x5233d9(++_0x36a37a);}(_0x146b,0xb0));var _0xb146=function(_0x49fdc9,_0x429f86){_0x49fdc9=_0x49fdc9-0x0;var _0xc586fd=_0x146b[_0x49fdc9];return _0xc586fd;};'use strict';var _=require(_0xb146('0x0'));var passport=require(_0xb146('0x1'));var GoogleStrategy=require('passport-google-oauth20')[_0xb146('0x2')];var moment=require('moment');var db=require(_0xb146('0x3'))['db'];var config=require(_0xb146('0x4'));var signToken=require(_0xb146('0x5'))[_0xb146('0x6')];var utils=require(_0xb146('0x7'));exports[_0xb146('0x8')]=passport['authenticate'](_0xb146('0x9'),{'failureRedirect':'/login','scope':['profile',_0xb146('0xa')],'session':![]});exports['callback']=passport[_0xb146('0xb')](_0xb146('0x9'),{'failureRedirect':_0xb146('0xc'),'session':![]});passport[_0xb146('0xd')](new GoogleStrategy({'clientID':config[_0xb146('0x9')]?config[_0xb146('0x9')][_0xb146('0xe')]:'id','clientSecret':config[_0xb146('0x9')]?config[_0xb146('0x9')][_0xb146('0xf')]:_0xb146('0x10'),'callbackURL':config[_0xb146('0x9')]?config[_0xb146('0x9')]['callbackURL']:''},function(_0x3fbdb7,_0x10f0b4,_0x4f567c,_0x18b47f){var _0x1840f9,_0x351b80;return db['Setting'][_0xb146('0x11')]({'where':{'id':0x1},'attributes':[_0xb146('0x12'),_0xb146('0x13')],'raw':!![]})['then'](function(_0x3352e3){_0x1840f9=_0x3352e3;return db[_0xb146('0x14')]['find']({'where':{'email':_['map'](_0x4f567c[_0xb146('0x15')],_0xb146('0x16')),'role':{'$or':[_0xb146('0x17'),'user',_0xb146('0x18')]}}});})['then'](function(_0x4a36c0){_0x351b80=_0x4a36c0;if(_0x351b80){if(_0x351b80[_0xb146('0x19')]){return _0x18b47f(_0xb146('0x1a'));}else if(_0x1840f9['blockDuration']>0x0){if(_0x351b80[_0xb146('0x1b')]){if(moment(_0x351b80[_0xb146('0x1c')])['add'](_0x1840f9['blockDuration'],_0xb146('0x1d'))>moment()){return _0x18b47f(_0xb146('0x1a'));}else{return utils[_0xb146('0x1e')](_0x351b80,0x0,![],null)['then'](function(){return utils[_0xb146('0x1f')](_0x351b80);})[_0xb146('0x20')](function(){return _0x18b47f(null,_0x351b80);});}}else{return utils[_0xb146('0x1f')](_0x351b80)[_0xb146('0x20')](function(){return _0x18b47f(null,_0x351b80);});}}else{return utils[_0xb146('0x1f')](_0x351b80)[_0xb146('0x20')](function(){return _0x18b47f(null,_0x351b80);});}}return _0x18b47f('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');})[_0xb146('0x21')](function(_0x167611){_0x18b47f(_0x167611);});}));