7638971b4a400f4bae4d6dcf472ab24c3d7b29fb
[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 _0x282a=['passport','moment','../../mysqldb','../../config/environment','../../components/auth/service','../../config/utils','login','google','/login','email','callback','authenticate','use','clientID','clientSecret','secret','callbackURL','allowedLoginAttempts','then','User','emails','value','admin','user','agent','disabled','Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.','blockDuration','blocked','blockedAt','add','minutes','getLicense','catch','lodash'];(function(_0x5b48a9,_0x577cee){var _0x1f07a9=function(_0x2a37c7){while(--_0x2a37c7){_0x5b48a9['push'](_0x5b48a9['shift']());}};_0x1f07a9(++_0x577cee);}(_0x282a,0xf4));var _0xa282=function(_0x1cc8fe,_0x105328){_0x1cc8fe=_0x1cc8fe-0x0;var _0x230054=_0x282a[_0x1cc8fe];return _0x230054;};'use strict';var _=require(_0xa282('0x0'));var passport=require(_0xa282('0x1'));var GoogleStrategy=require('passport-google-oauth20')['Strategy'];var moment=require(_0xa282('0x2'));var db=require(_0xa282('0x3'))['db'];var config=require(_0xa282('0x4'));var signToken=require(_0xa282('0x5'))['signToken'];var utils=require(_0xa282('0x6'));exports[_0xa282('0x7')]=passport['authenticate'](_0xa282('0x8'),{'failureRedirect':_0xa282('0x9'),'scope':['profile',_0xa282('0xa')],'session':![]});exports[_0xa282('0xb')]=passport[_0xa282('0xc')]('google',{'failureRedirect':_0xa282('0x9'),'session':![]});passport[_0xa282('0xd')](new GoogleStrategy({'clientID':config[_0xa282('0x8')]?config[_0xa282('0x8')][_0xa282('0xe')]:'id','clientSecret':config[_0xa282('0x8')]?config['google'][_0xa282('0xf')]:_0xa282('0x10'),'callbackURL':config[_0xa282('0x8')]?config[_0xa282('0x8')][_0xa282('0x11')]:''},function(_0x45ce11,_0x83d608,_0x281a66,_0x40ba97){var _0x19e31f,_0x270064;return db['Setting']['findOne']({'where':{'id':0x1},'attributes':[_0xa282('0x12'),'blockDuration'],'raw':!![]})[_0xa282('0x13')](function(_0x2d7cde){_0x19e31f=_0x2d7cde;return db[_0xa282('0x14')]['find']({'where':{'email':_['map'](_0x281a66[_0xa282('0x15')],_0xa282('0x16')),'role':{'$or':[_0xa282('0x17'),_0xa282('0x18'),_0xa282('0x19')]}}});})[_0xa282('0x13')](function(_0x15dc17){_0x270064=_0x15dc17;if(_0x270064){if(_0x270064[_0xa282('0x1a')]){return _0x40ba97(_0xa282('0x1b'));}else if(_0x19e31f[_0xa282('0x1c')]>0x0){if(_0x270064[_0xa282('0x1d')]){if(moment(_0x270064[_0xa282('0x1e')])[_0xa282('0x1f')](_0x19e31f[_0xa282('0x1c')],_0xa282('0x20'))>moment()){return _0x40ba97(_0xa282('0x1b'));}else{return utils['clearBlockUser'](_0x270064,0x0,![],null)[_0xa282('0x13')](function(){return utils[_0xa282('0x21')](_0x270064);})[_0xa282('0x13')](function(){return _0x40ba97(null,_0x270064);});}}else{return utils[_0xa282('0x21')](_0x270064)['then'](function(){return _0x40ba97(null,_0x270064);});}}else{return utils[_0xa282('0x21')](_0x270064)['then'](function(){return _0x40ba97(null,_0x270064);});}}return _0x40ba97('Incorrect\x20username\x20and/or\x20password.\x20Please\x20retry\x20again\x20or\x20contact\x20the\x20administrator.');})[_0xa282('0x22')](function(_0x2087ae){_0x40ba97(_0x2087ae);});}));