From 572c72716d4975eeaf13ceebb9819bbd91b1a519 Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Sat, 17 Aug 2019 18:57:39 +0200 Subject: [PATCH] Interface for searching for quotes --- lib/NDWeb/Controller/Quotes.pm | 55 ++++++++++++++++++++++++++++++++++ lib/NDWeb/Controller/Root.pm | 4 +++ root/lib/site/leftbar.tt2 | 1 + root/src/quotes/index.tt2 | 19 ++++++++++++ 4 files changed, 79 insertions(+) create mode 100644 lib/NDWeb/Controller/Quotes.pm create mode 100644 root/src/quotes/index.tt2 diff --git a/lib/NDWeb/Controller/Quotes.pm b/lib/NDWeb/Controller/Quotes.pm new file mode 100644 index 0000000..f9dca23 --- /dev/null +++ b/lib/NDWeb/Controller/Quotes.pm @@ -0,0 +1,55 @@ +package NDWeb::Controller::Quotes; + +use strict; +use warnings; +use parent 'Catalyst::Controller'; + +=head1 NAME + +NDWeb::Controller::Quotes - Catalyst Controller + +=head1 DESCRIPTION + +Catalyst Controller. + +=head1 METHODS + +=cut + + +=head2 index + +=cut + +sub index :Path :Args(0) { + my ( $self, $c ) = @_; + + $c->assert_user_roles(qw//); + + my $search = $c->req->param('search'); + $search =~ s/^\s+|\s+$//g if $search; + if ($search) { + $c->stash(search => $search); + my $dbh = $c->model; + my $query = $dbh->prepare(q{ +SELECT qid,quote FROM quotes +WHERE quote ILIKE '%' || $1 || '%' ORDER BY qid ASC + }); + + $query->execute($search); + + $c->stash(quotes => $query->fetchall_arrayref({})); + } +} + +=head1 AUTHOR + +Michael Andreen (harv@ruin.nu) + +=head1 LICENSE + +GPL 2.0, or later + +=cut + +1; diff --git a/lib/NDWeb/Controller/Root.pm b/lib/NDWeb/Controller/Root.pm index 5faa024..7878500 100644 --- a/lib/NDWeb/Controller/Root.pm +++ b/lib/NDWeb/Controller/Root.pm @@ -220,6 +220,10 @@ sub end : ActionClass('RenderView') { $c->stash->{template} = 'access_denied.tt2'; $c->res->status(403); $c->clear_errors; + }elsif ($c->error->[0] =~ m/No logged in user, and none supplied as argument/){ + $c->stash->{template} = 'access_denied.tt2'; + $c->res->status(403); + $c->clear_errors; } } diff --git a/root/lib/site/leftbar.tt2 b/root/lib/site/leftbar.tt2 index 601b89e..19c9703 100644 --- a/root/lib/site/leftbar.tt2 +++ b/root/lib/site/leftbar.tt2 @@ -14,6 +14,7 @@ [% IF user %]
  • New posts [% IF user.unreadposts %]([% user.unreadposts %])[% END %]
  • Priv msg
  • +
  • Quotes
  • Settings
  • Log out ([% c.user.username %])
  • [% ELSE %] diff --git a/root/src/quotes/index.tt2 b/root/src/quotes/index.tt2 new file mode 100644 index 0000000..22012c7 --- /dev/null +++ b/root/src/quotes/index.tt2 @@ -0,0 +1,19 @@ +[% META title = 'Quotes' %] +
    Search term + + +
    + + + + + + +[% debug(quotes.size) %] +[% FOR q IN quotes %] + + + + +[% END %] +
    IdQuote
    [% q.qid %][% q.quote | html %]
    -- 2.39.2