mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 16:19:19 +02:00
feat: prevent duplicate TFE submissions with logging and user feedback
- Add DuplicateThesisException (typed, carries existing thesis metadata) - Add Database::findDuplicateThesis(): matches on year + author + normalised title (exact, prefix, Levenshtein ≤10% of longer string) - ThesisCreateController::submit() runs duplicate check before any DB write and throws DuplicateThesisException on match - AppLogger::logDuplicate() writes status=duplicate entries to the JSON-lines log for audit purposes - App::flash/consumeFlash extended to support 'warning' flash type - admin/actions/formulaire.php: catches DuplicateThesisException, logs it, flashes an HTML warning toast with a clickable link to the existing thesis, and repopulates the form fields - partage/index.php: same catch block; surfaces a plain-text flash-warning banner on the student form with identifier, title, and year of the match; form is repopulated via session - toast.php: renders toast--warning variant - admin.css: .toast--warning + link colour rules - form.css: .flash-warning style for the partage form
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* ShareLink — model for student-access share links.
|
||||
*
|
||||
@@ -58,8 +59,8 @@ class ShareLink
|
||||
: null;
|
||||
|
||||
$stmt = $this->db->getConnection()->prepare(
|
||||
"INSERT INTO share_links (slug, objet_restriction, password_hash, is_active, created_by, expires_at)
|
||||
VALUES (?, ?, ?, 1, ?, ?)"
|
||||
'INSERT INTO share_links (slug, objet_restriction, password_hash, is_active, created_by, expires_at)
|
||||
VALUES (?, ?, ?, 1, ?, ?)'
|
||||
);
|
||||
$stmt->execute([$slug, $objetRestriction, $passwordHash, $createdBy, $expiresAt]);
|
||||
|
||||
@@ -74,7 +75,7 @@ class ShareLink
|
||||
public function findBySlug(string $slug): ?array
|
||||
{
|
||||
$stmt = $this->db->getConnection()->prepare(
|
||||
"SELECT * FROM share_links WHERE slug = ?"
|
||||
'SELECT * FROM share_links WHERE slug = ?'
|
||||
);
|
||||
$stmt->execute([$slug]);
|
||||
$row = $stmt->fetch();
|
||||
@@ -89,7 +90,7 @@ class ShareLink
|
||||
public function findById(int $id): ?array
|
||||
{
|
||||
$stmt = $this->db->getConnection()->prepare(
|
||||
"SELECT * FROM share_links WHERE id = ?"
|
||||
'SELECT * FROM share_links WHERE id = ?'
|
||||
);
|
||||
$stmt->execute([$id]);
|
||||
$row = $stmt->fetch();
|
||||
@@ -104,7 +105,7 @@ class ShareLink
|
||||
public function listAll(): array
|
||||
{
|
||||
$stmt = $this->db->getConnection()->query(
|
||||
"SELECT * FROM share_links ORDER BY created_at DESC"
|
||||
'SELECT * FROM share_links ORDER BY created_at DESC'
|
||||
);
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
@@ -115,7 +116,7 @@ class ShareLink
|
||||
public function toggleActive(int $id): void
|
||||
{
|
||||
$this->db->getConnection()->prepare(
|
||||
"UPDATE share_links SET is_active = NOT is_active WHERE id = ?"
|
||||
'UPDATE share_links SET is_active = NOT is_active WHERE id = ?'
|
||||
)->execute([$id]);
|
||||
}
|
||||
|
||||
@@ -128,7 +129,7 @@ class ShareLink
|
||||
{
|
||||
$hash = $password !== null ? password_hash($password, PASSWORD_BCRYPT) : null;
|
||||
$this->db->getConnection()->prepare(
|
||||
"UPDATE share_links SET password_hash = ? WHERE id = ?"
|
||||
'UPDATE share_links SET password_hash = ? WHERE id = ?'
|
||||
)->execute([$hash, $id]);
|
||||
}
|
||||
|
||||
@@ -138,7 +139,7 @@ class ShareLink
|
||||
public function delete(int $id): void
|
||||
{
|
||||
$this->db->getConnection()->prepare(
|
||||
"DELETE FROM share_links WHERE id = ?"
|
||||
'DELETE FROM share_links WHERE id = ?'
|
||||
)->execute([$id]);
|
||||
}
|
||||
|
||||
@@ -148,7 +149,7 @@ class ShareLink
|
||||
public function incrementUsage(int $id): void
|
||||
{
|
||||
$this->db->getConnection()->prepare(
|
||||
"UPDATE share_links SET usage_count = usage_count + 1 WHERE id = ?"
|
||||
'UPDATE share_links SET usage_count = usage_count + 1 WHERE id = ?'
|
||||
)->execute([$id]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user