1

I try to register a new user via Sentry, and Sentry::register throws an UserExistsException.

But I'm sure that it doesn't exist in my DB (email based login, and I created a random address).

Here's an excerpt of my code:

try {
try {
    Sentry::setUserProvider(new UserProvider\Provider(new Hashing\NativeHasher, 'Alsace\User'));
    $user = Sentry::register(['email' => $post['adresse_email'], 'password' => $mdp]);
    $code_activation  = $user->getActivationCode();
} catch (Cartalyst\Sentry\Users\LoginRequiredException $e) {
    throw new DomainException("Le champ email n'est pas renseigné.");
} catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) {
    throw new DomainException("Le champ mot de passe n'est pas renseigné.");
} catch (Cartalyst\Sentry\Users\UserExistsException $e) {
    throw new DomainException("Un utilisateur ayant cet e-mail existe déjà.");
}

$user->first_name = $post['prenom'];
$user->last_name  = $post['nom'];
$user->telephone  = !empty($post['portable']) ? $post['portable'] : null;
$user->save();

Alsace\Bureau::whereIn('id', $ids_bureaux)->get()->each(function($bureau) {
    global $user;

    $bureau->user_id = $user->id;
    $bureau->save();
});

// ...

header('201 Created', true, 201);
header('Content-Type: application/json');
echo json_encode(['success' => 'Création OK']);
exit();
}  catch (DomainException $e) {
  // header('200 OK', true, 200);
  header('Content-Type: application/json');
  echo json_encode(['exception' => $e->getMessage()]);
  exit();
}

My HTTP response is a JSON with status code 201, but the JSON's content corresponds to the one lanuch in my DomainException catch?

PS: I thought it could be because jQuery submits my form twice, but that's not the case.

Gustavo Straube
  • 3,744
  • 6
  • 39
  • 62
jpicaude
  • 356
  • 2
  • 8

0 Answers0