further improvements to login

git-svn-id: http://yolanda.mister-muffin.de/svn@15 7eef14d0-6ed0-489d-bf55-20463b2d70db
This commit is contained in:
josch 2007-10-10 16:05:54 +00:00
parent 482644fced
commit 6a62362820
4 changed files with 27 additions and 13 deletions

View file

@ -11,3 +11,14 @@ sub fill_tagcloud {
$sth->finish(); $sth->finish();
$dbh->disconnect(); $dbh->disconnect();
} }
sub get_username_from_sid {
my ($sid) = @_;
$dbh = DBI->connect("DBI:mysql:$database:$dbhost", $dbuser, $dbpass);
my $sth = $dbh->prepare(qq{select username from users where sid = '$sid'});
$sth->execute();
my ($username) = $sth->fetchrow_array();
$sth->finish();
$dbh->disconnect();
return $username;
}

View file

@ -9,8 +9,7 @@ my $session = new CGI::Session;
$page = XMLin('/var/www/perl/index.xml', ForceArray => 1, KeyAttr => {} ); $page = XMLin('/var/www/perl/index.xml', ForceArray => 1, KeyAttr => {} );
#fill tags #fill tags
$page->{sid} = [$session->id]; $page->{username} = get_username_from_sid($session->id);
$page->{loggedin} = [$session->param('auth')];
fill_tagcloud; fill_tagcloud;

View file

@ -5,8 +5,9 @@ $session = new CGI::Session;
$query = new CGI; $query = new CGI;
if($query->param('action')) { if($query->param('action')) {
if($query->param('action') eq "login") {
$dbh = DBI->connect("DBI:mysql:$database:$dbhost", $dbuser, $dbpass); $dbh = DBI->connect("DBI:mysql:$database:$dbhost", $dbuser, $dbpass);
if($query->param('action') eq "login") {
my $user = $query->param('user'); my $user = $query->param('user');
my $pass = $query->param('pass'); my $pass = $query->param('pass');
my $sth = $dbh->prepare(qq{select username from users my $sth = $dbh->prepare(qq{select username from users
@ -16,25 +17,30 @@ if($query->param('action')) {
$sth->execute(); $sth->execute();
if($sth->fetchrow_array()) { if($sth->fetchrow_array()) {
$session->param('auth', 'true'); my $sid = $session->id;
$sth = $dbh->prepare(qq{update users set sid = '$sid' where username = '$user'});
$sth->execute();
$sth->finish();
print $session->header(); print $session->header();
print "logged in"; print "logged in";
} else { } else {
print $session->header(); print $session->header();
print $query->param('action'); print "could not log you in";
} }
$sth->finish();
$dbh->disconnect();
} elsif($query->param('action') eq "logout") { } elsif($query->param('action') eq "logout") {
$session->param('auth', 'false'); $sth = $dbh->prepare(qq{update users set sid = '' where username = '$user'});
$sth->execute();
$sth->finish();
$session->delete();
print $session->header(); print $session->header();
print "logged out"; print "logged out";
} else { } else {
print $session->header(); print $session->header();
print "wtf?"; print "wtf?";
} }
$dbh->disconnect();
} else { } else {
print $session->header(); print $session->header();
print '<form action="" method="POST"><p> print '<form action="" method="POST"><p>

View file

@ -65,9 +65,7 @@
<div class="header2"> <div class="header2">
<a href="about:blank"><xsl:value-of select="$locale_strings/str[@id='register']" /></a> <a href="about:blank"><xsl:value-of select="$locale_strings/str[@id='register']" /></a>
<xsl:value-of select="$locale_strings/str[@id='separator']" /> <xsl:value-of select="$locale_strings/str[@id='separator']" />
<a href="login.pl?action=login"><xsl:value-of select="$locale_strings/str[@id='login']" /></a> <a href="login.pl"><xsl:value-of select="$locale_strings/str[@id='login']" /></a>
<xsl:value-of select="$locale_strings/str[@id='separator']" />
<a href="login.pl?action=logout"><xsl:value-of select="$locale_strings/str[@id='logout']" /></a>
<xsl:value-of select="$locale_strings/str[@id='separator']" /> <xsl:value-of select="$locale_strings/str[@id='separator']" />
<img class="openid-icon" src="./images/openid-icon.png" alt="open id logo" /> <img class="openid-icon" src="./images/openid-icon.png" alt="open id logo" />
<a href="about:blank"><xsl:value-of select="$locale_strings/str[@id='login_openid']" /></a> <a href="about:blank"><xsl:value-of select="$locale_strings/str[@id='login_openid']" /></a>
@ -90,7 +88,7 @@
<xsl:value-of select="//@username" /> <xsl:value-of select="//@username" />
</a> </a>
<xsl:value-of select="$locale_strings/str[@id='separator']" /> <xsl:value-of select="$locale_strings/str[@id='separator']" />
<a href="about:blank"><xsl:value-of select="$locale_strings/str[@id='logout']" /></a> <a href="login.pl?action=logout"><xsl:value-of select="$locale_strings/str[@id='logout']" /></a>
</div> </div>
</xsl:otherwise> </xsl:otherwise>
</xsl:choose> </xsl:choose>