Created
October 19, 2021 19:44
-
-
Save jjn1056/f065c4abb28d100f26f590d01f5dbaef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package MyApp::Model::Session; | |
use Moose; | |
extend 'Catalyst::ApplicationModel'; | |
has 'person' => (is=>'ro', required=>1, model=>'Schema::Person'); | |
sub authenticate($self, $username='', $password='') { | |
my $user = $self->person->authenticate($username, $password); | |
$self->ctx->session->{user_id} = $user->id if !$user->has_errors; | |
return $user; | |
} | |
sub user($self) { | |
return $self->ctx->stash->{user} ||= do { | |
my $id = $self->ctx->session->{user_id} // return; | |
my $person = $self->person->find({id=>$id}) // return; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment