在本教程中,他创建了一个自定义登录表单,只是为了展示它是如何完成的。请搜索
如何删除自定义登录并回退到默认登录?
代码看起来像这样
sub cgiapp_init {
my $self = shift;
my %CFG = $self->cfg;
# ...
$self->authen->config(
DRIVER => [ 'Authen::Simple::LDAP',
host => '',
basedn => '',
],
STORE => 'Session',
LOGOUT_RUNMODE => 'logout',
LOGIN_RUNMODE => 'login',
POST_LOGIN_RUNMODE => 'okay',
RENDER_LOGIN => \&my_login_form,
);
$self->authen->protected_runmodes(
'mustlogin',
);
}
sub login : Runmode {
my $self = shift;
my $url = $self->query->url;
my $user = $self->authen->username;
if ($user) {
my $message = "User $user is already logged in!";
my $template = $self->load_tmpl('default.html');
$template->param(MESSAGE => $message);
$template->param(MYURL => $url);
return $template->output;
} else {
my $url = $self->query->self_url;
unless ($url =~ /^https/) {
$url =~ s/^http/https/;
return $self->redirect($url);
}
return $self->my_login_form;
}
}
更新
这里提到 CGI::Application 有一个看起来比他更好的默认登录。
第 159 行指定了一个用于生成登录表单的子例程。请注意,身份验证插件带有一个您可以使用的默认表单。我将这个包括在内只是为了演示如何创建自己的一个,以防万一你真的想要。默认的实际上看起来比我的好得多,所以你可能希望注释掉第 159 行!