Built motion from commit (unavailable).|2.6.0
[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 _0x757c=['../../components/auth/service','../../config/utils','login','authenticate','/login','profile','callback','google','use','clientID','secret','callbackURL','findOne','allowedLoginAttempts','User','find','value','admin','user','then','disabled','Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.','blockDuration','blocked','add','minutes','clearBlockUser','getLicense','catch','lodash','passport','passport-google-oauth20','Strategy','moment','../../mysqldb','../../config/environment'];(function(_0x1f92bb,_0x8fe53a){var _0x4678d2=function(_0x175fc2){while(--_0x175fc2){_0x1f92bb['push'](_0x1f92bb['shift']());}};_0x4678d2(++_0x8fe53a);}(_0x757c,0xf5));var _0xc757=function(_0x3d426d,_0x131f72){_0x3d426d=_0x3d426d-0x0;var _0x2e6d48=_0x757c[_0x3d426d];return _0x2e6d48;};'use strict';var _=require(_0xc757('0x0'));var passport=require(_0xc757('0x1'));var GoogleStrategy=require(_0xc757('0x2'))[_0xc757('0x3')];var moment=require(_0xc757('0x4'));var db=require(_0xc757('0x5'))['db'];var config=require(_0xc757('0x6'));var signToken=require(_0xc757('0x7'))['signToken'];var utils=require(_0xc757('0x8'));exports[_0xc757('0x9')]=passport[_0xc757('0xa')]('google',{'failureRedirect':_0xc757('0xb'),'scope':[_0xc757('0xc'),'email'],'session':![]});exports[_0xc757('0xd')]=passport[_0xc757('0xa')](_0xc757('0xe'),{'failureRedirect':_0xc757('0xb'),'session':![]});passport[_0xc757('0xf')](new GoogleStrategy({'clientID':config[_0xc757('0xe')]?config[_0xc757('0xe')][_0xc757('0x10')]:'id','clientSecret':config[_0xc757('0xe')]?config[_0xc757('0xe')]['clientSecret']:_0xc757('0x11'),'callbackURL':config[_0xc757('0xe')]?config[_0xc757('0xe')][_0xc757('0x12')]:''},function(_0x5b394f,_0x302d2b,_0x5818e0,_0x53e826){var _0x116519,_0x33617e;return db['Setting'][_0xc757('0x13')]({'where':{'id':0x1},'attributes':[_0xc757('0x14'),'blockDuration'],'raw':!![]})['then'](function(_0x17e5e6){_0x116519=_0x17e5e6;return db[_0xc757('0x15')][_0xc757('0x16')]({'where':{'email':_['map'](_0x5818e0['emails'],_0xc757('0x17')),'role':{'$or':[_0xc757('0x18'),_0xc757('0x19'),'agent']}}});})[_0xc757('0x1a')](function(_0x12c6f3){_0x33617e=_0x12c6f3;if(_0x33617e){if(_0x33617e[_0xc757('0x1b')]){return _0x53e826(_0xc757('0x1c'));}else if(_0x116519[_0xc757('0x1d')]>0x0){if(_0x33617e[_0xc757('0x1e')]){if(moment(_0x33617e['blockedAt'])[_0xc757('0x1f')](_0x116519['blockDuration'],_0xc757('0x20'))>moment()){return _0x53e826('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');}else{return utils[_0xc757('0x21')](_0x33617e,0x0,![],null)[_0xc757('0x1a')](function(){return utils['getLicense'](_0x33617e);})[_0xc757('0x1a')](function(){return _0x53e826(null,_0x33617e);});}}else{return utils[_0xc757('0x22')](_0x33617e)[_0xc757('0x1a')](function(){return _0x53e826(null,_0x33617e);});}}else{return utils[_0xc757('0x22')](_0x33617e)[_0xc757('0x1a')](function(){return _0x53e826(null,_0x33617e);});}}return _0x53e826(_0xc757('0x1c'));})[_0xc757('0x23')](function(_0x245a7c){_0x53e826(_0x245a7c);});}));