Failed Conditions
Push — master ( e86240...46f2fd )
by Ryo
432:07 queued 412:43
created

ForgotController   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 147
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 8

Test Coverage

Coverage 98.25%

Importance

Changes 0
Metric Value
wmc 10
c 0
b 0
f 0
lcom 0
cbo 8
dl 0
loc 147
ccs 56
cts 57
cp 0.9825
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B index() 0 59 4
A complete() 0 4 1
B reset() 0 56 5
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
namespace Eccube\Controller;
25
26
use Eccube\Application;
27
use Eccube\Event\EccubeEvents;
28
use Eccube\Event\EventArgs;
29
use Symfony\Component\HttpFoundation\Request;
30
use Symfony\Component\HttpKernel\Exception as HttpException;
31
use Symfony\Component\Validator\Constraints as Assert;
32
33
class ForgotController extends AbstractController
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
34
{
35
    /**
36
     * パスワードリマインダ.
37
     *
38
     * @param Application $app
39
     * @param Request $request
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
40
     * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
41
     */
42 4
    public function index(Application $app, Request $request)
43
    {
44
45 4
        $builder = $app['form.factory']
46 4
            ->createNamedBuilder('', 'forgot');
47
48 4
        $event = new EventArgs(
49
            array(
50 4
                'builder' => $builder,
51
            ),
52
            $request
53
        );
54 4
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_FORGOT_INDEX_INITIALIZE, $event);
55
56 4
        $form = $builder->getForm();
57 4
        $form->handleRequest($request);
58
59 4
        if ($form->isSubmitted() && $form->isValid()) {
60 2
            $Customer = $app['eccube.repository.customer']
61 2
                ->getActiveCustomerByEmail($form->get('login_email')->getData());
62
63 2
            if (!is_null($Customer)) {
64
                // リセットキーの発行・有効期限の設定
65
                $Customer
66 2
                    ->setResetKey($app['eccube.repository.customer']->getUniqueResetKey($app))
67 2
                    ->setResetExpire(new \DateTime('+' . $app['config']['customer_reset_expire'] .' min'));
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
68
69
                // リセットキーを更新
70 2
                $app['orm.em']->persist($Customer);
71 2
                $app['orm.em']->flush();
72
73 2
                $event = new EventArgs(
74
                    array(
75 2
                        'form' => $form,
76 2
                        'Customer' => $Customer,
77
                    ),
78
                    $request
79
                );
80 2
                $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_FORGOT_INDEX_COMPLETE, $event);
81
82
                // 完了URLの生成
83 2
                $reset_url = $app->url('forgot_reset', array('reset_key' => $Customer->getResetKey()));
84
85
                // メール送信
86 2
                $app['eccube.service.mail']->sendPasswordResetNotificationMail($Customer, $reset_url);
87
88
                // ログ出力
89 2
                $app['monolog']->addInfo(
90 2
                    'send reset password mail to:'  . "{$Customer->getId()} {$Customer->getEmail()} {$request->getClientIp()}"
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
Coding Style introduced by
Variable "Customer" is not in valid camel caps format
Loading history...
91
                );
92
            }
93
94 2
            return $app->redirect($app->url('forgot_complete'));
95
        }
96
97 2
        return $app->render('Forgot/index.twig', array(
98 2
            'form' => $form->createView(),
99
        ));
100
    }
101
102
    /**
103
     * パスワードリマインダ完了画面.
104
     *
105
     * @param Application $app
106
     * @param Request $request
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
107
     * @return \Symfony\Component\HttpFoundation\Response
108
     */
109 1
    public function complete(Application $app, Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
110
    {
111 1
        return $app->render('Forgot/complete.twig');
112
    }
113
114
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$reset_key" missing
Loading history...
115
     * パスワード再発行実行画面.
116
     *
117
     * @param Application $app
118
     * @param Request $request
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
119
     * @param $reset_key
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
120
     * @return \Symfony\Component\HttpFoundation\Response
121
     */
122 4
    public function reset(Application $app, Request $request, $reset_key)
123
    {
124 4
        $errors = $app['validator']->validateValue($reset_key, array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
125 4
            new Assert\NotBlank(),
126 4
            new Assert\Regex(array(
127 4
                'pattern' => '/^[a-zA-Z0-9]+$/',
128
            )))
129
        );
130
131 4
        if ('GET' === $request->getMethod()
132 4
                && count($errors) === 0) {
133
            try {
134 3
                $Customer = $app['eccube.repository.customer']
135 3
                    ->getActiveCustomerByResetKey($reset_key);
136 1
            } catch (\Exception $e) {
137 1
                throw new HttpException\NotFoundHttpException('有効期限が切れているか、無効なURLです。');
138
            }
139
140
            // パスワードの発行・更新
141 2
            $pass = $app['eccube.repository.customer']->getResetPassword();
142 2
            $Customer->setPassword($pass);
143
144
            // 発行したパスワードの暗号化
145 2
            if ($Customer->getSalt() === null) {
146
                $Customer->setSalt($app['eccube.repository.customer']->createSalt(5));
147
            }
148 2
            $encPass = $app['eccube.repository.customer']->encryptPassword($app, $Customer);
149 2
            $Customer->setPassword($encPass);
150
151 2
            $Customer->setResetKey(null);
152
153
            // パスワードを更新
154 2
            $app['orm.em']->persist($Customer);
155 2
            $app['orm.em']->flush();
156
157 2
            $event = new EventArgs(
158
                array(
159 2
                    'Customer' => $Customer,
160
                ),
161
                $request
162
            );
163 2
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_FORGOT_RESET_COMPLETE, $event);
164
165
            // メール送信
166 2
            $app['eccube.service.mail']->sendPasswordResetCompleteMail($Customer, $pass);
167
168
            // ログ出力
169 2
            $app['monolog']->addInfo(
170 2
                'reset password complete:' . "{$Customer->getId()} {$Customer->getEmail()} {$request->getClientIp()}"
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
Coding Style introduced by
Variable "Customer" is not in valid camel caps format
Loading history...
171
            );
172
        } else {
173 1
            throw new HttpException\AccessDeniedHttpException('不正なアクセスです。');
174
        }
175
176 2
        return $app->render('Forgot/reset.twig');
177
    }
178
179
}
180