...
 
Commits (2)
# Top-most EditorConfig file.
root = true
[*.pm]
indent_style = tab
......@@ -29,6 +29,7 @@ my $mailing_lists = {
'membres@lists.unipoly.ch' => "The list of Unipoly members",
};
my $unipoly_main_group = 'membres';
my $unipoly_projects = {
'actions' => "Pôle d\'actions (actions/events group)",
'api' => 'Apiculture (Beekeeping)',
......@@ -607,14 +608,57 @@ get '/member/:username' => sub {
}
}
# A member is active if contained in the members group
my $members = Unipoly::Group->new($unipoly_main_group);
my $active = $members->contains(params->{username});
template 'member', {
'member' => $member,
'selected_projects' => $selected_projects,
'mailing_lists' => $mailing_lists,
'projects' => $unipoly_projects,
'active' => $active,
};
};
post '/member/:username/disable' => sub {
unless (is_admin or logged_as params->{username}) {
status '403';
return "Unauthorized";
}
my $member = Unipoly::Member->new(username => params->{username});
unless (defined $member) {
status '404';
return 'Member not found';
}
my $members = Unipoly::Group->new($unipoly_main_group);
unless ($members->contains(params->{username})) {
status '403';
return 'Member is inactive.';
}
my $message;
if ($members->contains(params->{username})) {
$members->remove(params->{username});
$message .= 'You have been removed from the members';
}
foreach my $project (keys %$unipoly_projects) {
my $group = Unipoly::Group->new($project);
if ($group->contains(params->{username})) {
$group->remove(params->{username});
$message .= 'You have been removed from: ' .
$unipoly_projects->{$project};
}
}
flash message => $message;
redirect '/member/' . params->{username};
};
post '/member/:username' => sub {
unless (is_admin or logged_as params->{username}) {
status '403';
......@@ -627,6 +671,12 @@ post '/member/:username' => sub {
return 'Member not found';
}
my $members = Unipoly::Group->new($unipoly_main_group);
unless ($members->contains(params->{username})) {
status '403';
return 'Member is inactive.';
}
my $message;
# Handle password modification
......@@ -677,7 +727,6 @@ post '/member/:username' => sub {
foreach my $project (keys %$unipoly_projects) {
my $value = params->{'project-' . $project};
my $group = Unipoly::Group->new($project);
debug Dumper $project;
if ($group->contains(params->{username})) {
if (!defined $value) {
$group->remove(params->{username});
......@@ -686,7 +735,7 @@ post '/member/:username' => sub {
}
} elsif (defined $value && $value eq 'on') {
$group->add(params->{username});
$message .= 'You have been added to: ' .
$message .= "\n You have been added to: " .
$unipoly_projects->{$project};
}
}
......@@ -703,5 +752,4 @@ post '/member/:username' => sub {
redirect '/member/' . params->{username};
};
true;
<h1>Hello, <% member.firstName %></h1>
<% unless active %>
<div class="alert alert-danger" role="alert">
This member account is inactive.
</div>
<% end %>
<p>
Please contact the IT manager (<code>webmaster@unipoly.ch</code>) if you
can't correct some information.
......@@ -127,3 +133,11 @@
<button class="btn btn-outline-primary btn-lg btn-block" type="submit">Save changes</button>
</form>
<hr />
<form method="POST" action="/member/<% member.username %>/disable">
<button class="btn btn-danger btn-sm btn-block" type="submit" onclick="return confirm('This will disable your account and remove you from mailing lists. Are you sure?');">
Disable my account, I want to leave Unipoly!
</button>
</form>