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

Revision 22857, 12.3 KB checked in by Seasoft, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.13.0)

  • 主に空白・空白行の調整。
  • 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-2013 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    var $objFormParam;
37
38    /** 秘密の質問の答え */
39    var $arrReminder;
40
41    /** 変更後パスワード */
42    var $temp_password;
43
44    /** エラーメッセージ */
45    var $errmsg;
46
47    /**
48     * Page を初期化する.
49     *
50     * @return void
51     */
52    function init()
53    {
54        parent::init();
55        $this->tpl_title = 'パスワードを忘れた方';
56        $this->tpl_mainpage = 'forgot/index.tpl';
57        $this->tpl_mainno = '';
58        $masterData = new SC_DB_MasterData_Ex();
59        $this->arrReminder = $masterData->getMasterData('mtb_reminder');
60        $this->device_type = SC_Display_Ex::detectDevice();
61        $this->httpCacheControl('nocache');
62        // デフォルトログインアドレスロード
63        $objCookie = new SC_Cookie_Ex();
64        $this->tpl_login_email = $objCookie->getCookie('login_email');
65    }
66
67    /**
68     * Page のプロセス.
69     *
70     * @return void
71     */
72    function process()
73    {
74        parent::process();
75        $this->action();
76        $this->sendResponse();
77    }
78
79    /**
80     * Page のアクション.
81     *
82     * @return void
83     */
84    function action()
85    {
86        // パラメーター管理クラス
87        $objFormParam = new SC_FormParam_Ex();
88
89        switch ($this->getMode()) {
90            case 'mail_check':
91                $this->lfInitMailCheckParam($objFormParam, $this->device_type);
92                $objFormParam->setParam($_POST);
93                $objFormParam->convParam();
94                $objFormParam->toLower('email');
95                $this->arrForm = $objFormParam->getHashArray();
96                $this->arrErr = $objFormParam->checkError();
97                if (SC_Utils_Ex::isBlank($this->arrErr)) {
98                    $this->errmsg = $this->lfCheckForgotMail($this->arrForm, $this->arrReminder);
99                    if (SC_Utils_Ex::isBlank($this->errmsg)) {
100                        $this->tpl_mainpage = 'forgot/secret.tpl';
101                    }
102                }
103                break;
104            case 'secret_check':
105                $this->lfInitSecretCheckParam($objFormParam, $this->device_type);
106                $objFormParam->setParam($_POST);
107                $objFormParam->convParam();
108                $objFormParam->toLower('email');
109                $this->arrForm = $objFormParam->getHashArray();
110                $this->arrErr = $objFormParam->checkError();
111                if (SC_Utils_Ex::isBlank($this->arrErr)) {
112                    $this->errmsg = $this->lfCheckForgotSecret($this->arrForm, $this->arrReminder);
113                    if (SC_Utils_Ex::isBlank($this->errmsg)) {
114                        // 完了ページへ移動する
115                        $this->tpl_mainpage = 'forgot/complete.tpl';
116                        // transactionidを更新させたいので呼び出し元(ログインフォーム側)をリロード。
117                        $this->tpl_onload .= 'opener.location.reload(true);';
118                    } else {
119                        // 秘密の答えが一致しなかった
120                        $this->tpl_mainpage = 'forgot/secret.tpl';
121                    }
122                } else {
123                    // 入力値エラー
124                    $this->tpl_mainpage = 'forgot/secret.tpl';
125                }
126                break;
127            default:
128                break;
129        }
130
131        // ポップアップ用テンプレート設定
132        if ($this->device_type == DEVICE_TYPE_PC) {
133            $this->setTemplate($this->tpl_mainpage);
134        }
135
136    }
137
138    /**
139     * メールアドレス・名前確認
140     *
141     * @param array $arrForm フォーム入力値
142     * @param array $arrReminder リマインダー質問リスト
143     * @return string エラー文字列 問題が無ければNULL
144     */
145    function lfCheckForgotMail(&$arrForm, &$arrReminder)
146    {
147        $errmsg = NULL;
148        $objQuery =& SC_Query_Ex::getSingletonInstance();
149        $where = '(email = ? OR email_mobile = ?) AND name01 = ? AND name02 = ? AND del_flg = 0';
150        $arrVal = array($arrForm['email'], $arrForm['email'], $arrForm['name01'], $arrForm['name02']);
151        $result = $objQuery->select('reminder, status', 'dtb_customer', $where, $arrVal);
152        if (isset($result[0]['reminder']) and isset($arrReminder[$result[0]['reminder']])) {
153            // 会員状態の確認
154            if ($result[0]['status'] == '2') {
155                // 正会員
156                $arrForm['reminder'] = $result[0]['reminder'];
157            } else if ($result[0]['status'] == '1') {
158                // 仮会員
159                $errmsg = 'ご入力のemailアドレスは現在仮登録中です。<br/>登録の際にお送りしたメールのURLにアクセスし、<br/>本会員登録をお願いします。';
160            }
161        } else {
162            $errmsg = 'お名前に間違いがあるか、このメールアドレスは登録されていません。';
163        }
164
165        return $errmsg;
166    }
167
168    /**
169     * メールアドレス確認におけるパラメーター情報の初期化
170     *
171     * @param array $objFormParam フォームパラメータークラス
172     * @param array $device_type デバイスタイプ
173     * @return void
174     */
175    function lfInitMailCheckParam(&$objFormParam, $device_type)
176    {
177        $objFormParam->addParam('お名前(姓)', 'name01', STEXT_LEN, 'aKV', array('EXIST_CHECK', 'NO_SPTAB', 'SPTAB_CHECK' ,'MAX_LENGTH_CHECK'));
178        $objFormParam->addParam('お名前(名)', 'name02', STEXT_LEN, 'aKV', array('EXIST_CHECK', 'NO_SPTAB', 'SPTAB_CHECK' , 'MAX_LENGTH_CHECK'));
179        if ($device_type === DEVICE_TYPE_MOBILE) {
180            $objFormParam->addParam('メールアドレス', 'email', null, 'a', array('EXIST_CHECK', 'EMAIL_CHECK', 'NO_SPTAB' ,'EMAIL_CHAR_CHECK', 'MOBILE_EMAIL_CHECK'));
181        } else {
182            $objFormParam->addParam('メールアドレス', 'email', null, 'a', array('NO_SPTAB', 'EXIST_CHECK', 'EMAIL_CHECK', 'SPTAB_CHECK' ,'EMAIL_CHAR_CHECK'));
183        }
184
185        return;
186    }
187
188    /**
189     * 秘密の質問確認
190     *
191     * @param array $arrForm フォーム入力値
192     * @param array $arrReminder リマインダー質問リスト
193     * @return string エラー文字列 問題が無ければNULL
194     */
195    function lfCheckForgotSecret(&$arrForm, &$arrReminder)
196    {
197        $errmsg = '';
198        $objQuery =& SC_Query_Ex::getSingletonInstance();
199        $cols = 'customer_id, reminder, reminder_answer, salt';
200        $table = 'dtb_customer';
201        $where = '(email = ? OR email_mobile = ?)'
202                    . ' AND name01 = ? AND name02 = ?'
203                    . ' AND status = 2 AND del_flg = 0';
204        $arrVal = array($arrForm['email'], $arrForm['email'],
205                            $arrForm['name01'], $arrForm['name02']);
206        $result = $objQuery->select($cols, $table, $where, $arrVal);
207        if (isset($result[0]['reminder']) and isset($arrReminder[$result[0]['reminder']])
208                and $result[0]['reminder'] == $arrForm['reminder']) {
209            $is_authorized = false;
210            if (empty($result[0]['salt'])) {
211                // 旧バージョン(2.11未満)からの移行を考慮
212                if ($result[0]['reminder_answer'] == $arrForm['reminder_answer']) {
213                    $is_authorized = true;
214                }
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 array $objFormParam フォームパラメータークラス
253     * @param array $device_type デバイスタイプ
254     * @return void
255     */
256    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     * @return void
271     */
272    function destroy()
273    {
274        parent::destroy();
275    }
276
277    /**
278     * パスワード変更お知らせメールを送信する.
279     *
280     * @param array $CONF 店舗基本情報の配列
281     * @param string $email 送信先メールアドレス
282     * @param string $customer_name 送信先氏名
283     * @param string $new_password 変更後の新パスワード
284     * @return void
285     *
286     * FIXME: メールテンプレート編集の方に足すのが望ましい
287     */
288    function lfSendMail(&$CONF, $email, $customer_name, $new_password)
289    {
290        // パスワード変更お知らせメール送信
291        $objMailText = new SC_SiteView_Ex(false);
292        $objMailText->setPage($this);
293        $objMailText->assign('customer_name', $customer_name);
294        $objMailText->assign('new_password', $new_password);
295        $toCustomerMail = $objMailText->fetch('mail_templates/forgot_mail.tpl');
296
297        $objHelperMail = new SC_Helper_Mail_Ex();
298        $objHelperMail->setPage($this);
299
300        // メール送信オブジェクトによる送信処理
301        $objMail = new SC_SendMail_Ex();
302        $objMail->setItem(
303            '' //宛先
304            , $objHelperMail->sfMakeSubject('パスワードを変更いたしました。')
305            , $toCustomerMail //本文
306            , $CONF['email03'] //配送元アドレス
307            , $CONF['shop_name'] // 配送元名
308            , $CONF['email03'] // reply to
309            , $CONF['email04'] //return_path
310            , $CONF['email04'] // errors_to
311            );
312        $objMail->setTo($email, $customer_name . ' 様');
313        $objMail->sendMail();
314
315        return;
316    }
317}
Note: See TracBrowser for help on using the repository browser.