2007-10-11 23:47:13 +00:00
|
|
|
require "functions.pl";
|
2007-10-10 21:48:12 +00:00
|
|
|
|
|
|
|
#initialize session data
|
2008-04-15 18:56:13 +00:00
|
|
|
CGI::Session->name($config->{"page_cookie_name"});
|
2007-10-10 21:48:12 +00:00
|
|
|
$query = new CGI;
|
|
|
|
$session = new CGI::Session;
|
|
|
|
|
2007-10-29 15:00:40 +00:00
|
|
|
@userinfo = get_userinfo_from_sid($session->id);
|
2007-10-27 09:17:30 +00:00
|
|
|
|
2008-04-27 00:42:15 +00:00
|
|
|
my $doc = XML::LibXML::Document->new( "1.0", "UTF-8" );
|
|
|
|
|
2008-04-27 10:39:21 +00:00
|
|
|
my $page = get_page_array(@userinfo);
|
2007-10-27 09:17:30 +00:00
|
|
|
|
|
|
|
#check if user is logged in
|
|
|
|
if($username)
|
|
|
|
{
|
2008-04-27 21:37:08 +00:00
|
|
|
$page->appendChild(message("error", "error_already_registered"));
|
2008-02-14 22:15:38 +00:00
|
|
|
|
2008-04-27 10:39:21 +00:00
|
|
|
$doc->setDocumentElement($page);
|
2008-04-27 00:42:15 +00:00
|
|
|
|
|
|
|
output_page($doc);
|
2007-10-27 09:17:30 +00:00
|
|
|
}
|
2007-10-10 21:48:12 +00:00
|
|
|
#if username and password are passed put them into the database
|
2007-10-29 08:48:51 +00:00
|
|
|
elsif($query->param('user') and $query->param('pass') and $query->param('pass_repeat'))
|
2007-10-11 17:26:39 +00:00
|
|
|
{
|
2008-02-14 22:15:38 +00:00
|
|
|
if($query->param('pass') eq $query->param('pass_repeat'))
|
|
|
|
{
|
|
|
|
my $sth = $dbh->prepare(qq{select id from users where username = ? limit 1 });
|
|
|
|
|
|
|
|
#execute query
|
|
|
|
$sth->execute($query->param('user'));
|
|
|
|
|
|
|
|
#if something was returned the selected username already exists
|
|
|
|
if($sth->fetchrow_array())
|
|
|
|
{
|
2008-04-27 10:39:21 +00:00
|
|
|
$page->appendChild(XML::LibXML::Element->new( "registerform" ));
|
2008-04-27 00:42:15 +00:00
|
|
|
|
2008-04-27 21:37:08 +00:00
|
|
|
$page->appendChild(message("error", "error_username_already_registered"));
|
2008-04-27 00:42:15 +00:00
|
|
|
|
2008-04-27 10:39:21 +00:00
|
|
|
$doc->setDocumentElement($page);
|
2008-04-27 00:42:15 +00:00
|
|
|
|
|
|
|
output_page($doc);
|
2008-02-14 22:15:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#insert new user
|
2008-05-01 07:07:36 +00:00
|
|
|
$dbh->do(qq{insert into users (username, password, timestamp) values ( ?, password( ? ), unix_timestamp())}, undef,
|
|
|
|
$query->param("user"), $query->param("pass")) or die $dbh->errstr;
|
2008-02-14 22:15:38 +00:00
|
|
|
|
|
|
|
print $query->redirect("index.pl?information=information_registered");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-04-27 10:39:21 +00:00
|
|
|
$page->appendChild(XML::LibXML::Element->new( "registerform" ));
|
2008-04-27 00:42:15 +00:00
|
|
|
|
2008-04-27 21:37:08 +00:00
|
|
|
$page->appendChild(message("error", "error_passwords_do_not_match"));
|
2008-04-27 00:42:15 +00:00
|
|
|
|
2008-04-27 10:39:21 +00:00
|
|
|
$doc->setDocumentElement($page);
|
2008-04-27 00:42:15 +00:00
|
|
|
|
|
|
|
output_page($doc);
|
2008-02-14 22:15:38 +00:00
|
|
|
}
|
2007-10-29 08:48:51 +00:00
|
|
|
}
|
2007-10-29 15:00:40 +00:00
|
|
|
elsif(not $query->param('user') and ($query->param('pass') or $query->param('pass_repeat')))
|
2007-10-29 08:48:51 +00:00
|
|
|
{
|
2008-04-27 10:39:21 +00:00
|
|
|
$page->appendChild(XML::LibXML::Element->new( "registerform" ));
|
2008-02-14 22:15:38 +00:00
|
|
|
|
2008-04-27 21:37:08 +00:00
|
|
|
$page->appendChild(message("error", "error_insert_username"));
|
2008-04-27 00:42:15 +00:00
|
|
|
|
2008-04-27 10:39:21 +00:00
|
|
|
$doc->setDocumentElement($page);
|
2008-04-27 00:42:15 +00:00
|
|
|
|
|
|
|
output_page($doc);
|
2007-10-29 08:48:51 +00:00
|
|
|
}
|
2007-10-29 15:00:40 +00:00
|
|
|
elsif(not $query->param('pass') and ($query->param('user') or $query->param('pass_repeat')))
|
2007-10-29 08:48:51 +00:00
|
|
|
{
|
2008-04-27 10:39:21 +00:00
|
|
|
$page->appendChild(XML::LibXML::Element->new( "registerform" ));
|
2008-02-14 22:15:38 +00:00
|
|
|
|
2008-04-27 21:37:08 +00:00
|
|
|
$page->appendChild(message("error", "error_insert_password"));
|
2008-04-27 00:42:15 +00:00
|
|
|
|
2008-04-27 10:39:21 +00:00
|
|
|
$doc->setDocumentElement($page);
|
2008-04-27 00:42:15 +00:00
|
|
|
|
|
|
|
output_page($doc);
|
2007-10-29 08:48:51 +00:00
|
|
|
}
|
2007-10-29 15:00:40 +00:00
|
|
|
elsif(not $query->param('pass_repeat') and ($query->param('user') or $query->param('pass')))
|
2007-10-29 08:48:51 +00:00
|
|
|
{
|
2008-04-27 10:39:21 +00:00
|
|
|
$page->appendChild(XML::LibXML::Element->new( "registerform" ));
|
2008-02-14 22:15:38 +00:00
|
|
|
|
2008-04-27 21:37:08 +00:00
|
|
|
$page->appendChild(message("error", "error_repeat_password"));
|
2008-04-27 00:42:15 +00:00
|
|
|
|
2008-04-27 10:39:21 +00:00
|
|
|
$doc->setDocumentElement($page);
|
2008-04-27 00:42:15 +00:00
|
|
|
|
|
|
|
output_page($doc);
|
2007-10-11 17:26:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-04-27 10:39:21 +00:00
|
|
|
$page->appendChild(XML::LibXML::Element->new( "registerform" ));
|
2008-02-14 22:15:38 +00:00
|
|
|
|
2008-04-27 10:39:21 +00:00
|
|
|
$doc->setDocumentElement($page);
|
2008-04-27 00:42:15 +00:00
|
|
|
|
|
|
|
output_page($doc);
|
2007-11-02 12:12:44 +00:00
|
|
|
}
|