1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of EC-CUBE |
5
|
|
|
* |
6
|
|
|
* Copyright(c) LOCKON CO.,LTD. All Rights Reserved. |
7
|
|
|
* |
8
|
|
|
* http://www.lockon.co.jp/ |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Eccube\Controller; |
15
|
|
|
|
16
|
|
|
use Eccube\Entity\BaseInfo; |
17
|
|
|
use Eccube\Entity\Master\CustomerStatus; |
18
|
|
|
use Eccube\Event\EccubeEvents; |
19
|
|
|
use Eccube\Event\EventArgs; |
20
|
|
|
use Eccube\Form\Type\Front\EntryType; |
21
|
|
|
use Eccube\Repository\CustomerRepository; |
22
|
|
|
use Eccube\Repository\Master\CustomerStatusRepository; |
23
|
|
|
use Eccube\Service\MailService; |
24
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
25
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
26
|
|
|
use Symfony\Component\HttpFoundation\Request; |
27
|
|
|
use Symfony\Component\HttpKernel\Exception as HttpException; |
28
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
29
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; |
30
|
|
|
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface; |
31
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
32
|
|
|
use Symfony\Component\Validator\Validator\ValidatorInterface; |
33
|
|
|
|
34
|
|
|
class EntryController extends AbstractController |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* @var CustomerStatusRepository |
38
|
|
|
*/ |
39
|
|
|
protected $customerStatusRepository; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var ValidatorInterface |
43
|
|
|
*/ |
44
|
|
|
protected $recursiveValidator; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var MailService |
48
|
|
|
*/ |
49
|
|
|
protected $mailService; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var BaseInfo |
53
|
|
|
*/ |
54
|
|
|
protected $BaseInfo; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var CustomerRepository |
58
|
|
|
*/ |
59
|
|
|
protected $customerRepository; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @var EncoderFactoryInterface |
63
|
|
|
*/ |
64
|
|
|
protected $encoderFactory; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @var TokenStorageInterface |
68
|
|
|
*/ |
69
|
|
|
protected $tokenStorage; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* EntryController constructor. |
73
|
|
|
* |
74
|
|
|
* @param CustomerStatusRepository $customerStatusRepository |
75
|
|
|
* @param MailService $mailService |
|
|
|
|
76
|
|
|
* @param BaseInfo $BaseInfo |
|
|
|
|
77
|
|
|
* @param CustomerRepository $customerRepository |
|
|
|
|
78
|
|
|
* @param EncoderFactoryInterface $encoderFactory |
|
|
|
|
79
|
|
|
* @param ValidatorInterface $validatorInterface |
|
|
|
|
80
|
|
|
* @param TokenStorageInterface $tokenStorage |
|
|
|
|
81
|
|
|
*/ |
82
|
9 |
|
public function __construct( |
83
|
|
|
CustomerStatusRepository $customerStatusRepository, |
84
|
|
|
MailService $mailService, |
85
|
|
|
BaseInfo $BaseInfo, |
86
|
|
|
CustomerRepository $customerRepository, |
87
|
|
|
EncoderFactoryInterface $encoderFactory, |
88
|
|
|
ValidatorInterface $validatorInterface, |
89
|
|
|
TokenStorageInterface $tokenStorage |
90
|
|
|
) { |
91
|
9 |
|
$this->customerStatusRepository = $customerStatusRepository; |
92
|
9 |
|
$this->mailService = $mailService; |
93
|
9 |
|
$this->BaseInfo = $BaseInfo; |
94
|
9 |
|
$this->customerRepository = $customerRepository; |
95
|
9 |
|
$this->encoderFactory = $encoderFactory; |
96
|
9 |
|
$this->recursiveValidator = $validatorInterface; |
97
|
9 |
|
$this->tokenStorage = $tokenStorage; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
|
|
|
|
101
|
|
|
* 会員登録画面. |
102
|
|
|
* |
103
|
|
|
* @Route("/entry", name="entry") |
104
|
|
|
* @Template("Entry/index.twig") |
105
|
|
|
*/ |
|
|
|
|
106
|
5 |
|
public function index(Request $request) |
107
|
|
|
{ |
108
|
5 |
|
if ($this->isGranted('ROLE_USER')) { |
109
|
|
|
log_info('認証済のためログイン処理をスキップ'); |
110
|
|
|
|
111
|
|
|
return $this->redirectToRoute('mypage'); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** @var $Customer \Eccube\Entity\Customer */ |
115
|
5 |
|
$Customer = $this->customerRepository->newCustomer(); |
116
|
|
|
|
117
|
|
|
/* @var $builder \Symfony\Component\Form\FormBuilderInterface */ |
118
|
5 |
|
$builder = $this->formFactory->createBuilder(EntryType::class, $Customer); |
119
|
|
|
|
120
|
5 |
|
$event = new EventArgs( |
121
|
|
|
[ |
122
|
5 |
|
'builder' => $builder, |
123
|
5 |
|
'Customer' => $Customer, |
124
|
|
|
], |
125
|
5 |
|
$request |
126
|
|
|
); |
127
|
5 |
|
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_ENTRY_INDEX_INITIALIZE, $event); |
128
|
|
|
|
129
|
|
|
/* @var $form \Symfony\Component\Form\FormInterface */ |
130
|
5 |
|
$form = $builder->getForm(); |
131
|
|
|
|
132
|
5 |
|
$form->handleRequest($request); |
133
|
|
|
|
134
|
5 |
|
if ($form->isSubmitted() && $form->isValid()) { |
135
|
3 |
|
switch ($request->get('mode')) { |
136
|
|
|
case 'confirm': |
137
|
1 |
|
log_info('会員登録確認開始'); |
138
|
1 |
|
log_info('会員登録確認完了'); |
139
|
|
|
|
140
|
1 |
|
return $this->render( |
141
|
1 |
|
'Entry/confirm.twig', |
142
|
|
|
[ |
143
|
1 |
|
'form' => $form->createView(), |
144
|
|
|
] |
145
|
|
|
); |
146
|
|
|
|
147
|
|
|
case 'complete': |
148
|
1 |
|
log_info('会員登録開始'); |
149
|
|
|
|
150
|
1 |
|
$encoder = $this->encoderFactory->getEncoder($Customer); |
151
|
1 |
|
$salt = $encoder->createSalt(); |
152
|
1 |
|
$password = $encoder->encodePassword($Customer->getPassword(), $salt); |
153
|
1 |
|
$secretKey = $this->customerRepository->getUniqueSecretKey(); |
154
|
|
|
|
155
|
|
|
$Customer |
156
|
1 |
|
->setSalt($salt) |
157
|
1 |
|
->setPassword($password) |
158
|
1 |
|
->setSecretKey($secretKey) |
159
|
1 |
|
->setPoint(0); |
160
|
|
|
|
161
|
1 |
|
$this->entityManager->persist($Customer); |
162
|
1 |
|
$this->entityManager->flush(); |
163
|
|
|
|
164
|
1 |
|
log_info('会員登録完了'); |
165
|
|
|
|
166
|
1 |
|
$event = new EventArgs( |
167
|
|
|
[ |
168
|
1 |
|
'form' => $form, |
169
|
1 |
|
'Customer' => $Customer, |
170
|
|
|
], |
171
|
1 |
|
$request |
172
|
|
|
); |
173
|
1 |
|
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_ENTRY_INDEX_COMPLETE, $event); |
174
|
|
|
|
175
|
1 |
|
$activateUrl = $this->generateUrl('entry_activate', ['secret_key' => $Customer->getSecretKey()]); |
176
|
|
|
|
177
|
1 |
|
$activateFlg = $this->BaseInfo->isOptionCustomerActivate(); |
178
|
|
|
|
179
|
|
|
// 仮会員設定が有効な場合は、確認メールを送信し完了画面表示. |
180
|
1 |
|
if ($activateFlg) { |
181
|
|
|
// メール送信 |
182
|
1 |
|
$this->mailService->sendCustomerConfirmMail($Customer, $activateUrl); |
183
|
|
|
|
184
|
1 |
|
if ($event->hasResponse()) { |
185
|
|
|
return $event->getResponse(); |
186
|
|
|
} |
187
|
|
|
|
188
|
1 |
|
log_info('仮会員登録完了画面へリダイレクト'); |
189
|
|
|
|
190
|
1 |
|
return $this->redirectToRoute('entry_complete'); |
191
|
|
|
// 仮会員設定が無効な場合は認証URLへ遷移させ、会員登録を完了させる. |
192
|
|
|
} else { |
193
|
|
|
log_info('本会員登録画面へリダイレクト'); |
194
|
|
|
|
195
|
|
|
return $this->redirect($activateUrl); |
196
|
|
|
} |
197
|
|
|
} |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
return [ |
201
|
3 |
|
'form' => $form->createView(), |
202
|
|
|
]; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* 会員登録完了画面. |
207
|
|
|
* |
208
|
|
|
* @Route("/entry/complete", name="entry_complete") |
209
|
|
|
* @Template("Entry/complete.twig") |
210
|
|
|
*/ |
|
|
|
|
211
|
1 |
|
public function complete() |
212
|
|
|
{ |
213
|
1 |
|
return []; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
|
|
|
|
217
|
|
|
* 会員のアクティベート(本会員化)を行う. |
218
|
|
|
* |
219
|
|
|
* @Route("/entry/activate/{secret_key}", name="entry_activate") |
220
|
|
|
* @Template("Entry/activate.twig") |
221
|
|
|
*/ |
|
|
|
|
222
|
3 |
|
public function activate(Request $request, $secret_key) |
223
|
|
|
{ |
224
|
3 |
|
$errors = $this->recursiveValidator->validate( |
225
|
3 |
|
$secret_key, |
226
|
|
|
[ |
227
|
3 |
|
new Assert\NotBlank(), |
228
|
3 |
|
new Assert\Regex( |
229
|
|
|
[ |
230
|
3 |
|
'pattern' => '/^[a-zA-Z0-9]+$/', |
231
|
|
|
] |
232
|
|
|
), |
233
|
|
|
] |
234
|
|
|
); |
235
|
|
|
|
236
|
3 |
|
if ($request->getMethod() === 'GET' && count($errors) === 0) { |
237
|
2 |
|
log_info('本会員登録開始'); |
238
|
2 |
|
$Customer = $this->customerRepository->getProvisionalCustomerBySecretKey($secret_key); |
239
|
2 |
|
if (is_null($Customer)) { |
240
|
1 |
|
throw new HttpException\NotFoundHttpException(trans('entrycontroller.text.error.registration')); |
241
|
|
|
} |
242
|
|
|
|
243
|
1 |
|
$CustomerStatus = $this->customerStatusRepository->find(CustomerStatus::REGULAR); |
244
|
1 |
|
$Customer->setStatus($CustomerStatus); |
245
|
1 |
|
$this->entityManager->persist($Customer); |
246
|
1 |
|
$this->entityManager->flush(); |
247
|
|
|
|
248
|
1 |
|
log_info('本会員登録完了'); |
249
|
|
|
|
250
|
1 |
|
$event = new EventArgs( |
251
|
|
|
[ |
252
|
1 |
|
'Customer' => $Customer, |
253
|
|
|
], |
254
|
1 |
|
$request |
255
|
|
|
); |
256
|
1 |
|
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_ENTRY_ACTIVATE_COMPLETE, $event); |
257
|
|
|
|
258
|
|
|
// メール送信 |
259
|
1 |
|
$this->mailService->sendCustomerCompleteMail($Customer); |
260
|
|
|
|
261
|
|
|
// 本会員登録してログイン状態にする |
262
|
1 |
|
$token = new UsernamePasswordToken($Customer, null, 'customer', ['ROLE_USER']); |
263
|
1 |
|
$this->tokenStorage->setToken($token); |
264
|
|
|
|
265
|
1 |
|
log_info('ログイン済に変更', [$this->getUser()->getId()]); |
266
|
|
|
|
267
|
1 |
|
return []; |
268
|
|
|
} else { |
269
|
1 |
|
throw new HttpException\AccessDeniedHttpException(trans('entrycontroller.text.error.authorization')); |
270
|
|
|
} |
271
|
|
|
} |
272
|
|
|
} |
273
|
|
|
|