Skip to content

Commit

Permalink
Allow free users to run test only if they have a verified email
Browse files Browse the repository at this point in the history
  • Loading branch information
lbartoli79 committed Dec 6, 2024
1 parent ee771ae commit bf0f790
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
35 changes: 29 additions & 6 deletions www/runtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
}
if (array_key_exists('resubmit', $_POST)) {
$test = GetTestInfo(trim($_POST['resubmit']));
if (array_key_exists('key', $test)){
if (array_key_exists('key', $test)) {
$test['key'] = null;
}
if ($test) {
Expand Down Expand Up @@ -221,7 +221,7 @@
$is_private = 0;

$is_private_api_call = !empty($user_api_key) && !empty($req_private) &&
((int)$req_private == 1 || $req_private == 'true');
((int)$req_private == 1 || $req_private == 'true');
$is_private_web_call = $isPaid && ($_POST['private'] == 'on');

if ($is_private_api_call || $is_private_web_call) {
Expand Down Expand Up @@ -900,6 +900,14 @@ function buildSelfHost($hosts)
return $selfHostScript;
}

$isFree = !is_null($request_context->getUser()) && $request_context->getUser()->isFree();

// Allow free user to run test only if email is verified
if ($isFree && !$request_context->getUser()->isVerified()) {
$errorTitle = 'Email address is not verified';
$error = 'Please verify your email address to use WebPageTest.';
}


if (!strlen($error) && CheckIp($test) && CheckUrl($test['url']) && CheckRateLimit($test, $error, $errorTitle)) {
$total_runs = Util::getRunCount($test['runs'], $test['fvonly'], $test['lighthouse'], $test['type']);
Expand Down Expand Up @@ -1827,9 +1835,24 @@ function ValidateParameters(&$test, $locations, &$error, $destination_url = null

// make sure on/off options are explicitly 1 or 0
$values = array(
'private', 'web10', 'ignoreSSL', 'tcpdump', 'standards', 'lighthouse',
'timeline', 'swrender', 'netlog', 'spdy3', 'noscript', 'fullsizevideo',
'blockads', 'sensitive', 'pngss', 'bodies', 'htmlbody', 'pss_advanced',
'private',
'web10',
'ignoreSSL',
'tcpdump',
'standards',
'lighthouse',
'timeline',
'swrender',
'netlog',
'spdy3',
'noscript',
'fullsizevideo',
'blockads',
'sensitive',
'pngss',
'bodies',
'htmlbody',
'pss_advanced',
'noheaders'
);
foreach ($values as $value) {
Expand Down Expand Up @@ -3555,7 +3578,7 @@ function CheckRateLimit($test, &$error, &$errorTitle)

$errorTemplate = "<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) {
$errorTitle = "{$errorTitleTemplate} this month";
$error = $errorTemplate;
Expand Down
5 changes: 5 additions & 0 deletions www/src/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public function isPaid(): bool
($this->payment_status == 'ACTIVE' || $this->isPendingCancelation());
}

public function isFree(): bool
{
return !$this->isPaid() && !$this->isAnon();
}

public function setPaidClient(bool $is_paid): void
{
$this->is_paid_cp_client = $is_paid;
Expand Down

0 comments on commit bf0f790

Please sign in to comment.