Sponsorenverwaltung - Team StarCraft e.V.
 All Data Structures Files Functions Variables
register.php
Go to the documentation of this file.
1 <?php
2 
3  /**
4  * @file register.php
5  *
6  * @brief Handles all the registration stuff. Provides input validation.
7  *
8  * @details
9  * Handles all the application logic needed for registration. This includes
10  * input validation (integrety, correctness) as well as the insertion of the
11  * new user into the database and emailing the user instructions for the next
12  * steps.
13  *
14  * This file is inspired by register.php from Usercake (Version 2.0.2)
15  *
16  * This file depends on inc/common.php and inc/templates/register.tpl.
17  *
18  * @copyright (c) 2013, Team StarCrcaft e.V.
19  * @version 1.0.0
20  * @author Usercake (http://www.usercake.com)
21  * @author Daniel Seichter
22  * @author Alexander Vorndran
23  * @date 02.07.2013
24  */
25 
26  /// @cond MAINPART
27  // include
28  include("inc/common.php");
29 
30 
31  // UserCake
32  if(!accessGranted($_SERVER['PHP_SELF'])) {
33  if (isUserLoggedIn()) {
34  exitWithErrorTemplate(array('Die angeforderte Seite ist gesperrt.'));
35  }
36  else {
37  exitWithErrorTemplateAndRedirect(array('Die angeforderte Seite ist gesperrt oder geschützt.'), 'login.php', 2);
38  }
39  }
40 
41  //Prevent the user visiting the login page if he/she is already logged in
42  if (isUserLoggedIn()) {
43  header("Location: home.php");
44  die();
45  }
46 
47  //Forms posted
48  if (!empty($_POST)) {
49  $email = trim($_POST["email"]);
50  $mobile = str_replace(array('/', ' ','-'), '', $_POST["mobile"]);
51  /* @var $firstname string */
52  $firstname = prepareNameForDatabase($_POST["firstname"]);
53  /* @var $lastname string */
54  $lastname = prepareNameForDatabase($_POST["lastname"]);
55  /* @var $username string */
56  $username = prepareNamesForUsername($firstname) . "." . prepareNamesForUsername($lastname);
57  /* @var $password string */
58  $password = trim($_POST["password"]);
59  /* @var $confirm_pass string */
60  $confirm_pass = trim($_POST["passwordc"]);
61  $captcha = md5($_POST["captcha"]);
62 
63 
64  if ($captcha != $_SESSION['captcha']) {
65  $errors[] = lang('CAPTCHA_FAIL');
66  }
67 
68  if (!isValidName($firstname)) {
69  $errors[] = lang('ACCOUNT_FIRST_INVALID_CHARACTERS');
70  }
71  if (!isValidName($lastname)) {
72  $errors[] = lang('ACCOUNT_LAST_INVALID_CHARACTERS');
73  }
74 
75  if (minMaxRange(8, 50, $password) && minMaxRange(8, 50, $confirm_pass)) {
76  $errors[] = lang("ACCOUNT_PASS_CHAR_LIMIT", array(8, 50));
77  } else
78  if ($password != $confirm_pass) {
79  $errors[] = lang("ACCOUNT_PASS_MISMATCH");
80  }
81 
82  if (!isValidEmail($email)) {
83  $errors[] = lang("ACCOUNT_INVALID_EMAIL");
84  }
85 
86  if (!isValidMobile($mobile)) {
87  $errors[] = lang("ACCOUNT_INVALID_MOBILE");
88  }
89 
90  //End data validation
91  if (count($errors) == 0) {
92  //Construct a user object
93  $user = new User($username, $firstname, $lastname, $password, $email, $mobile);
94 
95  //Checking this flag tells us whether there were any errors such as possible data duplication occured
96  if (!$user->status) {
97  if ($user->username_taken)
98  $errors[] = lang("ACCOUNT_USERNAME_IN_USE", array($username));
99  if ($user->email_taken)
100  $errors[] = lang("ACCOUNT_EMAIL_IN_USE", array($email));
101  if ($user->mobile_taken)
102  $errors[] = lang("ACCOUNT_MOBILE_IN_USE", array($mobile));
103  } else {
104  //Attempt to add the user to the database, carry out finishing tasks like emailing the user (if required)
105  if (!$user->userCakeAddUser()) {
106  if ($user->mail_failure)
107  $errors[] = lang("MAIL_ERROR");
108  if ($user->sql_failure)
109  $errors[] = lang("SQL_ERROR");
110  }
111  }
112 
113  if (count($errors) > 0) {
114  /* error + fill in vars */
115  $smarty->assign('firstname', $firstname);
116  $smarty->assign('lastname', $lastname);
117  $smarty->assign('email', $email);
118  $smarty->assign('mobile', $mobile);
119  } else {
120  $successes[] = $user->success;
121  unset($firstname);
122  unset($lastname);
123  unset($password);
124  unset($confirm_pass);
125  unset($email);
126  unset($mobile);
127  unset($username);
128  unset($captcha);
129  }
130  } else {
131  /* fill in vars */
132  $smarty->assign('firstname', $firstname);
133  $smarty->assign('lastname', $lastname);
134  $smarty->assign('email', $email);
135  $smarty->assign('mobile', $mobile);
136  }
137  }
138 
139  // run template
140  displayTemplateWithErrorsAndSuccesses('Registrieren','register.tpl');
141  /// @endcond
142 ?>