5 $page->title
= 'Account Registration';
7 if ( $user instanceof authuser
) {
8 isset($_POST['login']) ?
10 $page->errorfooter('logout');
13 if ( isset($_POST['prompt']) )
16 if ( isset($_POST['something']) ) {
21 if ( empty($_POST['reg_u']) ||
empty($_POST['reg_p']) ||
empty($_POST['reg_e']) )
22 throw new LengthException('You left one or more text fields empty.');
23 elseif ( $_POST['reg_p'] !== $_POST['reg_c'] )
24 throw new InvalidInputException('Both passwords must match exactly.');
25 elseif ( $DB->query('SELECT `userid` FROM `users`
26 WHERE `alias` = \''.$DB->escape_string($_POST['reg_u']).'\'')->num_rows
)
27 throw new InvalidInputException('That username is already in use. Try a different name.');
29 // I should make this run fail2ban or something
31 !isset($_GET['code']) ||
32 !isset($_GET['user']) ||
33 !$DB->query('SELECT `userid` FROM `invites`
34 WHERE `code` = \''.$DB->escape_string($_GET['code']).'\'
35 AND `userid` = '.intval($_GET['user']))->num_rows
37 throw new InvalidInputException('Form data was submitted incorrectly.');
41 isset($_COOKIE['auto']) ||
42 $DB->query('SELECT `userid` FROM `users`
43 WHERE `reg_ip` = INET_ATON(\''.$_SERVER['REMOTE_ADDR'].'\')
44 AND `register_date` > (UNIX_TIMESTAMP() - 3600)')->num_rows
46 throw new RateLimitException('You can only register a maximum of one account per hour. Try again in one hour.');
48 $DB->query('INSERT INTO `users` (
58 \''.$DB->escape_string(htmlspecialchars($_POST['reg_u'])).'\',
59 AES_ENCRYPT(\''.$DB->escape_string($_POST['reg_p']).'\',
60 INET_ATON(\''.$_SERVER['REMOTE_ADDR'].'\')),
61 '.intval($_GET['user']).',
64 \''.$DB->escape_string($_POST['reg_e']).'\',
65 INET_ATON(\''.$_SERVER['REMOTE_ADDR'].'\'),
66 INET_ATON(\''.$_SERVER['REMOTE_ADDR'].'\')
70 throw new DatabaseException('MySQL error in user creation: '.$DB->error
); // furry
71 $DB->query('DELETE FROM `invites`
72 WHERE `code` = \''.$DB->escape_string($_GET['code']).'\'
73 AND `userid` = '.intval($_GET['user']));
75 setcookie('auto', 'yes', time()+
3600);
77 echo '<p class="info">Account has been created.</p>';
80 } catch ( InvalidInputException
$e ) {
82 echo '<p class="error">',$e->getMessage(),'</p>';
83 } catch ( RateLimitException
$e ) {
84 setcookie('auto', 'yes', time()+
3600);
86 echo '<p class="error">',$e->getMessage(),'</p>';
89 !isset($_GET['code']) ||
90 !isset($_GET['user']) ||
91 !$DB->query('SELECT `userid` FROM `invites`
92 NATURAL LEFT JOIN `users`
93 WHERE `code` = \''.$DB->escape_string($_GET['code']).'\'
94 AND `users`.`userid` IS NOT NULL
95 AND `invites`.`userid` = '.intval($_GET['user']))->num_rows
99 <p
class="error">You need a valid invitation code to create an account
.</p
>
100 <form action
="register" method
="post">
101 <p
class="info">Enter the registration code you were given
and the user ID number of the person who gave you it
.</p
>
102 <table
class="inputlist">
103 <tr
><th scope
="row">Code
</th
>
104 <td
><input type
="text" name
="code"/></td
></tr
>
105 <tr
><th scope
="row">User ID
</th
>
106 <td
><input type
="text" name
="user"/></td
></tr
>
108 <p
><button type
="submit" name
="prompt" value
="yes">Confirm
</button
></p
>
116 if ( ip2long($_SERVER['REMOTE_ADDR']) === false ) { // lancelott is a ricer
117 echo '<p class="error">Error: You have to register from an IPv4 address.</p>',"\n";
122 <form action
="register?user=<?php echo intval($_GET['user']) ?>;code=<?php echo htmlentities($_GET['code']) ?>" method
="post">
123 <fieldset
class="content"><legend
>Register Account
</legend
>
124 <p
class="info">Fill in all fields
and click Register to make a
new account
.</p
>
125 <table
class="inputlist">
126 <tr
><th scope
="row">Username
</th
>
127 <td
><input type
="text" name
="reg_u"/></td
></tr
>
128 <tr
><th scope
="row">Password
</th
>
129 <td
><input type
="password" name
="reg_p"/></td
></tr
>
130 <tr
><th scope
="row">Confirm Password
</th
>
131 <td
><input type
="password" name
="reg_c"/></td
></tr
>
132 <tr
><th scope
="row">Email
</th
>
133 <td
><input type
="text" name
="reg_e"/></td
></tr
>
135 <p
><button type
="submit" name
="something" value
="reg">Register Account
</button
></p
>