Jifty/Plugin/Authentication/Password/Dispatcher.pm untested

filter: Statementstmt 0.0% 0 / 36 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 68 CC 1 SCAR 6.9
CC
1
Cov
0%
not_logged_in_nav
2.0
logged_in_nav
2.0
BEGIN
2.0
CRAP 2.0
1 use strict;
2 use warnings;
3  
4 package Jifty::Plugin::Authentication::Password::Dispatcher;
5 use Jifty::Dispatcher -base;
6  
7 my ($self) = Jifty->find_plugin('Jifty::Plugin::Authentication::Password');
8  
9 =head1 NAME
10  
11 Jifty::Plugin::Authentication::Password::Dispatcher - password plugin dispatcher
12  
13 =head1 DESCRIPTION
14  
15 All the dispatcher rules jifty needs to support L<Jifty::Authentication::Password/>
16  
17 =head1 RULES
18  
19 =cut
20  
21 before '*' => run {
22 Jifty->api->hide( 'Signup' );
23 } unless $self->signup;
24  
25 =head2 C<before logout>
26  
27 Logout and return home.
28  
29 See L<Jifty::Plugin::Authentication::Password::Action::Logout>.
30  
31 =cut
32  
33 before 'logout' => run {
34 Jifty->web->new_action( class => 'Logout', moniker => 'logout')->run;
35 redirect '/';
36 };
37  
38 # Make sure tangents work
39 # Before password reminders, login or signup, let's push the user off to the homepage if they're logged in
40  
41 =head2 C<before *>
42  
43 Setup the navigation menu for login or logout.
44  
45 =cut
46  
47 before '*' => run {
48 if ( Jifty->web->current_user->id ) {
49 logged_in_nav();
50 } else {
51 not_logged_in_nav();
52  
53 }
54  
55 } if $self->nav_menu;
56  
57 =head2 C<on qr/^(?:signup|lost_password)$/>
58  
59 Redirect to home if logged.
60  
61 Request a password reminder or signup for an account otherwise.
62  
63 =cut
64  
65 before qr'^/(?:signup|lost_password)$' => run {
66 redirect('/') if ( Jifty->web->current_user->id );
67 set 'next' => Jifty->web->request->continuation || Jifty::Continuation->new( request => Jifty::Request->new( path => "/login" ) );
68 };
69  
70 =head2 C<on login>
71  
72 Redirect to home if logged.
73  
74 Show the login form otherwise.
75  
76 =cut
77  
78 before qr|^/(?:login)$| => run {
79 redirect('/') if ( Jifty->web->current_user->id );
80 set 'next' => Jifty->web->request->continuation || Jifty::Continuation->new( request => Jifty::Request->new( path => "/" ) );
81 };
82  
83 =head2 C<before reset_lost_password>
84  
85 Request a password reset.
86  
87 =cut
88  
89 before qr|(?:reset_lost_password)| => run {
90 set 'next' => Jifty->web->request->continuation || Jifty::Continuation->new( request => Jifty::Request->new( path => "/" ) );
91 };
92 # Send a password reminder for a lost password
93  
94 =head2 C<before passwordreminder>
95  
96 Request a new password reminder to be sent by email.
97  
98 See L<Jifty::Plugin::Authentication::Password::Action::SendPasswordReminder>.
99  
100 =cut
101  
102 before 'passwordreminder' => run {
103 set 'action' => Jifty->web->new_action( class => 'SendPasswordReminder', moniker => 'password_reminder');
104 };
105  
106  
107 =head2 C<before signup>
108  
109 Sign up for an account.
110  
111 See L<Jifty::Plugin::Authentication::Password::Action::Signup>.
112  
113 =cut
114  
115 before 'signup' => run {
116 set 'action' => Jifty->web->new_action( class => 'Signup');
117  
118 };
119  
120 =head2 C<before login>
121  
122 Login to your account.
123  
124 See L<Jifty::Plugin::Authentication::Password::Action::Login>.
125  
126 =cut
127  
128 before 'login' => run {
129 set 'action' => Jifty->web->new_action( class => 'Login');
130 };
131  
132 =head2 not_logged_in_nav
133  
134 Adds the login and signup links to the navigation menu.
135  
136 =cut
137  
138 sub not_logged_in_nav {
139 Jifty->web->navigation->child(
140 'Login',
141 link => Jifty->web->tangent(
142 label => _('Login'),
143 url => '/login'
144 ),
145 sort_order => '999'
146 );
147 Jifty->web->navigation->child(
148 'Signup',
149 link => Jifty->web->tangent(
150 label => _('Sign up'),
151 url => '/signup'
152 ),
153 sort_order => '950'
154 );
155 }
156  
157 =head2 logged_in_nav
158  
159 Adds the logout link to the navigation menu.
160  
161 =cut
162  
163 sub logged_in_nav {
164 Jifty->web->navigation->child(
165 Logout => label => _('Logout') =>
166 url => '/logout',
167 sort_order => '999'
168 );
169  
170 }
171  
172 =head1 SEE ALSO
173  
174 L<Jifty::Plugin::Authentication::Password>, L<Jifty::Plugin::Authentication::Password::View>
175  
176 =head1 COPYRIGHT
177  
178 Jifty is Copyright 2005-2010 Best Practical Solutions, LLC.
179 Jifty is distributed under the same terms as Perl itself.
180  
181 =cut
182  
183 1;