1

教程中,他创建了一个自定义登录表单,只是为了展示它是如何完成的。请搜索

如何删除自定义登录并回退到默认登录?

代码看起来像这样

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 行!

4

2 回答 2

4

I'm the author of that tutorial. Sorry for the confusion! What I should have said is "comment out lines 157, 158, and 159 of Login.pm". To use the default form that's built in to the CGI::Application::Plugin::Authentication module, you don't need to specify LOGIN_RUNMODE, POST_LOGIN_RUNMODE, or RENDER_LOGIN. Those are all provided just to help you customize your login page. I included a customized version in the tutorial thinking that most people would need to know how to do so.

于 2011-06-28T21:34:56.217 回答
2

默认的实际上看起来比我的好得多,所以你可能希望注释掉第 159 行!

注释掉第 159 行。

于 2011-06-28T14:34:25.547 回答