Skip to content

Commit bf0f790

Browse files
committed
Allow free users to run test only if they have a verified email
1 parent ee771ae commit bf0f790

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

www/runtest.php

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
}
147147
if (array_key_exists('resubmit', $_POST)) {
148148
$test = GetTestInfo(trim($_POST['resubmit']));
149-
if (array_key_exists('key', $test)){
149+
if (array_key_exists('key', $test)) {
150150
$test['key'] = null;
151151
}
152152
if ($test) {
@@ -221,7 +221,7 @@
221221
$is_private = 0;
222222

223223
$is_private_api_call = !empty($user_api_key) && !empty($req_private) &&
224-
((int)$req_private == 1 || $req_private == 'true');
224+
((int)$req_private == 1 || $req_private == 'true');
225225
$is_private_web_call = $isPaid && ($_POST['private'] == 'on');
226226

227227
if ($is_private_api_call || $is_private_web_call) {
@@ -900,6 +900,14 @@ function buildSelfHost($hosts)
900900
return $selfHostScript;
901901
}
902902

903+
$isFree = !is_null($request_context->getUser()) && $request_context->getUser()->isFree();
904+
905+
// Allow free user to run test only if email is verified
906+
if ($isFree && !$request_context->getUser()->isVerified()) {
907+
$errorTitle = 'Email address is not verified';
908+
$error = 'Please verify your email address to use WebPageTest.';
909+
}
910+
903911

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

18281836
// make sure on/off options are explicitly 1 or 0
18291837
$values = array(
1830-
'private', 'web10', 'ignoreSSL', 'tcpdump', 'standards', 'lighthouse',
1831-
'timeline', 'swrender', 'netlog', 'spdy3', 'noscript', 'fullsizevideo',
1832-
'blockads', 'sensitive', 'pngss', 'bodies', 'htmlbody', 'pss_advanced',
1838+
'private',
1839+
'web10',
1840+
'ignoreSSL',
1841+
'tcpdump',
1842+
'standards',
1843+
'lighthouse',
1844+
'timeline',
1845+
'swrender',
1846+
'netlog',
1847+
'spdy3',
1848+
'noscript',
1849+
'fullsizevideo',
1850+
'blockads',
1851+
'sensitive',
1852+
'pngss',
1853+
'bodies',
1854+
'htmlbody',
1855+
'pss_advanced',
18331856
'noheaders'
18341857
);
18351858
foreach ($values as $value) {
@@ -3555,7 +3578,7 @@ function CheckRateLimit($test, &$error, &$errorTitle)
35553578

35563579
$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>";
35573580
$errorTitleTemplate = "You've reached the limit for";
3558-
3581+
35593582
if (!$passesMonthly) {
35603583
$errorTitle = "{$errorTitleTemplate} this month";
35613584
$error = $errorTemplate;

www/src/User.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ public function isPaid(): bool
8989
($this->payment_status == 'ACTIVE' || $this->isPendingCancelation());
9090
}
9191

92+
public function isFree(): bool
93+
{
94+
return !$this->isPaid() && !$this->isAnon();
95+
}
96+
9297
public function setPaidClient(bool $is_paid): void
9398
{
9499
$this->is_paid_cp_client = $is_paid;

0 commit comments

Comments
 (0)