|
|
|
|
@ -67,32 +67,57 @@ sub do_register ( $c ) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sub login ( $c ) { |
|
|
|
|
|
|
|
|
|
if ( $c->stash->{person} ) { |
|
|
|
|
$c->redirect_to( $c->url_for( 'show_dashboard' ) ); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#== |
|
|
|
|
# POST /login | do_login |
|
|
|
|
# email - The email address of the account to login to. |
|
|
|
|
# password - The password for the account to login to. |
|
|
|
|
# |
|
|
|
|
# Try to login to the account owned by the email address with the |
|
|
|
|
# supplied password. |
|
|
|
|
# |
|
|
|
|
# If the account exists and password matches, set the session uid |
|
|
|
|
# to the user's account id. This will load the correct account to |
|
|
|
|
# $c->stash->{person} on the next page load. |
|
|
|
|
# |
|
|
|
|
# Show the login page with error messages when there has been an error. |
|
|
|
|
# |
|
|
|
|
# Redirect the user to the dashboard on successful login. |
|
|
|
|
#== |
|
|
|
|
sub do_login ( $c ) { |
|
|
|
|
$c->stash->{template} = 'auth/login'; |
|
|
|
|
my $email = $c->stash->{form}->{email} = $c->param('email'); |
|
|
|
|
my $password = $c->stash->{form}->{password} = $c->param('password'); |
|
|
|
|
|
|
|
|
|
my $email = $c->stash->{form_email} = $c->param('email'); |
|
|
|
|
my $password = $c->stash->{form_password} = $c->param('password'); |
|
|
|
|
# Did we get an email address and a password? |
|
|
|
|
push @{$c->stash->{errors}}, "You must supply an email address to login." |
|
|
|
|
unless $email; |
|
|
|
|
|
|
|
|
|
push @{$c->stash->{errors}}, "You must suply a password to login." |
|
|
|
|
unless $password; |
|
|
|
|
|
|
|
|
|
return $c->redirect_error( 'show_login' ) |
|
|
|
|
if $c->stash->{errors}; |
|
|
|
|
|
|
|
|
|
# Can we load a user account? |
|
|
|
|
my $person = $c->db->resultset('Person')->find( { email => $email } ) |
|
|
|
|
or push @{$c->stash->{errors}}, "Invalid email address or password."; |
|
|
|
|
|
|
|
|
|
return 0 if $c->stash->{errors}; |
|
|
|
|
return $c->redirect_error( 'show_login' ) |
|
|
|
|
if $c->stash->{errors}; |
|
|
|
|
|
|
|
|
|
# Does the user account we loaded have a password that matches the one supplied? |
|
|
|
|
$person->auth_password->check_password( $password ) |
|
|
|
|
or push @{$c->stash->{errors}}, "Invalid email address or password."; |
|
|
|
|
|
|
|
|
|
return 0 if $c->stash->{errors}; |
|
|
|
|
|
|
|
|
|
$c->stash->{person} = $person; |
|
|
|
|
return $c->redirect_error( 'show_login' ) |
|
|
|
|
if $c->stash->{errors}; |
|
|
|
|
|
|
|
|
|
# Everything is good, log the user in and send them to the dashboard. |
|
|
|
|
$c->session->{uid} = $person->id; |
|
|
|
|
|
|
|
|
|
$c->redirect_to( $c->url_for( 'show_dashboard' ) ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|