2 /***************************************************************************
3 Copyright (C) 2004 - 2006 Marcus Campbell
4 http://sourceforge.net/projects/scuttle/
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 ***************************************************************************/
22 require_once('header.inc.php');
23 $userservice =& ServiceFactory::getServiceInstance('UserService');
24 $templateservice =& ServiceFactory::getServiceInstance('TemplateService');
28 if ($_POST['submitted']) {
29 $posteduser = trim(utf8_strtolower($_POST['username']));
31 // Check if form is incomplete
32 if (!($posteduser) || !($_POST['password']) || !($_POST['email'])) {
33 $tplVars['error'] = T_('You <em>must</em> enter a username, password and e-mail address.');
35 // Check if username is reserved
36 } elseif ($userservice->isReserved($posteduser)) {
37 $tplVars['error'] = T_('This username has been reserved, please make another choice.');
39 // Check if username already exists
40 } elseif ($userservice->getUserByUsername($posteduser)) {
41 $tplVars['error'] = T_('This username already exists, please make another choice.');
43 // Check if e-mail address is valid
44 } elseif (!$userservice->isValidEmail($_POST['email'])) {
45 $tplVars['error'] = T_('E-mail address is not valid. Please try again.');
48 } elseif ($userservice->addUser($posteduser, $_POST['password'], $_POST['email'])) {
49 // Log in with new username
50 $login = $userservice->login($posteduser, $_POST['password']);
52 header('Location: '. createURL('bookmarks', $posteduser));
54 $tplVars['msg'] = T_('You have successfully registered. Enjoy!');
56 $tplVars['error'] = T_('Registration failed. Please try again.');
60 $tplVars['loadjs'] = true;
61 $tplVars['subtitle'] = T_('Register');
62 $tplVars['formaction'] = createURL('register');
63 $templateservice->loadTemplate('register.tpl', $tplVars);