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