line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CatalystX::SimpleLogin::TraitFor::Controller::Login::WithRedirect; |
2
|
5
|
|
|
5
|
|
31099
|
use MooseX::MethodAttributes::Role; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
52
|
|
3
|
5
|
|
|
5
|
|
193817
|
use Moose::Autobox; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
46
|
|
4
|
5
|
|
|
5
|
|
2120
|
use namespace::autoclean; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
59
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
requires qw/ |
7
|
|
|
|
|
|
|
redirect_after_login_uri |
8
|
|
|
|
|
|
|
/; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
around 'redirect_after_login_uri' => sub { |
11
|
|
|
|
|
|
|
my ($orig, $self, $c, @args) = @_; |
12
|
|
|
|
|
|
|
if (!$c->can('session')) { |
13
|
|
|
|
|
|
|
$c->log->warn('No $c->session, cannot do ' . __PACKAGE__); |
14
|
|
|
|
|
|
|
return $self->$orig($c, @args); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
return $c->session->{redirect_to_after_login} |
17
|
|
|
|
|
|
|
? delete $c->session->{redirect_to_after_login} |
18
|
|
|
|
|
|
|
: $self->$orig($c, @args); |
19
|
|
|
|
|
|
|
}; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
before login_redirect => sub { |
22
|
|
|
|
|
|
|
my ($self, $c, $message) = @_; |
23
|
|
|
|
|
|
|
$c->flash->{error_msg} = $message; # FIXME - Flash horrible |
24
|
|
|
|
|
|
|
$c->session->{redirect_to_after_login} |
25
|
|
|
|
|
|
|
= $c->req->uri->as_string; |
26
|
|
|
|
|
|
|
}; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
1; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
__END__ |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 NAME |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
CatalystX::SimpleLogin::TraitFor::Controller::Login::WithRedirect - redirect |
35
|
|
|
|
|
|
|
users who login back to the page they originally requested. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 SYNOPSIS |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
package MyApp::Controller::NeedsAuth; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
use Moose; |
42
|
|
|
|
|
|
|
use namespace::autoclean; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# One needs to inherit from Catalyst::Controller in order |
45
|
|
|
|
|
|
|
# to get the Does('NeedsLogin') functionality. |
46
|
|
|
|
|
|
|
BEGIN { extends 'Catalyst::Controller'; } |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub inbox : Path Does('NeedsLogin') { |
49
|
|
|
|
|
|
|
# Redirects to /login if not logged in |
50
|
|
|
|
|
|
|
my ($self, $c) = @_; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
$c->stash->{template} = "inbox.tt2"; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
return; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# Turn on in config |
58
|
|
|
|
|
|
|
MyApp->config('Contoller::Login' => { traits => 'WithRedirect' }); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 DESCRIPTION |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Provides the C<login> |
63
|
|
|
|
|
|
|
action with a wrapper to redirect to a page which needs authentication, from which the |
64
|
|
|
|
|
|
|
user was previously redirected. Goes hand in hand with L<Catalyst::ActionRole::NeedsLogin> |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 WRAPPED METHODS |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 redirect_after_login_uri |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Make it use and extract C<< $c->session->{redirect_to_after_login} >> |
71
|
|
|
|
|
|
|
if it exists. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 METHODS |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head2 $controller->login_redirect($c, $message) |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
This sets the error message to $message and sets |
78
|
|
|
|
|
|
|
C<< $c->session->{redirect_to_after_login} >> to the current URL. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 SEE ALSO |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=over |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=item L<CatalystX::SimpleLogin::Controller::Login> |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=item L<CatalystX::SimpleLogin::Form::Login> |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=back |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 AUTHORS |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
See L<CatalystX::SimpleLogin> for authors. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 LICENSE |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
See L<CatalystX::SimpleLogin> for license. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=cut |
99
|
|
|
|
|
|
|
|