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 Symfony\Component\HttpFoundation\Request; |
30
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
31
|
|
|
use Symfony\Component\HttpKernel\Exception as HttpException; |
32
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; |
33
|
|
|
|
34
|
|
|
class EntryController extends AbstractController |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Index |
39
|
|
|
* |
40
|
|
|
* @param Application $app |
41
|
|
|
* @param Request $request |
|
|
|
|
42
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
43
|
|
|
*/ |
44
|
5 |
|
public function index(Application $app, Request $request) |
45
|
|
|
{ |
46
|
|
|
/** @var $Customer \Eccube\Entity\Customer */ |
47
|
|
|
$Customer = $app['eccube.repository.customer']->newCustomer(); |
48
|
|
|
|
49
|
|
|
/* @var $builder \Symfony\Component\Form\FormBuilderInterface */ |
50
|
|
|
$builder = $app['form.factory']->createBuilder('entry', $Customer); |
51
|
|
|
/* @var $form \Symfony\Component\Form\FormInterface */ |
52
|
|
|
$form = $builder->getForm(); |
53
|
|
|
$form->handleRequest($request); |
54
|
|
|
|
55
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
56
|
3 |
|
switch ($request->get('mode')) { |
57
|
3 |
View Code Duplication |
case 'confirm': |
|
|
|
|
58
|
|
|
$builder->setAttribute('freeze', true); |
59
|
|
|
$form = $builder->getForm(); |
60
|
|
|
$form->handleRequest($request); |
61
|
|
|
|
62
|
1 |
|
return $app['twig']->render('Entry/confirm.twig', array( |
63
|
1 |
|
'form' => $form->createView(), |
64
|
|
|
)); |
65
|
|
|
|
66
|
2 |
|
case 'complete': |
67
|
|
|
$Customer |
68
|
|
|
->setSalt( |
69
|
|
|
$app['eccube.repository.customer']->createSalt(5) |
70
|
|
|
) |
71
|
|
|
->setPassword( |
72
|
|
|
$app['eccube.repository.customer']->encryptPassword($app, $Customer) |
73
|
|
|
) |
74
|
|
|
->setSecretKey( |
75
|
|
|
$app['eccube.repository.customer']->getUniqueSecretKey($app) |
76
|
|
|
); |
77
|
|
|
|
78
|
|
|
$CustomerAddress = new \Eccube\Entity\CustomerAddress(); |
79
|
|
|
$CustomerAddress |
80
|
|
|
->setFromCustomer($Customer); |
81
|
|
|
|
82
|
|
|
$app['orm.em']->persist($Customer); |
83
|
|
|
$app['orm.em']->persist($CustomerAddress); |
84
|
|
|
$app['orm.em']->flush(); |
85
|
|
|
|
86
|
|
|
$activateUrl = $app->url('entry_activate', array('secret_key' => $Customer->getSecretKey())); |
87
|
|
|
|
88
|
|
|
/** @var $BaseInfo \Eccube\Entity\BaseInfo */ |
89
|
|
|
$BaseInfo = $app['eccube.repository.base_info']->get(); |
90
|
|
|
$activateFlg = $BaseInfo->getOptionCustomerActivate(); |
91
|
|
|
|
92
|
|
|
// 仮会員設定が有効な場合は、確認メールを送信し完了画面表示. |
93
|
1 |
|
if ($activateFlg) { |
94
|
|
|
// メール送信 |
95
|
|
|
$app['eccube.service.mail']->sendCustomerConfirmMail($Customer, $activateUrl); |
96
|
|
|
|
97
|
|
|
return $app->redirect($app->url('entry_complete')); |
98
|
|
|
// 仮会員設定が無効な場合は認証URLへ遷移させ、会員登録を完了させる. |
99
|
|
|
} else { |
100
|
|
|
return $app->redirect($activateUrl); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
3 |
|
return $app['view']->render('Entry/index.twig', array( |
106
|
3 |
|
'form' => $form->createView(), |
107
|
|
|
)); |
108
|
5 |
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Complete |
112
|
|
|
* |
113
|
|
|
* @param Application $app |
114
|
|
|
* @return mixed |
115
|
|
|
*/ |
116
|
1 |
|
public function complete(Application $app) |
117
|
|
|
{ |
118
|
|
|
return $app['view']->render('Entry/complete.twig', array()); |
119
|
1 |
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* 会員のアクティベート(本会員化)を行う |
123
|
|
|
* |
124
|
|
|
* @param Application $app |
125
|
|
|
* @param Request $request |
|
|
|
|
126
|
|
|
* @param string $secret_key |
|
|
|
|
127
|
|
|
* @return mixed |
128
|
|
|
*/ |
129
|
3 |
|
public function activate(Application $app, Request $request, $secret_key) |
130
|
|
|
{ |
131
|
|
|
$errors = $app['validator']->validateValue($secret_key, array( |
|
|
|
|
132
|
|
|
new Assert\NotBlank(), |
133
|
|
|
new Assert\Regex(array( |
134
|
|
|
'pattern' => '/^[a-zA-Z0-9]+$/', |
135
|
|
|
)) |
136
|
3 |
|
) |
137
|
|
|
); |
138
|
|
|
|
139
|
|
|
if ($request->getMethod() === 'GET' && count($errors) === 0) { |
140
|
|
|
try { |
141
|
|
|
$Customer = $app['eccube.repository.customer'] |
142
|
|
|
->getNonActiveCustomerBySecretKey($secret_key); |
143
|
|
|
} catch (\Exception $e) { |
144
|
|
|
throw new HttpException\NotFoundHttpException('※ 既に会員登録が完了しているか、無効なURLです。'); |
145
|
2 |
|
} |
146
|
|
|
|
147
|
|
|
$CustomerStatus = $app['eccube.repository.customer_status']->find(CustomerStatus::ACTIVE); |
148
|
|
|
$Customer->setStatus($CustomerStatus); |
149
|
|
|
$app['orm.em']->persist($Customer); |
150
|
|
|
$app['orm.em']->flush(); |
151
|
|
|
|
152
|
|
|
// メール送信 |
153
|
|
|
$app['eccube.service.mail']->sendCustomerCompleteMail($Customer); |
154
|
|
|
|
155
|
|
|
// 本会員登録してログイン状態にする |
156
|
|
|
$token = new UsernamePasswordToken($Customer, null, 'customer', array('ROLE_USER')); |
157
|
|
|
$this->getSecurity($app)->setToken($token); |
158
|
|
|
|
159
|
|
|
return $app['view']->render('Entry/activate.twig'); |
160
|
|
|
} else { |
161
|
|
|
throw new HttpException\AccessDeniedHttpException('不正なアクセスです。'); |
162
|
|
|
} |
163
|
3 |
|
} |
164
|
|
|
} |
165
|
|
|
|