blob: de473903d2a1807a5e2d9ab823735af1c5c37f98 [file] [log] [blame]
package Kalamar::Controller::User;
use Mojo::Base 'Mojolicious::Controller';
# Login action
sub login {
my $c = shift;
# Validate input
my $v = $c->validation;
$v->required('handle_or_email', 'trim');
$v->required('pwd', 'trim');
if ($v->has_error) {
$c->notify(error => 'Login fail');
}
# Login user
elsif ($c->user->login(
$v->param('handle_or_email'),
$v->param('pwd')
)) {
$c->notify(success => 'Login successful!');
};
# Redirect to slash
return $c->redirect_to('/');
};
sub logout {
shift->user->logout;
};
sub register {
my $c = shift;
$c->render(json => {
response => 'register'
});
};
sub pwdforgotten {
my $c = shift;
$c->render(json => {
response => 'pwdforgotten'
});
};
1;