|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of EC-CUBE |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved. |
|
6
|
|
|
* |
|
7
|
|
|
* http://www.lockon.co.jp/ |
|
8
|
|
|
* |
|
9
|
|
|
* This program is free software; you can redistribute it and/or |
|
10
|
|
|
* modify it under the terms of the GNU General Public License |
|
11
|
|
|
* as published by the Free Software Foundation; either version 2 |
|
12
|
|
|
* of the License, or (at your option) any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU General Public License |
|
20
|
|
|
* along with this program; if not, write to the Free Software |
|
21
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
namespace Eccube\Controller; |
|
26
|
|
|
|
|
27
|
|
|
use Eccube\Application; |
|
28
|
|
|
use Eccube\Entity\Master\CustomerStatus; |
|
29
|
|
|
use Eccube\Event\EccubeEvents; |
|
30
|
|
|
use Eccube\Event\EventArgs; |
|
31
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
32
|
|
|
use Symfony\Component\HttpKernel\Exception as HttpException; |
|
33
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; |
|
34
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
|
35
|
|
|
|
|
36
|
|
|
class EntryController extends AbstractController |
|
|
|
|
|
|
37
|
|
|
{ |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* 会員登録画面. |
|
41
|
|
|
* |
|
42
|
|
|
* @param Application $app |
|
43
|
|
|
* @param Request $request |
|
|
|
|
|
|
44
|
5 |
|
* @return \Symfony\Component\HttpFoundation\Response |
|
45
|
|
|
*/ |
|
46
|
|
|
public function index(Application $app, Request $request) |
|
47
|
|
|
{ |
|
48
|
|
|
/** @var $Customer \Eccube\Entity\Customer */ |
|
49
|
|
|
$Customer = $app['eccube.repository.customer']->newCustomer(); |
|
50
|
|
|
|
|
51
|
|
|
/* @var $builder \Symfony\Component\Form\FormBuilderInterface */ |
|
52
|
|
|
$builder = $app['form.factory']->createBuilder('entry', $Customer); |
|
53
|
|
|
|
|
54
|
|
|
$event = new EventArgs( |
|
55
|
|
|
array( |
|
|
|
|
|
|
56
|
3 |
|
'builder' => $builder, |
|
57
|
3 |
|
'Customer' => $Customer |
|
58
|
|
|
), |
|
59
|
|
|
$request |
|
60
|
|
|
); |
|
61
|
|
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_ENTRY_INDEX_INITIALIZE, $event); |
|
62
|
1 |
|
|
|
63
|
1 |
|
/* @var $form \Symfony\Component\Form\FormInterface */ |
|
64
|
|
|
$form = $builder->getForm(); |
|
65
|
|
|
|
|
66
|
2 |
|
$form->handleRequest($request); |
|
67
|
|
|
|
|
68
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
|
69
|
|
|
switch ($request->get('mode')) { |
|
70
|
|
View Code Duplication |
case 'confirm': |
|
|
|
|
|
|
71
|
|
|
$builder->setAttribute('freeze', true); |
|
72
|
|
|
$form = $builder->getForm(); |
|
73
|
|
|
$form->handleRequest($request); |
|
74
|
|
|
|
|
75
|
|
|
return $app->render('Entry/confirm.twig', array( |
|
76
|
|
|
'form' => $form->createView(), |
|
77
|
|
|
)); |
|
78
|
|
|
|
|
79
|
|
|
case 'complete': |
|
80
|
|
|
$Customer |
|
81
|
|
|
->setSalt( |
|
82
|
|
|
$app['eccube.repository.customer']->createSalt(5) |
|
83
|
|
|
) |
|
84
|
|
|
->setPassword( |
|
85
|
|
|
$app['eccube.repository.customer']->encryptPassword($app, $Customer) |
|
86
|
|
|
) |
|
87
|
|
|
->setSecretKey( |
|
88
|
|
|
$app['eccube.repository.customer']->getUniqueSecretKey($app) |
|
89
|
|
|
); |
|
90
|
|
|
|
|
91
|
|
|
$CustomerAddress = new \Eccube\Entity\CustomerAddress(); |
|
92
|
|
|
$CustomerAddress |
|
93
|
1 |
|
->setFromCustomer($Customer); |
|
94
|
|
|
|
|
95
|
|
|
$app['orm.em']->persist($Customer); |
|
96
|
|
|
$app['orm.em']->persist($CustomerAddress); |
|
97
|
|
|
$app['orm.em']->flush(); |
|
98
|
|
|
|
|
99
|
|
|
$event = new EventArgs(array( |
|
100
|
|
|
'form' => $form, |
|
101
|
|
|
'Customer' => $Customer, |
|
102
|
|
|
'CustomerAddress' => $CustomerAddress, |
|
103
|
|
|
), $request |
|
104
|
|
|
); |
|
105
|
3 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_ENTRY_INDEX_COMPLETE, $event); |
|
106
|
3 |
|
|
|
107
|
|
|
$activateUrl = $app->url('entry_activate', array('secret_key' => $Customer->getSecretKey())); |
|
108
|
5 |
|
|
|
109
|
|
|
/** @var $BaseInfo \Eccube\Entity\BaseInfo */ |
|
110
|
|
|
$BaseInfo = $app['eccube.repository.base_info']->get(); |
|
111
|
|
|
$activateFlg = $BaseInfo->getOptionCustomerActivate(); |
|
112
|
|
|
|
|
113
|
|
|
// 仮会員設定が有効な場合は、確認メールを送信し完了画面表示. |
|
114
|
|
|
if ($activateFlg) { |
|
115
|
|
|
// メール送信 |
|
116
|
1 |
|
$app['eccube.service.mail']->sendCustomerConfirmMail($Customer, $activateUrl); |
|
117
|
|
|
|
|
118
|
|
|
if ($event->hasResponse()) { |
|
119
|
1 |
|
return $event->getResponse(); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
return $app->redirect($app->url('entry_complete')); |
|
123
|
|
|
// 仮会員設定が無効な場合は認証URLへ遷移させ、会員登録を完了させる. |
|
124
|
|
|
} else { |
|
125
|
|
|
return $app->redirect($activateUrl); |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
3 |
|
|
|
130
|
|
|
return $app->render('Entry/index.twig', array( |
|
131
|
|
|
'form' => $form->createView(), |
|
132
|
|
|
)); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
3 |
|
* 会員登録完了画面. |
|
137
|
|
|
* |
|
138
|
|
|
* @param Application $app |
|
139
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
|
140
|
|
|
*/ |
|
141
|
|
|
public function complete(Application $app) |
|
142
|
|
|
{ |
|
143
|
|
|
return $app->render('Entry/complete.twig', array()); |
|
144
|
|
|
} |
|
145
|
2 |
|
|
|
146
|
|
|
/** |
|
|
|
|
|
|
147
|
|
|
* 会員のアクティベート(本会員化)を行う. |
|
148
|
|
|
* |
|
149
|
|
|
* @param Application $app |
|
150
|
|
|
* @param Request $request |
|
|
|
|
|
|
151
|
|
|
* @param $secret_key |
|
|
|
|
|
|
152
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
|
153
|
|
|
*/ |
|
154
|
|
|
public function activate(Application $app, Request $request, $secret_key) |
|
155
|
|
|
{ |
|
156
|
|
|
$errors = $app['validator']->validateValue($secret_key, array( |
|
|
|
|
|
|
157
|
|
|
new Assert\NotBlank(), |
|
158
|
|
|
new Assert\Regex(array( |
|
159
|
|
|
'pattern' => '/^[a-zA-Z0-9]+$/', |
|
160
|
|
|
)) |
|
161
|
|
|
) |
|
162
|
|
|
); |
|
163
|
3 |
|
|
|
164
|
|
|
if ($request->getMethod() === 'GET' && count($errors) === 0) { |
|
165
|
|
|
try { |
|
166
|
|
|
$Customer = $app['eccube.repository.customer'] |
|
167
|
|
|
->getNonActiveCustomerBySecretKey($secret_key); |
|
168
|
|
|
} catch (\Exception $e) { |
|
169
|
|
|
throw new HttpException\NotFoundHttpException('※ 既に会員登録が完了しているか、無効なURLです。'); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
$CustomerStatus = $app['eccube.repository.customer_status']->find(CustomerStatus::ACTIVE); |
|
173
|
|
|
$Customer->setStatus($CustomerStatus); |
|
174
|
|
|
$app['orm.em']->persist($Customer); |
|
175
|
|
|
$app['orm.em']->flush(); |
|
176
|
|
|
|
|
177
|
|
|
$event = new EventArgs( |
|
178
|
|
|
array( |
|
|
|
|
|
|
179
|
|
|
'Customer' => $Customer |
|
180
|
|
|
), |
|
181
|
|
|
$request |
|
182
|
|
|
); |
|
183
|
|
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_ENTRY_ACTIVATE_COMPLETE, $event); |
|
184
|
|
|
|
|
185
|
|
|
// メール送信 |
|
186
|
|
|
$app['eccube.service.mail']->sendCustomerCompleteMail($Customer); |
|
187
|
|
|
|
|
188
|
|
|
// 本会員登録してログイン状態にする |
|
189
|
|
|
$token = new UsernamePasswordToken($Customer, null, 'customer', array('ROLE_USER')); |
|
190
|
|
|
$this->getSecurity($app)->setToken($token); |
|
191
|
|
|
|
|
192
|
|
|
return $app->render('Entry/activate.twig'); |
|
193
|
|
|
} else { |
|
194
|
|
|
throw new HttpException\AccessDeniedHttpException('不正なアクセスです。'); |
|
195
|
|
|
} |
|
196
|
|
|
} |
|
197
|
|
|
} |
|
198
|
|
|
|