108 lines
2.6 KiB
PHP
108 lines
2.6 KiB
PHP
<?php
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] != "POST") {
|
|
die();
|
|
}
|
|
|
|
require_once 'general.php';
|
|
require_once 'vendor/autoload.php';
|
|
|
|
use PHPMailer\PHPMailer\PHPMailer;
|
|
use Rakit\Validation\Validator;
|
|
|
|
$validator = new Validator;
|
|
|
|
$validation = $validator->make($_POST,[
|
|
'name' => 'required',
|
|
'email' => 'required|email',
|
|
'year' => 'required|numeric',
|
|
'birthday' => 'required|date',
|
|
'vocation' => 'required',
|
|
'privacy' => 'required'
|
|
]);
|
|
|
|
$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"
|
|
|
|
]);
|
|
|
|
$validation->validate();
|
|
|
|
if($validation->fails()) {
|
|
$errors = $validation->errors();
|
|
echo "<pre>";
|
|
print_r($errors->firstOfAll());
|
|
echo "</pre>";
|
|
exit;
|
|
}
|
|
|
|
$validData = $validation->getValidData();
|
|
|
|
$config = getConfig();
|
|
|
|
$validData['verify'] = 0;
|
|
unset($validData['privacy']);
|
|
|
|
$db = getDatabase();
|
|
$statement = $db->prepare("INSERT INTO entries(name, mail, year, birthday, verify, vocation, creation) VALUES (:name, :email, :year, :birthday, :verify, :vocation, CURDATE())");
|
|
|
|
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'];
|
|
|
|
$mail = new PHPMailer(true);
|
|
|
|
$mail->isSMTP();
|
|
$mail->SMTPAuth = true;
|
|
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
|
|
$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'];
|
|
$mail->FromName = $config['mail_name'];
|
|
try {
|
|
$mail->addAddress($validData['email'], $validData['name']);
|
|
} catch (\PHPMailer\PHPMailer\Exception $e) {
|
|
echo $e->getMessage();
|
|
}
|
|
|
|
$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>';
|
|
|
|
|
|
try {
|
|
!$mail->send();
|
|
} catch (\PHPMailer\PHPMailer\Exception $e) {
|
|
echo $e;
|
|
}
|
|
|
|
returnHeader();
|
|
?>
|
|
|
|
Vielen Dank, bitte bestätige deine E-Mail Adresse
|
|
|
|
<?php
|
|
returnFooter();
|