Merged in feature/PMC-1158 (pull request #7089)
PMC-721 PMCORE-1015 Approved-by: Paula Quispe <paula.quispe@processmaker.com>
This commit is contained in:
@@ -3,6 +3,7 @@ namespace ProcessMaker\Services\OAuth2;
|
||||
|
||||
use Luracast\Restler\iAuthenticate;
|
||||
use Luracast\Restler\RestException;
|
||||
use OAuth2\Request;
|
||||
/*----------------------------------********---------------------------------*/
|
||||
use ProcessMaker\ChangeLog\ChangeLog;
|
||||
/*----------------------------------********---------------------------------*/
|
||||
@@ -411,6 +412,19 @@ class Server implements iAuthenticate
|
||||
|
||||
public static function getUserId()
|
||||
{
|
||||
// If is empty, get the User Uid using the current request
|
||||
if (empty(self::$userId) && !empty(self::$dsn)) {
|
||||
// Get current request object
|
||||
$request = Request::createFromGlobals();
|
||||
|
||||
// Get token data
|
||||
$serverInstance = new Server();
|
||||
$server = $serverInstance->getServer();
|
||||
$tokenData = $server->getAccessTokenData($request);
|
||||
|
||||
// Set the User Uid
|
||||
self::$userId = $tokenData['user_id'];
|
||||
}
|
||||
return self::$userId;
|
||||
}
|
||||
|
||||
|
||||
@@ -70,18 +70,18 @@ class ValidationUploadedFiles
|
||||
->validate($file, function($file) {
|
||||
$systemConfiguration = System::getSystemConfiguration('', '', config("system.workspace"));
|
||||
$filesWhiteList = explode(',', $systemConfiguration['upload_attempts_limit_per_user']);
|
||||
$userId = Server::getUserId();
|
||||
$userId = !empty($_SESSION['USER_LOGGED']) ? $_SESSION['USER_LOGGED'] : Server::getUserId();
|
||||
$key = config("system.workspace") . '/' . $userId;
|
||||
$attemps = (int) trim($filesWhiteList[0]);
|
||||
$attempts = (int) trim($filesWhiteList[0]);
|
||||
$minutes = (int) trim($filesWhiteList[1]);
|
||||
$pastAttemps = Cache::remember($key, $minutes, function() {
|
||||
$pastAttempts = Cache::remember($key, $minutes, function() {
|
||||
return 1;
|
||||
});
|
||||
//We only increase when the file path exists, useful when pre-validation is done.
|
||||
if (isset($file->path)) {
|
||||
Cache::increment($key, 1);
|
||||
}
|
||||
if ($pastAttemps <= $attemps) {
|
||||
if ($pastAttempts <= $attempts) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user