From: Michael Andreen Date: Fri, 20 Jun 2008 14:55:05 +0000 (+0200) Subject: Converted settings to catalyst X-Git-Url: https://ruin.nu/git/?p=ndwebbie.git;a=commitdiff_plain;h=b56f06604e4e01c764201b73bfe6c1d746942516 Converted settings to catalyst --- diff --git a/NDWeb/Pages/Settings.pm b/NDWeb/Pages/Settings.pm deleted file mode 100644 index 962035e..0000000 --- a/NDWeb/Pages/Settings.pm +++ /dev/null @@ -1,59 +0,0 @@ -#************************************************************************** -# Copyright (C) 2006 by Michael Andreen * -# * -# This program is free software; you can redistribute it and/or modify * -# it under the terms of the GNU General Public License as published by * -# the Free Software Foundation; either version 2 of the License, or * -# (at your option) any later version. * -# * -# This program is distributed in the hope that it will be useful, * -# but WITHOUT ANY WARRANTY; without even the implied warranty of * -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -# GNU General Public License for more details. * -# * -# You should have received a copy of the GNU General Public License * -# along with this program; if not, write to the * -# Free Software Foundation, Inc., * -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * -#**************************************************************************/ - -package NDWeb::Pages::Settings; -use strict; -use warnings FATAL => 'all'; -use ND::Include; -use CGI qw/:standard/; -use NDWeb::Include; - -use base qw/NDWeb::XMLPage/; - -$NDWeb::Page::PAGES{settings} = __PACKAGE__; - -sub render_body { - my $self = shift; - my ($BODY) = @_; - $self->{TITLE} = 'Edit site preferences'; - my $DBH = $self->{DBH}; - - if (defined param 'cmd'){ - if(param('cmd') eq 'stylesheet'){ - my $query = $DBH->prepare(q{UPDATE users SET css = NULLIF($2,'Default') WHERE uid = $1}); - $query->execute($ND::UID,escapeHTML(param 'stylesheet')) or $ND::ERROR .= p $DBH->errstr; - } - } - if(param('oldpass') && param('pass')){ - my $query = $DBH->prepare('UPDATE users SET password = MD5(?) WHERE password = MD5(?) AND uid = ?'); - $query->execute(param('pass'),param('oldpass'),$ND::UID); - } - my ($css) = $DBH->selectrow_array(q{SELECT css FROM users WHERE uid = $1},undef,$ND::UID); - my @stylesheets = ({Style => 'Default'}); - $css = '' unless defined $css; - while (){ - if(m{stylesheets/(\w+)\.css}){ - push @stylesheets,{Style => $1, Selected => $1 eq $css ? 1 : 0}; - } - } - $BODY->param(StyleSheets => \@stylesheets); - return $BODY; -} - -1; diff --git a/lib/NDWeb/Controller/Settings.pm b/lib/NDWeb/Controller/Settings.pm new file mode 100644 index 0000000..79c66ed --- /dev/null +++ b/lib/NDWeb/Controller/Settings.pm @@ -0,0 +1,76 @@ +package NDWeb::Controller::Settings; + +use strict; +use warnings; +use parent 'Catalyst::Controller'; + +use NDWeb::Include; + +=head1 NAME + +NDWeb::Controller::Settings - Catalyst Controller + +=head1 DESCRIPTION + +Catalyst Controller. + +=head1 METHODS + +=cut + + +=head2 index + +=cut + +sub index :Path :Args(0) { + my ( $self, $c ) = @_; + + my @stylesheets = ('Default'); + my $dir = $c->path_to('root/static/css/black.css')->dir; + while (my $file = $dir->next){ + if(!$file->is_dir && $file->basename =~ m{^(\w+)\.css$}){ + push @stylesheets,$1; + } + } + $c->stash(stylesheets => \@stylesheets); + +} + +sub changeStylesheet : Local { + my ( $self, $c ) = @_; + my $dbh = $c->model; + + my $query = $dbh->prepare(q{UPDATE users SET css = NULLIF($2,'Default') + WHERE uid = $1 + }); + $query->execute($c->user->id,html_escape $c->req->param('stylesheet')); + + $c->res->redirect($c->uri_for('')); +} + + +sub changePassword : Local { + my ( $self, $c ) = @_; + my $dbh = $c->model; + + my $query = $dbh->prepare(q{UPDATE users SET password = MD5($1) + WHERE password = MD5($2) AND uid = $3 + }); + $query->execute($c->req->param('pass'),$c->req->param('oldpass'),$c->user->id); + + $c->res->redirect($c->uri_for('')); +} + + +=head1 AUTHOR + +Michael Andreen (harv@ruin.nu) + +=head1 LICENSE + +GPL 2.0, or later. + +=cut + +1; diff --git a/root/src/settings/index.tt2 b/root/src/settings/index.tt2 new file mode 100644 index 0000000..62478b1 --- /dev/null +++ b/root/src/settings/index.tt2 @@ -0,0 +1,20 @@ +[% META title = 'Site preferences' %] + +
Style + Stylesheet: +
+ +
+
Change password +

Old password: + + New password: + + +

+
+
diff --git a/t/controller_Settings.t b/t/controller_Settings.t new file mode 100644 index 0000000..add70bd --- /dev/null +++ b/t/controller_Settings.t @@ -0,0 +1,10 @@ +use strict; +use warnings; +use Test::More tests => 3; + +BEGIN { use_ok 'Catalyst::Test', 'NDWeb' } +BEGIN { use_ok 'NDWeb::Controller::Settings' } + +ok( request('/settings')->is_success, 'Request should succeed' ); + + diff --git a/templates/settings.tmpl b/templates/settings.tmpl deleted file mode 100644 index b95ba5c..0000000 --- a/templates/settings.tmpl +++ /dev/null @@ -1,21 +0,0 @@ -
Style - - - Stylesheet: -
-
-
Change password - - -

Old password: - - New password: - - -

-
-