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( |
100
|
|
|
array( |
101
|
|
|
'form' => $form, |
102
|
|
|
'Customer' => $Customer, |
103
|
|
|
'CustomerAddress' => $CustomerAddress, |
104
|
|
|
), |
105
|
3 |
|
$request |
106
|
3 |
|
); |
107
|
|
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_ENTRY_INDEX_COMPLETE, $event); |
108
|
5 |
|
|
109
|
|
|
$activateUrl = $app->url('entry_activate', array('secret_key' => $Customer->getSecretKey())); |
110
|
|
|
|
111
|
|
|
/** @var $BaseInfo \Eccube\Entity\BaseInfo */ |
112
|
|
|
$BaseInfo = $app['eccube.repository.base_info']->get(); |
113
|
|
|
$activateFlg = $BaseInfo->getOptionCustomerActivate(); |
114
|
|
|
|
115
|
|
|
// 仮会員設定が有効な場合は、確認メールを送信し完了画面表示. |
116
|
1 |
|
if ($activateFlg) { |
117
|
|
|
// メール送信 |
118
|
|
|
$app['eccube.service.mail']->sendCustomerConfirmMail($Customer, $activateUrl); |
119
|
1 |
|
|
120
|
|
|
if ($event->hasResponse()) { |
121
|
|
|
return $event->getResponse(); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
return $app->redirect($app->url('entry_complete')); |
125
|
|
|
// 仮会員設定が無効な場合は認証URLへ遷移させ、会員登録を完了させる. |
126
|
|
|
} else { |
127
|
|
|
return $app->redirect($activateUrl); |
128
|
|
|
} |
129
|
3 |
|
} |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
return $app->render('Entry/index.twig', array( |
133
|
|
|
'form' => $form->createView(), |
134
|
|
|
)); |
135
|
|
|
} |
136
|
3 |
|
|
137
|
|
|
/** |
138
|
|
|
* 会員登録完了画面. |
139
|
|
|
* |
140
|
|
|
* @param Application $app |
141
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
142
|
|
|
*/ |
143
|
|
|
public function complete(Application $app) |
144
|
|
|
{ |
145
|
2 |
|
return $app->render('Entry/complete.twig', array()); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
|
|
|
|
149
|
|
|
* 会員のアクティベート(本会員化)を行う. |
150
|
|
|
* |
151
|
|
|
* @param Application $app |
152
|
|
|
* @param Request $request |
|
|
|
|
153
|
|
|
* @param $secret_key |
|
|
|
|
154
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
155
|
|
|
*/ |
156
|
|
|
public function activate(Application $app, Request $request, $secret_key) |
157
|
|
|
{ |
158
|
|
|
$errors = $app['validator']->validateValue($secret_key, array( |
|
|
|
|
159
|
|
|
new Assert\NotBlank(), |
160
|
|
|
new Assert\Regex(array( |
161
|
|
|
'pattern' => '/^[a-zA-Z0-9]+$/', |
162
|
|
|
)) |
163
|
3 |
|
) |
164
|
|
|
); |
165
|
|
|
|
166
|
|
|
if ($request->getMethod() === 'GET' && count($errors) === 0) { |
167
|
|
|
try { |
168
|
|
|
$Customer = $app['eccube.repository.customer'] |
169
|
|
|
->getNonActiveCustomerBySecretKey($secret_key); |
170
|
|
|
} catch (\Exception $e) { |
171
|
|
|
throw new HttpException\NotFoundHttpException('※ 既に会員登録が完了しているか、無効なURLです。'); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
$CustomerStatus = $app['eccube.repository.customer_status']->find(CustomerStatus::ACTIVE); |
175
|
|
|
$Customer->setStatus($CustomerStatus); |
176
|
|
|
$app['orm.em']->persist($Customer); |
177
|
|
|
$app['orm.em']->flush(); |
178
|
|
|
|
179
|
|
|
$event = new EventArgs( |
180
|
|
|
array( |
181
|
|
|
'Customer' => $Customer, |
182
|
|
|
), |
183
|
|
|
$request |
184
|
|
|
); |
185
|
|
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_ENTRY_ACTIVATE_COMPLETE, $event); |
186
|
|
|
|
187
|
|
|
// メール送信 |
188
|
|
|
$app['eccube.service.mail']->sendCustomerCompleteMail($Customer); |
189
|
|
|
|
190
|
|
|
// 本会員登録してログイン状態にする |
191
|
|
|
$token = new UsernamePasswordToken($Customer, null, 'customer', array('ROLE_USER')); |
192
|
|
|
$this->getSecurity($app)->setToken($token); |
193
|
|
|
|
194
|
|
|
return $app->render('Entry/activate.twig'); |
195
|
|
|
} else { |
196
|
|
|
throw new HttpException\AccessDeniedHttpException('不正なアクセスです。'); |
197
|
|
|
} |
198
|
|
|
} |
199
|
|
|
} |
200
|
|
|
|