aboutsummaryrefslogtreecommitdiff
path: root/app/Http/Controllers/GuestbookController.php
diff options
context:
space:
mode:
authorFrankie B <git@diskfloppy.me>2024-06-11 18:02:01 +0100
committerGitHub <noreply@github.com>2024-06-11 18:02:01 +0100
commit0f52d80ca67a49258b235f5831163dd72fbd54cf (patch)
tree9c5cd36b6e0a233e09ac88a4409fb68c63e4781a /app/Http/Controllers/GuestbookController.php
parenta64bcc2c4639d5804b6dada23151bfcb8b198121 (diff)
Merge MVC rewrite into master (#21)
* Just commit it all * Require auth * crap * Update homepage * Block AI scrapers * Update cache update script * Add dummy file * Remove unnecessary lastfm config var * Use withQueryParameters for LastFM API * Fix embeds * Update example env * Smard
Diffstat (limited to 'app/Http/Controllers/GuestbookController.php')
-rw-r--r--app/Http/Controllers/GuestbookController.php49
1 files changed, 29 insertions, 20 deletions
diff --git a/app/Http/Controllers/GuestbookController.php b/app/Http/Controllers/GuestbookController.php
index 70707d7..df726ef 100644
--- a/app/Http/Controllers/GuestbookController.php
+++ b/app/Http/Controllers/GuestbookController.php
@@ -2,37 +2,46 @@
namespace App\Http\Controllers;
+use App\Models\GuestbookEntry;
use Illuminate\Http\Request;
-use DB;
+use Illuminate\Http\RedirectResponse;
+use Illuminate\Contracts\View\View;
+use Illuminate\Validation\ValidationException;
+use UAParser\Parser;
class GuestbookController extends Controller {
- public function guestbook() {
- return view('pages.guestbook');
+ public function show(): View {
+ $entries = GuestbookEntry::selectEntries();
+ $parser = Parser::create();
+
+ return view('guestbook')
+ ->with('entries', $entries)
+ ->with('parser', $parser);
}
- public function guestbookPost(Request $request) {
+ /**
+ * Creates a new guestbook entry
+ *
+ * @param Request $request
+ * @return RedirectResponse
+ * @throws ValidationException
+ */
+ public function addEntry(Request $request): RedirectResponse {
$this->validate($request, [
'name' => 'required',
'message' => 'required'
]);
- $matching_bans = DB::select('SELECT reason FROM guestbook__bans WHERE ip_address = ?', array($request->ip()));
-
- if (!empty($matching_bans)) {
- return view('errors.guestbook-ipban')->with('reason', $matching_bans[0]->reason);
- }
-
- DB::insert(
- 'INSERT INTO guestbook__entries (name, timestamp, ip_address, agent, message) values (?, ?, ?, ?, ?)',
- [
- htmlspecialchars($request->get('name')),
- time(),
- $request->ip(),
- $request->userAgent(),
- htmlspecialchars($request->get('message'))
- ]
- );
+ GuestbookEntry::insertGuestbookEntry($request);
return back()->with('success', 'Entry submitted successfully!');
}
+
+ public function banIP(string $addr) {
+ // TODO: Add banning system
+ // $matching_bans = DB::select('SELECT reason FROM guestbook__bans WHERE ip_address = ?', array($request->ip()));
+ // if (!empty($matching_bans)) {
+ // return view('errors.guestbook-ipban')->with('reason', $matching_bans[0]->reason);
+ // }
+ }
}