|
@@ -1,4 +1,5 @@
|
1
|
1
|
<?php
|
|
2
|
+
|
2
|
3
|
namespace Logipro\Phoenix\Controller\Catalog;
|
3
|
4
|
|
4
|
5
|
use Logipro\Phoenix\Events;
|
|
@@ -32,11 +33,11 @@ use Logipro\Phoenix\Service\LoginService;
|
32
|
33
|
class LoginController extends CatalogController
|
33
|
34
|
{
|
34
|
35
|
protected function phxRenderView(string $view, array $parameters = array()): string
|
35
|
|
- {
|
36
|
|
- $view = str_replace($this->viewPath,'',$view);
|
|
36
|
+ {
|
|
37
|
+ $view = str_replace($this->viewPath, '', $view);
|
37
|
38
|
$view = $this->viewPath . $view;
|
38
|
39
|
|
39
|
|
- return parent::phxRenderView($view,$parameters);
|
|
40
|
+ return parent::phxRenderView($view, $parameters);
|
40
|
41
|
}
|
41
|
42
|
|
42
|
43
|
private function createLoginForm()
|
|
@@ -63,16 +64,16 @@ class LoginController extends CatalogController
|
63
|
64
|
private function createRecoverForm()
|
64
|
65
|
{
|
65
|
66
|
$formBuilder = $this->createFormBuilder();
|
66
|
|
-
|
|
67
|
+
|
67
|
68
|
$formBuilder->add('username', TextType::class, array(
|
68
|
|
- 'required' => true,
|
|
69
|
+ 'required' => true,
|
69
|
70
|
'label_format' => 'catalog_recover_%id%'
|
70
|
71
|
));
|
71
|
72
|
|
72
|
73
|
return $formBuilder->getForm();
|
73
|
74
|
}
|
74
|
75
|
|
75
|
|
- public function manageLogin(Request $request, UserPasswordEncoderInterface $passwordEncoder,SessionInterface $session)
|
|
76
|
+ public function manageLogin(Request $request, UserPasswordEncoderInterface $passwordEncoder, SessionInterface $session)
|
76
|
77
|
{
|
77
|
78
|
$continue = $request->request->get('continue');
|
78
|
79
|
|
|
@@ -80,7 +81,7 @@ class LoginController extends CatalogController
|
80
|
81
|
|
81
|
82
|
$formLogin = $this->createLoginForm();
|
82
|
83
|
|
83
|
|
- $formSubscribe = $this->createForm(CatalogSubscribeType::class,$person);
|
|
84
|
+ $formSubscribe = $this->createForm(CatalogSubscribeType::class, $person);
|
84
|
85
|
|
85
|
86
|
$formRecover = $this->createRecoverForm();
|
86
|
87
|
|
|
@@ -95,14 +96,13 @@ class LoginController extends CatalogController
|
95
|
96
|
"form_recover" => $formRecover->createView()
|
96
|
97
|
);
|
97
|
98
|
|
98
|
|
- $html = $this->phxRenderView('layouts/partials/header/modal-login-content.html.twig',$renderVars);
|
|
99
|
+ $html = $this->phxRenderView('layouts/partials/header/modal-login-content.html.twig', $renderVars);
|
99
|
100
|
|
100
|
101
|
$response['html'] = $html;
|
101
|
102
|
$response['nav'] = $this->phxRenderView('layouts/partials/header/header.html.twig');
|
102
|
|
-
|
|
103
|
+
|
103
|
104
|
$response['success'] = false;
|
104
|
|
- if ($this->getUser())
|
105
|
|
- {
|
|
105
|
+ if ($this->getUser()) {
|
106
|
106
|
$response['success'] = true;
|
107
|
107
|
}
|
108
|
108
|
$response['continue'] = $continue;
|
|
@@ -110,63 +110,56 @@ class LoginController extends CatalogController
|
110
|
110
|
return $this->json($response);
|
111
|
111
|
}
|
112
|
112
|
|
113
|
|
- public function validateSubscribe(Request $request,LearnerAccountGenerator $accountGenerator,ValidatorInterface $validator, EventDispatcherInterface $eventDispatcher,LoginService $loginService)
|
|
113
|
+ public function validateSubscribe(Request $request, LearnerAccountGenerator $accountGenerator, ValidatorInterface $validator, EventDispatcherInterface $eventDispatcher, LoginService $loginService)
|
114
|
114
|
{
|
115
|
115
|
// si l'utilisateur est connecté => erreur
|
116
|
|
- if ($this->getLearnerSpaceUser())
|
117
|
|
- {
|
|
116
|
+ if ($this->getLearnerSpaceUser()) {
|
118
|
117
|
throw $this->createAccessDeniedException($this->translate('error_403_message'));
|
119
|
118
|
}
|
120
|
|
-
|
|
119
|
+
|
121
|
120
|
$person = new Person();
|
122
|
121
|
|
123
|
122
|
$service = $this->get('phxSettings');
|
124
|
123
|
$person->setSociety($service->getDefaultSociety());
|
125
|
124
|
|
126
|
|
- $formSubscribe = $this->createForm(CatalogSubscribeType::class,$person);
|
|
125
|
+ $formSubscribe = $this->createForm(CatalogSubscribeType::class, $person);
|
127
|
126
|
|
128
|
127
|
$succes = $error = null;
|
129
|
128
|
|
130
|
129
|
$response = array();
|
131
|
|
- try
|
132
|
|
- {
|
133
|
|
- if ($request->isMethod('POST'))
|
134
|
|
- {
|
|
130
|
+ try {
|
|
131
|
+ if ($request->isMethod('POST')) {
|
135
|
132
|
$formSubscribe->handleRequest($request);
|
136
|
133
|
|
137
|
134
|
// valide l'objet distant et remonte l'erreur sur le formulaire d'origine
|
138
|
135
|
$result = $validator->validate($person->getLearnerAccount());
|
139
|
136
|
$learnerAccountField = $formSubscribe->get('learnerAccount');
|
140
|
|
- foreach ($result as $error)
|
141
|
|
- {
|
142
|
|
- $this->addFormError($learnerAccountField->get($error->getPropertyPath()),$error->getMessage());
|
|
137
|
+ foreach ($result as $error) {
|
|
138
|
+ $this->addFormError($learnerAccountField->get($error->getPropertyPath()), $error->getMessage());
|
143
|
139
|
}
|
144
|
140
|
|
145
|
141
|
// test rgpd
|
146
|
142
|
$rgpdField = $formSubscribe->get('rgpd');
|
147
|
|
- if (!$rgpdField->getData())
|
148
|
|
- {
|
|
143
|
+ if (!$rgpdField->getData()) {
|
149
|
144
|
// ajoute une erreur sur le champ
|
150
|
145
|
$message = 'la case doit être cochée';
|
151
|
|
- $this->addFormError($rgpdField,$message);
|
|
146
|
+ $this->addFormError($rgpdField, $message);
|
152
|
147
|
}
|
153
|
148
|
|
154
|
149
|
// test le mot de passe
|
155
|
150
|
$plainPasswordField = $learnerAccountField->get('plainPassword')->get('first');
|
156
|
151
|
$plainPassword = $plainPasswordField->getData();
|
157
|
|
- $errorMsg = PasswordValidator::renderError($this->get('translator'),$this->get('phxSettings'),$plainPassword);
|
158
|
|
- if ($errorMsg != '')
|
159
|
|
- {
|
160
|
|
- $this->addFormError($plainPasswordField,$errorMsg);
|
|
152
|
+ $errorMsg = PasswordValidator::renderError($this->get('translator'), $this->get('phxSettings'), $plainPassword);
|
|
153
|
+ if ($errorMsg != '') {
|
|
154
|
+ $this->addFormError($plainPasswordField, $errorMsg);
|
161
|
155
|
}
|
162
|
156
|
|
163
|
|
- if ($formSubscribe->isSubmitted() && $formSubscribe->isValid())
|
164
|
|
- {
|
|
157
|
+ if ($formSubscribe->isSubmitted() && $formSubscribe->isValid()) {
|
165
|
158
|
$learnerAccount = $accountGenerator->generateLearnerAccount($person);
|
166
|
159
|
|
167
|
160
|
//$learnerAccount = $person->getLearnerAccount();
|
168
|
161
|
$encoder = $this->get('security.password_encoder');
|
169
|
|
- $learnerAccount->setPassword($encoder->encodePassword($learnerAccount,$plainPassword));
|
|
162
|
+ $learnerAccount->setPassword($encoder->encodePassword($learnerAccount, $plainPassword));
|
170
|
163
|
$learnerAccount->setUsername($learnerAccountField->get('username')->getData());
|
171
|
164
|
$learnerAccount->setStatus(EnumAccountStatusType::STATUS_ENABLED);
|
172
|
165
|
$person->setLearnerAccount($learnerAccount);
|
|
@@ -176,40 +169,34 @@ class LoginController extends CatalogController
|
176
|
169
|
|
177
|
170
|
$manager->persist($person);
|
178
|
171
|
$manager->persist($learnerAccount);
|
179
|
|
-
|
|
172
|
+
|
180
|
173
|
$manager->flush();
|
181
|
174
|
|
182
|
175
|
// connecte l'utilisateur
|
183
|
|
- $loginService->loginCatalogUser($learnerAccount,$plainPassword);
|
|
176
|
+ $loginService->loginCatalogUser($learnerAccount, $plainPassword);
|
184
|
177
|
|
185
|
178
|
// envoi l'email
|
186
|
179
|
$event = new GenericEvent($person);
|
187
|
|
- $eventDispatcher->dispatch($event,Events::LEARNER_SUBSCRIBE);
|
|
180
|
+ $eventDispatcher->dispatch($event, Events::LEARNER_SUBSCRIBE);
|
188
|
181
|
|
189
|
182
|
$succes = true;
|
190
|
|
- }
|
191
|
|
- else
|
192
|
|
- {
|
|
183
|
+ } else {
|
193
|
184
|
$errors = $this->getFormFieldError($formSubscribe);
|
194
|
185
|
throw $this->createNotFoundException($this->serializeFormFieldError($errors));
|
195
|
186
|
}
|
196
|
187
|
}
|
197
|
|
- }
|
198
|
|
- catch (\Exception $exp)
|
199
|
|
- {
|
|
188
|
+ } catch (\Exception $exp) {
|
200
|
189
|
$succes = false;
|
201
|
|
-
|
|
190
|
+
|
202
|
191
|
$errors = $this->getFormFieldError($formSubscribe);
|
203
|
192
|
|
204
|
193
|
$response['error'] = $exp->getMessage();
|
205
|
194
|
$response['formError'] = array();
|
206
|
195
|
|
207
|
196
|
// parcours les erreurs
|
208
|
|
- foreach ($errors as $fieldId => $errorField)
|
209
|
|
- {
|
|
197
|
+ foreach ($errors as $fieldId => $errorField) {
|
210
|
198
|
$message = $this->getFormFieldErrorMessage($errorField);
|
211
|
|
- if ($message)
|
212
|
|
- {
|
|
199
|
+ if ($message) {
|
213
|
200
|
$response['formError'][$fieldId] = $message;
|
214
|
201
|
}
|
215
|
202
|
}
|
|
@@ -224,36 +211,29 @@ class LoginController extends CatalogController
|
224
|
211
|
|
225
|
212
|
public function validateRecover(Request $request, EventDispatcherInterface $eventDispatcher)
|
226
|
213
|
{
|
227
|
|
- if ($this->getLearnerSpaceUser())
|
228
|
|
- {
|
|
214
|
+ if ($this->getLearnerSpaceUser()) {
|
229
|
215
|
throw $this->createErrorException($this->translate('error_recover_password_logged'));
|
230
|
216
|
}
|
231
|
217
|
|
232
|
218
|
$error = $succes = null;
|
233
|
|
- try
|
234
|
|
- {
|
235
|
|
- if ($request->isMethod('POST'))
|
236
|
|
- {
|
|
219
|
+ try {
|
|
220
|
+ if ($request->isMethod('POST')) {
|
237
|
221
|
$formRecover = $this->createRecoverForm();
|
238
|
222
|
$formRecover->handleRequest($request);
|
239
|
|
- if ($formRecover->isSubmitted() && $formRecover->isValid())
|
240
|
|
- {
|
|
223
|
+ if ($formRecover->isSubmitted() && $formRecover->isValid()) {
|
241
|
224
|
// cherche le compte
|
242
|
225
|
$learnerAccountRepository = $this->getRepository(LearnerAccount::class);
|
243
|
226
|
$learnerAccountSearch = $learnerAccountRepository->loadUserByUsername($formRecover->get('username')->getData());
|
244
|
|
- if (!$learnerAccountSearch)
|
245
|
|
- {
|
|
227
|
+ if (!$learnerAccountSearch) {
|
246
|
228
|
throw $this->createNotFoundException();
|
247
|
229
|
}
|
248
|
230
|
|
249
|
231
|
// déclanche l'événement du mail
|
250
|
232
|
$event = new GenericEvent($learnerAccountSearch);
|
251
|
|
- $eventDispatcher->dispatch($event,Events::LEARNER_RECOVER_ON_CATALOG);
|
|
233
|
+ $eventDispatcher->dispatch($event, Events::LEARNER_RECOVER_ON_CATALOG);
|
252
|
234
|
}
|
253
|
235
|
}
|
254
|
|
- }
|
255
|
|
- catch (\Exception $exp)
|
256
|
|
- {
|
|
236
|
+ } catch (\Exception $exp) {
|
257
|
237
|
$error = $exp->getMessage();
|
258
|
238
|
}
|
259
|
239
|
|
|
@@ -268,8 +248,7 @@ class LoginController extends CatalogController
|
268
|
248
|
|
269
|
249
|
public function validateLogout(Request $request)
|
270
|
250
|
{
|
271
|
|
- if (!$this->getLearnerSpaceUser())
|
272
|
|
- {
|
|
251
|
+ if (!$this->getLearnerSpaceUser()) {
|
273
|
252
|
throw $this->createAccessDeniedException($this->translate('error_403_message'));
|
274
|
253
|
}
|
275
|
254
|
|
|
@@ -281,89 +260,85 @@ class LoginController extends CatalogController
|
281
|
260
|
$session->set('_security_' . $name, null);
|
282
|
261
|
$session->save();
|
283
|
262
|
|
284
|
|
-// $request->getSession()->invalidate();
|
|
263
|
+ // $request->getSession()->invalidate();
|
285
|
264
|
|
286
|
265
|
$response['nav'] = $this->phxRenderView('layouts/partials/header/header.html.twig');
|
287
|
266
|
return $this->json($response);
|
288
|
267
|
}
|
289
|
268
|
|
290
|
|
- public function manageDefinePassword(Request $request,LoginService $loginService)
|
|
269
|
+ public function manageDefinePassword(Request $request, LoginService $loginService)
|
291
|
270
|
{
|
292
|
|
- if ($this->getLearnerSpaceUser())
|
293
|
|
- {
|
|
271
|
+ if ($this->getLearnerSpaceUser()) {
|
294
|
272
|
throw $this->createErrorException($this->translate('error_recover_password_logged'));
|
295
|
273
|
}
|
296
|
274
|
$token = $request->get('token');
|
|
275
|
+ if (!$token) {
|
|
276
|
+ throw $this->createNotFoundException($this->translate('error_403_message'));
|
|
277
|
+ }
|
297
|
278
|
|
298
|
279
|
$tokenData = PasswordRecoverNotifyLearner::decrytUrlArg($token);
|
299
|
280
|
if (!$tokenData) {
|
300
|
|
- // token expiré
|
301
|
|
- $parameters = array(
|
302
|
|
- 'text' => $this->translate('catalog_password_expired'),
|
303
|
|
- 'path' => 'catalog_homepage',
|
304
|
|
- 'go' => $this->translate('catalog_password_return')
|
305
|
|
- );
|
306
|
|
- return $this->phxRender('bundles/TwigBundle/Exception/definePassword.html.twig', $parameters);
|
|
281
|
+ $response = new Response('', 404);
|
|
282
|
+
|
|
283
|
+ // token expiré
|
|
284
|
+ $parameters = array(
|
|
285
|
+ 'text' => $this->translate('catalog_password_expired'),
|
|
286
|
+ 'path' => 'catalog_homepage',
|
|
287
|
+ 'go' => $this->translate('catalog_password_return')
|
|
288
|
+ );
|
|
289
|
+ return $this->phxRender('bundles/TwigBundle/Exception/definePassword.html.twig', $parameters,$response);
|
307
|
290
|
}
|
308
|
|
-
|
|
291
|
+
|
309
|
292
|
$respository = $this->getRepository(LearnerAccount::class);
|
310
|
293
|
$learnerAccount = $respository->findOneBy(array('learnerAccountId' => $tokenData['learnerAccountId']));
|
311
|
|
- if (!$learnerAccount)
|
312
|
|
- {
|
|
294
|
+ if (!$learnerAccount) {
|
313
|
295
|
throw $this->createNotFoundException($this->translate('error_403_message'));
|
314
|
296
|
}
|
315
|
|
- $form = $this->createForm(CatalogDefinePasswordType::class,$learnerAccount);
|
|
297
|
+ $form = $this->createForm(CatalogDefinePasswordType::class, $learnerAccount);
|
316
|
298
|
|
317
|
|
- try
|
318
|
|
- {
|
319
|
|
- if ($request->isMethod('POST'))
|
320
|
|
- {
|
|
299
|
+ try {
|
|
300
|
+ if ($request->isMethod('POST')) {
|
321
|
301
|
$form->handleRequest($request);
|
322
|
302
|
|
323
|
303
|
// test le mot de passe
|
324
|
304
|
$plainPasswordField = $form->get('plainPassword')->get('first');
|
325
|
305
|
$plainPassword = $plainPasswordField->getData();
|
326
|
|
- $errorMsg = PasswordValidator::renderError($this->get('translator'),$this->get('phxSettings'),$plainPassword);
|
327
|
|
- if ($errorMsg != '')
|
328
|
|
- {
|
329
|
|
- $this->addFormError($plainPasswordField,$errorMsg);
|
|
306
|
+ $errorMsg = PasswordValidator::renderError($this->get('translator'), $this->get('phxSettings'), $plainPassword);
|
|
307
|
+ if ($errorMsg != '') {
|
|
308
|
+ $this->addFormError($plainPasswordField, $errorMsg);
|
330
|
309
|
}
|
331
|
310
|
|
332
|
311
|
// test le formulaire
|
333
|
|
- if ($form->isSubmitted() && $form->isValid())
|
334
|
|
- {
|
|
312
|
+ if ($form->isSubmitted() && $form->isValid()) {
|
335
|
313
|
$encoder = $this->get('security.password_encoder');
|
336
|
|
- $learnerAccount->setPassword($encoder->encodePassword($learnerAccount,$plainPassword));
|
|
314
|
+ $learnerAccount->setPassword($encoder->encodePassword($learnerAccount, $plainPassword));
|
337
|
315
|
|
338
|
316
|
$manager = $this->getManager();
|
339
|
317
|
$manager->flush();
|
340
|
318
|
|
341
|
319
|
// logue l'utilisateur
|
342
|
|
- $loginService->loginCatalogUser($learnerAccount,$plainPassword);
|
343
|
|
-
|
|
320
|
+ $loginService->loginCatalogUser($learnerAccount, $plainPassword);
|
|
321
|
+
|
344
|
322
|
//$this->addFlash('success', "mot de passe redéfini");
|
345
|
323
|
|
346
|
324
|
// redirige sur le catalogue
|
347
|
325
|
$route = $tokenData['route'];
|
348
|
|
- if ($route)
|
349
|
|
- {
|
|
326
|
+ if ($route) {
|
350
|
327
|
$route = 'catalog_homepage';
|
351
|
328
|
}
|
352
|
329
|
|
353
|
330
|
$this->addFlash('success', $this->translate('new_password_defined'));
|
354
|
|
-
|
|
331
|
+
|
355
|
332
|
return $this->redirectToRoute($route);
|
356
|
333
|
}
|
357
|
334
|
}
|
358
|
|
- }
|
359
|
|
- catch (\Exception $exp)
|
360
|
|
- {
|
|
335
|
+ } catch (\Exception $exp) {
|
361
|
336
|
$error = $exp->getMessage();
|
362
|
337
|
$succes = false;
|
363
|
338
|
}
|
364
|
339
|
|
365
|
340
|
// affiche la vue pour définir le mot de passe
|
366
|
|
- $parameters = array('token' => $token,'form' => $form->createView());
|
367
|
|
- return $this->phxRender('catalog/pages/define_password.html.twig',$parameters);
|
|
341
|
+ $parameters = array('token' => $token, 'form' => $form->createView());
|
|
342
|
+ return $this->phxRender('catalog/pages/define_password.html.twig', $parameters);
|
368
|
343
|
}
|
369
|
|
-}
|
|
344
|
+}
|