| 1 | use warnings; | ||
| 2 | use strict; | ||
| 3 | |||
| 4 | =head1 NAME | ||
| 5 | |||
| 6 | Jifty::Plugin::Authentication::Password::View - views for password plugin | ||
| 7 | |||
| 8 | =head1 DESCRIPTION | ||
| 9 | |||
| 10 | This provides the templates for the pages and forms used by the | ||
| 11 | password authentication plugin. | ||
| 12 | |||
| 13 | =cut | ||
| 14 | |||
| 15 | package Jifty::Plugin::Authentication::Password::View; | ||
| 16 | use Jifty::View::Declare -base; | ||
| 17 | |||
| 18 | my ($self) = Jifty->find_plugin('Jifty::Plugin::Authentication::Password'); | ||
| 19 | |||
| 20 | =head1 TEMPLATES | ||
| 21 | |||
| 22 | =head2 signup | ||
| 23 | |||
| 24 | Displays a sign-up form. | ||
| 25 | |||
| 26 | =cut | ||
| 27 | |||
| 28 | if ($self->signup) { | ||
| 29 | template 'signup' => page { title => _('Sign up') } content { | ||
| 30 | show 'signup_widget'; | ||
| 31 | }; | ||
| 32 | |||
| 33 | template 'signup_widget' => sub { | ||
| 34 | my ( $action, $next ) = get(qw(action next)); | ||
| 35 | $action ||= new_action( class => 'Signup' ); | ||
| 36 | $next ||= Jifty::Continuation->new( request => Jifty::Request->new(path => "/") ); | ||
| 37 | Jifty->web->form->start( call => $next ); | ||
| 38 | render_param( $action => 'name' , focus => 1); | ||
| 39 | render_param( $action => $_ ) for ( grep {$_ ne 'name'} $action->argument_names ); | ||
| 40 | form_return( label => _('Sign up'), submit => $action ); | ||
| 41 | Jifty->web->form->end(); | ||
| 42 | }; | ||
| 43 | } | ||
| 44 | |||
| 45 | =head2 login | ||
| 46 | |||
| 47 | Displays the login form. | ||
| 48 | |||
| 49 | =cut | ||
| 50 | |||
| 51 | template login => page { title => _('Login!') } content { | ||
| 52 | show('/login_widget'); | ||
| 53 | }; | ||
| 54 | |||
| 55 | =head2 login_widget | ||
| 56 | |||
| 57 | A handy template for embedding the login form. Just include it in your templates via: | ||
| 58 | |||
| 59 | show('/login_widget'); | ||
| 60 | |||
| 61 | See L<Jifty::Plugin::Authentication::Password::Action::Login>. | ||
| 62 | |||
| 63 | =cut | ||
| 64 | |||
| 65 | template login_widget => sub { | ||
| 66 | |||
| 67 | my ( $action, $next ) = get( 'action', 'next' ); | ||
| 68 | $action ||= new_action( class => 'Login' ); | ||
| 69 | my $moniker = $action->moniker; | ||
| 70 | $next ||= Jifty::Continuation->new( | ||
| 71 | request => Jifty::Request->new( path => "/" ) ); | ||
| 72 | unless ( Jifty->web->current_user->id ) { | ||
| 73 | p {{ class is 'signup-pointer' }; | ||
| 74 | outs( _( "No account yet? It's quick and easy. " )); | ||
| 75 | tangent( label => _("Sign up for an account!"), url => '/signup'); | ||
| 76 | }; | ||
| 77 | h3 { _('Login with a password') }; | ||
| 78 | div { | ||
| 79 | attr { id => 'jifty-login' }; | ||
| 80 | Jifty->web->form->start( call => $next ); | ||
| 81 | if ($action->login_by eq 'username' ) { | ||
| 82 | render_param( $action, 'username', focus => 1 ); | ||
| 83 | } else { | ||
| 84 | render_param( $action, 'email', focus => 1 ); | ||
| 85 | }; | ||
| 86 | render_param( $action, $_ ) for (qw(password remember token hashed_password)); | ||
| 87 | form_return( | ||
| 88 | label => _(q{Login}), | ||
| 89 | submit => $action, | ||
| 90 | onclick => "return getPasswordToken('$moniker');" | ||
| 91 | ); | ||
| 92 | hyperlink( | ||
| 93 | label => _("Lost your password?"), | ||
| 94 | url => "/lost_password" | ||
| 95 | ); | ||
| 96 | Jifty->web->form->end(); | ||
| 97 | }; | ||
| 98 | } else { | ||
| 99 | outs( _("You're already logged in.") ); | ||
| 100 | } | ||
| 101 | }; | ||
| 102 | |||
| 103 | =head2 let/reset_lost_password | ||
| 104 | |||
| 105 | After requesting a password reset and clicking on the link sent by email, this receives that click and provides the form for resetting the password. | ||
| 106 | |||
| 107 | See L<Jifty::Plugin::Authentication::Action::ResetLostPassword>. | ||
| 108 | |||
| 109 | =cut | ||
| 110 | |||
| 111 | template 'let/reset_lost_password' => page { title => _('Reset lost password') } content { | ||
| 112 | my ( $next ) = get(qw(next)); | ||
| 113 | my $action = Jifty->web->new_action( class => 'ResetLostPassword' ); | ||
| 114 | |||
| 115 | Jifty->web->form->start( call => $next ); | ||
| 116 | render_param( $action => $_ ) for ( $action->argument_names ); | ||
| 117 | form_return( label => _("New password"), submit => $action ); | ||
| 118 | Jifty->web->form->end(); | ||
| 119 | }; | ||
| 120 | |||
| 121 | =head2 lost_password | ||
| 122 | |||
| 123 | Starts the process of sending a link to reset a lost password by email. | ||
| 124 | |||
| 125 | See L<Jifty::Plugin::Authentication::Password::SendPasswordReminder>. | ||
| 126 | |||
| 127 | =cut | ||
| 128 | |||
| 129 | template 'lost_password' => page { title => 'Send a link to reset your password' } content { | ||
| 130 | my ( $next ) = get(qw(next)); | ||
| 131 | my $action = Jifty->web->new_action( | ||
| 132 | moniker => 'password_reminder', | ||
| 133 | class => 'SendPasswordReminder', | ||
| 134 | ); | ||
| 135 | |||
| 136 | outs( _( "You lost your password. A link to reset it will be sent to the following email address:")); | ||
| 137 | my $focused = 0; | ||
| 138 | Jifty->web->form->start( call => $next ); | ||
| 139 | render_param( $action => $_, focus => $focused++ ? 0 : 1 ) for ( $action->argument_names ); | ||
| 140 | form_return( label => _(q{Send}), submit => $action); | ||
| 141 | Jifty->web->form->end; | ||
| 142 | |||
| 143 | }; | ||
| 144 | |||
| 145 | =head2 let/confirm_email | ||
| 146 | |||
| 147 | Handles the work of confirming an email address for a new account. | ||
| 148 | |||
| 149 | See L<Jifty::Plugin::Authenticaiton::Password::View>. | ||
| 150 | |||
| 151 | =cut | ||
| 152 | |||
| 153 | template 'let/confirm_email' => sub { | ||
| 154 | new_action( class => 'ConfirmEmail' )->run; | ||
| 155 | redirect("/"); | ||
| 156 | }; | ||
| 157 | |||
| 158 | =head2 resend_confirmation | ||
| 159 | |||
| 160 | Request a new email confirmation message be sent to your email account. | ||
| 161 | |||
| 162 | See L<Jifty::Plugin::Authentication::Password::Action::ResendConfirmation>. | ||
| 163 | |||
| 164 | =cut | ||
| 165 | |||
| 166 | template 'resend_confirmation' => page { title => 'Resend Confirmation Email' } content { | ||
| 167 | my $resend = Jifty->web->new_action( | ||
| 168 | class => 'ResendConfirmation', | ||
| 169 | moniker => 'resendconf' | ||
| 170 | ); | ||
| 171 | |||
| 172 | if ( Jifty->web->current_user->id | ||
| 173 | and Jifty->web->current_user->user_object->email_confirmed ) | ||
| 174 | { | ||
| 175 | Jifty->web->redirect('/'); | ||
| 176 | } else { | ||
| 177 | div { | ||
| 178 | attr { id => 'overview' }; | ||
| 179 | form { | ||
| 180 | Jifty->web->form->next_page( url => '/' ); | ||
| 181 | |||
| 182 | p { | ||
| 183 | _( q{Fill in your address below, and we'll send out another confirmation email to you. } | ||
| 184 | ); | ||
| 185 | render_param( $resend => 'email', focus => 1 ); | ||
| 186 | form_submit( label => 'Resend Confirmation' ); | ||
| 187 | } | ||
| 188 | } | ||
| 189 | } | ||
| 190 | |||
| 191 | } | ||
| 192 | }; | ||
| 193 | |||
| 194 | =head1 SEE ALSO | ||
| 195 | |||
| 196 | L<Jifty::Plugin::Authentication::Password>, L<Jifty::Plugin::Authentication::Password::Dispatcher> | ||
| 197 | |||
| 198 | =head1 LICENSE | ||
| 199 | |||
| 200 | Jifty is Copyright 2005-2010 Best Practical Solutions, LLC. | ||
| 201 | Jifty is distributed under the same terms as Perl itself. | ||
| 202 | |||
| 203 | =cut | ||
| 204 | |||
| 205 | |||
| 206 | 1; |