|
2 | 2 |
|
3 | 3 | namespace App\Controller; |
4 | 4 |
|
| 5 | +use App\Controller\Jury\UserController; |
5 | 6 | use App\Entity\Team; |
6 | 7 | use App\Entity\TeamAffiliation; |
7 | 8 | use App\Entity\TeamCategory; |
|
12 | 13 | use Doctrine\ORM\EntityManagerInterface; |
13 | 14 | use Ramsey\Uuid\Uuid; |
14 | 15 | use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
| 16 | +use Symfony\Component\Form\FormInterface; |
15 | 17 | use Symfony\Component\HttpFoundation\Request; |
16 | 18 | use Symfony\Component\HttpFoundation\Response; |
17 | 19 | use Symfony\Component\HttpKernel\Exception\HttpException; |
@@ -103,58 +105,62 @@ public function registerAction( |
103 | 105 | $registration_form->handleRequest($request); |
104 | 106 | if ($registration_form->isSubmitted() && $registration_form->isValid()) { |
105 | 107 | $plainPass = $registration_form->get('plainPassword')->getData(); |
106 | | - $password = $passwordHasher->hashPassword($user, $plainPass); |
107 | | - $user->setPassword($password); |
108 | | - if ($user->getName() === null) { |
109 | | - $user->setName($user->getUsername()); |
110 | | - } |
| 108 | + if (strlen($plainPass) < UserController::MIN_PASSWORD_LENGTH) { |
| 109 | + $this->addFlash('danger', "Password should be " . UserController::MIN_PASSWORD_LENGTH . "+ chars."); |
| 110 | + } else { |
| 111 | + $password = $passwordHasher->hashPassword($user, $plainPass); |
| 112 | + $user->setPassword($password); |
| 113 | + if ($user->getName() === null) { |
| 114 | + $user->setName($user->getUsername()); |
| 115 | + } |
111 | 116 |
|
112 | | - $teamName = $registration_form->get('teamName')->getData(); |
| 117 | + $teamName = $registration_form->get('teamName')->getData(); |
113 | 118 |
|
114 | | - if ($selfRegistrationCategoriesCount === 1) { |
115 | | - $teamCategory = $em->getRepository(TeamCategory::class)->findOneBy(['allow_self_registration' => 1]); |
116 | | - } else { |
117 | | - // $selfRegistrationCategoriesCount > 1, 'teamCategory' field exists |
118 | | - $teamCategory = $registration_form->get('teamCategory')->getData(); |
119 | | - } |
| 119 | + if ($selfRegistrationCategoriesCount === 1) { |
| 120 | + $teamCategory = $em->getRepository(TeamCategory::class)->findOneBy(['allow_self_registration' => 1]); |
| 121 | + } else { |
| 122 | + // $selfRegistrationCategoriesCount > 1, 'teamCategory' field exists |
| 123 | + $teamCategory = $registration_form->get('teamCategory')->getData(); |
| 124 | + } |
120 | 125 |
|
121 | | - // Create a team to go with the user, then set some team attributes. |
122 | | - $team = new Team(); |
123 | | - $user->setTeam($team); |
124 | | - $team |
125 | | - ->setExternalid(Uuid::uuid4()->toString()) |
126 | | - ->addUser($user) |
127 | | - ->setName($teamName) |
128 | | - ->setCategory($teamCategory) |
129 | | - ->setInternalComments('Registered by ' . $this->dj->getClientIp() . ' on ' . date('r')); |
130 | | - |
131 | | - if ($this->config->get('show_affiliations')) { |
132 | | - switch ($registration_form->get('affiliation')->getData()) { |
133 | | - case 'new': |
134 | | - $affiliation = new TeamAffiliation(); |
135 | | - $affiliation |
136 | | - ->setExternalid(Uuid::uuid4()->toString()) |
137 | | - ->setName($registration_form->get('affiliationName')->getData()) |
138 | | - ->setShortname($registration_form->get('affiliationShortName')->getData()); |
139 | | - if ($registration_form->has('affiliationCountry')) { |
140 | | - $affiliation->setCountry($registration_form->get('affiliationCountry')->getData()); |
141 | | - } |
142 | | - $team->setAffiliation($affiliation); |
143 | | - $em->persist($affiliation); |
144 | | - break; |
145 | | - case 'existing': |
146 | | - $team->setAffiliation($registration_form->get('existingAffiliation')->getData()); |
147 | | - break; |
| 126 | + // Create a team to go with the user, then set some team attributes. |
| 127 | + $team = new Team(); |
| 128 | + $user->setTeam($team); |
| 129 | + $team |
| 130 | + ->setExternalid(Uuid::uuid4()->toString()) |
| 131 | + ->addUser($user) |
| 132 | + ->setName($teamName) |
| 133 | + ->setCategory($teamCategory) |
| 134 | + ->setInternalComments('Registered by ' . $this->dj->getClientIp() . ' on ' . date('r')); |
| 135 | + |
| 136 | + if ($this->config->get('show_affiliations')) { |
| 137 | + switch ($registration_form->get('affiliation')->getData()) { |
| 138 | + case 'new': |
| 139 | + $affiliation = new TeamAffiliation(); |
| 140 | + $affiliation |
| 141 | + ->setExternalid(Uuid::uuid4()->toString()) |
| 142 | + ->setName($registration_form->get('affiliationName')->getData()) |
| 143 | + ->setShortname($registration_form->get('affiliationShortName')->getData()); |
| 144 | + if ($registration_form->has('affiliationCountry')) { |
| 145 | + $affiliation->setCountry($registration_form->get('affiliationCountry')->getData()); |
| 146 | + } |
| 147 | + $team->setAffiliation($affiliation); |
| 148 | + $em->persist($affiliation); |
| 149 | + break; |
| 150 | + case 'existing': |
| 151 | + $team->setAffiliation($registration_form->get('existingAffiliation')->getData()); |
| 152 | + break; |
| 153 | + } |
148 | 154 | } |
149 | | - } |
150 | 155 |
|
151 | | - $em->persist($user); |
152 | | - $em->persist($team); |
153 | | - $em->flush(); |
| 156 | + $em->persist($user); |
| 157 | + $em->persist($team); |
| 158 | + $em->flush(); |
154 | 159 |
|
155 | | - $this->addFlash('success', 'Account registered successfully. Please log in.'); |
| 160 | + $this->addFlash('success', 'Account registered successfully. Please log in.'); |
156 | 161 |
|
157 | | - return $this->redirectToRoute('login'); |
| 162 | + return $this->redirectToRoute('login'); |
| 163 | + } |
158 | 164 | } |
159 | 165 |
|
160 | 166 | return $this->render('security/register.html.twig', ['registration_form' => $registration_form]); |
|
0 commit comments