]> ruin.nu Git - ndwebbie.git/commitdiff
Move sms and hostname to settings
authorMichael Andreen <michael@andreen.dev>
Fri, 13 Jan 2023 15:30:08 +0000 (16:30 +0100)
committerMichael Andreen <michael@andreen.dev>
Fri, 13 Jan 2023 15:30:08 +0000 (16:30 +0100)
lib/NDWeb/Controller/Members.pm
lib/NDWeb/Controller/Settings.pm
root/src/members/index.tt2
root/src/settings/index.tt2

index c4d2e2974038f541854d907d5ef7bae19bcf32a0..fb0e6e41d309b425c15ba0004919341e26e27f43 100644 (file)
@@ -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;
index 03dc7824687a9bd21282ceadc38b9fd233e427c9..c983c7643ac9257e0c2421c3f95810b218dc1821 100644 (file)
@@ -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
 
index b166e4cfb596edfeb79b499662859f4b59ca8789..8eb11a4d00b84a6be0cba184899f8b714a8beaa6 100644 (file)
@@ -108,29 +108,6 @@ CrBs: <input type="checkbox" name="class" value="z"[% IF attackgroups.grep('z').
 </p>
 </form>
 </fieldset>
-<form action="[% c.uri_for('posthostupdate') %]" method="post">
-<fieldset class="forum-post"> <legend>Hostname</legend>
-       <p>Hostname:
-       <input style="width:25em" type="text" name="hostname" value="[% u.hostmask %]">
-       <input type="submit" value="Submit">
-       </p>
-</fieldset>
-</form>
-<form action="[% c.uri_for('postsmsupdate') %]" method="post">
-<fieldset class="forum-post"> <legend>SMS</legend>
-       <p>Number:
-       <input type="text" name="sms" value="[% u.sms %]">
-       Info to DCs: <input type="text" name="smsnote" value="[% u.sms_note | html %]">
-       </p>
-       <p>
-       Wake me up if needed:
-       <input type="checkbox" name="callme" value="TRUE"
-       [% IF u.call_if_needed %]checked[% END %]>
-       <input type="submit" value="Submit">
-       </p>
-</fieldset>
-</form>
-</div>
 [% IF c.user.planet %]
 <img class="graph" src="[% c.uri_for('/graphs/planetstats',c.user.planet,STICK) %]" alt="stats for your planet" height="300" width="500">
 <img class="graph" src="[% c.uri_for('/graphs/planetranks',c.user.planet,STICK) %]" alt="ranks for your planet" height="300" width="500">
index 8cafbf4890200404918ffe880fd707d3a62eff55..78e1a145970ddb76135cd15436fa6dbcb5d37783 100644 (file)
@@ -9,6 +9,20 @@
        <br>
        <input type="submit" value="Change">
 </fieldset></form>
+<form action="[% c.uri_for('postsmsupdate') %]" method="post">
+<fieldset class="forum-post"> <legend>SMS</legend>
+       <p>Number:
+       <input type="text" name="sms" value="[% u.sms %]">
+       Info to DCs: <input type="text" name="smsnote" value="[% u.sms_note | html %]">
+       </p>
+       <p>
+       Wake me up if needed:
+       <input type="checkbox" name="callme" value="TRUE"
+       [% IF u.call_if_needed %]checked[% END %]>
+       <input type="submit" value="Submit">
+       </p>
+</fieldset>
+</form>
 <form action="[% c.uri_for('changeDiscordId') %]" method="post"><fieldset> <legend>Discord ID</legend>
        <input type="text" name="discord_id" value="[% discord_id | html %]" class="discord_id">
        <br><input type="submit" value="Change">
@@ -19,7 +33,7 @@
 </fieldset></form>
 <form action="[% c.uri_for('changeBirthday') %]" method="post"><fieldset> <legend>Birthday</legend>
        YYYY-MM-DD:
-       <input type="text" name="birthday" value="[% birthday %]" id="birthday">
+       <input type="text" name="birthday" value="[% u.birthday %]" id="birthday">
        <br><input type="submit" value="Change">
 </fieldset></form>
 <form action="[% c.uri_for('changePassword') %]" method="post"> <fieldset> <legend>Change password</legend>
        <input type="submit" value="Change"></p>
        <p>Remember that GMT stays the same all year, so if you're in the UK you should pick Europe/London.</p>
 </form></fieldset>
+<form action="[% c.uri_for('posthostupdate') %]" method="post">
+<fieldset class="forum-post"> <legend>Hostname</legend>
+       <p>Hostname:
+       <input style="width:25em" type="text" name="hostname" value="[% u.hostmask %]">
+       <input type="submit" value="Submit">
+       </p>
+</fieldset>
+</form>
+</div>
 [%- site.stylesheets = ['ui/ui.datepicker.css'] %]
 <script type="text/javascript" src="/static/ui/ui.core.min.js"></script>
 <script type="text/javascript" src="/static/ui/ui.datepicker.min.js"></script>