}
$c->stash(stylesheets => \@stylesheets);
- my ($birthday,$timezone,$email) = $dbh->selectrow_array(q{
-SELECT birthday,timezone,email FROM users WHERE uid = $1
+ my $u = $dbh->selectrow_hashref(q{
+SELECT birthday,timezone,email,discord_id,sms,call_if_needed,sms_note,hostmask
+FROM users WHERE uid = $1
},undef,$c->user->id);
- $c->stash(birthday => $birthday);
- $c->stash(email => $c->flash->{email} // $email);
+ $c->stash(u => $u);
+ $c->stash(email => $c->flash->{email} // $u->{email});
+ $c->stash(discord_id => $c->flash->{discord_id} // $u->{discord_id});
- my @timezone = split m{/},$timezone,2;
+ my @timezone = split m{/},$u->{timezone},2;
$c->stash(timezone => \@timezone);
my @cat = DateTime::TimeZone->categories;
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'));
+ my $css = html_escape $c->req->param('stylesheet');
+ $query->execute($c->user->id,$css);
$c->res->redirect($c->uri_for(''));
}
WHERE uid = $1
});
eval{
- $query->execute($c->user->id,html_escape $c->req->param('birthday'));
+ my $birthday = html_escape $c->req->param('birthday');
+ $query->execute($c->user->id,$birthday);
};
if ($@){
if ($@ =~ /invalid input syntax for type date/){
my ( $self, $c ) = @_;
my $dbh = $c->model;
- if (length $c->req->param('pass') < 4) {
+ my $pass = $c->req->param('pass');
+ if (length $pass < 4) {
$c->flash(error => "Your password need to be at least 4 characters");
} else {
my $query = $dbh->prepare(q{UPDATE users SET password = $1
WHERE password = crypt($2,password) AND uid = $3
});
- $query->execute($c->req->param('pass'),$c->req->param('oldpass'),$c->user->id);
+ my $oldpass = $c->req->param('oldpass');
+ $query->execute($pass,$oldpass,$c->user->id);
$c->flash(error => "Old password was invalid") unless $query->rows;
}
my $email = $c->req->param('email');
+ if ($email =~ /^\s*$/) {
+ my $update = $dbh->prepare(q{
+UPDATE users SET email = NULL WHERE uid = $1;
+ });
+ $update->execute($c->user->id);
+ $c->flash(error => 'email cleared');
+ $c->res->redirect($c->uri_for(''));
+ return,
+ }
+
unless (Email::Valid->address($email)){
$c->flash(email => $email);
$c->flash(error => 'Invalid email address');
my ($id) = $insert->fetchrow_array;
my %mail = (
- smtp => 'ruin.nu',
+ smtp => 'localhost',
To => $email,
From => 'NewDawn Command <nd@ruin.nu>',
'Content-type' => 'text/plain; charset="UTF-8"',
if (sendmail %mail) {
$c->flash(error => 'Sent mail for confirmation.');
}else {
+ $c->flash(email => $email);
$c->flash(error => $Mail::Sendmail::error);
}
};
$c->res->redirect($c->uri_for(''));
}
+sub postsmsupdate : Local {
+ my ( $self, $c ) = @_;
+ my $dbh = $c->model;
+
+ my $callme = $c->req->param('callme') || 0;
+ my $sms = html_escape $c->req->param('sms');
+ my $smsnote = $c->req->param('smsnote');
+ $dbh->do(q{
+UPDATE users SET sms = $1, call_if_needed = $2, sms_note = $3 WHERE uid = $4
+ },undef, $sms, $callme, $smsnote, $c->user->id);
+
+ $c->res->redirect($c->uri_for(''));
+}
+
+sub changeDiscordId : Local {
+ my ( $self, $c ) = @_;
+ my $dbh = $c->model;
+
+ my $discord_id = $c->req->param('discord_id');
+
+ if ($discord_id =~ /^\s*$/) {
+ my $update = $dbh->prepare(q{
+UPDATE users SET discord_id = NULL WHERE uid = $1;
+ });
+ $update->execute($c->user->id);
+ $c->flash(error => 'discord id cleared');
+ $c->res->redirect($c->uri_for(''));
+ return,
+ }
+
+ eval{
+ my $update = $dbh->prepare(q{
+UPDATE users SET discord_id = $2 WHERE uid = $1;
+ });
+ $update->execute($c->user->id,$discord_id);
+ };
+ if($@){
+ if($@ =~ /duplicate key value violates unique constraint/){
+ $c->flash(discord_id => $discord_id);
+ $c->flash(error => 'Someone else is using this discord id, duplicate account?');
+ }else{
+ die $@;
+ }
+ }
+ $c->res->redirect($c->uri_for(''));
+}
+
sub confirmEmail : Local {
my ( $self, $c, $id ) = @_;
my $dbh = $c->model;
$c->res->redirect($c->uri_for(''));
}
+sub posthostupdate : Local {
+ my ( $self, $c ) = @_;
+ my $dbh = $c->model;
+
+ my $hostname = html_escape $c->req->param('hostname');
+ $dbh->do(q{UPDATE users SET hostmask = ? WHERE uid = ?
+ },undef, $hostname, $c->user->id);
+
+ $c->res->redirect($c->uri_for(''));
+}
=head1 AUTHOR