funktionierende Seite, bereit fürs Testing

This commit is contained in:
Johannes Theiner 2021-05-04 09:44:45 +02:00
parent 08d5f3c68f
commit 9dfe5d8a5e
8 changed files with 176 additions and 1026 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,9 @@
{ {
"require": { "require": {
"phpmailer/phpmailer": "^6.4", "phpmailer/phpmailer": "^6.4.1",
"rakit/validation": "v1.4.0", "rakit/validation": "v1.4.0",
"ext-pdo": "*" "ext-pdo": "*"
} },
"name": "digihelfer/alumni",
"description": ""
} }

86
composer.lock generated
View File

@ -4,20 +4,84 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "59230ec995edc426fe883cde9a32b541", "content-hash": "727d168ee56a61f6a6c16e13977daac8",
"packages": [ "packages": [
{ {
"name": "phpmailer/phpmailer", "name": "parsecsv/php-parsecsv",
"version": "v6.4.0", "version": "1.3.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/PHPMailer/PHPMailer.git", "url": "https://github.com/parsecsv/parsecsv-for-php.git",
"reference": "050d430203105c27c30efd1dce7aa421ad882d01" "reference": "b444afae2f407537ae713f98a7a0c94e296918e6"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/050d430203105c27c30efd1dce7aa421ad882d01", "url": "https://api.github.com/repos/parsecsv/parsecsv-for-php/zipball/b444afae2f407537ae713f98a7a0c94e296918e6",
"reference": "050d430203105c27c30efd1dce7aa421ad882d01", "reference": "b444afae2f407537ae713f98a7a0c94e296918e6",
"shasum": ""
},
"require": {
"php": ">=5.5"
},
"require-dev": {
"phpunit/phpunit": "^6",
"squizlabs/php_codesniffer": "^3.5"
},
"suggest": {
"illuminate/support": "Fluent array interface for map functions"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"ParseCsv\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jim Myhrberg",
"email": "contact@jimeh.me"
},
{
"name": "William Knauss",
"email": "will.knauss@gmail.com"
},
{
"name": "Susann Sgorzaly",
"homepage": "https://github.com/susgo"
},
{
"name": "Christian Bläul",
"homepage": "https://github.com/Fonata"
}
],
"description": "CSV data parser for PHP",
"support": {
"issues": "https://github.com/parsecsv/parsecsv-for-php/issues",
"source": "https://github.com/parsecsv/parsecsv-for-php"
},
"time": "2021-04-14T18:14:01+00:00"
},
{
"name": "phpmailer/phpmailer",
"version": "v6.4.1",
"source": {
"type": "git",
"url": "https://github.com/PHPMailer/PHPMailer.git",
"reference": "9256f12d8fb0cd0500f93b19e18c356906cbed3d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/9256f12d8fb0cd0500f93b19e18c356906cbed3d",
"reference": "9256f12d8fb0cd0500f93b19e18c356906cbed3d",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -72,7 +136,7 @@
"description": "PHPMailer is a full-featured email creation and transfer class for PHP", "description": "PHPMailer is a full-featured email creation and transfer class for PHP",
"support": { "support": {
"issues": "https://github.com/PHPMailer/PHPMailer/issues", "issues": "https://github.com/PHPMailer/PHPMailer/issues",
"source": "https://github.com/PHPMailer/PHPMailer/tree/v6.4.0" "source": "https://github.com/PHPMailer/PHPMailer/tree/v6.4.1"
}, },
"funding": [ "funding": [
{ {
@ -80,7 +144,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2021-03-31T20:06:42+00:00" "time": "2021-04-29T12:25:04+00:00"
}, },
{ {
"name": "rakit/validation", "name": "rakit/validation",
@ -135,7 +199,9 @@
"stability-flags": [], "stability-flags": [],
"prefer-stable": false, "prefer-stable": false,
"prefer-lowest": false, "prefer-lowest": false,
"platform": [], "platform": {
"ext-pdo": "*"
},
"platform-dev": [], "platform-dev": [],
"plugin-api-version": "2.0.0" "plugin-api-version": "2.0.0"
} }

View File

@ -1,5 +1,5 @@
create table entries(id bigint auto_increment primary key, name varchar(255), mail varchar(255) unique, create table entries(id bigint auto_increment primary key, name varchar(255), mail varchar(255),
year int(4), birthday date, verify bool, vocation varchar(255) year int(4), birthday date, verify bool, vocation varchar(255), creation DATE
); );
create table verify(id bigint primary key, uuid VARCHAR(36),foreign key verify(id) REFERENCES entries(id)); create table verify(id bigint primary key, uuid VARCHAR(36),foreign key verify(id) REFERENCES entries(id));

View File

@ -1,23 +1,25 @@
<?php <?php
require_once 'general.php'; require_once 'general.php';
returnHeader();
session_start(); session_start();
$config = getConfig(); $config = getConfig();
if (isset($_POST['user']) && !empty($_POST['user']) if (isset($_POST['user']) && !empty($_POST['user']) && !empty($_POST['password'])) {
&& !empty($_POST['password'])) {
if ($_POST['user'] == $config['user'] && $_POST['password'] == $config['password']) { if ($_POST['user'] == $config['user'] && $_POST['password'] == $config['password']) {
$_SESSION['user'] = "Hello World"; $_SESSION['user'] = "Hello World";
?>
Solltest du nicht weitergeleitet werden, klicke
<a href="overview.php">hier</a>
<?php
header('Location: ' . $config['url'] . '/overview.php'); header('Location: ' . $config['url'] . '/overview.php');
die();//https://thedailywtf.com/articles/WellIntentioned-Destruction die();//https://thedailywtf.com/articles/WellIntentioned-Destruction
} }
else { else {
echo "passwort nicht akzeptiert"; echo "Passwort nicht akzeptiert";
} }
} }
returnHeader();
?> ?>
<div class="container"> <div class="container">

View File

@ -1,5 +1,8 @@
<?php <?php
require_once 'general.php'; require_once 'general.php';
require_once 'vendor/autoload.php';
session_start(); session_start();
if(!isset($_SESSION['user'])) { if(!isset($_SESSION['user'])) {
@ -8,8 +11,6 @@ if(!isset($_SESSION['user'])) {
exit; exit;
} }
returnHeader();
$statement = getDatabase()->prepare("SELECT * from entries WHERE verify = 1"); $statement = getDatabase()->prepare("SELECT * from entries WHERE verify = 1");
if(!$statement->execute()) { if(!$statement->execute()) {
@ -18,6 +19,39 @@ if(!$statement->execute()) {
$entries = $statement->fetchAll(PDO::FETCH_ASSOC); $entries = $statement->fetchAll(PDO::FETCH_ASSOC);
if($_GET['export'] != null) {
if($statement->rowCount() > 0){
$delimiter = ";";
$filename = "ehemalige_" . date('Y-m-d') . ".csv";
//create a file pointer
$f = fopen('php://memory', 'w');
//set column headers
$fields = array("ID", "Name", "E-Mail", "Abschlussjahrgang", "Geburtstag", "Email validiert", "Tätigkeit", "Eintragungsdatum");
fputcsv($f, $fields, $delimiter);
//output each row of the data, format line as csv and write to file pointer
foreach ($entries as $entry) {
$lineData = array($entry['id'], $entry['name'], $entry['mail'], $entry['year'], $entry['birthday'], $entry['verify'], $entry['vocation'], $entry['creation']);
fputcsv($f, $lineData, $delimiter);
}
//move back to beginning of file
fseek($f, 0);
//set headers to download file rather than displayed
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="' . $filename . '";');
//output all remaining data on a file pointer
fpassthru($f);
}
exit;
}
returnHeader();
?> ?>
<div class="flex flex-col"> <div class="flex flex-col">
@ -26,7 +60,7 @@ $entries = $statement->fetchAll(PDO::FETCH_ASSOC);
<div class="shadow overflow-hidden border-b border-gray-200 sm:rounded-lg relative space-y-32"> <div class="shadow overflow-hidden border-b border-gray-200 sm:rounded-lg relative space-y-32">
<div class="md:mt-6 top-0 right-0 absolute"> <div class="md:mt-6 top-0 right-0 absolute">
<button class="bg-blue-500 px-2 py-2 text-lg font-semibold tracking-wider text-white rounded hover:bg-blue-600">als CSV exportieren</button> <a href="overview.php?export=true" class="bg-blue-500 px-2 py-2 text-lg font-semibold tracking-wider text-white rounded hover:bg-blue-600">als CSV exportieren</a>
<a href="logout.php" class="bg-blue-500 px-4 py-2 text-lg font-semibold tracking-wider text-white rounded hover:bg-blue-600">ausloggen</a> <a href="logout.php" class="bg-blue-500 px-4 py-2 text-lg font-semibold tracking-wider text-white rounded hover:bg-blue-600">ausloggen</a>
</div> </div>
@ -38,6 +72,7 @@ $entries = $statement->fetchAll(PDO::FETCH_ASSOC);
<th>E-Mail Adresse</th> <th>E-Mail Adresse</th>
<th>Jahrgang</th> <th>Jahrgang</th>
<th>Alter</th> <th>Alter</th>
<th>Eintragung</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -47,6 +82,7 @@ $entries = $statement->fetchAll(PDO::FETCH_ASSOC);
foreach ($entries as $entry) { foreach ($entries as $entry) {
$age = date_diff(date_create($entry['birthday']), date_create('now'))->y; $age = date_diff(date_create($entry['birthday']), date_create('now'))->y;
$creationDate = date_create($entry["creation"]);
?> ?>
<tr> <tr>
<td><?php echo $entry["name"] ?></td> <td><?php echo $entry["name"] ?></td>
@ -54,6 +90,7 @@ $entries = $statement->fetchAll(PDO::FETCH_ASSOC);
<td><?php echo $entry["mail"] ?></td> <td><?php echo $entry["mail"] ?></td>
<td><?php echo $entry["year"] ?></td> <td><?php echo $entry["year"] ?></td>
<td><?php echo $age ?></td> <td><?php echo $age ?></td>
<td><?php echo date_format($creationDate, "d.m.Y") ?></td>
</tr> </tr>
<?php <?php
} }

View File

@ -1,9 +1,8 @@
<?php <?php
/**
if ($_SERVER['REQUEST_METHOD'] != "POST") { if ($_SERVER['REQUEST_METHOD'] != "POST") {
die(); die();
} }
* */
require_once 'general.php'; require_once 'general.php';
require_once 'vendor/autoload.php'; require_once 'vendor/autoload.php';
@ -48,7 +47,7 @@ $validData['verify'] = 0;
unset($validData['privacy']); unset($validData['privacy']);
$db = getDatabase(); $db = getDatabase();
$statement = $db->prepare("INSERT INTO entries(name, mail, year, birthday, verify, vocation) VALUES (:name, :email, :year, :birthday, :verify, :vocation)"); $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)) { if(!$statement->execute($validData)) {
echo "Datenbank Fehler"; echo "Datenbank Fehler";
@ -75,6 +74,7 @@ $mail = new PHPMailer(true);
$mail->isSMTP(); $mail->isSMTP();
$mail->SMTPAuth = true; $mail->SMTPAuth = true;
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Host = $config['mail_server']; $mail->Host = $config['mail_server'];
$mail->Port = $config['mail_port']; $mail->Port = $config['mail_port'];
$mail->Username = $config['mail_user']; $mail->Username = $config['mail_user'];

43
verify.php Normal file
View File

@ -0,0 +1,43 @@
<?php
require_once 'general.php';
if ($_SERVER['REQUEST_METHOD'] != "GET") {
die();
}
$uuid = $_GET['id'];
if($uuid == null) {
die();
}
$db = getDatabase();
$statement = $db->prepare("SELECT id from verify WHERE uuid = :uuid");
if(!$statement->execute(['uuid' => $uuid])) {
echo "Database Error";
die();
}
if($statement->rowCount() != 1) {
echo "Kein Eintrag mit dieser ID gefunden";
die();
}
$id = $statement->fetch(PDO::FETCH_ASSOC)['id'];
if($id == null) {
die();
}
$statement = $db->prepare("UPDATE entries SET verify = 1 WHERE id = :id");
if(!$statement->execute(['id' => $id])) {
echo "Database Error";
die();
}
$statement = $db->prepare("DELETE FROM verify WHERE id = :id");
if(!$statement->execute(['id' => $id])) {
echo "Database Error";
die();
}
echo "Danke für die Bestätigung";