Adds validation to registration form
parent
d2a9280d7d
commit
6c37a082bf
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
// sanitize all input vars that may end up in URLs or forms
|
// sanitize all input vars that may end up in URLs or forms
|
||||||
|
|
||||||
$platform_id = htmlspecialchars($_REQUEST['platform']);
|
$platform_id = htmlspecialchars($_REQUEST['platform'] ?? '');
|
||||||
if (isset($_REQUEST['page'])) {
|
if (isset($_REQUEST['page'])) {
|
||||||
$page = htmlspecialchars($_REQUEST['page']);
|
$page = htmlspecialchars($_REQUEST['page']);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -17,21 +17,47 @@ if ($config['registration_enabled'] == true) {
|
||||||
$dbWeb = connectDB($config);
|
$dbWeb = connectDB($config);
|
||||||
|
|
||||||
if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
|
if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
|
||||||
$username = $_POST['username'];
|
require_once '../app/classes/validator.php';
|
||||||
$password = $_POST['password'];
|
|
||||||
|
|
||||||
// registering
|
$validator = new Validator($_POST);
|
||||||
$result = $userObject->register($username, $password);
|
$rules = [
|
||||||
|
'username' => [
|
||||||
|
'required' => true,
|
||||||
|
'min' => 3,
|
||||||
|
'max' => 20
|
||||||
|
],
|
||||||
|
'password' => [
|
||||||
|
'required' => true,
|
||||||
|
'min' => 8,
|
||||||
|
'max' => 100
|
||||||
|
],
|
||||||
|
'confirm_password' => [
|
||||||
|
'required' => true,
|
||||||
|
'matches' => 'password'
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
// redirect to login
|
if ($validator->validate($rules)) {
|
||||||
if ($result === true) {
|
$username = $_POST['username'];
|
||||||
Messages::flash('NOTICE', 'DEFAULT', "Registration successful.<br />You can log in now.");
|
$password = $_POST['password'];
|
||||||
header('Location: ' . htmlspecialchars($app_root));
|
|
||||||
exit();
|
// registering
|
||||||
// registration fail, redirect to login
|
$result = $userObject->register($username, $password);
|
||||||
|
|
||||||
|
// redirect to login
|
||||||
|
if ($result === true) {
|
||||||
|
Messages::flash('NOTICE', 'DEFAULT', "Registration successful. You can log in now.");
|
||||||
|
header('Location: ' . htmlspecialchars($app_root));
|
||||||
|
exit();
|
||||||
|
// registration fail, redirect to login
|
||||||
|
} else {
|
||||||
|
Messages::flash('ERROR', 'DEFAULT', "Registration failed. $result");
|
||||||
|
header('Location: ' . htmlspecialchars($app_root));
|
||||||
|
exit();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Messages::flash('ERROR', 'DEFAULT', "Registration failed. $result");
|
Messages::flash('ERROR', 'DEFAULT', $validator->getFirstError());
|
||||||
header('Location: ' . htmlspecialchars($app_root));
|
header('Location: ' . htmlspecialchars($app_root . '?page=register'));
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
<input type="text" name="username" placeholder="Username" required autofocus />
|
<input type="text" name="username" placeholder="Username" required autofocus />
|
||||||
<br />
|
<br />
|
||||||
<input type="password" name="password" placeholder="Password" required />
|
<input type="password" name="password" placeholder="Password" required />
|
||||||
|
<br />
|
||||||
|
<input type="password" name="confirm_password" placeholder="Confirm password" required />
|
||||||
<br /> <br />
|
<br /> <br />
|
||||||
<input type="submit" class="btn btn-primary" value="Register" />
|
<input type="submit" class="btn btn-primary" value="Register" />
|
||||||
</form>
|
</form>
|
||||||
|
|
Loading…
Reference in New Issue