package Project::Login;
use strict;
use warnings;
our @ISA = qw( Org::Bgw::Pas::SessionPage );
sub execute
{
my($self) = @_;
return $self->handleUserLoggingIn if $self->isAction('loggingIn');
return $self->handleLogUserOut if $self->isAction('loggingOut');
return $self->forward_request('login.psp');
}
sub isAction
{
my($self,$action) = @_;
return undef unless defined $self->query->param('action');
return $action eq $self->query->param('action');
}
sub handleUserLoggingIn
{
my($self) = @_;
my $profile = Project::DB::UserProfile->loadByUserName(
$self->query->param('userName')
);
unless( $profile ) {
return $self->loginError("Error, invalid username or password.");
}
unless( $self->query->param('password') eq $profile->password ) {
return $self->loginError("Error, invalid username or password.");
}
$profile->isLoggedIn(1);
$self->session->param('project.userProfile',$profile);
return $self->response->set_redirect('/pas/project/UserProfile');
}
sub loginError
{
my($self,@msg) = @_;
$self->query->param('login.error',join('',@msg));
return $self->forward_request('login.psp');
}
sub handleUserLoggingIn
{
my($self) = @_;
$self->session->param('project.userProfile', Project::DB::UserProfile->new );
return $self->response->set_redirect('login.psp');
}
1;
|