source: branches/version-2_13-dev/data/class/pages/forgot/LC_Page_Forgot.php @ 23605

Revision 23605, 12.3 KB checked in by kimoto, 10 years ago (diff)

#2448 typo修正・ソース整形・ソースコメントの改善 for 2.13.3

Scrutinizer Auto-Fixes

This patch was automatically generated as part of the following inspection:
 https://scrutinizer-ci.com/g/nobuhiko/EC-CUBE/inspections/d8722894-69a6-4b1b-898d-43618035c60d

Enabled analysis tools:

  • PHP Analyzer
  • PHP PDepend
  • PHP Similarity Analyzer
  • PHP Change Tracking Analyzer
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2014 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
24require_once CLASS_EX_REALDIR . 'page_extends/LC_Page_Ex.php';
25
26/**
27 * パスワード発行 のページクラス.
28 *
29 * @package Page
30 * @author LOCKON CO.,LTD.
31 * @version $Id$
32 */
33class LC_Page_Forgot extends LC_Page_Ex
34{
35    /** フォームパラメーターの配列 */
36    public $objFormParam;
37
38    /** 秘密の質問の答え */
39    public $arrReminder;
40
41    /** 変更後パスワード */
42    public $temp_password;
43
44    /** エラーメッセージ */
45    public $errmsg;
46
47    /**
48     * Page を初期化する.
49     *
50     * @return void
51     */
52    public function init()
53    {
54        $this->skip_load_page_layout = true;
55        parent::init();
56        $this->tpl_title = 'パスワードを忘れた方';
57        $this->tpl_mainpage = 'forgot/index.tpl';
58        $this->tpl_mainno = '';
59        $masterData = new SC_DB_MasterData_Ex();
60        $this->arrReminder = $masterData->getMasterData('mtb_reminder');
61        $this->device_type = SC_Display_Ex::detectDevice();
62        $this->httpCacheControl('nocache');
63        // デフォルトログインアドレスロード
64        $objCookie = new SC_Cookie_Ex();
65        $this->tpl_login_email = $objCookie->getCookie('login_email');
66    }
67
68    /**
69     * Page のプロセス.
70     *
71     * @return void
72     */
73    public function process()
74    {
75        parent::process();
76        $this->action();
77        $this->sendResponse();
78    }
79
80    /**
81     * Page のアクション.
82     *
83     * @return void
84     */
85    public function action()
86    {
87        // パラメーター管理クラス
88        $objFormParam = new SC_FormParam_Ex();
89
90        switch ($this->getMode()) {
91            case 'mail_check':
92                $this->lfInitMailCheckParam($objFormParam, $this->device_type);
93                $objFormParam->setParam($_POST);
94                $objFormParam->convParam();
95                $objFormParam->toLower('email');
96                $this->arrForm = $objFormParam->getHashArray();
97                $this->arrErr = $objFormParam->checkError();
98                if (SC_Utils_Ex::isBlank($this->arrErr)) {
99                    $this->errmsg = $this->lfCheckForgotMail($this->arrForm, $this->arrReminder);
100                    if (SC_Utils_Ex::isBlank($this->errmsg)) {
101                        $this->tpl_mainpage = 'forgot/secret.tpl';
102                    }
103                }
104                break;
105            case 'secret_check':
106                $this->lfInitSecretCheckParam($objFormParam, $this->device_type);
107                $objFormParam->setParam($_POST);
108                $objFormParam->convParam();
109                $objFormParam->toLower('email');
110                $this->arrForm = $objFormParam->getHashArray();
111                $this->arrErr = $objFormParam->checkError();
112                if (SC_Utils_Ex::isBlank($this->arrErr)) {
113                    $this->errmsg = $this->lfCheckForgotSecret($this->arrForm, $this->arrReminder);
114                    if (SC_Utils_Ex::isBlank($this->errmsg)) {
115                        // 完了ページへ移動する
116                        $this->tpl_mainpage = 'forgot/complete.tpl';
117                        // transactionidを更新させたいので呼び出し元(ログインフォーム側)をリロード。
118                        $this->tpl_onload .= 'opener.location.reload(true);';
119                    } else {
120                        // 秘密の答えが一致しなかった
121                        $this->tpl_mainpage = 'forgot/secret.tpl';
122                    }
123                } else {
124                    // 入力値エラー
125                    $this->tpl_mainpage = 'forgot/secret.tpl';
126                }
127                break;
128            default:
129                break;
130        }
131
132        // ポップアップ用テンプレート設定
133        if ($this->device_type == DEVICE_TYPE_PC) {
134            $this->setTemplate($this->tpl_mainpage);
135        }
136
137    }
138
139    /**
140     * メールアドレス・名前確認
141     *
142     * @param  array  $arrForm     フォーム入力値
143     * @param  array  $arrReminder リマインダー質問リスト
144     * @return string エラー文字列 問題が無ければNULL
145     */
146    public function lfCheckForgotMail(&$arrForm, &$arrReminder)
147    {
148        $errmsg = NULL;
149        $objQuery =& SC_Query_Ex::getSingletonInstance();
150        $where = '(email = ? OR email_mobile = ?) AND name01 = ? AND name02 = ? AND del_flg = 0';
151        $arrVal = array($arrForm['email'], $arrForm['email'], $arrForm['name01'], $arrForm['name02']);
152        $result = $objQuery->select('reminder, status', 'dtb_customer', $where, $arrVal);
153        if (isset($result[0]['reminder']) and isset($arrReminder[$result[0]['reminder']])) {
154            // 会員状態の確認
155            if ($result[0]['status'] == '2') {
156                // 正会員
157                $arrForm['reminder'] = $result[0]['reminder'];
158            } elseif ($result[0]['status'] == '1') {
159                // 仮会員
160                $errmsg = 'ご入力のemailアドレスは現在仮登録中です。<br/>登録の際にお送りしたメールのURLにアクセスし、<br/>本会員登録をお願いします。';
161            }
162        } else {
163            $errmsg = 'お名前に間違いがあるか、このメールアドレスは登録されていません。';
164        }
165
166        return $errmsg;
167    }
168
169    /**
170     * メールアドレス確認におけるパラメーター情報の初期化
171     *
172     * @param  array $objFormParam フォームパラメータークラス
173     * @param  array $device_type  デバイスタイプ
174     * @return void
175     */
176    public function lfInitMailCheckParam(&$objFormParam, $device_type)
177    {
178        $objFormParam->addParam('お名前(姓)', 'name01', STEXT_LEN, 'aKV', array('EXIST_CHECK', 'NO_SPTAB', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
179        $objFormParam->addParam('お名前(名)', 'name02', STEXT_LEN, 'aKV', array('EXIST_CHECK', 'NO_SPTAB', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
180        if ($device_type === DEVICE_TYPE_MOBILE) {
181            $objFormParam->addParam('メールアドレス', 'email', null, 'a', array('EXIST_CHECK', 'EMAIL_CHECK', 'NO_SPTAB', 'EMAIL_CHAR_CHECK', 'MOBILE_EMAIL_CHECK'));
182        } else {
183            $objFormParam->addParam('メールアドレス', 'email', null, 'a', array('NO_SPTAB', 'EXIST_CHECK', 'EMAIL_CHECK', 'SPTAB_CHECK', 'EMAIL_CHAR_CHECK'));
184        }
185
186        return;
187    }
188
189    /**
190     * 秘密の質問確認
191     *
192     * @param  array  $arrForm     フォーム入力値
193     * @param  array  $arrReminder リマインダー質問リスト
194     * @return string エラー文字列 問題が無ければNULL
195     */
196    public function lfCheckForgotSecret(&$arrForm, &$arrReminder)
197    {
198        $errmsg = '';
199        $objQuery =& SC_Query_Ex::getSingletonInstance();
200        $cols = 'customer_id, reminder, reminder_answer, salt';
201        $table = 'dtb_customer';
202        $where = '(email = ? OR email_mobile = ?)'
203                    . ' AND name01 = ? AND name02 = ?'
204                    . ' AND status = 2 AND del_flg = 0';
205        $arrVal = array($arrForm['email'], $arrForm['email'],
206                            $arrForm['name01'], $arrForm['name02']);
207        $result = $objQuery->select($cols, $table, $where, $arrVal);
208        if (isset($result[0]['reminder']) and isset($arrReminder[$result[0]['reminder']])
209                and $result[0]['reminder'] == $arrForm['reminder']) {
210            $is_authorized = false;
211            if (empty($result[0]['salt'])) {
212                // 旧バージョン(2.11未満)からの移行を考慮
213                if ($result[0]['reminder_answer'] == $arrForm['reminder_answer']) {
214                    $is_authorized = true;
215                }
216            } elseif (SC_Utils_Ex::sfIsMatchHashPassword($arrForm['reminder_answer'],
217                    $result[0]['reminder_answer'], $result[0]['salt'])) {
218                $is_authorized = true;
219            }
220
221            if ($is_authorized) {
222                // 秘密の答えが一致
223                // 新しいパスワードを設定する
224                $new_password = GC_Utils_Ex::gfMakePassword(8);
225                if (FORGOT_MAIL == 1) {
226                    // メールで変更通知をする
227                    $objDb = new SC_Helper_DB_Ex();
228                    $CONF = $objDb->sfGetBasisData();
229                    $this->lfSendMail($CONF, $arrForm['email'], $arrForm['name01'], $new_password);
230                }
231                $sqlval = array();
232                $sqlval['password'] = $new_password;
233                SC_Helper_Customer_Ex::sfEditCustomerData($sqlval, $result[0]['customer_id']);
234                $arrForm['new_password'] = $new_password;
235            } else {
236                // 秘密の答えが一致しなかった
237                $errmsg = '秘密の質問が一致しませんでした。';
238            }
239        } else {
240            //不正なアクセス リマインダー値が前画面と異なる。
241            // 新リファクタリング基準ではここで遷移は不許可なのでエラー表示
242            //SC_Utils_Ex::sfDispSiteError(PAGE_ERROR, '', true);
243            $errmsg = '秘密の質問が一致しませんでした。';
244        }
245
246        return $errmsg;
247    }
248
249    /**
250     * 秘密の質問確認におけるパラメーター情報の初期化
251     *
252     * @param  SC_FormParam_Ex $objFormParam フォームパラメータークラス
253     * @param  array $device_type  デバイスタイプ
254     * @return void
255     */
256    public function lfInitSecretCheckParam(&$objFormParam, $device_type)
257    {
258        // メールチェックと同等のチェックを再度行う
259        $this->lfInitMailCheckParam($objFormParam, $device_type);
260        // 秘密の質問チェックの追加
261        $objFormParam->addParam('パスワード確認用の質問', 'reminder', STEXT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK'));
262        $objFormParam->addParam('パスワード確認用の質問の答え', 'reminder_answer', STEXT_LEN, 'aKV', array('EXIST_CHECK', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
263
264        return;
265    }
266
267    /**
268     * パスワード変更お知らせメールを送信する.
269     *
270     * @param  array  $CONF          店舗基本情報の配列
271     * @param  string $email         送信先メールアドレス
272     * @param  string $customer_name 送信先氏名
273     * @param  string $new_password  変更後の新パスワード
274     * @return void
275     *
276     * FIXME: メールテンプレート編集の方に足すのが望ましい
277     */
278    public function lfSendMail(&$CONF, $email, $customer_name, $new_password)
279    {
280        // パスワード変更お知らせメール送信
281        $objMailText = new SC_SiteView_Ex(false);
282        $objMailText->setPage($this);
283        $objMailText->assign('customer_name', $customer_name);
284        $objMailText->assign('new_password', $new_password);
285        $toCustomerMail = $objMailText->fetch('mail_templates/forgot_mail.tpl');
286
287        $objHelperMail = new SC_Helper_Mail_Ex();
288        $objHelperMail->setPage($this);
289
290        // メール送信オブジェクトによる送信処理
291        $objMail = new SC_SendMail_Ex();
292        $objMail->setItem(
293            '', //宛先
294            $objHelperMail->sfMakeSubject('パスワードを変更いたしました。'),
295            $toCustomerMail, //本文
296            $CONF['email03'], //配送元アドレス
297            $CONF['shop_name'], // 配送元名
298            $CONF['email03'], // reply to
299            $CONF['email04'], //return_path
300            $CONF['email04'] // errors_to
301            );
302        $objMail->setTo($email, $customer_name . ' 様');
303        $objMail->sendMail();
304
305        return;
306    }
307}
Note: See TracBrowser for help on using the repository browser.