diff --git a/composer.json b/composer.json index 79d77c4..d240d70 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,7 @@ { "require": { - "phpmailer/phpmailer": "^6.4" + "phpmailer/phpmailer": "^6.4", + "rakit/validation": "v1.4.0", + "ext-pdo": "*" } } diff --git a/composer.lock b/composer.lock index 359230a..bd21252 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d01b4a542231b112db557e6b7e5a5121", + "content-hash": "59230ec995edc426fe883cde9a32b541", "packages": [ { "name": "phpmailer/phpmailer", @@ -81,6 +81,52 @@ } ], "time": "2021-03-31T20:06:42+00:00" + }, + { + "name": "rakit/validation", + "version": "v1.4.0", + "source": { + "type": "git", + "url": "https://github.com/rakit/validation.git", + "reference": "ff003a35cdf5030a5f2482299f4c93f344a35b29" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/rakit/validation/zipball/ff003a35cdf5030a5f2482299f4c93f344a35b29", + "reference": "ff003a35cdf5030a5f2482299f4c93f344a35b29", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "php": ">=7.0" + }, + "require-dev": { + "php-coveralls/php-coveralls": "^2.2", + "phpunit/phpunit": "^6.5", + "squizlabs/php_codesniffer": "^3" + }, + "type": "library", + "autoload": { + "psr-4": { + "Rakit\\Validation\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Muhammad Syifa", + "email": "emsifa@gmail.com" + } + ], + "description": "PHP Laravel like standalone validation library", + "support": { + "issues": "https://github.com/rakit/validation/issues", + "source": "https://github.com/rakit/validation/tree/v1.4.0" + }, + "time": "2020-08-27T05:07:01+00:00" } ], "packages-dev": [], diff --git a/config.ini.php.sample b/config.ini.php.sample index 6f28f02..6998c83 100644 --- a/config.ini.php.sample +++ b/config.ini.php.sample @@ -1,5 +1,9 @@ ; +url = http://localhost +user = sample +password = password + [database] db_host = localhost db_database = alumni @@ -12,6 +16,7 @@ mail_port = 25 mail_user = mail_address = mail_password = +mail_name = Alumni Max Emden [style] title = Alumni Max Emden diff --git a/create.sql b/create.sql index d935a39..6d9aa69 100644 --- a/create.sql +++ b/create.sql @@ -2,4 +2,6 @@ create table entries(id bigint auto_increment primary key, name varchar(255), ma year int(4), birthday date, verify bool, vocation varchar(255) ); -create table verify(id bigint primary key, uuid BINARY(16) ,foreign key verify(id) REFERENCES entries(id)); \ No newline at end of file +create table verify(id bigint primary key, uuid VARCHAR(36),foreign key verify(id) REFERENCES entries(id)); + +CREATE TRIGGER before_insert_verify BEFORE INSERT ON verify FOR EACH ROW SET new.uuid = uuid(); \ No newline at end of file diff --git a/general.php b/general.php index 38028f1..cbe07b8 100644 --- a/general.php +++ b/general.php @@ -1,15 +1,21 @@ getMessage(); } - return null; } function returnHeader() { diff --git a/login.php b/login.php new file mode 100644 index 0000000..26f2330 --- /dev/null +++ b/login.php @@ -0,0 +1,17 @@ + \ No newline at end of file diff --git a/overview.php b/overview.php index 2d64e87..dd0806d 100644 --- a/overview.php +++ b/overview.php @@ -1,19 +1,22 @@ prepare("SELECT * from entries WHERE verify = 1"); + +if(!$statement->execute()) { + echo "database Error"; } -$entries = json_decode($file, true); -if ($entries === null) { - die(); -} - -$config = getConfig(); +$entries = $statement->fetchAll(PDO::FETCH_ASSOC); ?> @@ -43,13 +46,14 @@ $config = getConfig(); foreach ($entries as $entry) { + $age = date_diff(date_create($entry['birthday']), date_create('now'))->y; ?> - + - + 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 "
";
+    print_r($errors->firstOfAll());
+    echo "
"; + 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) VALUES (:name, :email, :year, :birthday, :verify, :vocation)"); + +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(); @@ -32,15 +81,16 @@ $mail->Username = $config['mail_user']; $mail->Password = $config['mail_password']; $mail->From = $config['mail_address']; -$mail->FromName = 'Mailer'; +$mail->FromName = $config['mail_name']; try { - $mail->addAddress('test@joethei.de', 'Joe User'); + $mail->addAddress($validData['email'], $validData['name']); } catch (\PHPMailer\PHPMailer\Exception $e) { + echo $e->getMessage(); } -$mail->Subject = 'Here is the subject'; -$mail->AltBody = 'Message without html'; -$mail->Body = 'This is the HTML message body in bold!'; +$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 hier'; try { @@ -48,3 +98,11 @@ try { } catch (\PHPMailer\PHPMailer\Exception $e) { echo $e; } + +returnHeader(); +?> + +Vielen Dank, bitte bestätige deine E-Mail Adresse + +