From 202d442fc929b5e4cea904406dc546098516fde1 Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Fri, 13 Jan 2023 16:30:08 +0100 Subject: [PATCH] Move sms and hostname to settings --- lib/NDWeb/Controller/Members.pm | 27 +---------------------- lib/NDWeb/Controller/Settings.pm | 38 +++++++++++++++++++++++++++----- root/src/members/index.tt2 | 23 ------------------- root/src/settings/index.tt2 | 25 ++++++++++++++++++++- 4 files changed, 57 insertions(+), 56 deletions(-) diff --git a/lib/NDWeb/Controller/Members.pm b/lib/NDWeb/Controller/Members.pm index c4d2e29..fb0e6e4 100644 --- a/lib/NDWeb/Controller/Members.pm +++ b/lib/NDWeb/Controller/Members.pm @@ -34,7 +34,7 @@ sub index : Path : Args(0) { $c->stash(u => $dbh->selectrow_hashref(q{SELECT pid AS planet,defense_points ,attack_points,scan_points,humor_points , (attack_points+defense_points+scan_points/20)::NUMERIC(5,1) as total_points - , sms,rank,hostmask,call_if_needed,sms_note,defprio + , rank,defprio FROM users_defprio WHERE uid = ? },undef,$c->user->id) ); @@ -83,17 +83,6 @@ SELECT array_agg(gid) FROM groupmembers WHERE gid IN ('x','y','z') AND uid = $1 } -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('')); -} - sub postattackgroups : Local { my ( $self, $c ) = @_; my $dbh = $c->model; @@ -111,20 +100,6 @@ sub postattackgroups : Local { $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 postowncoords : Local { my ( $self, $c ) = @_; my $dbh = $c->model; diff --git a/lib/NDWeb/Controller/Settings.pm b/lib/NDWeb/Controller/Settings.pm index 03dc782..c983c76 100644 --- a/lib/NDWeb/Controller/Settings.pm +++ b/lib/NDWeb/Controller/Settings.pm @@ -43,14 +43,15 @@ sub index :Path :Args(0) { } $c->stash(stylesheets => \@stylesheets); - my ($birthday,$timezone,$email,$discord_id) = $dbh->selectrow_array(q{ -SELECT birthday,timezone,email,discord_id 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(discord_id => $c->flash->{discord_id} // $discord_id); + $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; @@ -179,6 +180,7 @@ use the following url to confirm the change: if (sendmail %mail) { $c->flash(error => 'Sent mail for confirmation.'); }else { + $c->flash(email => $email); $c->flash(error => $Mail::Sendmail::error); } }; @@ -193,6 +195,20 @@ use the following url to confirm the change: $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; @@ -250,6 +266,16 @@ RETURNING email $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 diff --git a/root/src/members/index.tt2 b/root/src/members/index.tt2 index b166e4c..8eb11a4 100644 --- a/root/src/members/index.tt2 +++ b/root/src/members/index.tt2 @@ -108,29 +108,6 @@ CrBs: -
-
Hostname -

Hostname: - - -

-
-
-
-
SMS -

Number: - - Info to DCs: -

-

- Wake me up if needed: - - -

-
-
- [% IF c.user.planet %] stats for your planet ranks for your planet diff --git a/root/src/settings/index.tt2 b/root/src/settings/index.tt2 index 8cafbf4..78e1a14 100644 --- a/root/src/settings/index.tt2 +++ b/root/src/settings/index.tt2 @@ -9,6 +9,20 @@
+
+
SMS +

Number: + + Info to DCs: +

+

+ Wake me up if needed: + + +

+
+
Discord ID
@@ -19,7 +33,7 @@
Birthday YYYY-MM-DD: - +
Change password @@ -47,6 +61,15 @@

Remember that GMT stays the same all year, so if you're in the UK you should pick Europe/London.

+
+
Hostname +

Hostname: + + +

+
+
+ [%- site.stylesheets = ['ui/ui.datepicker.css'] %] -- 2.39.2