sub index : Private { my ( $self, $c ) = @_; # Get the username and password from form my $username = $c->req->param('username'); my $password = $c->req->param('password'); # If the username and password values were found in form if ( $username && $password ) { # Attempt to log the user in if ( $c->login( $username, $password ) ) { my $redirect_url = $c->req->param('next_page') ? $c->uri_for( $c->req->param('next_page') ) : $c->uri_for( '/users/view', $username ); $c->log->debug( "Redirect:" . $redirect_url ); # If successful, then let them use the application $c->res->redirect( $redirect_url ); } else { # Set an error message $c->stash->{error_msg} = "Bad username or password."; $c->stash->{template} = 'login.tt2'; return; } } # If either of above don't work out, send to the login page $c->stash->{template} = 'login.tt2'; }