diff --git a/includes/common.php b/includes/common.php
index 4cd07e5..e83629d 100644
--- a/includes/common.php
+++ b/includes/common.php
@@ -117,6 +117,27 @@ function getFlashes() {
return $flashes;
}
+function outputFlashes($flashes) {
+ function __outputFlash($level, $flash) {
+ echo '
+ '
+ . pp_html_escape($flash) .
+ '
';
+ }
+
+ 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 */
function getSiteInfo() : array {
return require(__DIR__ . '/../config/site.php');
diff --git a/login.php b/login.php
index 7a00cf6..7273d92 100644
--- a/login.php
+++ b/login.php
@@ -105,7 +105,7 @@ if (isset($_POST['forgot'])) {
$error = 'All fields must be filled out.';
} elseif (strlen($username) > 25) {
$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.';
} else {
if (User::where('username', $username)->first()) {
diff --git a/theme/bulma/css/paste.css b/theme/bulma/css/paste.css
index f62773d..a10a53c 100644
--- a/theme/bulma/css/paste.css
+++ b/theme/bulma/css/paste.css
@@ -229,3 +229,8 @@ button.button--no-style {
margin-bottom: 1rem;
color: black;
}
+
+.flash i {
+ margin-right: 0.5rem;
+ font-size: 1.25rem;
+}
\ No newline at end of file
diff --git a/theme/bulma/errors.php b/theme/bulma/errors.php
index 4217a4f..168ba3a 100644
--- a/theme/bulma/errors.php
+++ b/theme/bulma/errors.php
@@ -20,7 +20,10 @@
New Paste
+
+
+ Go Home
diff --git a/theme/bulma/user_profile.php b/theme/bulma/user_profile.php
index 896cbaf..7a569f0 100644
--- a/theme/bulma/user_profile.php
+++ b/theme/bulma/user_profile.php
@@ -71,15 +71,7 @@
?>
- ' . pp_html_escape($success) . '';
- }
-
- foreach ($flashes['error'] as $error) {
- echo '' . pp_html_escape($error) . '
';
- }
- ?>
+
Some of your statistics:
diff --git a/user.php b/user.php
index 8b28e44..edf573b 100644
--- a/user.php
+++ b/user.php
@@ -8,8 +8,8 @@ use PonePaste\Models\Paste;
if (empty($_GET['user'])) {
// No username provided
- header("Location: ../error.php");
- die();
+ flashError('User not found.');
+ goto Render;
}
$profile_username = trim($_GET['user']);
@@ -21,8 +21,8 @@ $profile_info = User::with('favourites')
if (!$profile_info) {
// Invalid username
- header("Location: ../error.php");
- die();
+ flashError('User not found.');
+ goto Render;
}
$p_title = $profile_username . "'s Public Pastes";
@@ -66,7 +66,16 @@ $is_current_user = ($current_user !== null) && ($profile_info->id == $current_us
updatePageViews();
$csrf_token = setupCsrfToken();
-$page_title = 'Profile of ' . $profile_username;
-$page_template = 'user_profile';
-$script_bundles[] = 'user_profile';
+
+Render:
+
+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');