}
$c->stash(stylesheets => \@stylesheets);
- my ($birthday,$timezone,$email) = $dbh->selectrow_array(q{
-SELECT birthday,timezone,email FROM users WHERE uid = $1
+ my ($birthday,$timezone,$email,$discord_id) = $dbh->selectrow_array(q{
+SELECT birthday,timezone,email,discord_id 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);
my @timezone = split m{/},$timezone,2;
$c->stash(timezone => \@timezone);
$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;
my $dbh = $c->model;
my $query = $dbh->prepare(q{
-SELECT uid,username,pnick,array_to_string(array_agg(g.groupname),', ') AS groups
+SELECT uid,username,discord_id,pnick,array_to_string(array_agg(g.groupname),', ') AS groups
FROM users u LEFT OUTER JOIN (groupmembers gm NATURAL JOIN groups g) USING (uid)
WHERE uid > 0
GROUP BY u.uid,username,pnick
<br>
<input type="submit" value="Change">
</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">
+</fieldset></form>
<form action="[% c.uri_for('changeEmail') %]" method="post"><fieldset> <legend>Email</legend>
<input type="text" name="email" value="[% email | html %]" class="email">
<br><input type="submit" value="Change">
[% META title = 'User listing' %]
<table>
- <tr><th>User</th><th>P-nick</th><th>Groups</th></tr>
+ <tr><th>User</th><th>Discord</th><th>P-nick</th><th>Groups</th></tr>
[% FOR u IN users %]
<tr class="[% loop.count % 2 == 0 ? 'even' : 'odd' %]">
<td><a href="[% c.uri_for('edit',u.uid) %]">[% u.username | html %]</a></td>
- <td>[% u.pnick %]</td>
+ <td>[% u.discord_id | html %]</td>
+ <td>[% u.pnick | html %]</td>
<td>[% u.groups %]</td>
</tr>
[% END %]