2023-07-16 00:49:09 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2024-06-11 17:02:01 +00:00
|
|
|
use App\Models\GuestbookEntry;
|
2023-07-16 00:49:09 +00:00
|
|
|
use Illuminate\Http\Request;
|
2024-06-11 17:02:01 +00:00
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
use Illuminate\Contracts\View\View;
|
|
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
use UAParser\Parser;
|
2023-07-16 00:49:09 +00:00
|
|
|
|
|
|
|
class GuestbookController extends Controller {
|
2024-06-11 17:02:01 +00:00
|
|
|
public function show(): View {
|
|
|
|
$entries = GuestbookEntry::selectEntries();
|
|
|
|
$parser = Parser::create();
|
|
|
|
|
|
|
|
return view('guestbook')
|
|
|
|
->with('entries', $entries)
|
|
|
|
->with('parser', $parser);
|
2023-07-16 00:49:09 +00:00
|
|
|
}
|
|
|
|
|
2024-06-11 17:02:01 +00:00
|
|
|
/**
|
|
|
|
* Creates a new guestbook entry
|
|
|
|
*
|
|
|
|
* @param Request $request
|
|
|
|
* @return RedirectResponse
|
|
|
|
* @throws ValidationException
|
|
|
|
*/
|
|
|
|
public function addEntry(Request $request): RedirectResponse {
|
2023-07-16 00:49:09 +00:00
|
|
|
$this->validate($request, [
|
|
|
|
'name' => 'required',
|
|
|
|
'message' => 'required'
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
2024-06-11 17:02:01 +00:00
|
|
|
GuestbookEntry::insertGuestbookEntry($request);
|
2023-07-16 00:49:09 +00:00
|
|
|
return back()->with('success', 'Entry submitted successfully!');
|
|
|
|
}
|
2024-06-11 17:02:01 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
// }
|
|
|
|
}
|
2023-07-16 00:49:09 +00:00
|
|
|
}
|