X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=lib%2FNDWeb%2FController%2FSettings.pm;h=4a60ebebf53354378a35390568121cc6cafcbb45;hb=9fae09d27e069fafcc411d1bb2f3df60055056a7;hp=79c66ed720e5b58d008e52b665663622744e85ad;hpb=b56f06604e4e01c764201b73bfe6c1d746942516;p=ndwebbie.git diff --git a/lib/NDWeb/Controller/Settings.pm b/lib/NDWeb/Controller/Settings.pm index 79c66ed..4a60ebe 100644 --- a/lib/NDWeb/Controller/Settings.pm +++ b/lib/NDWeb/Controller/Settings.pm @@ -6,6 +6,8 @@ use parent 'Catalyst::Controller'; use NDWeb::Include; +use DateTime::TimeZone; + =head1 NAME NDWeb::Controller::Settings - Catalyst Controller @@ -25,7 +27,10 @@ Catalyst Controller. sub index :Path :Args(0) { my ( $self, $c ) = @_; - + my $dbh = $c->model; + + $c->stash(error => $c->flash->{error}); + my @stylesheets = ('Default'); my $dir = $c->path_to('root/static/css/black.css')->dir; while (my $file = $dir->next){ @@ -35,6 +40,20 @@ sub index :Path :Args(0) { } $c->stash(stylesheets => \@stylesheets); + my ($birthday,$timezone) = $dbh->selectrow_array(q{ +SELECT birthday,timezone FROM users WHERE uid = $1 + },undef,$c->user->id); + $c->stash(birthday => $birthday); + + my @timezone = split m{/},$timezone,2; + $c->stash(timezone => \@timezone); + + my @cat = DateTime::TimeZone->categories; + unshift @cat, 'GMT'; + $c->stash(tzcategories => \@cat); + + my @countries = DateTime::TimeZone->names_in_category($timezone[0]); + $c->stash(tzcountries => \@countries); } sub changeStylesheet : Local { @@ -49,6 +68,41 @@ sub changeStylesheet : Local { $c->res->redirect($c->uri_for('')); } +sub changeBirthday : Local { + my ( $self, $c ) = @_; + my $dbh = $c->model; + + my $query = $dbh->prepare(q{UPDATE users SET birthday = NULLIF($2,'')::date + WHERE uid = $1 + }); + eval{ + $query->execute($c->user->id,html_escape $c->req->param('birthday')); + }; + if ($@){ + if ($@ =~ /invalid input syntax for type date/){ + $c->flash(error => 'Bad syntax for day, use YYYY-MM-DD.'); + }else{ + $c->flash(error => $@); + } + } + $c->res->redirect($c->uri_for('')); +} + +sub changeTimezone : Local { + my ( $self, $c ) = @_; + my $dbh = $c->model; + + my $timezone = $c->req->param('timezone'); + my $query = $dbh->prepare(q{UPDATE users SET timezone = $2 WHERE uid = $1}); + eval{ + $dbh->selectrow_array(q{SELECT NOW() AT TIME ZONE $1},undef,$timezone); + $query->execute($c->user->id,$timezone ); + }; + if ($@){ + $c->flash(error => $@); + } + $c->res->redirect($c->uri_for('')); +} sub changePassword : Local { my ( $self, $c ) = @_;