]> ruin.nu Git - ndwebbie.git/commitdiff
Interface for searching for quotes
authorMichael Andreen <harv@ruin.nu>
Sat, 17 Aug 2019 16:57:39 +0000 (18:57 +0200)
committerMichael Andreen <harv@ruin.nu>
Sat, 17 Aug 2019 16:57:39 +0000 (18:57 +0200)
lib/NDWeb/Controller/Quotes.pm [new file with mode: 0644]
lib/NDWeb/Controller/Root.pm
root/lib/site/leftbar.tt2
root/src/quotes/index.tt2 [new file with mode: 0644]

diff --git a/lib/NDWeb/Controller/Quotes.pm b/lib/NDWeb/Controller/Quotes.pm
new file mode 100644 (file)
index 0000000..f9dca23
--- /dev/null
@@ -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;
index 5faa024d2567b5c72c0c55aa82262dfd69d367ee..787850019a9929d1fb17a2d3fe9d4088ce5dda3e 100644 (file)
@@ -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;
                }
        }
 
index 601b89e19326015cb6b855ff0ee383c41d122a99..19c9703498f49049fb91f535a53192f136ae9518 100644 (file)
@@ -14,6 +14,7 @@
 [% IF user %]
        <li><a href="/forum/allUnread">New posts [% IF user.unreadposts %](<span class="[% IF user.newposts %]newposts[% ELSE %]unreadposts[% END %]">[% user.unreadposts %]</span>)[% END %]</a></li>
        <li><a href="/forum/privmsg">Priv msg</a></li>
+       <li><a href="/quotes">Quotes</a></li>
        <li><a href="/settings">Settings</a></li>
        <li><a href="/logout">Log out ([% c.user.username %])</a></li>
 [% ELSE %]
diff --git a/root/src/quotes/index.tt2 b/root/src/quotes/index.tt2
new file mode 100644 (file)
index 0000000..22012c7
--- /dev/null
@@ -0,0 +1,19 @@
+[% META title = 'Quotes' %]
+<form action="[% c.uri_for('') %]" method="post"><fieldset> <legend>Search term</legend>
+       <input type="text" name="search" value="[% search | html %]" class="search">
+       <input type="submit" value="Search">
+</fieldset></form>
+
+<table>
+       <tr>
+               <th>Id</th><th>Quote</th>
+       </tr>
+
+[% debug(quotes.size) %]
+[% FOR q IN quotes %]
+       <tr align="center" class="[% loop.count % 2 == 0 ? 'even' : 'odd' %]">
+       <td align="right">[% q.qid %]</td>
+       <td align="left">[% q.quote | html %]</td>
+       </tr>
+[% END %]
+</table>