Commit 04168253 authored by Timothée Floure's avatar Timothée Floure

Allow users without username to set one

parent 385ed22a
Pipeline #1663 failed with stages
in 10 seconds
......@@ -17,7 +17,8 @@ use Package::Alias
# Export shared variables for use in submodules.
use Exporter 'import';
our @EXPORT_OK = qw(
$mailing_lists $public_mailing_lists $unipoly_main_group $unipoly_groups $mobile_regex
$mailing_lists $public_mailing_lists $unipoly_main_group $unipoly_groups
$mobile_regex $username_regex
);
our $VERSION = '0.1';
......@@ -100,6 +101,7 @@ our $unipoly_groups = {
};
our $mobile_regex = '([0-9\s\-]{7,})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?$';
our $username_regex = '^\w+$';
###
# Load Dancer routes.
......
......@@ -8,7 +8,8 @@ require Lists;
use Package::Alias Mailer => 'MemberManagement::Mail';
use MemberManagement qw(
$unipoly_groups $unipoly_main_group $mailing_lists $mobile_regex $public_mailing_lists
$unipoly_groups $unipoly_main_group $mailing_lists $mobile_regex
$public_mailing_lists $username_regex
);
use MemberManagement::Web::Main qw(is_admin logged_as check_password_token);
......@@ -187,6 +188,16 @@ post '/member/:username' => sub {
}
}
# Handle uid edit (ONLY if no existing username)
if (params->{uid} and not $member->uid) {
if (params->{uid} =~ $username_regex) {
$member->uid(params->{uid});
$message .= "Your username has been set.<br/>";
} else {
$message .= "The username you specified is malformed.<br/>";
}
}
# Handle mobile modification
if (params->{mobile} and not params->{mobile} eq $member->mobile) {
if (params->{mobile} =~ $mobile_regex) {
......
......@@ -342,6 +342,24 @@ sub username {
return $self->{username};
}
=head2 Uid
C<< $members->uid >>
Returns the member's uid.
C<< $member->uid $string >>
Set the uid of the member to the given string. Use with CAUTION.
=cut
sub uid {
my ($self, $new_value) = @_;
if (defined $new_value && not defined $self->{uid}) {
$self->_modify(uid => $new_value);
}
return $self->{uid};
}
=head2 Password
C<< $member->password >>
......
......@@ -16,8 +16,8 @@
<div class="row">
<div class="col-6">
<div class="form-group">
<label for="username">Username</label>
<input type="text" name="username" class="form-control" value="<% member.uid %>" disabled />
<label for="uid">Username</label>
<input type="text" name="uid" class="form-control" value="<% member.uid %>" <% if member.uid %>disabled<% end %>/>
</div>
</div>
<div class="col-6">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment