+++ /dev/null
-#**************************************************************************
-# Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu> *
-# *
-# 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 (<htdocs/stylesheets/*.css>){
- if(m{stylesheets/(\w+)\.css}){
- push @stylesheets,{Style => $1, Selected => $1 eq $css ? 1 : 0};
- }
- }
- $BODY->param(StyleSheets => \@stylesheets);
- return $BODY;
-}
-
-1;
--- /dev/null
+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;
--- /dev/null
+[% META title = 'Site preferences' %]
+
+<form action="[% c.uri_for('changeStylesheet') %]" method="post"><fieldset> <legend>Style</legend>
+ Stylesheet: <select name="stylesheet">
+[% FOR style IN stylesheets %]
+ <option value="[% style %]" [% IF style == user.css %]selected[% END %]>[% style %]</option>
+[% END %]
+ </select>
+ <br>
+ <input type="submit" value="Change">
+</fieldset></form>
+<form action="[% c.uri_for('changePassword') %]" method="post"> <fieldset> <legend>Change password</legend>
+ <p>Old password:
+ <input type="password" name="oldpass" value="">
+ New password:
+ <input type="password" name="pass" value="">
+ <input type="submit" value="Submit">
+ </p>
+</fieldset>
+</form>
--- /dev/null
+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' );
+
+
+++ /dev/null
-<form action="/<TMPL_VAR NAME=PAGE>" method="post"><fieldset> <legend>Style</legend>
- <input type="hidden" name="page" value="<TMPL_VAR NAME=PAGE>"/>
- <input type="hidden" name="cmd" value="stylesheet"/>
- Stylesheet: <select name="stylesheet">
- <TMPL_LOOP StyleSheets>
- <option value="<TMPL_VAR NAME=Style>" <TMPL_IF NAME=Selected>selected="selected"</TMPL_IF>><TMPL_VAR NAME=Style></option>
- </TMPL_LOOP>
- </select>
- <br/><input type="submit" value="Change"/>
-</fieldset></form>
-<form action="/<TMPL_VAR NAME=PAGE>" method="post"> <fieldset> <legend>Change password</legend>
- <input type="hidden" name="cmd" value="password"/>
- <input type="hidden" name="page" value="<TMPL_VAR NAME=PAGE>"/>
- <p>Old password:
- <input type="password" name="oldpass" value=""/>
- New password:
- <input type="password" name="pass" value=""/>
- <input type="submit" value="Submit"/>
- </p>
-</fieldset>
-</form>