2007-10-11 16:25:56 +00:00
|
|
|
#!/usr/bin/perl
|
2007-10-11 17:06:08 +00:00
|
|
|
require "include.pl";
|
2007-10-11 23:47:13 +00:00
|
|
|
require "functions.pl";
|
2007-10-10 21:48:12 +00:00
|
|
|
|
|
|
|
#initialize session data
|
|
|
|
CGI::Session->name($session_name);
|
|
|
|
$query = new CGI;
|
|
|
|
$session = new CGI::Session;
|
|
|
|
|
2007-10-27 09:17:30 +00:00
|
|
|
$username = get_username_from_sid($session->id);
|
|
|
|
|
|
|
|
%page = ();
|
|
|
|
|
|
|
|
$page->{'username'} = $username;
|
2007-10-29 08:48:51 +00:00
|
|
|
($page->{'locale'}) = $query->http('HTTP_ACCEPT_LANGUAGE') =~ /^([^,]+),.*$/;
|
2007-10-27 09:17:30 +00:00
|
|
|
$page->{'stylesheet'} = $stylesheet;
|
|
|
|
$page->{'xmlns:dc'} = $xmlns_dc;
|
|
|
|
$page->{'xmlns:cc'} = $xmlns_cc;
|
|
|
|
$page->{'xmlns:rdf'} = $xmlns_rdf;
|
|
|
|
|
|
|
|
#check if user is logged in
|
|
|
|
if($username)
|
|
|
|
{
|
|
|
|
$page->{'message'}->{'type'} = "error";
|
|
|
|
$page->{'message'}->{'text'} = "error_already_registered";
|
|
|
|
}
|
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
|
|
|
{
|
2007-10-29 08:48:51 +00:00
|
|
|
if($query->param('pass') eq $query->param('pass_repeat'))
|
|
|
|
{
|
|
|
|
#connect to db
|
|
|
|
my $dbh = DBI->connect("DBI:mysql:$database:$host", $dbuser, $dbpass) or die $dbh->errstr;
|
2007-10-10 21:48:12 +00:00
|
|
|
|
2007-10-29 08:48:51 +00:00
|
|
|
#do query
|
2007-10-29 08:54:16 +00:00
|
|
|
$dbh->do(qq{insert into users (username, password, timestamp, locale) values ( ?, password( ? ), unix_timestamp(), ?)}, undef,
|
2007-10-29 08:48:51 +00:00
|
|
|
$query->param("user"), $query->param("pass"), $page->{'locale'}) or die $dbh->errstr;
|
2007-10-11 10:00:38 +00:00
|
|
|
|
2007-10-29 08:48:51 +00:00
|
|
|
#disconnect db
|
|
|
|
$dbh->disconnect() or die $dbh->errstr;
|
2007-10-10 21:48:12 +00:00
|
|
|
|
2007-10-29 08:48:51 +00:00
|
|
|
#print a little confirmation
|
|
|
|
$page->{'message'}->{'type'} = "information";
|
|
|
|
$page->{'message'}->{'text'} = "information_registered";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$page->{'registerform'} = [''];
|
|
|
|
$page->{'message'}->{'type'} = "error";
|
|
|
|
$page->{'message'}->{'text'} = "error_passwords_do_not_match";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif(not $query->param('user'))
|
|
|
|
{
|
|
|
|
$page->{'registerform'} = [''];
|
|
|
|
$page->{'message'}->{'type'} = "error";
|
|
|
|
$page->{'message'}->{'text'} = "error_insert_username";
|
|
|
|
}
|
|
|
|
elsif(not $query->param('pass'))
|
|
|
|
{
|
|
|
|
$page->{'registerform'} = [''];
|
|
|
|
$page->{'message'}->{'type'} = "error";
|
|
|
|
$page->{'message'}->{'text'} = "error_insert_password";
|
|
|
|
}
|
|
|
|
elsif(not $query->param('pass_repeat'))
|
|
|
|
{
|
|
|
|
$page->{'registerform'} = [''];
|
|
|
|
$page->{'message'}->{'type'} = "error";
|
|
|
|
$page->{'message'}->{'text'} = "error_repeat_password";
|
2007-10-11 17:26:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-10-27 09:17:30 +00:00
|
|
|
$page->{'registerform'} = [''];
|
|
|
|
}
|
2007-10-11 23:47:13 +00:00
|
|
|
|
2007-10-27 09:17:30 +00:00
|
|
|
#print xml http header along with session cookie
|
|
|
|
print $session->header(-type=>'text/xml', -charset=>'UTF-8');
|
2007-10-11 23:47:13 +00:00
|
|
|
|
2007-10-27 09:17:30 +00:00
|
|
|
print XMLout($page, KeyAttr => {}, XMLDecl => $XMLDecl, RootName => 'page', AttrIndent => '1');
|