2 /***************************************************************************
3 Copyright (c) 2004 - 2010 Marcus Campbell
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ***************************************************************************/
21 require_once 'header.inc.php';
22 $userservice =& ServiceFactory::getServiceInstance('UserService');
23 $templateservice =& ServiceFactory::getServiceInstance('TemplateService');
28 if ($_POST['submitted']) {
30 $posteduser = trim(utf8_strtolower($_POST['username']));
31 $postedpass = trim($_POST['password']);
32 $postedconf = trim($_POST['passconf']);
35 if (!isset($_SESSION['token']) || $_POST['token'] != $_SESSION['token']) {
36 $tplVars['error'] = T_('Form could not be authenticated. Please try again.');
39 // Check if form is incomplete
40 elseif (!$posteduser || !$postedpass || !($_POST['email'])) {
41 $tplVars['error'] = T_('You <em>must</em> enter a username, password and e-mail address.');
44 // Check if username is reserved
45 elseif ($userservice->isReserved($posteduser)) {
46 $tplVars['error'] = T_('This username has been reserved, please make another choice.');
49 // Check if username already exists
50 elseif ($userservice->getUserByUsername($posteduser)) {
51 $tplVars['error'] = T_('This username already exists, please make another choice.');
54 // Check that password is long enough
55 elseif ($postedpass != '' && strlen($postedpass) < 6) {
56 $tplVars['error'] = T_('Password must be at least 6 characters long.');
59 // Check if password matches confirmation
60 elseif ($postedpass != $postedconf) {
61 $tplVars['error'] = T_('Password and confirmation do not match.');
64 // Check if e-mail address is blocked
65 elseif ($userservice->isBlockedEmail($_POST['email'])) {
66 $tplVars['error'] = T_('This e-mail address is not permitted.');
69 // Check if e-mail address is valid
70 elseif (!$userservice->isValidEmail($_POST['email'])) {
71 $tplVars['error'] = T_('E-mail address is not valid. Please try again.');
75 elseif ($userservice->addUser($posteduser, $_POST['password'], $_POST['email'])) {
76 // Log in with new username
77 $login = $userservice->login($posteduser, $_POST['password']);
79 header('Location: '. createURL('bookmarks', $posteduser));
81 $tplVars['msg'] = T_('You have successfully registered. Enjoy!');
84 $tplVars['error'] = T_('Registration failed. Please try again.');
88 $tplVars['msg'] = T_('Woah there, go easy on the Register button! Your registration was successful. Check your e-mail for instructions on how to verify your account.');
92 // Generate anti-CSRF token
93 $token = md5(uniqid(rand(), TRUE));
94 $_SESSION['token'] = $token;
95 $_SESSION['token_time'] = time();
97 $tplVars['loadjs'] = TRUE;
98 $tplVars['subtitle'] = T_('Register');
99 $tplVars['formaction'] = createURL('register');
100 $tplVars['token'] = $token;
101 $templateservice->loadTemplate('register.tpl', $tplVars);