我正在尝试在我的Dancer2中集成一个小的PostgreSQL数据库.... 在架构部署之后,我在app.pm文件中使用它来连接架构:
my $schema = My::Schema->connect("dbi:Pg:dbname=mytestdb;host=localhost;port=5432;","test","test");
当我启动我的应用程序时,我可以使用此请求创建一个新用户(插入数据库中):
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 '/';
};
但是当我尝试使用它登录时:
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
}
};
我的应用程序死于此错误:
DBIx::Class::Storage::DBI::catch {...} (): DBI Connection failed: DBI connect('dbname=mytestdb','test',...) failed: FATAL: Peer authentication failed for user "test"
。
答案 0 :(得分:0)
我在/etc/postgresql/9.3/main/pg_hba.conf中编辑了我的pg_hba.conf文件 通过添加以下行:
# IPv4 local connections:
host all all 127.0.0.1/32 md5
local all all trust
通过这些修改我的应用程序登录。