62128db7bf82f43ee845d8057df6d0baddc5079d
[scuttle] / register.php
1 <?php
2 /***************************************************************************
3 Copyright (c) 2004 - 2010 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
22 require_once 'header.inc.php';
23 $userservice      =& ServiceFactory::getServiceInstance('UserService');
24 $templateservice  =& ServiceFactory::getServiceInstance('TemplateService');
25
26 $tplVars = array();
27
28 if ($_POST['submitted']) {
29     $posteduser = trim(utf8_strtolower($_POST['username']));
30
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.');
34
35     // Check if username is reserved
36     } elseif ($userservice->isReserved($posteduser)) {
37         $tplVars['error'] = T_('This username has been reserved, please make another choice.');
38
39     // Check if username already exists
40     } elseif ($userservice->getUserByUsername($posteduser)) {
41         $tplVars['error'] = T_('This username already exists, please make another choice.');
42     
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.');
46
47     // Register details
48     } elseif ($userservice->addUser($posteduser, $_POST['password'], $_POST['email'])) {
49         // Log in with new username
50         $login = $userservice->login($posteduser, $_POST['password']);
51         if ($login) {
52             header('Location: '. createURL('bookmarks', $posteduser));
53         }
54         $tplVars['msg'] = T_('You have successfully registered. Enjoy!');
55     } else {
56         $tplVars['error'] = T_('Registration failed. Please try again.');
57     }
58 }
59
60 $tplVars['loadjs']      = true;
61 $tplVars['subtitle']    = T_('Register');
62 $tplVars['formaction']  = createURL('register');
63 $templateservice->loadTemplate('register.tpl', $tplVars);

Benjamin Mako Hill || Want to submit a patch?