Merged in bugfix/PMCORE-779 (pull request #7223)

PMCORE-779

Approved-by: Julio Cesar Laura Avendaño <contact@julio-laura.com>
This commit is contained in:
Roly
2020-01-24 16:09:07 +00:00
committed by Julio Cesar Laura Avendaño
3 changed files with 45 additions and 17 deletions

View File

@@ -1,5 +1,7 @@
<?php
use Illuminate\Support\Facades\Cache;
global $RBAC;
$resultRbac = $RBAC->requirePermissions('PM_SETUP_EMAIL');
@@ -9,6 +11,12 @@ if (!$resultRbac) {
die();
}
$messageSent = "";
if (Cache::has('errorMessageIfNotAuthenticate')) {
$messageSent = Cache::get('errorMessageIfNotAuthenticate');
}
Cache::forget('errorMessageIfNotAuthenticate');
//Data
$configuration = new Configurations();
$arrayConfigPage = $configuration->getConfiguration("emailServerList", "pageSize", null, $_SESSION["USER_LOGGED"]);
@@ -20,6 +28,7 @@ $headPublisher = headPublisher::getSingleton();
$headPublisher->addContent("emailServer/emailServer"); //Adding a HTML file
$headPublisher->addExtJsScript("emailServer/emailServer", false); //Adding a JavaScript file
$headPublisher->assign("CONFIG", $arrayConfig);
$headPublisher->assign("errorMessageIfNotAuthenticate", $messageSent);
/*----------------------------------********---------------------------------*/
$headPublisher->assign("EMAILSERVER_LICENSED", (PMLicensedFeatures::getSingleton()->verifyfeature("zIKRGpDM3pjcHFsWGplNDN0dTl5bGN3UTNiOWdQU0E5Q05QTksrU1ladWQ0VT0=")) ? 1 : 0);

View File

@@ -1,26 +1,41 @@
<?php
use Illuminate\Support\Facades\Cache;
use ProcessMaker\Core\System;
use ProcessMaker\GmailOAuth\GmailOAuth;
$header = "location:" . System::getServerMainPath() . "/setup/main?s=EMAIL_SERVER";
Cache::forget('errorMessageIfNotAuthenticate');
try {
$header = "location:" . System::getServerMainPath() . "/setup/main?s=EMAIL_SERVER";
$validInput = empty($_GET['code']) || empty($_SESSION['gmailOAuth']) || !is_object($_SESSION['gmailOAuth']);
if ($validInput) {
G::header($header);
$validInput = empty($_GET['code']) || empty($_SESSION['gmailOAuth']) || !is_object($_SESSION['gmailOAuth']);
if ($validInput) {
G::header($header);
exit();
}
$RBAC->allows(basename(__FILE__), "code");
$gmailOAuth = $_SESSION['gmailOAuth'];
$googleClient = $gmailOAuth->getGoogleClient();
$result = $googleClient->authenticate($_GET['code']);
if (isset($result["error"])) {
Cache::put('errorMessageIfNotAuthenticate', G::json_decode($result["error"]), 2);
G::header($header);
exit();
}
$gmailOAuth->setRefreshToken($googleClient->getRefreshToken());
$gmailOAuth->saveEmailServer();
$gmailOAuth->sendTestMailWithPHPMailerOAuth();
} catch (Exception $e) {
/**
* The laravel cache is volatile in each session, you can specify the duration
* value in minutes for each session. We use 2 minutes, enough time to retrieve
* the error message if there is one.
*/
Cache::put('errorMessageIfNotAuthenticate', $e->getMessage(), 2);
}
$RBAC->allows(basename(__FILE__), "code");
$gmailOAuth = $_SESSION['gmailOAuth'];
$googleClient = $gmailOAuth->getGoogleClient();
$result = $googleClient->authenticate($_GET['code']);
if (isset($result["error"])) {
G::header($header);
}
$gmailOAuth->setRefreshToken($googleClient->getRefreshToken());
$gmailOAuth->saveEmailServer();
$gmailOAuth->sendTestMailWithPHPMailerOAuth();
G::header($header);
exit();

View File

@@ -1283,6 +1283,10 @@ emailServer.application = {
autoScroll: false,
items: [grdpnlMain]
});
if (errorMessageIfNotAuthenticate && errorMessageIfNotAuthenticate !== "") {
Ext.MessageBox.alert(_("ID_INVALID_DATA"), errorMessageIfNotAuthenticate);
}
}
}