From 6ba502f6a4aae7802e713afd35f30f0e3698d647 Mon Sep 17 00:00:00 2001 From: josch Date: Mon, 11 Feb 2008 20:18:48 +0000 Subject: [PATCH] check if username already exists git-svn-id: http://yolanda.mister-muffin.de/svn@235 7eef14d0-6ed0-489d-bf55-20463b2d70db --- trunk/locale/en-us.xml | 1 + trunk/register.pl | 25 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/trunk/locale/en-us.xml b/trunk/locale/en-us.xml index 5b63eb0..4abc5a3 100755 --- a/trunk/locale/en-us.xml +++ b/trunk/locale/en-us.xml @@ -56,6 +56,7 @@ You seem to be already logged in. Please log out to log in again. Username and password do not match. Passwords do not match. + Your desired Username was already registered Please insert a username. Please insert a password. Please repeat your password. diff --git a/trunk/register.pl b/trunk/register.pl index e95d3ea..b01bf96 100644 --- a/trunk/register.pl +++ b/trunk/register.pl @@ -22,11 +22,28 @@ elsif($query->param('user') and $query->param('pass') and $query->param('pass_re { if($query->param('pass') eq $query->param('pass_repeat')) { - #do query - $dbh->do(qq{insert into users (username, password, timestamp, locale) values ( ?, password( ? ), unix_timestamp(), ?)}, undef, - $query->param("user"), $query->param("pass"), $page->{'locale'}) or die $dbh->errstr; + my $sth = $dbh->prepare(qq{select id from users where username = ? limit 1 }); + + #execute query + $sth->execute($query->param('user')); - print $query->redirect("index.pl?information=information_registered"); + #if something was returned the selected username already exists + if($sth->fetchrow_array()) + { + $page->{'registerform'} = ['']; + $page->{'message'}->{'type'} = "error"; + $page->{'message'}->{'text'} = "error_username_already_registered"; + + print output_page(); + } + else + { + #insert new user + $dbh->do(qq{insert into users (username, password, timestamp, locale) values ( ?, password( ? ), unix_timestamp(), ?)}, undef, + $query->param("user"), $query->param("pass"), $page->{'locale'}) or die $dbh->errstr; + + print $query->redirect("index.pl?information=information_registered"); + } } else {