Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AZU174879: Update Messaging on Page Displayed when Anonymous User Hits Limit #2953

Merged
merged 6 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions www/runtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@

$redirect_cache = array();
$error = null;
$errorTitle = null;
$xml = false;
$usingAPI = false;
$usingApi2 = false;
Expand Down Expand Up @@ -897,7 +898,7 @@ function buildSelfHost($hosts)
}


if (!strlen($error) && CheckIp($test) && CheckUrl($test['url']) && CheckRateLimit($test, $error)) {
if (!strlen($error) && CheckIp($test) && CheckUrl($test['url']) && CheckRateLimit($test, $error, $errorTitle)) {
$total_runs = Util::getRunCount($test['runs'], $test['fvonly'], $test['lighthouse'], $test['type']);
$hasRunsAvailable = !is_null($request_context->getUser()) && $request_context->getUser()->hasEnoughRemainingRuns($total_runs);
$isAnon = !is_null($request_context->getUser()) && $request_context->getUser()->isAnon();
Expand Down Expand Up @@ -1452,6 +1453,7 @@ function buildSelfHost($hosts)
echo $tpl->render('runlimit');
} else {
echo $tpl->render('runtest', array(
'errorTitle' => $errorTitle,
'error' => $error
));
}
Expand Down Expand Up @@ -3498,8 +3500,8 @@ function loggedOutLoginForm()
{
$ret = <<<HTML
<ul class="testerror_login">
<li><a href="/login">Login</a></li>
<li><a class="pill" href="/signup">Sign-up</a></li>
<li><a href="/login">Login</a></li>
</ul>
HTML;

Expand All @@ -3510,15 +3512,15 @@ function loggedInPerks()
{
$msg = <<<HTML
<ul class="testerror_loginperks">
<li>Access to 13 months of saved tests, making it easier to compare tests and analyze trends.</li>
<li>The ability to save your tests! Access up to 13 months of tests, making it easier to compare tests and analyze results</li>
<li>Ability to contribute to the <a href="https://forums.webpagetest.org/">WebPageTest Forum</a>.</li>
<li>Access to upcoming betas and new features that will enhance your WebPageTest experience.</li>
<li>Access to upcoming betas and new features to enhance your WebPageTest experience.</li>
</ul>
HTML;
return $msg;
}

function CheckRateLimit($test, &$error)
function CheckRateLimit($test, &$error, &$errorTitle)
{
global $USER_EMAIL;
global $supportsCPAuth;
Expand Down Expand Up @@ -3551,8 +3553,11 @@ function CheckRateLimit($test, &$error)
$cmrl = new RateLimiter($test['ip'], $monthly_limit);
$passesMonthly = $cmrl->check($total_runs);

$error = "<p>Don't worry! You can keep testing for free once you log in, which will give you access to other excellent features like:</p>";
$errorTitleTemplate = "You've reached the limit for";

if (!$passesMonthly) {
$error = "<p>You've reached the limit for logged-out tests this month, but don't worry! You can keep testing once you log in, which will give you access to other nice features like:</p>";
$errorTitle = "{$errorTitleTemplate} this month";
$error .= <<<HTML
<script>
var intervalId = setInterval(function () {
Expand Down Expand Up @@ -3580,8 +3585,7 @@ function CheckRateLimit($test, &$error)
$count += $total_runs;
Cache::store($cache_key, $count, 1800);
} else {
$apiUrl = Util::getSetting('api_url');
$error = '<p>You\'ve reached the limit for logged-out tests per hour, but don\'t worry! You can keep testing once you log in, which will give you access to other nice features like:</p>';
$errorTitle = "{$errorTitleTemplate} this month";
$error .= <<<HTML
<script>
var intervalId = setInterval(function () {
Expand All @@ -3594,9 +3598,6 @@ function CheckRateLimit($test, &$error)
HTML;

$error .= loggedInPerks();
if ($apiUrl) {
$error .= "<p>And also, if you need to run tests programmatically you might be interested in the <a href='$apiUrl'>WebPageTest API</a></p>";
}
$error .= loggedOutLoginForm();
$ret = false;
}
Expand Down
12 changes: 9 additions & 3 deletions www/templates/errors/runtest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<div class="testerror box">
<h1>Oops! <em>There was a problem with the test.</em></h1>
<h1>Oops! <em>
<?php

echo $error; ?>
$title = "There was a problem with the test.";
if (strlen($errorTitle)) {
$title = $errorTitle ;
}
echo $title;
mjkozicki marked this conversation as resolved.
Show resolved Hide resolved
?>
</em></h1>
<?php echo $error; ?>
</div>
Loading