/[transports]/trunk/lib/Transports/Action/Login.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /trunk/lib/Transports/Action/Login.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5 - (hide annotations)
Thu May 4 21:54:50 2006 UTC (18 years, 1 month ago) by dpavlin
File size: 2448 byte(s)
partly added login and logout from wifty
1 dpavlin 5 use warnings;
2     use strict;
3    
4     =head1 NAME
5    
6     Transports::Action::Login
7    
8     =cut
9    
10     package Transports::Action::Login;
11     use base qw/Transports::Action Jifty::Action/;
12    
13     =head2 arguments
14    
15     Return the email and password form fields
16    
17     =cut
18    
19     sub arguments {
20     return( { email => { label => 'Email address',
21     mandatory => 1,
22     ajax_validates => 1,
23     } ,
24    
25     password => { type => 'password',
26     label => 'Password',
27     mandatory => 1
28     },
29     remember => { type => 'checkbox',
30     label => 'Remember me?',
31     hints => 'If you want, your browser can remember your login for you',
32     default => 0,
33     }
34     });
35    
36     }
37    
38     =head2 validate_email ADDRESS
39    
40     Makes sure that the email submitted is a legal email address and that there's a user in the database with it.
41    
42    
43     =cut
44    
45     sub validate_email {
46     my $self = shift;
47     my $email = shift;
48    
49     unless ( $email =~ /\S\@\S/ ) {
50     return $self->validation_error(email => "That doesn't look like an email address." );
51     }
52    
53     my $u = Transports::Model::User->new(current_user => Transports::CurrentUser->superuser);
54     $u->load_by_cols( email => $email );
55     return $self->validation_error(email => 'No account has that email address.') unless ($u->id);
56    
57    
58     return $self->validation_ok('email');
59     }
60    
61     =head2 take_action
62    
63     Actually check the user's password. If it's right, log them in.
64     Otherwise, throw an error.
65    
66    
67     =cut
68    
69     sub take_action {
70     my $self = shift;
71     my $user = Transports::CurrentUser->new( email => $self->argument_value('email'));
72    
73     unless ( $user->id && $user->password_is($self->argument_value('password'))) {
74     $self->result->error( 'You may have mistyped your email address or password. Give it another shot?' );
75     return;
76     }
77    
78     unless ($user->user_object->email_confirmed) {
79     $self->result->error( q{You haven't confirmed your account yet.} );
80     return;
81     }
82    
83     # Set up our login message
84     $self->result->message("Welcome back, " . $user->user_object->name . "." );
85    
86     # Actually do the signin thing.
87     Jifty->web->current_user($user);
88     Jifty->web->session->expires($self->argument_value('remember') ? '+1y' : undef);
89     Jifty->web->session->set_cookie;
90    
91     return 1;
92     }
93    
94     1;

  ViewVC Help
Powered by ViewVC 1.1.26