Forgot-Password hinzugefügt
This commit is contained in:
parent
872efe66ea
commit
3afced16db
@ -64,6 +64,18 @@ function getAll($columnname,$tablename,$conditionvalue = "")
|
||||
return $result;
|
||||
}
|
||||
|
||||
function saveResetToken($userId, $token, $expiry) {
|
||||
global $conn;
|
||||
$userId = validate($userId);
|
||||
$token = validate($token);
|
||||
$expiry = validate($expiry);
|
||||
|
||||
$query = "UPDATE users SET reset_token='$token', reset_token_expiry='$expiry' WHERE userid='$userId'";
|
||||
$result = mysqli_query($conn, $query);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function getById($tableName, $id)
|
||||
{
|
||||
global $conn;
|
||||
@ -918,6 +930,27 @@ function getStudentAssignments($studentID)
|
||||
}
|
||||
}
|
||||
|
||||
function updatePassword($userId, $newPassword) {
|
||||
global $conn;
|
||||
$userId = validate($userId);
|
||||
$newPassword = validate($newPassword);
|
||||
|
||||
$query = "UPDATE users SET password='$newPassword' WHERE id='$userId'";
|
||||
$result = mysqli_query($conn, $query);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function deleteResetToken($userId) {
|
||||
global $conn;
|
||||
$userId = validate($userId);
|
||||
|
||||
$query = "UPDATE users SET reset_token=NULL, reset_token_expiry=NULL WHERE id='$userId'";
|
||||
$result = mysqli_query($conn, $query);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function isStudentRegisteredForCourse($studentId, $courseId) {
|
||||
// Hier eine Abfrage zur Datenbank machen, um zu prüfen, ob ein Eintrag in tbl_assign_students_courses existiert
|
||||
global $conn; // Annahme, dass $conn die Datenbankverbindung ist
|
||||
|
75
forgot_password.php
Normal file
75
forgot_password.php
Normal file
@ -0,0 +1,75 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Scolify - Schule Lachenzelg</title>
|
||||
<link rel="shortcut icon" type="image/png" href="assets/images/logos/favicon.png" />
|
||||
<link rel="stylesheet" href="assets/css/styles.min.css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<!-- Body Wrapper -->
|
||||
<div class="page-wrapper" id="main-wrapper" data-layout="vertical" data-navbarbg="skin6" data-sidebartype="full"
|
||||
data-sidebar-position="fixed" data-header-position="fixed">
|
||||
<div
|
||||
class="position-relative overflow-hidden radial-gradient min-vh-100 d-flex align-items-center justify-content-center">
|
||||
<div class="d-flex align-items-center justify-content-center w-100">
|
||||
<div class="row justify-content-center w-100">
|
||||
<div class="col-md-8 col-lg-6 col-xxl-3">
|
||||
<div class="card mb-0">
|
||||
<div class="card-body">
|
||||
<a href="./index.php" class="text-nowrap logo-img text-center d-block py-3 w-100">
|
||||
<img src="assets/images/logos/login.png" width="180" alt="">
|
||||
</a>
|
||||
|
||||
<form action="forgot_password.php" method="POST">
|
||||
<label for="user_id">Benutzer-ID:</label>
|
||||
<input type="text" name="user_id" required>
|
||||
<button class="btn btn-primary py-8 fs-4 w-100 mb-2 mt-3 rounded-2" type="btn submit">Passwort zurücksetzen</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="assets/libs/jquery/dist/jquery.min.js"></script>
|
||||
<script src="assets/libs/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
|
||||
|
||||
|
||||
<?php
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
$userId = $_POST['user_id'];
|
||||
|
||||
// Hole den Benutzer anhand der User-ID
|
||||
$userResponse = getById('tbl_students', $userId);
|
||||
|
||||
if ($userResponse['status'] == 200) {
|
||||
$user = $userResponse['data'];
|
||||
|
||||
// Überprüfe, ob eine E-Mail-Adresse für den Benutzer vorhanden ist
|
||||
if (!empty($user['emailstudent'])) {
|
||||
// Generiere ein Token für das Zurücksetzen des Passworts
|
||||
$token = bin2hex(random_bytes(50));
|
||||
$expiry = date('Y-m-d H:i:s', strtotime('+1 hour'));
|
||||
|
||||
// Speichere das Token und das Ablaufdatum in der Datenbank
|
||||
saveResetToken($user['id'], $token, $expiry);
|
||||
|
||||
// Sende die E-Mail mit dem Token-Link
|
||||
$resetLink = "http://localhost/reset_password.php?token=$token";
|
||||
mail($user['emailstudent'], "Passwort zurücksetzen", "Klicke auf diesen Link, um dein Passwort zurückzusetzen: $resetLink");
|
||||
|
||||
echo "Überprüfe deine E-Mails, um dein Passwort zurückzusetzen.";
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
@ -49,7 +49,7 @@
|
||||
Beispiel: </b> 06.04.2002
|
||||
</div>
|
||||
<div class="d-flex align-items-center justify-content-between mb-4">
|
||||
<a class="text-primary fw-bold" href="./forgot-password.php">Kennwort vergessen?</a>
|
||||
<a class="text-primary fw-bold" href="./forgot_password.php">Kennwort vergessen?</a>
|
||||
</div>
|
||||
<button type="submit" name="login" class="btn btn-primary w-100 py-8 fs-4 mb-4 rounded-2">Anmelden</button>
|
||||
</form>
|
||||
|
30
reset_password.php
Normal file
30
reset_password.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
if (isset($_GET['token'])) {
|
||||
$token = $_GET['token'];
|
||||
|
||||
// Hole den Benutzer, der das Token hat und prüfe, ob das Token gültig ist
|
||||
$userResponse = getById('users', $token);
|
||||
|
||||
if ($userResponse['status'] == 200) {
|
||||
$user = $userResponse['data'];
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
$newPassword = password_hash($_POST['password'], PASSWORD_DEFAULT);
|
||||
|
||||
// Setze das neue Passwort und lösche das Token
|
||||
updatePassword($user['id'], $newPassword);
|
||||
deleteResetToken($user['id']);
|
||||
|
||||
echo "Dein Passwort wurde erfolgreich zurückgesetzt.";
|
||||
}
|
||||
} else {
|
||||
echo "Das Token ist ungültig oder abgelaufen.";
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<form action="reset_password.php?token=<?php echo $token; ?>" method="POST">
|
||||
<label for="password">Neues Passwort:</label>
|
||||
<input type="password" name="password" required>
|
||||
<button type="submit">Passwort zurücksetzen</button>
|
||||
</form>
|
Loading…
Reference in New Issue
Block a user