| 1 | package Galileo::User; | ||
| 2 | use Mojo::Base 'Mojolicious::Controller'; | ||
| 3 | |||
| 4 | sub login { | ||
| 5 | my $self = shift; | ||
| 6 | my $name = $self->param('username'); | ||
| 7 | my $pass = $self->param('password'); | ||
| 8 | my $from = $self->param('from'); | ||
| 9 | |||
| 10 | my $schema = $self->schema; | ||
| 11 | |||
| 12 | my $user = $schema->resultset('User')->single({name => $name}); | ||
| 13 | if ($user and $user->check_password($pass)) { | ||
| 14 | $self->humane_flash( 'Welcome Back!' ); | ||
| 15 | $self->session->{id} = $user->user_id; | ||
| 16 | $self->session->{username} = $name; | ||
| 17 | } else { | ||
| 18 | $self->humane_flash( 'Sorry try again' ); | ||
| 19 | } | ||
| 20 | $self->redirect_to( $from ); | ||
| 21 | } | ||
| 22 | |||
| 23 | sub logout { | ||
| 24 | my $self = shift; | ||
| 25 | $self->session( expires => 1 ); | ||
| 26 | $self->humane_flash( 'Goodbye' ); | ||
| 27 | $self->redirect_to( $self->home_page ); | ||
| 28 | } | ||
| 29 | |||
| 30 | 1; | ||
| 31 |