Users using the Tequila login are invited to migrate to gitlab.epfl.ch. This instance will close for Tequila users by May 2020.

Commit 96f8f8cf authored by Florian Vessaz's avatar Florian Vessaz

Fix page display after updating a subscription

parent f6841700
......@@ -270,18 +270,18 @@ post '/member/:username' => sub {
};
};
get '/subscriptions' => sub {
any ['get', 'post'] => '/subscriptions' => sub {
unless (is_admin) {
status '403';
return "Unauthorized";
}
my $message;
my @members = sort {
($b->subscription_expire <=> $a->subscription_expire)
or ($b->subscription <=> $a->subscription)
or ($a->username cmp $b->username)
} values(%{GnuGeneration::Member->all_members});
my %active_members_by_year;
my %inactive_members_by_year;
foreach my $member (@members) {
......@@ -293,57 +293,42 @@ get '/subscriptions' => sub {
}
}
template 'subscriptions', {
'members' => \@members,
'active_members_by_year' => \%active_members_by_year,
'inactive_members_by_year' => \%inactive_members_by_year,
};
};
post '/subscriptions' => sub {
unless (is_admin) {
status '403';
return "Unauthorized";
}
my $members = GnuGeneration::Member->all_members;
my $message;
foreach my $username (keys %$members) {
my $member = $members->{$username};
my $pay_now = params->{$username . '-now'};
my $date = params->{$username . '-date'};
my $ts;
if ($pay_now) {
$ts = time;
} else {
$date =~ m/^(\d\d\d\d)-(\d\d?)-(\d\d?)/;
if ($1 <= 1900 or $2 < 1 or $2 > 12 or $3 < 1 or $3 > 31) {
$message .= "Malformed date for $username.<br/>";
last;
if (request->is_post) {
foreach my $member (@members) {
my $username = $member->username;
my $pay_now = params->{$username . '-now'};
my $date = params->{$username . '-date'};
my $ts;
if ($pay_now) {
$ts = time;
} else {
$ts = POSIX::mktime(0, 0, 0, $3, $2 - 1, $1 - 1900);
$date =~ m/^(\d\d\d\d)-(\d\d?)-(\d\d?)/;
if ($1 <= 1900 or $2 < 1 or $2 > 12 or $3 < 1 or $3 > 31) {
$message .= "Malformed date for $username.<br/>";
last;
} else {
$ts = POSIX::mktime(0, 0, 0, $3, $2 - 1, $1 - 1900);
}
}
}
if (defined $ts) {
my $old_date = POSIX::strftime("%Y-%m-%d", localtime $member->subscription);
my $new_date = POSIX::strftime("%Y-%m-%d", localtime $ts);
unless ($old_date eq $new_date) {
$member->subscription($ts);
$member->shadow_expire_update;
my $expire = $member->subscription_expire_as_string;
$message .= "Updated subscription date for $username, expiration date is now $expire.<br/>";
if (defined $ts) {
my $old_date = POSIX::strftime("%Y-%m-%d", localtime $member->subscription);
my $new_date = POSIX::strftime("%Y-%m-%d", localtime $ts);
unless ($old_date eq $new_date) {
$member->subscription($ts);
$member->shadow_expire_update;
my $expire = $member->subscription_expire_as_string;
$message .= "Updated subscription date for $username, expiration date is now $expire.<br/>";
}
}
}
}
my @members;
push @members, $members->{$_} foreach (sort keys(%$members));
template 'subscriptions', {
'members' => \@members,
'message' => $message,
'members' => \@members,
'active_members_by_year' => \%active_members_by_year,
'inactive_members_by_year' => \%inactive_members_by_year,
};
};
......
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