mirror of
https://github.com/Neetpone/ponepaste.git
synced 2025-03-12 06:30:07 +01:00
Improve error page, make it so blank usernames are not valid, make it so you can log in.
This commit is contained in:
parent
628f3fa944
commit
f1e3166eec
6 changed files with 47 additions and 17 deletions
|
@ -117,6 +117,27 @@ function getFlashes() {
|
||||||
return $flashes;
|
return $flashes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function outputFlashes($flashes) {
|
||||||
|
function __outputFlash($level, $flash) {
|
||||||
|
echo '<div class="notification is-' . $level . ' flash">
|
||||||
|
<i class="fa fa-exclamation-circle" aria-hidden="true"></i>'
|
||||||
|
. pp_html_escape($flash) .
|
||||||
|
'</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($flashes['success'] as $flash) {
|
||||||
|
__outputFlash('info', $flash);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($flashes['warning'] as $flash) {
|
||||||
|
__outputFlash('warning', $flash);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($flashes['error'] as $flash) {
|
||||||
|
__outputFlash('danger', $flash);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Database functions */
|
/* Database functions */
|
||||||
function getSiteInfo() : array {
|
function getSiteInfo() : array {
|
||||||
return require(__DIR__ . '/../config/site.php');
|
return require(__DIR__ . '/../config/site.php');
|
||||||
|
|
|
@ -105,7 +105,7 @@ if (isset($_POST['forgot'])) {
|
||||||
$error = 'All fields must be filled out.';
|
$error = 'All fields must be filled out.';
|
||||||
} elseif (strlen($username) > 25) {
|
} elseif (strlen($username) > 25) {
|
||||||
$error = 'Username too long.'; // "Username already taken.";
|
$error = 'Username too long.'; // "Username already taken.";
|
||||||
} elseif (preg_match('/[^A-Za-z0-9._\\-$]/', $username)) {
|
} elseif (!preg_match('/^[A-Za-z0-9._\\-]+$/', $username)) {
|
||||||
$error = 'Username is invalid - please use A-Za-z0-9, periods, hyphens, and underscores only.';
|
$error = 'Username is invalid - please use A-Za-z0-9, periods, hyphens, and underscores only.';
|
||||||
} else {
|
} else {
|
||||||
if (User::where('username', $username)->first()) {
|
if (User::where('username', $username)->first()) {
|
||||||
|
|
|
@ -229,3 +229,8 @@ button.button--no-style {
|
||||||
margin-bottom: 1rem;
|
margin-bottom: 1rem;
|
||||||
color: black;
|
color: black;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.flash i {
|
||||||
|
margin-right: 0.5rem;
|
||||||
|
font-size: 1.25rem;
|
||||||
|
}
|
|
@ -20,7 +20,10 @@
|
||||||
</form>
|
</form>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<a href="/" class="btn btn-default">New Paste</a>
|
<a href="/" class="btn btn-default">New Paste</a>
|
||||||
|
<?php elseif (isset($flashes)): ?>
|
||||||
|
<?php outputFlashes($flashes) ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
<a href="/" class="button">Go Home</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -71,15 +71,7 @@
|
||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php
|
<?php outputFlashes($flashes) ?>
|
||||||
foreach ($flashes['success'] as $success) {
|
|
||||||
echo '<div class="notification is-info"><i class="fa fa-exclamation-circle" aria-hidden="true"></i>' . pp_html_escape($success) . '</div>';
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($flashes['error'] as $error) {
|
|
||||||
echo '<div class="notification is-danger"><i class="fa fa-exclamation-circle" aria-hidden="true"></i>' . pp_html_escape($error) . '</div>';
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
|
|
||||||
<?php if ($is_current_user): ?>
|
<?php if ($is_current_user): ?>
|
||||||
Some of your statistics:
|
Some of your statistics:
|
||||||
|
|
23
user.php
23
user.php
|
@ -8,8 +8,8 @@ use PonePaste\Models\Paste;
|
||||||
|
|
||||||
if (empty($_GET['user'])) {
|
if (empty($_GET['user'])) {
|
||||||
// No username provided
|
// No username provided
|
||||||
header("Location: ../error.php");
|
flashError('User not found.');
|
||||||
die();
|
goto Render;
|
||||||
}
|
}
|
||||||
|
|
||||||
$profile_username = trim($_GET['user']);
|
$profile_username = trim($_GET['user']);
|
||||||
|
@ -21,8 +21,8 @@ $profile_info = User::with('favourites')
|
||||||
|
|
||||||
if (!$profile_info) {
|
if (!$profile_info) {
|
||||||
// Invalid username
|
// Invalid username
|
||||||
header("Location: ../error.php");
|
flashError('User not found.');
|
||||||
die();
|
goto Render;
|
||||||
}
|
}
|
||||||
|
|
||||||
$p_title = $profile_username . "'s Public Pastes";
|
$p_title = $profile_username . "'s Public Pastes";
|
||||||
|
@ -66,7 +66,16 @@ $is_current_user = ($current_user !== null) && ($profile_info->id == $current_us
|
||||||
updatePageViews();
|
updatePageViews();
|
||||||
|
|
||||||
$csrf_token = setupCsrfToken();
|
$csrf_token = setupCsrfToken();
|
||||||
$page_title = 'Profile of ' . $profile_username;
|
|
||||||
$page_template = 'user_profile';
|
Render:
|
||||||
$script_bundles[] = 'user_profile';
|
|
||||||
|
if (isset($profile_info)) {
|
||||||
|
$page_title = 'Profile of ' . $profile_username;
|
||||||
|
$page_template = 'user_profile';
|
||||||
|
$script_bundles[] = 'user_profile';
|
||||||
|
} else {
|
||||||
|
$page_title = 'User not found';
|
||||||
|
$page_template = 'errors';
|
||||||
|
}
|
||||||
|
|
||||||
require_once('theme/' . $default_theme . '/common.php');
|
require_once('theme/' . $default_theme . '/common.php');
|
||||||
|
|
Loading…
Add table
Reference in a new issue