second release
This commit is contained in:
7
errors.php
Normal file
7
errors.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php if (count($errors) > 0) : ?>
|
||||
<div class="error">
|
||||
<?php foreach ($errors as $error) : ?>
|
||||
<p><?php echo $error ?></p>
|
||||
<?php endforeach ?>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
93
index.php
Normal file
93
index.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
session_start();
|
||||
if (!isset($_SESSION['username'])) {
|
||||
$_SESSION['msg'] = "Bitte zuerst einloggen.";
|
||||
}
|
||||
if (isset($_GET['logout'])) {
|
||||
session_destroy();
|
||||
unset($_SESSION['username']);
|
||||
header("location: index.php");
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="de" dir="ltr">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<meta name="author" content="Victor Giers"/>
|
||||
<meta name="created" content="2019-01-10"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Direkter Tausch - Online Platform für das Repair Café</title>
|
||||
<link rel="stylesheet" type="text/css" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="header">
|
||||
<h2>Direkter Tausch - Online Platform für das Repair Café</h2>
|
||||
</div>
|
||||
<div class="content">
|
||||
<!-- notification message -->
|
||||
<?php if (isset($_SESSION['success'])) : ?>
|
||||
<div class="error success" >
|
||||
<h3>
|
||||
<?php
|
||||
echo $_SESSION['success'];
|
||||
unset($_SESSION['success']);
|
||||
?>
|
||||
</h3>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
|
||||
<!-- logged in user information -->
|
||||
<?php
|
||||
|
||||
|
||||
$db_server = '';
|
||||
$db_user = '';
|
||||
$db_password = '';
|
||||
$db_name = '';
|
||||
$user_table = '';
|
||||
$entry_table = '';
|
||||
$conn = new mysqli($db_server, $db_user, $db_password, $db_name);
|
||||
$conn->set_charset("utf8");
|
||||
if ($conn->connect_error) {
|
||||
die("Connection failed: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
if (isset($_SESSION['username'])){
|
||||
echo "<p>Sie sind eingeloggt als: <strong>" . $_SESSION['username'] . "</strong></p>
|
||||
<p> <a href='index.php?logout=1' style='color: red;''>Ausloggen</a><br><br></p>
|
||||
<p> <a href='newentry.php'>Neuer Eintrag</a><br><br></p>";
|
||||
|
||||
} else {
|
||||
echo "<p>Um Einträge zu verfassen, <strong><a href='register.php'>registrieren Sie sich</a></strong> oder <strong><a href='login.php'>loggen Sie sich ein</a></strong>.</p>
|
||||
<br><br>";
|
||||
}
|
||||
|
||||
|
||||
$entries = "SELECT $entry_table.*, $user_table.username, $user_table.email FROM $entry_table INNER JOIN $user_table ON $entry_table.user = $user_table.id ORDER BY $entry_table.id DESC";
|
||||
|
||||
$result = $conn->query($entries);
|
||||
if ($result->num_rows > 0) {
|
||||
echo "<table id='entries'>\n<tr>\n<th>Datum</th><th>Name</th><th>Bietet an</th><th>Möchte dafür</th><th>Kontakt</th>\n</tr>\n";
|
||||
|
||||
while($row = $result->fetch_assoc()) {
|
||||
echo "<tr>\n";
|
||||
echo "<td id='date'><div class='tablediv'>" . date("d.m.Y", strtotime($row["date"])) . "</div></td><td id='username'><div class='tablediv'>" . $row["username"] . "</div></td><td id='does'><div class='tablediv'>" . $row["does"] . "</div></td><td id='wants'><div class='tablediv'>" . $row["wants"] . "</div></td><td id='email'><div class='tablediv'><a href='mailto:" . $row["email"] . "'>" . $row["email"] . "</a></div>\n";
|
||||
echo "</tr>\n";
|
||||
}
|
||||
echo("</table>\n");
|
||||
} else {
|
||||
echo "Keine Einträge vorhanden.\n";
|
||||
}
|
||||
|
||||
|
||||
/*----*/
|
||||
|
||||
$conn->close();
|
||||
?>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
38
login.php
Normal file
38
login.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php include('server.php') ?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="de" dir="ltr">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<meta name="author" content="Victor Giers"/>
|
||||
<meta name="created" content="2019-01-10"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Login - Direkter Tausch - Online Platform für das Repair Café</title>
|
||||
<link rel="stylesheet" type="text/css" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="header" style="width:30%;">
|
||||
<h2>Einloggen - Direkter Tausch - Online Platform für das Repair Café</h2>
|
||||
</div>
|
||||
|
||||
<form method="post" action="login.php" style="width:30%;">
|
||||
<div id='errordiv'>
|
||||
<?php include('errors.php'); ?>
|
||||
</div>
|
||||
<div class="input-group">
|
||||
<label>Benutzername</label>
|
||||
<input type="text" name="username" >
|
||||
</div>
|
||||
<div class="input-group">
|
||||
<label>Passwort</label>
|
||||
<input type="password" name="password">
|
||||
</div>
|
||||
<div class="input-group">
|
||||
<button type="submit" class="btn" name="login_user">Einloggen</button>
|
||||
</div>
|
||||
<p>
|
||||
Sollten Sie noch kein Benutzerkonto haben, <a href="register.php">registrieren Sie sich hier</a>.
|
||||
</p>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
35
newentry.php
Normal file
35
newentry.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php include('server.php') ?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="de" dir="ltr">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<meta name="author" content="Victor Giers"/>
|
||||
<meta name="created" content="2019-01-10"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Neuer Eintrag - Direkter Tausch - Online Platform für das Repair Café</title>
|
||||
<link rel="stylesheet" type="text/css" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="header" style="width:30%;">
|
||||
<h2>Neuer Eintrag - Direkter Tausch</h2>
|
||||
</div>
|
||||
|
||||
<form method="post" action="newentry.php" style="width:30%;">
|
||||
<div id='errordiv'>
|
||||
<?php include('errors.php'); ?>
|
||||
</div>
|
||||
<div class="input-group">
|
||||
<label>Ich biete an...</label>
|
||||
<input type="text" name="does">
|
||||
</div>
|
||||
<div class="input-group">
|
||||
<label>Erwünschte Gegenleistung (optional)</label>
|
||||
<input type="text" name="wants">
|
||||
</div>
|
||||
<div class="input-group">
|
||||
<button type="submit" class="btn" name="make_entry">Eintrag hinzufügen</button>
|
||||
</div>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
43
register.php
Normal file
43
register.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php include('server.php') ?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="de" dir="ltr">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<meta name="author" content="Victor Giers"/>
|
||||
<meta name="created" content="2019-01-10"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Registrieren - Direkter Tausch - Online Platform für das Repair Café</title>
|
||||
<link rel="stylesheet" type="text/css" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="header" style="width:30%;">
|
||||
<h2>Registrieren - Direkter Tausch - Online Platform für das Repair Café</h2>
|
||||
</div>
|
||||
|
||||
<form method="post" action="register.php" style="width:30%;">
|
||||
<div id='errordiv'>
|
||||
<?php include('errors.php'); ?>
|
||||
</div>
|
||||
<div class="input-group">
|
||||
<label>Name</label>
|
||||
<input type="text" name="username" value="<?php echo $username; ?>">
|
||||
</div>
|
||||
<div class="input-group">
|
||||
<label>Email-Adresse</label>
|
||||
<input type="email" name="email" value="<?php echo $email; ?>">
|
||||
</div>
|
||||
<div class="input-group">
|
||||
<label>Passwort</label>
|
||||
<input type="password" name="password_1">
|
||||
</div>
|
||||
<div class="input-group">
|
||||
<label>Passwort wiederholen</label>
|
||||
<input type="password" name="password_2">
|
||||
</div>
|
||||
<div class="input-group">
|
||||
<button type="submit" class="btn" name="reg_user">Registrieren</button>
|
||||
</div>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
114
server.php
Normal file
114
server.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
// initializing variables
|
||||
$username = "";
|
||||
$email = "";
|
||||
$errors = array();
|
||||
|
||||
// connect to the database
|
||||
$db = mysqli_connect('', '', '', '');
|
||||
mysqli_set_charset($db, "utf8");
|
||||
|
||||
// REGISTER USER
|
||||
if (isset($_POST['reg_user'])) {
|
||||
// receive all input values from the form
|
||||
$username = mysqli_real_escape_string($db, $_POST['username']);
|
||||
$email = mysqli_real_escape_string($db, $_POST['email']);
|
||||
$password_1 = mysqli_real_escape_string($db, $_POST['password_1']);
|
||||
$password_2 = mysqli_real_escape_string($db, $_POST['password_2']);
|
||||
|
||||
// form validation: ensure that the form is correctly filled ...
|
||||
// by adding (array_push()) corresponding error unto $errors array
|
||||
if (empty($username)) { array_push($errors, "Benutzername wird benötigt"); }
|
||||
if (empty($email)) { array_push($errors, "email-Adresse wird benötigt"); }
|
||||
if (empty($password_1)) { array_push($errors, "Passwort wird benötigt"); }
|
||||
if ($password_1 != $password_2) {
|
||||
array_push($errors, "Die Passwörter stimmen nicht überein");
|
||||
}
|
||||
|
||||
// first check the database to make sure
|
||||
// a user does not already exist with the same username and/or email
|
||||
$user_check_query = "SELECT * FROM repair_users WHERE username='$username' OR email='$email' LIMIT 1";
|
||||
$result = mysqli_query($db, $user_check_query);
|
||||
$user = mysqli_fetch_assoc($result);
|
||||
|
||||
if ($user) { // if user exists
|
||||
if ($user['username'] === $username) {
|
||||
array_push($errors, "Benutzername ist bereits vorhanden");
|
||||
}
|
||||
|
||||
if ($user['email'] === $email) {
|
||||
array_push($errors, "eMail-Adresse ist bereits vorhanden.");
|
||||
}
|
||||
}
|
||||
|
||||
// Finally, register user if there are no errors in the form
|
||||
if (count($errors) == 0) {
|
||||
$password = md5($password_1);//encrypt the password before saving in the database
|
||||
|
||||
$query = "INSERT INTO repair_users (username, email, password)
|
||||
VALUES('$username', '$email', '$password')";
|
||||
mysqli_query($db, $query);
|
||||
$_SESSION['username'] = $username;
|
||||
$_SESSION['success'] = "Sie sind nun eingeloggt.";
|
||||
header('location: index.php');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// LOGIN USER
|
||||
if (isset($_POST['login_user'])) {
|
||||
$username = mysqli_real_escape_string($db, $_POST['username']);
|
||||
$password = mysqli_real_escape_string($db, $_POST['password']);
|
||||
|
||||
if (empty($username)) {
|
||||
array_push($errors, "Benutzername wird benötigt");
|
||||
}
|
||||
if (empty($password)) {
|
||||
array_push($errors, "Passwort wird benötigt");
|
||||
}
|
||||
|
||||
if (count($errors) == 0) {
|
||||
$password = md5($password);
|
||||
$query = "SELECT * FROM repair_users WHERE username='$username' AND password='$password'";
|
||||
$results = mysqli_query($db, $query);
|
||||
if (mysqli_num_rows($results) == 1) {
|
||||
$_SESSION['username'] = $username;
|
||||
$_SESSION['success'] = "Sie sind nun eingeloggt.";
|
||||
header('location: index.php');
|
||||
}else {
|
||||
array_push($errors, "Falsche Kombination aus Benutzername und Passwort");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MAKE ENTRY
|
||||
|
||||
if (isset($_POST['make_entry'])) {
|
||||
$does = mysqli_real_escape_string($db, $_POST['does']);
|
||||
$wants = mysqli_real_escape_string($db, $_POST['wants']);
|
||||
if (empty($does)) { array_push($errors, "Angebot wird benötigt"); }
|
||||
if (!isset($_SESSION['username'])){ array_push($errors, "Nicht eingeloggt"); }
|
||||
if (count($errors) == 0) {
|
||||
$username = $_SESSION['username'];
|
||||
$user_check_query = "SELECT * FROM repair_users WHERE username='$username' LIMIT 1";
|
||||
$result = mysqli_query($db, $user_check_query);
|
||||
$user = mysqli_fetch_assoc($result);
|
||||
$userID = $user['id'];
|
||||
$thisdate = date('Y-m-d H:i:s');
|
||||
$query = "INSERT INTO repair_entries (user, date, does, wants)
|
||||
VALUES('$userID', '$thisdate', '$does', '$wants')";
|
||||
mysqli_query($db, $query);
|
||||
$_SESSION['success'] = "Eintrag wurde erstellt.";
|
||||
header('location: index.php');
|
||||
}
|
||||
}
|
||||
|
||||
// GET ENTRIES
|
||||
|
||||
|
||||
?>
|
||||
92
style.css
Normal file
92
style.css
Normal file
@@ -0,0 +1,92 @@
|
||||
* {
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
}
|
||||
body {
|
||||
font-family: sans-serif;
|
||||
font-size: 100%;
|
||||
background: #F8F8FF;
|
||||
}
|
||||
|
||||
.header {
|
||||
margin: 50px auto 0px;
|
||||
color: white;
|
||||
background: #5F9EA0;
|
||||
text-align: center;
|
||||
border: 1px solid #B0C4DE;
|
||||
border-bottom: none;
|
||||
border-radius: 10px 10px 0px 0px;
|
||||
padding: 20px;
|
||||
}
|
||||
form, .content {
|
||||
margin: 0px auto;
|
||||
padding: 20px;
|
||||
border: 1px solid #B0C4DE;
|
||||
background: white;
|
||||
border-radius: 0px 0px 10px 10px;
|
||||
}
|
||||
table {
|
||||
margin: 0px auto;
|
||||
border: 1px solid black;
|
||||
/*width: 40%;*/
|
||||
}
|
||||
td {
|
||||
border: 1px solid black;
|
||||
padding: 10px;
|
||||
}
|
||||
.tablediv{
|
||||
max-height:4em;
|
||||
overflow: auto;
|
||||
}
|
||||
#username {
|
||||
white-space: nowrap;
|
||||
max-width: 10em;
|
||||
}
|
||||
#email {
|
||||
|
||||
|
||||
}
|
||||
.input-group {
|
||||
margin: 10px 0px 10px 0px;
|
||||
}
|
||||
.input-group label {
|
||||
display: block;
|
||||
text-align: left;
|
||||
margin: 3px;
|
||||
}
|
||||
.input-group input {
|
||||
height: 30px;
|
||||
width: 93%;
|
||||
padding: 5px 10px;
|
||||
font-size: 16px;
|
||||
border-radius: 5px;
|
||||
border: 1px solid gray;
|
||||
}
|
||||
.btn {
|
||||
padding: 10px;
|
||||
font-size: 15px;
|
||||
color: white;
|
||||
background: #5F9EA0;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
}
|
||||
#errordiv{
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
}
|
||||
.error {
|
||||
display: inline-block;
|
||||
margin: 0px auto;
|
||||
padding: 10px;
|
||||
border: 1px solid #a94442;
|
||||
color: #a94442;
|
||||
background: #f2dede;
|
||||
border-radius: 5px;
|
||||
text-align: left;
|
||||
}
|
||||
.success {
|
||||
color: #3c763d;
|
||||
background: #dff0d8;
|
||||
border: 1px solid #3c763d;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
Reference in New Issue
Block a user