I'm trying to integrate a small PostgreSQL database in my Dancer2.... After schema deployment I used this in my app.pm file to connect to the schema:
my $schema = My::Schema->connect("dbi:Pg:dbname=mytestdb;host=localhost;port=5432;","test","test");
When I start my app I'm able to create a new user (which is inserted in the db) with this request:
post '/register' => sub {
my $username = params->{username};
my $fullname = params->{fullname};
my $password = params->{password};
warn "The pass is |$password|\n";
my $saved_pass = &crypt_password($password);
$schema->resultset('User')->create({
username => $username,
fullname => $fullname,
password => $saved_pass,
});
redirect '/';
};
But when I attempt to log in using this:
post '/login' => sub {
my $username = params->{username};
my $password = params->{password};
my $user = $schema->resultset('User')->search({ username => $username })->first;
my ($success, $realm) = authenticate_user(
$username, $password
);
if ($success) {
session logged_in_user => $success;
session logged_in_user_realm => $realm;
session user => $user;
} else {
authentication failed
}
};
My app dies with this error: DBIx::Class::Storage::DBI::catch {...} (): DBI Connection failed: DBI connect('dbname=mytestdb','test',...) failed: FATAL: Peer authentication failed for user "test"
.
I edited my pg_hba.conf file inside /etc/postgresql/9.3/main/pg_hba.conf by adding this lines :
# IPv4 local connections:
host all all 127.0.0.1/32 md5
local all all trust
With these modifications my app logs in.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.