[Maypole] Problem with authentication

Nikola Knezevic indy@galeb.etf.bg.ac.yu
Wed, 12 May 2004 20:41:08 +0200 (CEST)


Hi,
I can't take this anymore. I've spent last day and a half modifying this code, failing to find error, which exists.
The problem is Auth. I have 3 kinds of users: guests (not logged), users and admin. So I decided to add a link to login page, where gusets can log in, instead of following the some other link and then loging if credentials are wrong.
And it fails in one this. It works, but because the form references localhost/gtm/login, even if they log in, they arent redirected. Bumer. I wrote $r->{template}="frontpage", but it isn't followed.

Any help?

Also, how can I initialy set no_cache(1)? GTM->{ar}->no_cache(1) fails if put after GTM->setup(...)

Thanks.		



This is relevant part:

----8<----
package GTM;
use strict;
use base qw(Maypole::Authentication::UserSessionCookie Apache::MVC);
use Class::DBI::Loader::Relationship;
use Digest::MD5;
use Apache::Constants qw(:common);
use Apache::Cookie;

#XXX: to use the benefits of Apache::Reload, I even tried:
# BEGIN {GTM->setup(...)}
# use GTM::Korisnik;
# but it fails to reload with error: Invalid CODE attribute: Exported
# double bumer
GTM->setup("dbi:mysql:gtm_db;host=localhost",'gtm_test','gtm');
GTM::Korisnik->require;

	GTM->config->{uri_base} = "http://localhost/gtm";
....
# konfiguracija - autentifikacija
	GTM->config->{auth}{user_class} = 'GTM::Korisnik';
	GTM->config->{auth}{user_field} = 'user_name';
	GTM->config->{auth}{password_field} = 'password';
	GTM->config->{auth}{cookie_name} = "gtm_login";
	GTM->config->{auth}{session_args} = {
				LockDirectory => "/tmp/locks/",
				Directory => "/tmp/sessions/"
	};

....
sub authenticate {
	my ($self, $r) = @_;
	$r->{ar}->no_cache(1);
	$r->get_user;

    if ($r->{user}) { 
			return $r->model_class->sub_authenticate($r)
					if $r->model_class->can("sub_authenticate");
			$r->{template}="frontpage"
								if $r->{path} eq "login";
	    	return OK;
	};
		
# samo ako nije ulogovan
	$r->{template}="login";
    return OK;
}

1;
----->8----------- custom/login
[% WRAPPER sablon title="login page" %]
<h1>This is login page</h1>
[% SET args = request.args.join("/"); %]
<h2> You need to log in </h2>  
[% IF login_error %]
<DIV CLASS="messages"> [% login_error %] </DIV>
[% END %]
<form action="[% base %]/login" method="post">
Username: <input type="text" name="[% config.auth.user_field || "user_name" %]"> <br>
	Password: <input type="password" name="[% config.auth.password_field || "password" %]"> <br>
	<input type="submit">
	</form>
[% END %]	
------8<--------- custom/login_part
# this is a component, which provides a link to login page
[% IF request.user %]
Pozdrav, [% request.user.login_name %]. [ <a href="[% base %]/korisnik/logout">logout</a> ]
[% ELSE %]
[% SET args = request.args.join("/"); %]
<a href="[% base %]/subscribe">subscribe</a>
<a href="[% base %]/[% IF request.action and request.action != "logout" %][% request.table %]/[% request.action %]/[% args %][% ELSE %]login[% END %]">login</a>
[% END %]