How to remove login form from this CGI::Application example?

512 Views Asked by At

In this tutorial he creates a custom login form, just to show how it is done. Please search for

How do I remove the custom login and fall back to the default?

To code looks like this

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;
    }
}

Update

Here is mentions that CGI::Application have a default login that looks better than his.

Line 159 specifies a subroutine to use to generate a login form. Note that the Authentication plugin comes with a default form that you can use. I'm including this one just to demonstrate how to go about creating one of your own, in case you really want to. The default one actually looks much better than mine, so you might wish to comment out line 159!

2

There are 2 best solutions below

6
On BEST ANSWER

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.

1
On

The default one actually looks much better than mine, so you might wish to comment out line 159!

Comment out line 159.