RGPD/GDRP and Kirby

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());
        }
    }
],

An option would be a custom route Routes | Kirby CMS where you collect all the data and/or files (depends on what data you store for your users) and generate e.g. a ZIP file.

To return a download from a route, probably have a look at Response::download() | Kirby CMS

A note on your hooks code, running through the whole site index is a quite performance-heavy operation. I would suggest to merge the two foreach loops as you’re running through some pages twice with your current code.