diff --git a/public/static/img/fart.png b/public/static/img/fart.png deleted file mode 100644 index eba7dfe..0000000 Binary files a/public/static/img/fart.png and /dev/null differ diff --git a/routes/willychat.php b/routes/willychat.php index 993904d..add9be4 100644 --- a/routes/willychat.php +++ b/routes/willychat.php @@ -27,34 +27,39 @@ Route::match('get|post','/willychat/', function() { $default_nick = 'Willy'; $nick = $default_nick; $just_sent_message = false; + $errmsg = false; if (!empty($_POST)) { $nick = filter_input(INPUT_POST, 'nick'); $text = filter_input(INPUT_POST, 'text'); - if (empty(trim($nick, ' '))) { - $nick = $default_nick; - } + $errmsg = (function() use (&$text, &$nick): string|false { - if (strlen($nick) > 128) { - view('pages/willychat/error', [ - 'error' => 'Your nickname is too long.' - ]); - die(); - } + if (empty(trim($nick, ' '))) { + return 'You must choose a nickname.'; + } - if (strlen($text) > 4096) { - view('pages/willychat/error', [ - 'error' => 'Do not send EXTREMELY long messages.' - ]); - die(); - } + $nick_max_chars = 128; + if (strlen($nick) > $nick_max_chars) { + return 'Your nickname is too long.'; + } - if (count(WillyChat::$messages) > 10) { - array_pop(WillyChat::$messages); - } + $text_max_chars = 4096; + if (strlen($text) > $text_max_chars) { + return 'Your message is too long. ' . strlen($text) . ' out of ' . $text_max_chars . ' characters.'; + } - if (!empty(trim($text, ' '))) { + if (empty(trim($text, ' '))) { + return 'Message body cannot be empty.'; + } + + return false; + })(); + + if (!$errmsg) { + if (count(WillyChat::$messages) > 10) { + array_pop(WillyChat::$messages); + } array_unshift(WillyChat::$messages, [ 'nick' => $nick, @@ -68,13 +73,13 @@ Route::match('get|post','/willychat/', function() { ) ); } - $just_sent_message = true; } view('pages/willychat/index', [ 'nick' => $nick, 'just_sent_message' => $just_sent_message, + 'errmsg' => $errmsg ]); }); diff --git a/views/pages/willychat/error.php b/views/pages/willychat/error.php deleted file mode 100644 index 43f9e84..0000000 --- a/views/pages/willychat/error.php +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - What are you doing? - - - - - -
- -

- - I understand. - -
- - - \ No newline at end of file diff --git a/views/pages/willychat/index.php b/views/pages/willychat/index.php index b6f5952..4807742 100644 --- a/views/pages/willychat/index.php +++ b/views/pages/willychat/index.php @@ -37,6 +37,7 @@ padding-left: 0; padding-right: 0; border: 0; + text-indent: .5rem; } table { border-collapse: collapse; @@ -44,7 +45,7 @@ width: 100%; } td { - border: 1px solid #aaa; + border: 1px solid silver; } @@ -52,16 +53,20 @@
- + - +
+ +

Error:

+ +
diff --git a/views/pages/willychat/messages.php b/views/pages/willychat/messages.php index f199986..6d1fed1 100644 --- a/views/pages/willychat/messages.php +++ b/views/pages/willychat/messages.php @@ -27,7 +27,7 @@
- says: +