简体   繁体   English

带有PostgreSQL数据库的Dancer2应用

[英]Dancer2 app with PostgreSQL database

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: 我正在尝试在Dancer2中集成一个小的PostgreSQL数据库。...部署架构后,我在app.pm文件中使用了该数据库以连接到架构:

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" . 我的应用程序因以下错误DBIx::Class::Storage::DBI::catch {...} (): DBI Connection failed: DBI connect('dbname=mytestdb','test',...) failed: FATAL: Peer authentication failed for user "test"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 : 我通过添加以下行在/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

With these modifications my app logs in. 经过这些修改,我的应用程序登录了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM