Hello!
I’m making progress on my project where I’m trying to create a member area, but I’m stuck on the subscribe.php controller.
I’m getting the error 'You are not allowed to create this user'.
I’ve created a blueprint ‘member’ with
title: Member
permissions:
access:
panel: false
and this is my controller :
<?php
use Kirby\Toolkit\V;
return function ($kirby) {
$error = null;
$success = null;
if ($kirby->request()->is('POST')) {
$data = [
'email' => $kirby->request()->get('email'),
'password' => $kirby->request()->get('password'),
'csrf' => $kirby->request()->get('csrf')
];
// Vérification du token CSRF
if (!csrf($data['csrf'])) {
$error = 'Token CSRF invalide. Veuillez réessayer.';
} else {
// Validation des données
if (!V::email($data['email'])) {
$error = 'Adresse email invalide.';
} elseif (strlen($data['password']) < 8) {
$error = 'Le mot de passe doit comporter au moins 8 caractères.';
} else {
try {
// Création de l'utilisateur
$kirby->users()->create([
'email' => $data['email'],
'password' => $data['password'],
'role' => 'member'
]);
$success = 'Inscription réussie. Vous pouvez maintenant vous connecter.';
} catch (Exception $e) {
$error = 'Erreur lors de la création du compte : ' . $e->getMessage();
}
}
}
}
return compact('error', 'success');
};
Don’t know where would it come from, I’m disconnected from the panel…?
O.