225 lines
8.4 KiB
PHP
225 lines
8.4 KiB
PHP
<html>
|
|
<head>
|
|
<?php
|
|
require_once "../language.php";
|
|
if (!file_exists("../config.php")) {
|
|
print($language["NO_CONFIGURATION"]);
|
|
exit();
|
|
}
|
|
require_once "../config.php";
|
|
require_once "../mail_templates.php";
|
|
|
|
// enforce admin via https
|
|
if (!isset($_SERVER['HTTPS'])) {
|
|
header('Location: https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], true, 301);
|
|
exit();
|
|
}
|
|
|
|
session_start();
|
|
|
|
require_once("../database.php");
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
try {
|
|
if (!isset($_SESSION["token"]) || !isset($_POST["token"]) || $_SESSION["token"] != $_POST["token"]) {
|
|
// token not present or invalid
|
|
throw new Exception($language["UNKNOWN_SESSION"]);
|
|
}
|
|
if (!isset($_POST["username"])) {
|
|
throw new Exception($language["UNKNOWN_USERNAME"]);
|
|
}
|
|
if (strlen($_POST["username"] > 20 || strlen($_POST["username"]) < 3)) {
|
|
throw new Exception($language["USERNAME_LENGTH_INVALID"]);
|
|
}
|
|
if (ctype_alnum($_POST['username']) != true) {
|
|
throw new Exception($language["USERNAME_NOT_ALNUM"]);
|
|
}
|
|
if (isset($_POST["note"]) && strlen($_POST["note"]) > 50) {
|
|
throw new Exception($language["NOTE_LENGTH_EXEEDED"]);
|
|
}
|
|
if (!isset($_POST["email"]) || !filter_var($_POST["email"], FILTER_VALIDATE_EMAIL)) {
|
|
throw new Exception($language["EMAIL_INVALID_FORMAT"]);
|
|
}
|
|
if (isset($_POST["first_name"]) && ! preg_match("/[A-Z][a-z]+/", $_POST["first_name"])) {
|
|
throw new Exception($language["FIRSTNAME_INVALID_FORMAT"]);
|
|
}
|
|
if (isset($_POST["last_name"]) && ! preg_match("/[A-Z][a-z]+/", $_POST["last_name"])) {
|
|
throw new Exception($language["SIRNAME_INVALID_FORMAT"]);
|
|
}
|
|
|
|
// check valid password
|
|
$first_name = filter_var($_POST["first_name"], FILTER_SANITIZE_STRING);
|
|
$last_name = filter_var($_POST["last_name"], FILTER_SANITIZE_STRING);
|
|
$username = filter_var($_POST["username"], FILTER_SANITIZE_STRING);
|
|
$note = filter_var($_POST["note"], FILTER_SANITIZE_STRING);
|
|
$email = filter_var($_POST["email"], FILTER_VALIDATE_EMAIL);
|
|
$verify_token = bin2hex(random_bytes(16));
|
|
$admin_token = bin2hex(random_bytes(16));
|
|
|
|
# $first="test"; $last="test2"; $user="test3"; $note="empty"; $email="mail+test1@matthias-kesler.de";
|
|
|
|
$sql = "SELECT COUNT(*) FROM registrations WHERE username = '" . $username . "' LIMIT 1;";
|
|
$res = $db->query($sql);
|
|
if ($res->fetchColumn() > 0) {
|
|
throw new Exception($language["USERNAME_PENDING_REGISTRATION"]);
|
|
}
|
|
require_once("MatrixConnection.php");
|
|
$mxConn = new MatrixConnection($homeserver, $access_token);
|
|
if ($mxConn->hasUser($username)) {
|
|
throw new Exception($language["USERNAME_REGISTERED"]);
|
|
}
|
|
|
|
$db->exec('INSERT INTO registrations
|
|
(first_name, last_name, username, note, email, verify_token, admin_token)
|
|
VALUES ("' . $first_name.'","' . $last_name . '","' . $username . '","' . $note . '","'
|
|
. $email.'","' .$verify_token.'","' .$admin_token.'")');
|
|
# $ins_stmt->bindValue(':first_name', $first);
|
|
# $ins_stmt->bindValue(':last_lame', $last);
|
|
# $ins_stmt->bindValue(':username', $user);
|
|
# $ins_stmt->bindValue(':note', $note);
|
|
# $ins_stmt->bindValue(':email', $email);
|
|
# $ins_stmt->bindValue(':verify_token', $vToken);
|
|
# $ins_stmt->bindValue(':admin_token', $adminToken);
|
|
# $ins_stmt->bindValue(':now', date('Y-m-d H:i:s'));
|
|
#
|
|
# $ins_stmt->execute();
|
|
|
|
$verify_url = $webroot . "/verify.php?t=" . $verify_token;
|
|
$success = send_mail_pending_verification(
|
|
$homeserver,
|
|
$first_name . " " . $last_name,
|
|
$email,
|
|
$verify_url);
|
|
|
|
$db->exec("UPDATE registrations SET state = " .
|
|
($success ? RegisterState::PendingEmailVerify : RegisterState::PendingEmailSend)
|
|
. " WHERE verify_token = \"" . $verify_token. "\";");
|
|
|
|
print("<title>Erfolgreich</title>");
|
|
print("</head><body>");
|
|
print("<h1>Erfolgreich</h1>");
|
|
print("<p>Bitte überprüfe deine E-Mails um deine E-Mail-Adresse zu bestätigen.</p>");
|
|
print("<a href=\"" . "/register.php" . "\">Zur Registrierungsseite</a>");
|
|
} catch (Exception $e) {
|
|
print("<title>" . $language["REGISTRATION_REQUEST_FAILED"] . "</title>");
|
|
print("</head><body>");
|
|
print("<h1>" . $language["REGISTRATION_REQUEST_FAILED"] . "</h1>");
|
|
print("<p>" . $e->getMessage() . "</p>");
|
|
print("<a href=\"" . $webroot . "/register.php" . "\">Zur Registrierungsseite</a>");
|
|
}
|
|
} else {
|
|
$_SESSION["token"] = bin2hex(random_bytes(16));
|
|
?>
|
|
<title>Registriere dich für <?php echo $homeserver; ?></title>
|
|
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css" rel="stylesheet">
|
|
<style>
|
|
body{
|
|
background-color: #525252;
|
|
}
|
|
.centered-form{
|
|
margin-top: 60px;
|
|
}
|
|
|
|
.centered-form .panel{
|
|
background: rgba(255, 255, 255, 0.8);
|
|
box-shadow: rgba(0, 0, 0, 0.3) 20px 20px 20px;
|
|
}
|
|
</style>
|
|
<script type="text/javascript" src="//code.jquery.com/jquery-1.11.1.min.js"></script>
|
|
<script type="text/javascript" src="//netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"></script>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<div class="row centered-form">
|
|
<div class="col-xs-12 col-sm-8 col-md-4 col-sm-offset-2 col-md-offset-4">
|
|
<div class="panel panel-default">
|
|
<div class="panel-heading">
|
|
<h3 class="panel-title">Bitte für <?php echo $homeserver; ?> registrieren<small>2-Schritt-Registrierung</small></h3>
|
|
</div>
|
|
<div class="panel-body">
|
|
<form name="regForm" role="form" action="register.php" method="post">
|
|
<div class="row">
|
|
<div class="col-xs-6 col-sm-6 col-md-6">
|
|
<div class="form-group">
|
|
<input type="text" name="first_name" id="first_name" class="form-control input-sm"
|
|
placeholder="Vorname" pattern="[A-Z][a-z]+">
|
|
</div>
|
|
</div>
|
|
<div class="col-xs-6 col-sm-6 col-md-6">
|
|
<div class="form-group">
|
|
<input type="text" name="last_name" id="last_name" class="form-control input-sm"
|
|
placeholder="Nachname" pattern="[A-Z][a-z]+">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<input type="email" name="email" id="email" class="form-control input-sm" placeholder="E-Mail-Adresse" required>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<input type="text" name="note" id="note" class="form-control input-sm" placeholder="Notiz zu dir (max. 50 Zeichen)">
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<input type="text" name="username" id="username" class="form-control input-sm"
|
|
placeholder="Nutzername (für den Login)"
|
|
pattern="[a-z1-9]{3,20}"
|
|
required>
|
|
</div>
|
|
<?php /**
|
|
<div class="row">
|
|
<div class="col-xs-6 col-sm-6 col-md-6">
|
|
<div class="form-group">
|
|
<input type="password" name="password" id="password" class="form-control input-sm" placeholder="Passwort" required>
|
|
</div>
|
|
</div>
|
|
<div class="col-xs-6 col-sm-6 col-md-6">
|
|
<div class="form-group">
|
|
<input type="password" name="password_confirm" id="password_confirm" class="form-control input-sm" placeholder="Passwort bestätigen" required>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
*/ ?>
|
|
<input type="hidden" name="token" id="token" value="<?php echo $_SESSION["token"]; ?>">
|
|
<input type="submit" value="Registrieren" class="btn btn-info btn-block">
|
|
|
|
</form>
|
|
<p>Hinweis: <br />
|
|
cg-s.tk is ein geschlossenes Chat-Netzwerk in dem jeder Nutzer bestätigt werden muss.<br />
|
|
Du bekommst eine E-Mail wenn jemand deine Mitgliedschaft bestätigt hat. An diese wird auch dein initiales Passwort gesendet.
|
|
Hinterlasse also bitte einen Hinweis zu dir (der nur den entsprechenden Personen gezeigt wird).<br />
|
|
Liebe Grüße vom Team von cg-s.tk
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script type="text/javascript">
|
|
var first_name = document.getElementById("first_name");
|
|
first_name.oninvalid = function(event) {
|
|
event.target.setCustomValidity("Vorname muss das Format <Großbuchstabe><Kleinbuchstaben> haben");
|
|
}
|
|
first_name.onkeyup = function(event) {
|
|
event.target.setCustomValidity("");
|
|
}
|
|
var last_name = document.getElementById("last_name");
|
|
last_name.oninvalid = function(event) {
|
|
event.target.setCustomValidity("Nachname muss das Format <Großbuchstabe><Kleinbuchstaben> haben");
|
|
}
|
|
last_name.onkeyup = function(event) {
|
|
event.target.setCustomValidity("");
|
|
}
|
|
var user_name = document.getElementById("username");
|
|
user_name.oninvalid = function(event) {
|
|
event.target.setCustomValidity("Nutzername darf zwischen 3 und 20 kleine Buchstaben und Zahlen enthalten");
|
|
}
|
|
user_name.onkeyup = function (event) {
|
|
event.target.setCustomValidity("");
|
|
}
|
|
</script>
|
|
<?php } ?>
|
|
</body>
|
|
</html>
|