check if username already exists

git-svn-id: http://yolanda.mister-muffin.de/svn@235 7eef14d0-6ed0-489d-bf55-20463b2d70db
This commit is contained in:
josch 2008-02-11 20:18:48 +00:00
parent 6262fd714e
commit 6ba502f6a4
2 changed files with 22 additions and 4 deletions

View file

@ -56,6 +56,7 @@
<string id="error_already_logged_in">You seem to be already logged in. Please log out to log in again.</string>
<string id="error_username_password_do_not_match">Username and password do not match.</string>
<string id="error_passwords_do_not_match">Passwords do not match.</string>
<string id="error_username_already_registered">Your desired Username was already registered</string>
<string id="error_insert_username">Please insert a username.</string>
<string id="error_insert_password">Please insert a password.</string>
<string id="error_repeat_password">Please repeat your password.</string>

View file

@ -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
{