]> ruin.nu Git - ndwebbie.git/blob - lib/NDWeb/Controller/Settings.pm
9277c7fadc2d2519cc82465981d165693907642b
[ndwebbie.git] / lib / NDWeb / Controller / Settings.pm
1 package NDWeb::Controller::Settings;
2
3 use strict;
4 use warnings;
5 use parent 'Catalyst::Controller';
6
7 use NDWeb::Include;
8
9 =head1 NAME
10
11 NDWeb::Controller::Settings - Catalyst Controller
12
13 =head1 DESCRIPTION
14
15 Catalyst Controller.
16
17 =head1 METHODS
18
19 =cut
20
21
22 =head2 index 
23
24 =cut
25
26 sub index :Path :Args(0) {
27         my ( $self, $c ) = @_;
28         my $dbh = $c->model;
29
30         $c->stash(error => $c->flash->{error});
31
32         my @stylesheets = ('Default');
33         my $dir = $c->path_to('root/static/css/black.css')->dir;
34         while (my $file = $dir->next){
35                 if(!$file->is_dir && $file->basename =~ m{^(\w+)\.css$}){
36                         push @stylesheets,$1;
37                 }
38         }
39         $c->stash(stylesheets => \@stylesheets);
40         $c->stash(birthday => $dbh->selectrow_array(q{
41                         SELECT birthday FROM users WHERE uid = $1
42                         },undef,$c->user->id)
43         );
44 }
45
46 sub changeStylesheet : Local {
47         my ( $self, $c ) = @_;
48         my $dbh = $c->model;
49
50         my $query = $dbh->prepare(q{UPDATE users SET css = NULLIF($2,'Default')
51                 WHERE uid = $1
52         });
53         $query->execute($c->user->id,html_escape $c->req->param('stylesheet'));
54
55         $c->res->redirect($c->uri_for(''));
56 }
57
58 sub changeBirthday : Local {
59         my ( $self, $c ) = @_;
60         my $dbh = $c->model;
61
62         my $query = $dbh->prepare(q{UPDATE users SET birthday = NULLIF($2,'')::date
63                 WHERE uid = $1
64                 });
65         eval{
66                 $query->execute($c->user->id,html_escape $c->req->param('birthday'));
67         };
68         if ($@){
69                 if ($@ =~ /invalid input syntax for type date/){
70                         $c->flash(error => 'Bad syntax for day, use YYYY-MM-DD.');
71                 }else{
72                         $c->flash(error => $@);
73                 }
74         }
75         $c->res->redirect($c->uri_for(''));
76 }
77
78
79 sub changePassword : Local {
80         my ( $self, $c ) = @_;
81         my $dbh = $c->model;
82
83         my $query = $dbh->prepare(q{UPDATE users SET password = MD5($1)
84                 WHERE password = MD5($2) AND uid = $3
85                 });
86         $query->execute($c->req->param('pass'),$c->req->param('oldpass'),$c->user->id);
87
88         $c->res->redirect($c->uri_for(''));
89 }
90
91
92 =head1 AUTHOR
93
94 Michael Andreen (harv@ruin.nu)
95
96 =head1 LICENSE
97
98 GPL 2.0, or later.
99
100 =cut
101
102 1;