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 ...@@ -48,8 +48,7 @@ class UserBuilder
!StringHelper::isNullOrWhitespace($plainPassword), !StringHelper::isNullOrWhitespace($plainPassword),
'A user should have none empty password' 'A user should have none empty password'
); );
$this->user->setSalt($salt); $this->user->plainPassword = $plainPassword;
$this->user->setPassword($this->password_hasher->hashPassword($this->user, $plainPassword));
return $this; return $this;
} }
...@@ -87,14 +86,16 @@ class UserBuilder ...@@ -87,14 +86,16 @@ class UserBuilder
"A user must have a first name (current:'" . $this->user->getFirstName() . "')" "A user must have a first name (current:'" . $this->user->getFirstName() . "')"
); );
ContractHelper::requires( ContractHelper::requires(
!StringHelper::isNullOrWhitespace($this->user->getPassword()), !StringHelper::isNullOrWhitespace($this->user->plainPassword),
"A user must have a have a none empty or whitespace password" "A user must have a have a none empty or whitespace password"
); );
ContractHelper::requires( ContractHelper::requires(
!empty($this->user->getRoles()), !empty($this->user->getRoles()),
"A user must have a have roles" "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; return $this->user;
} }
......
...@@ -56,15 +56,6 @@ class RegistrationController extends AbstractController ...@@ -56,15 +56,6 @@ class RegistrationController extends AbstractController
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
$userBuilder = new UserBuilder($userPasswordHasher, $user); $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->persist($userBuilder->createUser());
$this->entity_manager->flush(); $this->entity_manager->flush();
......
...@@ -99,6 +99,11 @@ class User implements UserInterface, LegacyPasswordAuthenticatedUserInterface ...@@ -99,6 +99,11 @@ class User implements UserInterface, LegacyPasswordAuthenticatedUserInterface
*/ */
private Collection $capsules; private Collection $capsules;
/**
* @var string $plainPassword plain password to store before hashing it
*/
public string $plainPassword;
public function __construct() public function __construct()
{ {
$this->capsules = new ArrayCollection(); $this->capsules = new ArrayCollection();
...@@ -199,7 +204,7 @@ class User implements UserInterface, LegacyPasswordAuthenticatedUserInterface ...@@ -199,7 +204,7 @@ class User implements UserInterface, LegacyPasswordAuthenticatedUserInterface
public function eraseCredentials(): void public function eraseCredentials(): void
{ {
// If you store any temporary, sensitive data on the user, clear it here // If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null; $this->plainPassword = "";
} }
public function isVerified(): bool public function isVerified(): bool
......
...@@ -51,7 +51,6 @@ class RegistrationFormType extends AbstractType ...@@ -51,7 +51,6 @@ class RegistrationFormType extends AbstractType
) )
->add('plainPassword', RepeatedType::class, [ ->add('plainPassword', RepeatedType::class, [
'type' => PasswordType::class, 'type' => PasswordType::class,
'mapped' => false,
'required' => true, 'required' => true,
'constraints' => [ 'constraints' => [
new NotBlank(['message' => 'password.not_blank']), new NotBlank(['message' => 'password.not_blank']),
...@@ -80,7 +79,6 @@ class RegistrationFormType extends AbstractType ...@@ -80,7 +79,6 @@ class RegistrationFormType extends AbstractType
'acceptGeneralConditions', 'acceptGeneralConditions',
CheckboxType::class, CheckboxType::class,
[ [
'mapped' => false,
'constraints' => [ 'constraints' => [
new IsTrue(['message' => 'agreeTerms']), 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