Skip to content

Commit

Permalink
Item9410: ad autologin when using remember me cookie for joomla 1.5
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk/JoomlaUsersContrib@8363 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
SvenDowideit authored and SvenDowideit committed Jul 31, 2010
1 parent 7def854 commit d027ac9
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
1 change: 1 addition & 0 deletions data/System/JoomlaUsersContrib.txt
Expand Up @@ -49,6 +49,7 @@ Settings are in =lib/LocalSite.cfg=. the Foswiki configure script does not curre
| Dependencies: | %$DEPENDENCIES% |
| Version: | %$VERSION% |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 30 Jul 2010 | add soe support for joomla session cookie auto login |
| 14 Aug 2009 | rename login template from login.joomla.tmpl to loginjoomla.tmpl to enable user skins |
| 1 Aug 2009 | update to work with Joomla 1.3 _and_ 1.5, migrate to the more modern Foswiki:Extensions.DbiContrib |
| Mar 2009 | port to Foswiki |
Expand Down
24 changes: 23 additions & 1 deletion lib/Foswiki/LoginManager/JoomlaLogin.pm
Expand Up @@ -61,7 +61,29 @@ sub loadSession {
# see if there is a joomla username and password cookie
#TODO: think i should check the password is right too.. otherwise ignore it
my %cookies = fetch CGI::Cookie;
if ( defined( $cookies{'usercookie[username]'} ) ) {
if ( $Foswiki::cfg{Plugins}{JoomlaUser}{JoomlaVersionOnePointFive} ) {
#1.5 uses some magic token as key (I've not spent time to reverse engineer it
#but the value of that key is the session_id in the database.
foreach my $key (keys(%cookies)) {

#print STDERR "--- $key (".length($key).")".$cookies{$key}->value."(".length($cookies{$key}->value).")\n";


next if (length($key) != 32);
next if (length($cookies{$key}->value) != 32);

print STDERR "--- $key ".$cookies{$key}->value."\n";

#TODO: boooooom
my $username = $twiki->{users}->{mapping}->joomlaSessionUserId($cookies{$key}->value);
if (defined($username)) {
$authUser = $username;
$this->userLoggedIn($authUser);
last;
}
}
} elsif ( defined( $cookies{'usercookie[username]'} ) ) {
#the 1.0 joomla cookie
my $id = $cookies{'usercookie[username]'}->value;
my $password = $cookies{'usercookie[password]'}->value;
my $user = $twiki->{users}->getCanonicalUserID( $id, undef, 1 );
Expand Down
28 changes: 28 additions & 0 deletions lib/Foswiki/Users/JoomlaUserMapping.pm
Expand Up @@ -876,4 +876,32 @@ sub deleteUser {
return 1;
}


=pod
---++ ObjectMethod joomlaSessionUserId ($session_id) -> loginname
called by the joomlaLogin module to try to detect that the user has logged into joomla
=cut

sub joomlaSessionUserId {
my ( $this, $session_id ) = @_;

ASSERT($this->{JoomlaOnePointFive}) if DEBUG;

my $sessionSelectStatement = 'select username from jos_session where session_id = ?';
my $userIdDataSet = $this->{DB}->select($sessionSelectStatement, $session_id );
if ( exists $$userIdDataSet[0] ) {

print STDERR "$session_id is a user (".$$userIdDataSet[0]{username}.")\n";
return $$userIdDataSet[0]{username};
}

print STDERR "$session_id is __not__ a session\n";

#not our session
return undef;
}

1;

0 comments on commit d027ac9

Please sign in to comment.