diff options
Diffstat (limited to 'frontend/pages/register.php')
-rw-r--r-- | frontend/pages/register.php | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/frontend/pages/register.php b/frontend/pages/register.php new file mode 100644 index 0000000..344ee25 --- /dev/null +++ b/frontend/pages/register.php @@ -0,0 +1,66 @@ +<?php +function init_register() { + global $S; + if (isset($S['user'])) { + header('Location: '.url()); + return 'welcome'; + } + if (isset($request['token']) && preg_match('/^[a-zA-Z0-9]{30}$/', $request['token'])) { + $r=$S['pdo']->query('SELECT * FROM `tokens` WHERE `id`=\''.$request['token'].'\''); + if ($r->rowCount()) { + $S['register.token']=new sql_registrationtoken($r->fetch(PDO::FETCH_ASSOC)); + if (isset($request['password'])) { + $S['register.fail']=''; + if (!isset($request['name']) || !Validate::username($request['name'])) + $S['register.fail'].=print_warning('The username you entered is invalid. Names must be at least two characters long and may contain alphanumeric characters, period, space, underscore, and dash.'); + if (!isset($request['password']) || strlen($request['password']) <= 4) + $S['register.fail'].=print_warning('Please enter a password at least five characters long.'); + if ($S['register.fail']=='') { + $S['user']=new sql_user(null, $S['register.token']->email, $request['name'], sha1($request['password']), ''); + $S['user']->write(); + $S['register.token']->delete(); + unset($S['register.token']); + sql_session::create(); + } + } + } + } + return array('title' => 'Register'); +} +function body_register() { + global $S, $request, $conf; + if (isset($S['user'])) + echo print_success('Account creation complete.'); + elseif (isset($request['email'])) { + if (!Validate::email($request['email'])) + echo print_warning('The email address you entered is invalid.').'<a href="javascript:history.go(-1)">Back</a>'; + // 5.3.0 - goto print form + else { + if ($S['pdo']->query('SELECT COUNT(*) FROM `users` WHERE `email`='.$S['pdo']->quote($request['email']))->fetch(PDO::FETCH_COLUMN)) + echo print_warning('An account already exists with this email address.').'<a href="'.url('login').'">Login</a>'; + else { + if ($token=$S['pdo']->query('SELECT * FROM `registrationtokens` WHERE `email`='.$S['pdo']->quote($request['email']))->fetch(PDO::FETCH_ASSOC)) { + echo print_warning('A confirmation email has already been sent to this email address... sending another email.'); + $token=new sql_registrationtoken($token); + } else { + $token=sql_registrationtoken::create(); + $token->email=$request['email']; + } + $token->expire=time()+24*3600; // 24 Hours before expiration (not implemented) + $token->write(); + xhtmlemail($request['email'], null, $conf['title'].' account creation', 'To complete your account registration, click this link: <a href="'.url('register/'.$token->id).'">'.url('register/'.$token->id).'</a>.'); + echo print_success('You will receive an email soon at '.htmlentities($request['email']).' with instructions to finish creating your account.'); + } + } + } elseif (isset($S['register.token'])) { + if (isset($S['register.fail'])) + echo $S['register.fail']; + else + echo '<h3>Register</h3><form action="'.url('register').'" method="post"><input type="hidden" name="token" value="'.$request['token'].'" />Display name: <input name="name" /><br/>Password: <input type="password" name="password" /><br/><input type="submit" value="Create Account" /></form>'; + } else + echo '<h3>Register</h3><form action="'.url('register').'" method="post"> + E-mail: <input name="email" /><br/> + <input type="submit" value="Create Account" /> + </form>'; +} +?> |