Change password feature (maybe)
This commit is contained in:
@@ -86,6 +86,7 @@ curl -fsSL https://get.docker.com | bash
|
|||||||
```bash
|
```bash
|
||||||
git clone https://git.vichingo455.freeddns.org/emmev-code/orario
|
git clone https://git.vichingo455.freeddns.org/emmev-code/orario
|
||||||
cd orario
|
cd orario
|
||||||
|
git checkout dev # richiesto per passare alla versione di sviluppo
|
||||||
docker compose up -d
|
docker compose up -d
|
||||||
```
|
```
|
||||||
3. Il container dovrebbe diventare disponibile su ``http://localhost:8080``
|
3. Il container dovrebbe diventare disponibile su ``http://localhost:8080``
|
||||||
|
@@ -1,5 +1,3 @@
|
|||||||
version: "3.8"
|
|
||||||
|
|
||||||
services:
|
services:
|
||||||
web:
|
web:
|
||||||
build: .
|
build: .
|
||||||
@@ -9,7 +7,6 @@ services:
|
|||||||
depends_on:
|
depends_on:
|
||||||
- db
|
- db
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|
||||||
db:
|
db:
|
||||||
image: mariadb:11
|
image: mariadb:11
|
||||||
container_name: orario-db
|
container_name: orario-db
|
||||||
@@ -22,6 +19,5 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- db_data:/var/lib/mysql
|
- db_data:/var/lib/mysql
|
||||||
- ./schema.sql:/docker-entrypoint-initdb.d/init.sql:ro
|
- ./schema.sql:/docker-entrypoint-initdb.d/init.sql:ro
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
db_data:
|
db_data:
|
81
htdocs/admin/changepassword.php
Normal file
81
htdocs/admin/changepassword.php
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
include("../db.php");
|
||||||
|
|
||||||
|
if (!isset($_SESSION['admin']) || $_SESSION['auth_type'] != 'local') {
|
||||||
|
header("Location: login.php");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$message = '';
|
||||||
|
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||||
|
$old = $_POST['old_password'];
|
||||||
|
$new = $_POST['new_password'];
|
||||||
|
$confirm = $_POST['confirm_password'];
|
||||||
|
$user = $_SESSION['admin'];
|
||||||
|
|
||||||
|
if ($new !== $confirm) {
|
||||||
|
$message = "Le nuove password non coincidono.";
|
||||||
|
} else {
|
||||||
|
// Recupera hash password attuale
|
||||||
|
$stmt = $conn->prepare("SELECT password FROM admins WHERE username = ?");
|
||||||
|
$stmt->bind_param("s", $user);
|
||||||
|
$stmt->execute();
|
||||||
|
$res = $stmt->get_result();
|
||||||
|
$row = $res->fetch_assoc();
|
||||||
|
|
||||||
|
if ($row && password_verify($old, $row['password'])) {
|
||||||
|
$newHash = password_hash($new, PASSWORD_DEFAULT);
|
||||||
|
$stmt = $conn->prepare("UPDATE admins SET password = ? WHERE username = ?");
|
||||||
|
$stmt->bind_param("ss", $newHash, $user);
|
||||||
|
$stmt->execute();
|
||||||
|
$message = "Password cambiata con successo.";
|
||||||
|
} else {
|
||||||
|
$message = "Password attuale errata.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Cambia Password</title>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<link rel="stylesheet" href="style.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="navbar">
|
||||||
|
<div class="logo">Admin Dashboard</div>
|
||||||
|
<div class="links">
|
||||||
|
<a href="index.php">Dashboard</a>
|
||||||
|
<a href="logout.php">Logout</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="admin-container">
|
||||||
|
<h1>Cambia Password</h1>
|
||||||
|
<?php if ($message): ?>
|
||||||
|
<p style="color:<?php echo strpos($message,'successo')!==false ? 'green':'red'; ?>;"><?php echo $message; ?></p>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<form method="POST">
|
||||||
|
<label>Password attuale:<br>
|
||||||
|
<input type="password" name="old_password" required>
|
||||||
|
</label><br><br>
|
||||||
|
|
||||||
|
<label>Nuova password:<br>
|
||||||
|
<input type="password" name="new_password" required>
|
||||||
|
</label><br><br>
|
||||||
|
|
||||||
|
<label>Conferma nuova password:<br>
|
||||||
|
<input type="password" name="confirm_password" required>
|
||||||
|
</label><br><br>
|
||||||
|
|
||||||
|
<button type="submit">Cambia password</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
@@ -29,6 +29,11 @@ if (!isset($_SESSION['admin'])) {
|
|||||||
<a href="classes.php">Gestisci Classi</a>
|
<a href="classes.php">Gestisci Classi</a>
|
||||||
<a href="subjects.php">Gestisci Materie</a>
|
<a href="subjects.php">Gestisci Materie</a>
|
||||||
<a href="timetable.php">Gestisci Orario</a>
|
<a href="timetable.php">Gestisci Orario</a>
|
||||||
|
<?php
|
||||||
|
if ($_SESSION['auth_type'] === 'local') {
|
||||||
|
echo '<a href="changepassword.php">Cambia Password</a>';
|
||||||
|
}
|
||||||
|
?>
|
||||||
<!--<a href="logout.php">Logout</a>-->
|
<!--<a href="logout.php">Logout</a>-->
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
|
@@ -12,6 +12,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|||||||
if ($row = $res->fetch_assoc()) {
|
if ($row = $res->fetch_assoc()) {
|
||||||
if (password_verify($password, $row['password'])) {
|
if (password_verify($password, $row['password'])) {
|
||||||
$_SESSION['admin'] = $row['username'];
|
$_SESSION['admin'] = $row['username'];
|
||||||
|
$_SESSION['auth_type'] = 'local';
|
||||||
header("Location: index.php");
|
header("Location: index.php");
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
@@ -14,5 +14,6 @@ $oidc->setRedirectURL('https://<APP_DOMAIN>/admin/login.php');
|
|||||||
$oidc->authenticate();
|
$oidc->authenticate();
|
||||||
$userinfo = $oidc->getVerifiedClaims();
|
$userinfo = $oidc->getVerifiedClaims();
|
||||||
$_SESSION['admin'] = $userinfo->preferred_username;
|
$_SESSION['admin'] = $userinfo->preferred_username;
|
||||||
|
$_SESSION['auth_type'] = 'keycloak';
|
||||||
header("Location: index.php");
|
header("Location: index.php");
|
||||||
exit;
|
exit;
|
||||||
|
Reference in New Issue
Block a user