Skip to content

Commit

Permalink
Added template to choose the access duration
Browse files Browse the repository at this point in the history
  • Loading branch information
fdurand committed Jul 16, 2019
1 parent a52caba commit 9d65755
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,21 @@ sub doSponsorRegistration : Private {
}
# Verify if the user has the role mark as sponsor
my $source_match = $c->user_session->{source_match} || $c->user_session->{source_id};
my $value = pf::authentication::match($source_match, {username => $c->user_session->{"username"}, rule_class => $Rules::ADMIN, 'context' => $pf::constants::realm::PORTAL_CONTEXT}, $Actions::MARK_AS_SPONSOR);
unless (defined $value) {
my $matched = pf::authentication::match2($source_match, {username => $c->user_session->{"username"}, rule_class => $Rules::ADMIN, 'context' => $pf::constants::realm::PORTAL_CONTEXT});
my $values = $matched->{values};

unless (defined $values->{$Actions::MARK_AS_SPONSOR}) {
$c->log->error( $c->user_session->{"username"} . " does not have permission to sponsor a user" );
$c->user_session->{username} = undef;
$self->showError($c,"does not have permission to sponsor a user");
$c->detach('login');
}
if ($values->{$Actions::CHOOSE_ACCESS_DURATION}) {
my @options_duration = map { { value => $_, label => $_ } } split(',', $values->{$Actions::CHOOSE_ACCESS_DURATION});
$c->stash->{choose_access_duration} = \@options_duration;
$c->detach('choose_access_duration');
}
}

# handling log out (not exposed to the UI at this point)
# TODO: if we ever expose it, we'll need to alter the form action to make sure to trim it
# otherwise we'll submit our authentication but with ?action=logout so it'll delete the session right away
Expand Down Expand Up @@ -229,6 +235,22 @@ sub doSponsorRegistration : Private {
}
}

=head2 choose_access_duration
=cut

sub choose_access_duration : Private {
my ( $self, $c ) = @_;
if ( $c->has_errors ) {
$c->stash->{txt_auth_error} = join(' ', grep { ref ($_) eq '' } @{$c->error});
$c->clear_errors;
}
$c->stash(
title => "Choose the access duration",
template => $pf::web::guest::SPONSOR_CHOOSE_ACCESS_DURATION_TEMPLATE,
);
}

=head1 AUTHOR
Inverse inc. <info@inverse.ca>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<form method="post" action="[% post_uri %]">

<div class="o-layout o-layout--center u-padding">

<div class="o-layout__item">

[% IF choose_access_duration.size > 1 %]
<div class="input-container">
<label>[% i18n("Access duration") %]</label>
<select name="access_duration">
<option value="">[% i18n('Select access duration') %]</option>
[% FOREACH access_duration IN choose_access_duration %]
<option value='[% access_duration.value %]'>[% access_duration.label %]</option>
[% END %]
</select>
</div>
[% END %]

[%# submit %]
<div class="u-margin-top">
<button type="submit" name="submit" class="c-btn c-btn--primary u-1/1">
[% i18n('Validate') %]
</button>
</div>

</div>
</div>

</form>

1 change: 1 addition & 0 deletions lib/pf/web/guest.pm
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ our $VERSION = 1.41;

our $SPONSOR_CONFIRMED_TEMPLATE = "activation/sponsor_accepted.html";
our $SPONSOR_LOGIN_TEMPLATE = "activation/sponsor_login.html";
our $SPONSOR_CHOOSE_ACCESS_DURATION_TEMPLATE = "activation/sponsor_choose_access_duration.html";

# flag used in URLs
Readonly our $GUEST_REGISTRATION => "guest-register";
Expand Down

0 comments on commit 9d65755

Please sign in to comment.