2021-04-21 10:17:02 +02:00
|
|
|
<?php
|
2021-05-04 09:44:45 +02:00
|
|
|
|
2021-04-23 09:17:58 +02:00
|
|
|
if ($_SERVER['REQUEST_METHOD'] != "POST") {
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
|
|
|
require_once 'general.php';
|
|
|
|
require_once 'vendor/autoload.php';
|
2021-04-21 10:17:02 +02:00
|
|
|
|
|
|
|
use PHPMailer\PHPMailer\PHPMailer;
|
2021-04-27 12:11:43 +02:00
|
|
|
use Rakit\Validation\Validator;
|
|
|
|
|
|
|
|
$validator = new Validator;
|
|
|
|
|
|
|
|
$validation = $validator->make($_POST,[
|
|
|
|
'name' => 'required',
|
|
|
|
'email' => 'required|email',
|
2021-05-05 12:40:57 +02:00
|
|
|
'phone' => 'nullable|numeric',
|
|
|
|
'location' => 'nullable|alpha',
|
2021-04-27 12:11:43 +02:00
|
|
|
'year' => 'required|numeric',
|
|
|
|
'birthday' => 'required|date',
|
|
|
|
'vocation' => 'required',
|
|
|
|
'privacy' => 'required'
|
|
|
|
]);
|
2021-04-21 10:17:02 +02:00
|
|
|
|
2021-04-27 12:11:43 +02:00
|
|
|
$validation->setMessages([
|
|
|
|
'required' => ":attribute muss ausgefüllt werden",
|
|
|
|
'email' => "Die E-Mail Adresse :email ist nicht gültig",
|
|
|
|
'numeric' => ":numeric muss eine Zahl sein",
|
|
|
|
'date' => ":attribute muss ein Datum sein"
|
2021-04-23 09:17:58 +02:00
|
|
|
|
2021-04-27 12:11:43 +02:00
|
|
|
]);
|
2021-04-23 09:17:58 +02:00
|
|
|
|
2021-04-27 12:11:43 +02:00
|
|
|
$validation->validate();
|
|
|
|
|
|
|
|
if($validation->fails()) {
|
|
|
|
$errors = $validation->errors();
|
|
|
|
echo "<pre>";
|
|
|
|
print_r($errors->firstOfAll());
|
|
|
|
echo "</pre>";
|
|
|
|
exit;
|
|
|
|
}
|
2021-04-23 09:17:58 +02:00
|
|
|
|
2021-04-27 12:11:43 +02:00
|
|
|
$validData = $validation->getValidData();
|
2021-04-23 09:17:58 +02:00
|
|
|
|
2021-04-21 10:17:02 +02:00
|
|
|
$config = getConfig();
|
|
|
|
|
2021-04-27 12:11:43 +02:00
|
|
|
$validData['verify'] = 0;
|
|
|
|
unset($validData['privacy']);
|
|
|
|
|
|
|
|
$db = getDatabase();
|
2021-05-05 12:40:57 +02:00
|
|
|
$statement = $db->prepare("INSERT INTO entries(name, mail, phone, location, year, birthday, verify, vocation, creation) VALUES (:name, :email, :phone, :location, :year, :birthday, :verify, :vocation, CURDATE())");
|
2021-04-27 12:11:43 +02:00
|
|
|
|
|
|
|
if(!$statement->execute($validData)) {
|
|
|
|
echo "Datenbank Fehler";
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
$id = $db->lastInsertId();
|
|
|
|
|
|
|
|
$statement = $db->prepare("INSERT INTO verify(id) VALUES (:id)");
|
|
|
|
|
|
|
|
if(!$statement->execute(['id' => $id])) {
|
|
|
|
echo "Datenbank Fehler";
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
$statement = $db->prepare("SELECT uuid from verify WHERE id = :id");
|
|
|
|
|
|
|
|
if(!$statement->execute(['id' => $id])) {
|
|
|
|
echo "database Error";
|
|
|
|
}
|
|
|
|
|
|
|
|
$uuid = $statement->fetch(PDO::FETCH_ASSOC)['uuid'];
|
|
|
|
|
2021-04-21 10:17:02 +02:00
|
|
|
$mail = new PHPMailer(true);
|
|
|
|
|
2021-04-23 09:17:58 +02:00
|
|
|
$mail->isSMTP();
|
|
|
|
$mail->SMTPAuth = true;
|
2021-05-04 09:44:45 +02:00
|
|
|
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
|
2021-04-21 10:17:02 +02:00
|
|
|
$mail->Host = $config['mail_server'];
|
|
|
|
$mail->Port = $config['mail_port'];
|
|
|
|
$mail->Username = $config['mail_user'];
|
|
|
|
$mail->Password = $config['mail_password'];
|
|
|
|
|
|
|
|
$mail->From = $config['mail_address'];
|
2021-04-27 12:11:43 +02:00
|
|
|
$mail->FromName = $config['mail_name'];
|
2021-04-23 09:17:58 +02:00
|
|
|
try {
|
2021-04-27 12:11:43 +02:00
|
|
|
$mail->addAddress($validData['email'], $validData['name']);
|
2021-04-23 09:17:58 +02:00
|
|
|
} catch (\PHPMailer\PHPMailer\Exception $e) {
|
2021-04-27 12:11:43 +02:00
|
|
|
echo $e->getMessage();
|
2021-04-23 09:17:58 +02:00
|
|
|
}
|
2021-04-21 10:17:02 +02:00
|
|
|
|
2021-04-27 12:11:43 +02:00
|
|
|
$mail->Subject = 'Bestätigung einer Eintragung';
|
|
|
|
$mail->AltBody = 'Bitte bestätige deine Eintragung unter folgendem Link: ' . $config['url'] . "/verify.php/?id=" . $uuid;
|
|
|
|
$mail->Body = 'Bitte bestätige deine Eintragung bitte <a href="' . $config['url'] . "/verify.php/?id=" . $uuid . '">hier</a>';
|
2021-04-21 10:17:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
!$mail->send();
|
|
|
|
} catch (\PHPMailer\PHPMailer\Exception $e) {
|
|
|
|
echo $e;
|
|
|
|
}
|
2021-04-27 12:11:43 +02:00
|
|
|
|
|
|
|
returnHeader();
|
|
|
|
?>
|
|
|
|
|
|
|
|
Vielen Dank, bitte bestätige deine E-Mail Adresse
|
|
|
|
|
|
|
|
<?php
|
|
|
|
returnFooter();
|