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