1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* WellCommerce Open-Source E-Commerce Platform |
4
|
|
|
* |
5
|
|
|
* This file is part of the WellCommerce package. |
6
|
|
|
* |
7
|
|
|
* (c) Adam Piotrowski <[email protected]> |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, |
10
|
|
|
* please view the LICENSE file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace WellCommerce\Bundle\AppBundle\Controller\Box; |
14
|
|
|
|
15
|
|
|
use WellCommerce\Bundle\AppBundle\Entity\Client; |
16
|
|
|
use WellCommerce\Bundle\AppBundle\Exception\NotFoundException; |
17
|
|
|
use WellCommerce\Bundle\AppBundle\Manager\ClientManager; |
18
|
|
|
use WellCommerce\Bundle\CoreBundle\Controller\Box\AbstractBoxController; |
19
|
|
|
use WellCommerce\Component\Form\Elements\FormInterface; |
20
|
|
|
use WellCommerce\Component\Layout\Collection\LayoutBoxSettingsCollection; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class ClientForgotPasswordBoxController |
24
|
|
|
* |
25
|
|
|
* @author Adam Piotrowski <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
class ClientForgotPasswordBoxController extends AbstractBoxController |
28
|
|
|
{ |
29
|
|
|
public function resetAction(LayoutBoxSettingsCollection $boxSettings) |
30
|
|
|
{ |
31
|
|
|
$form = $this->formBuilder->createForm(); |
32
|
|
|
|
33
|
|
|
if ($form->handleRequest()->isSubmitted()) { |
34
|
|
|
$data = $form->getValue(); |
35
|
|
|
|
36
|
|
|
try { |
37
|
|
|
$client = $this->getManager()->getClientByUsername($data['_username']); |
38
|
|
|
$this->getManager()->resetPassword($client); |
39
|
|
|
$this->getFlashHelper()->addSuccess('client.flash.reset_password.success'); |
40
|
|
|
|
41
|
|
|
$this->getMailerHelper()->sendEmail([ |
42
|
|
|
'recipient' => $client->getContactDetails()->getEmail(), |
43
|
|
|
'subject' => $this->getTranslatorHelper()->trans('client.email.heading.reset_password'), |
44
|
|
|
'template' => 'WellCommerceAppBundle:Email:reset_password.html.twig', |
45
|
|
|
'parameters' => [ |
46
|
|
|
'client' => $client, |
47
|
|
|
], |
48
|
|
|
'configuration' => $client->getShop()->getMailerConfiguration(), |
49
|
|
|
]); |
50
|
|
|
|
51
|
|
|
} catch (\Exception $e) { |
52
|
|
|
$this->getFlashHelper()->addError($e->getMessage()); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return $this->getRouterHelper()->redirectTo('front.client_password.reset'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return $this->displayTemplate('reset', [ |
59
|
|
|
'form' => $form, |
60
|
|
|
'boxSettings' => $boxSettings, |
61
|
|
|
]); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function changeAction(LayoutBoxSettingsCollection $boxSettings) |
65
|
|
|
{ |
66
|
|
|
$hash = $this->getRequestHelper()->getAttributesBagParam('hash'); |
67
|
|
|
$client = $this->getManager()->getRepository()->findOneBy(['clientDetails.resetPasswordHash' => $hash]); |
68
|
|
|
|
69
|
|
|
if (!$client instanceof Client) { |
70
|
|
|
return $this->getRouterHelper()->redirectToAction('reset'); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$client->getClientDetails()->setPassword(''); |
74
|
|
|
$client->getClientDetails()->setLegacyPasswordEncoder(null); |
75
|
|
|
$client->getClientDetails()->setLegacyPassword(null); |
76
|
|
|
|
77
|
|
|
$form = $this->createChangePasswordForm($client); |
78
|
|
|
|
79
|
|
|
if ($form->handleRequest()->isSubmitted()) { |
80
|
|
|
if ($form->isValid()) { |
81
|
|
|
$this->getManager()->updateResource($client); |
82
|
|
|
$this->getFlashHelper()->addSuccess('client.flash.change_password.success'); |
83
|
|
|
|
84
|
|
|
return $this->getRouterHelper()->redirectTo('front.client.login'); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$this->getFlashHelper()->addError('client.flash.change_password.error'); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
return $this->displayTemplate('change', [ |
92
|
|
|
'form' => $form, |
93
|
|
|
'boxSettings' => $boxSettings, |
94
|
|
|
]); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
protected function getManager(): ClientManager |
98
|
|
|
{ |
99
|
|
|
return parent::getManager(); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
private function createChangePasswordForm(Client $client): FormInterface |
103
|
|
|
{ |
104
|
|
|
return $this->get('client_change_password.form_builder.front')->createForm($client, [ |
105
|
|
|
'name' => 'change_password', |
106
|
|
|
'validation_groups' => ['client_password_change'], |
107
|
|
|
]); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|