5b37cfef5e5589e8eaef50db3af313490953caae
[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 _0x6f8b=['getLicense','catch','passport','passport-google-oauth20','Strategy','moment','../../mysqldb','../../config/environment','../../components/auth/service','signToken','../../config/utils','login','google','/login','email','callback','authenticate','use','clientSecret','secret','Setting','allowedLoginAttempts','blockDuration','then','User','find','map','emails','value','admin','user','agent','Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.','blocked','blockedAt','add','minutes'];(function(_0x1eb6cc,_0x165c4f){var _0xbeacea=function(_0x104568){while(--_0x104568){_0x1eb6cc['push'](_0x1eb6cc['shift']());}};_0xbeacea(++_0x165c4f);}(_0x6f8b,0x1be));var _0xb6f8=function(_0x39f42a,_0x3c68dc){_0x39f42a=_0x39f42a-0x0;var _0x44a41d=_0x6f8b[_0x39f42a];return _0x44a41d;};'use strict';var _=require('lodash');var passport=require(_0xb6f8('0x0'));var GoogleStrategy=require(_0xb6f8('0x1'))[_0xb6f8('0x2')];var moment=require(_0xb6f8('0x3'));var db=require(_0xb6f8('0x4'))['db'];var config=require(_0xb6f8('0x5'));var signToken=require(_0xb6f8('0x6'))[_0xb6f8('0x7')];var utils=require(_0xb6f8('0x8'));exports[_0xb6f8('0x9')]=passport['authenticate'](_0xb6f8('0xa'),{'failureRedirect':_0xb6f8('0xb'),'scope':['profile',_0xb6f8('0xc')],'session':![]});exports[_0xb6f8('0xd')]=passport[_0xb6f8('0xe')]('google',{'failureRedirect':'/login','session':![]});passport[_0xb6f8('0xf')](new GoogleStrategy({'clientID':config[_0xb6f8('0xa')]?config[_0xb6f8('0xa')]['clientID']:'id','clientSecret':config[_0xb6f8('0xa')]?config[_0xb6f8('0xa')][_0xb6f8('0x10')]:_0xb6f8('0x11'),'callbackURL':config[_0xb6f8('0xa')]?config[_0xb6f8('0xa')]['callbackURL']:''},function(_0x10ed95,_0xedbb6f,_0x1a109f,_0x69329e){var _0x7133e2,_0x17f09b;return db[_0xb6f8('0x12')]['findOne']({'where':{'id':0x1},'attributes':[_0xb6f8('0x13'),_0xb6f8('0x14')],'raw':!![]})[_0xb6f8('0x15')](function(_0x1c67e4){_0x7133e2=_0x1c67e4;return db[_0xb6f8('0x16')][_0xb6f8('0x17')]({'where':{'email':_[_0xb6f8('0x18')](_0x1a109f[_0xb6f8('0x19')],_0xb6f8('0x1a')),'role':{'$or':[_0xb6f8('0x1b'),_0xb6f8('0x1c'),_0xb6f8('0x1d')]}}});})[_0xb6f8('0x15')](function(_0x5ce62f){_0x17f09b=_0x5ce62f;if(_0x17f09b){if(_0x17f09b['disabled']){return _0x69329e(_0xb6f8('0x1e'));}else if(_0x7133e2[_0xb6f8('0x14')]>0x0){if(_0x17f09b[_0xb6f8('0x1f')]){if(moment(_0x17f09b[_0xb6f8('0x20')])[_0xb6f8('0x21')](_0x7133e2[_0xb6f8('0x14')],_0xb6f8('0x22'))>moment()){return _0x69329e(_0xb6f8('0x1e'));}else{return utils['clearBlockUser'](_0x17f09b,0x0,![],null)[_0xb6f8('0x15')](function(){return utils[_0xb6f8('0x23')](_0x17f09b);})['then'](function(){return _0x69329e(null,_0x17f09b);});}}else{return utils[_0xb6f8('0x23')](_0x17f09b)['then'](function(){return _0x69329e(null,_0x17f09b);});}}else{return utils[_0xb6f8('0x23')](_0x17f09b)[_0xb6f8('0x15')](function(){return _0x69329e(null,_0x17f09b);});}}return _0x69329e(_0xb6f8('0x1e'));})[_0xb6f8('0x24')](function(_0xdeece1){_0x69329e(_0xdeece1);});}));