[error] authenticate called with nonexistant realm: 'default'.
####
__PACKAGE__->config( 'Plugin::Authentication' => {
use_session => 1,
default_realm => 'default',
default => {
credentials => {
class => 'Password',
password_field => 'Password',
password_type => 'hashed',
password_hash_type => 'SHA-1'
},
store => {
class => 'DBIx::Class',
user_model => 'MyDB::Users',
id_field => 'Username',
use_userdata_from_session => 1
}
}
}
);
####
sub base :Chained('/') :PathPart('myapp') :CaptureArgs(0) {}
sub unauthenticated :Chained('base') :PathPart('authentication') :CaptureArgs(0) {}
sub login :Chained('unauthenticated') :PathPart('login') :ActionClass('REST') {}
sub login_POST
{
my $this = shift;
my $c = shift;
my $username = $c->request->data->{'username'} || '';
my $password = $c->request->data->{'password'} || '';
if($username eq '' ||
$password eq '')
{
$this->status_bad_request(
$c,
message => "Invalid username or password"
);
$c->dispatch('end');
my $is_authenticated = $c->authenticate(
{
username => $username,
password => $password
}
);
if(! $is_authenticated)
{
$this->status_bad_request(
$c,
message => "Invalid username or password"
);
$c->dispatch('end');
}
}