Gossamer Forum
Home : Products : Gossamer Forum : Development, Plugins and Globals :

Plugin for authenticate running PRE

Quote Reply
Plugin for authenticate running PRE
Hi,

I have problems to run a Plugin with type PRE for the hook "authenticate".

For example I want to login the user "test" with password "test" when the URL .../gforum.cgi ist called first time.

So I try the Plugin LoginLH.pm

Code:
# ==================================================================
# Plugins::GForum::LoginLH - Auto Generated Program Module
#
# Plugins::GForum::LoginLH
# Author : Johannes
# Version : 0.1
# Updated : Thu Apr 3 15:39:35 2003
#
# ==================================================================
#

package Plugins::GForum::LoginLH;
# ==================================================================

use strict;
use GT::Base qw/$PERSIST $MOD_PERL $SPEEDY/;
use GForum::Plugins;
use GForum::Group;
use GT::Plugins qw/STOP CONTINUE/;
use GForum qw/$IN $DB $CFG/;

use vars qw/$DEBUG $MOD_PERL
$IN $DB $CFG $USER $GUEST $SESSION $SESSION_TYPE %HIDDEN $TEMPLATE_SET %CAT_CACHE
$GLOBALS $LANGUAGE $DATE_LOADED
$VERSION @ISA/;

# Inherit from base class for debug and error methods
@Plugins::GForum::LoginLH::ISA = qw(GT::Base);

# Your code begins here! Good Luck!


# PLUGIN HOOKS
# ===================================================================


sub einloggen {
# -------------------------------------------------------------------
# This subroutine will get called whenever the hook 'authenticate'
# is run. You should call GT::Plugins->action ( STOP ) if you don't
# want the regular code to run, otherwise the code will continue as
# normal.
#
my (@args) = @_;

# Do something useful here

# my $nothing = "nothing";

GForum::Authenticate::auth('valid_user', 'test', 'test') ;
$USER->{user_first_logon} = 1;
$DB->table('User')->update({ user_last_logon => CORE::time }, { user_id => $USER->{user_id} });
# create_session returns true if a redirect was printed, so we need to return its negation.
return not GForum::Authenticate::auth('create_session');

return @args;

}

# Always end with a 1.
1;

This is the plugin.cfg

Code:
$DUMP = {
'LoginLH' => {
'version' => '0.1',
'hooks' => [
[
'authenticate',
'PRE',
'Plugins::GForum::LoginLH::einloggen',
'1'
]
],
'meta' => {
'version' => '0.1',
'url' => '',
'prog_ver' => '1.1.8',
'author' => 'Johannes',
'license' => 'Freeware',
'description' => 'Wer sich bereits in ...
}
}
};


Now, if I call Gossamer-Forum .../gforum.cgi I'm just a guest. If I reload the page, then I'm logged in as user "test".

So it seems that the plugin isn't run before authenticate.

If I put the above code into
sub _plg_authenticate
then it's running correct (means I'm logged in as user "test" the first time I call the forum-script).

What am I doing wrong?

Regards
Johannes

Last edited by:

jmar: Apr 4, 2003, 1:51 PM
Quote Reply
Re: [jmar] Plugin for authenticate running PRE In reply to
Hi Johannes,

Can you add this line before the return line?

GT::Plugin->action(STOP);

return not GForum::Authenticate::auth('create_session');

Hope that helps

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] Plugin for authenticate running PRE In reply to
Yes, it works. Now you're logged in as user "test" on first visit.

But with the action(STOP) the sub _plg_authenticate from GForum.pm isn't running at all, isn't it?!

Thanks and Regards
Johannes

Last edited by:

jmar: Apr 7, 2003, 1:07 AM
Quote Reply
Re: [jmar] Plugin for authenticate running PRE In reply to
Yes, the GT::Plugin->action is usefull when called in a hook. Otherwise seems not helped

Cheers,

Cheers,

Dat

Programming and creating plugins and templates
Blog