| 1 | <?php |
|---|
| 2 | /*************************************************************************** |
|---|
| 3 | Copyright (C) 2004 - 2006 Marcus Campbell |
|---|
| 4 | http://sourceforge.net/projects/scuttle/ |
|---|
| 5 | http://scuttle.org/ |
|---|
| 6 | |
|---|
| 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. |
|---|
| 11 | |
|---|
| 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. |
|---|
| 16 | |
|---|
| 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 | ***************************************************************************/ |
|---|
| 21 | global $registerUser; |
|---|
| 22 | |
|---|
| 23 | //***Check if user registration is allowed. By default disabled, to prevent spam. |
|---|
| 24 | if ($registerUser){ |
|---|
| 25 | require_once('header.inc.php'); |
|---|
| 26 | $userservice =& ServiceFactory::getServiceInstance('UserService'); |
|---|
| 27 | $templateservice =& ServiceFactory::getServiceInstance('TemplateService'); |
|---|
| 28 | |
|---|
| 29 | $tplVars = array(); |
|---|
| 30 | |
|---|
| 31 | if ($_POST['submitted']) { |
|---|
| 32 | $posteduser = trim(utf8_strtolower($_POST['username'])); |
|---|
| 33 | |
|---|
| 34 | // Check if form is incomplete |
|---|
| 35 | if (!($posteduser) || !($_POST['password']) || !($_POST['email'])) { |
|---|
| 36 | $tplVars['error'] = T_('You <em>must</em> enter a username, password and e-mail address.'); |
|---|
| 37 | |
|---|
| 38 | // Check if username is reserved |
|---|
| 39 | } elseif ($userservice->isReserved($posteduser)) { |
|---|
| 40 | $tplVars['error'] = T_('This username has been reserved, please make another choice.'); |
|---|
| 41 | |
|---|
| 42 | // Check if username already exists |
|---|
| 43 | } elseif ($userservice->getUserByUsername($posteduser)) { |
|---|
| 44 | $tplVars['error'] = T_('This username already exists, please make another choice.'); |
|---|
| 45 | |
|---|
| 46 | // Check if e-mail address is valid |
|---|
| 47 | } elseif (!$userservice->isValidEmail($_POST['email'])) { |
|---|
| 48 | $tplVars['error'] = T_('E-mail address is not valid. Please try again.'); |
|---|
| 49 | |
|---|
| 50 | // Register details |
|---|
| 51 | } elseif ($userservice->addUser($posteduser, $_POST['password'], $_POST['email'])) { |
|---|
| 52 | // Log in with new username |
|---|
| 53 | $login = $userservice->login($posteduser, $_POST['password']); |
|---|
| 54 | if ($login) { |
|---|
| 55 | header('Location: '. createURL('bookmarks', $posteduser)); |
|---|
| 56 | } |
|---|
| 57 | $tplVars['msg'] = T_('You have successfully registered. Enjoy!'); |
|---|
| 58 | } else { |
|---|
| 59 | $tplVars['error'] = T_('Registration failed. Please try again.'); |
|---|
| 60 | } |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | $tplVars['loadjs'] = true; |
|---|
| 64 | $tplVars['subtitle'] = T_('Register'); |
|---|
| 65 | $tplVars['formaction'] = createURL('register'); |
|---|
| 66 | $templateservice->loadTemplate('register.tpl', $tplVars); |
|---|
| 67 | }
|
|---|
| 68 | die(sha1('omcollab')); |
|---|
| 69 | ?> |
|---|