Skip to content
Snippets Groups Projects
Verified Commit 855bef00 authored by David Beniamine's avatar David Beniamine
Browse files

Mapp plainPassword and acceptGeneralConditions

All RegistrationForm fields are mapped to the userEntity
parent bfefa763
No related branches found
No related tags found
1 merge request!46Tuleap 88 db migration
Pipeline #788 passed
......@@ -48,8 +48,7 @@ class UserBuilder
!StringHelper::isNullOrWhitespace($plainPassword),
'A user should have none empty password'
);
$this->user->setSalt($salt);
$this->user->setPassword($this->password_hasher->hashPassword($this->user, $plainPassword));
$this->user->plainPassword = $plainPassword;
return $this;
}
......@@ -87,14 +86,16 @@ class UserBuilder
"A user must have a first name (current:'" . $this->user->getFirstName() . "')"
);
ContractHelper::requires(
!StringHelper::isNullOrWhitespace($this->user->getPassword()),
!StringHelper::isNullOrWhitespace($this->user->plainPassword),
"A user must have a have a none empty or whitespace password"
);
ContractHelper::requires(
!empty($this->user->getRoles()),
"A user must have a have roles"
);
$this->user->setSalt(random_bytes(100));
$this->user->setPassword($this->password_hasher->hashPassword($this->user, $this->user->plainPassword));
$this->user->eraseCredentials();
return $this->user;
}
......
......@@ -56,15 +56,6 @@ class RegistrationController extends AbstractController
if ($form->isSubmitted() && $form->isValid()) {
$userBuilder = new UserBuilder($userPasswordHasher, $user);
// Ugly fix because I don't understand why those values aren't set correctly
$userBuilder->withAcceptGeneralConditions($form->get('acceptGeneralConditions')->getData());
$userBuilder
->withPassword(
random_bytes(100),
$form->get('plainPassword')->getData()
);
$this->entity_manager->persist($userBuilder->createUser());
$this->entity_manager->flush();
......
......@@ -99,6 +99,11 @@ class User implements UserInterface, LegacyPasswordAuthenticatedUserInterface
*/
private Collection $capsules;
/**
* @var string $plainPassword plain password to store before hashing it
*/
public string $plainPassword;
public function __construct()
{
$this->capsules = new ArrayCollection();
......@@ -199,7 +204,7 @@ class User implements UserInterface, LegacyPasswordAuthenticatedUserInterface
public function eraseCredentials(): void
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
$this->plainPassword = "";
}
public function isVerified(): bool
......
......@@ -51,7 +51,6 @@ class RegistrationFormType extends AbstractType
)
->add('plainPassword', RepeatedType::class, [
'type' => PasswordType::class,
'mapped' => false,
'required' => true,
'constraints' => [
new NotBlank(['message' => 'password.not_blank']),
......@@ -80,7 +79,6 @@ class RegistrationFormType extends AbstractType
'acceptGeneralConditions',
CheckboxType::class,
[
'mapped' => false,
'constraints' => [
new IsTrue(['message' => 'agreeTerms']),
],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment