我正在尝试使用DBIx::Class
来自 Catalyst 应用程序的身份验证用户。我已经完成的步骤:
1) 创建 SQLite 数据库
CREATE TABLE people (
id integer primary key,
name text not null,
password text not null);
2) 创建了 Catalyst 模型 People;
3) 在 MyApp.pm 中设置 auth 配置
__PACKAGE__->config('Plugin::Authentication' => {
default => { credential => {
class => 'Password',
password_field => 'password',
password_type => 'clear'
},
store => {
class => 'DBIx::Class',
user_model => 'People'
}
}
}
);
4)创建控制器身份验证并在其中设置方法登录:
sub login : Local {
my ($self, $c) = @_;
if (my $user = $c->req->params->{user} and my $password = $c->req->params->{password} ) {
if ( $c->authenticate( { username => $user, password => $password } ) ) {
$c->res->body( "hello " . $c->user->get("id") );
} else {
# login incorrect
$c->res->body("Wrong pass or name!");
}
} else {
# invalid form input
$c->res->body("Type name & pass");
}
}
5) 提交带有用户和密码数据的表单时调用方法登录。我收到了这条消息:
在 MyApp::Controller::Auth->login “无法通过 /usr/local/share/perl/5.14.2/Catalyst/ 的包“MyApp::Model::People”定位对象方法“result_source”中捕获异常Authentication/Store/DBIx/Class/User.pm 第 35 行,第 999 行。”
如何修复?