In France and the European Union, it seems to me that it is necessary to allow a user to be able to download all this data and also to allow the total deletion of the account. This is the GDPR law (General Data Protection Regulation)
How can I authorize the user (registered on the site) to download this data?
For deletion there is no problem, I use a Hook:
'hooks' => [
'user.delete:before' => function ($user) {
$userId = $user->id();
$pages = site()->index();
foreach ($pages as $page) {
$userImages = $page->images()->filterBy('user_id', $userId);
foreach ($userImages as $image) {
try {
$image->delete();
} catch (Exception $e) {
error_log('Image not deleted: ' . $e->getMessage());
}
}
}
$userPages = $pages->filterBy('author', $userId);
foreach ($userPages as $userPage) {
try {
$userPage->delete(true);
} catch (Exception $e) {
error_log('Page not deleted: ' . $e->getMessage());
}
}
},
'user.delete:after' => function ($user) {
try {
kirby()->email([
'template' => 'account-deleted',
'from' => 'yourcontactform@yourcompany.com',
'replyTo' => 'admin@yourcompany.com',
'to' => $user->email(),
'subject' => 'Confirmation de la suppression de votre compte',
'data' => [
'name' => $user->name()
]
]);
} catch (Exception $e) {
error_log('Email not sent: ' . $e->getMessage());
}
}
],