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

Revision 23057, 12.2 KB checked in by Seasoft, 11 years ago (diff)

#2327 (SC_Helper_PageLayout#sfGetPageLayout ページ情報が取得できない場合の動作が不定)

  • 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        $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    function process()
74    {
75        parent::process();
76        $this->action();
77        $this->sendResponse();
78    }
79
80    /**
81     * Page のアクション.
82     *
83     * @return void
84     */
85    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    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            } else if ($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    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    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            }
217            elseif (SC_Utils_Ex::sfIsMatchHashPassword($arrForm['reminder_answer'],
218                    $result[0]['reminder_answer'], $result[0]['salt'])) {
219                $is_authorized = true;
220            }
221
222            if ($is_authorized) {
223                // 秘密の答えが一致
224                // 新しいパスワードを設定する
225                $new_password = GC_Utils_Ex::gfMakePassword(8);
226                if (FORGOT_MAIL == 1) {
227                    // メールで変更通知をする
228                    $objDb = new SC_Helper_DB_Ex();
229                    $CONF = $objDb->sfGetBasisData();
230                    $this->lfSendMail($CONF, $arrForm['email'], $arrForm['name01'], $new_password);
231                }
232                $sqlval = array();
233                $sqlval['password'] = $new_password;
234                SC_Helper_Customer_Ex::sfEditCustomerData($sqlval, $result[0]['customer_id']);
235                $arrForm['new_password'] = $new_password;
236            } else {
237                // 秘密の答えが一致しなかった
238                $errmsg = '秘密の質問が一致しませんでした。';
239            }
240        } else {
241            //不正なアクセス リマインダー値が前画面と異なる。
242            // 新リファクタリング基準ではここで遷移は不許可なのでエラー表示
243            //SC_Utils_Ex::sfDispSiteError(PAGE_ERROR, '', true);
244            $errmsg = '秘密の質問が一致しませんでした。';
245        }
246
247        return $errmsg;
248    }
249
250    /**
251     * 秘密の質問確認におけるパラメーター情報の初期化
252     *
253     * @param array $objFormParam フォームパラメータークラス
254     * @param array $device_type デバイスタイプ
255     * @return void
256     */
257    function lfInitSecretCheckParam(&$objFormParam, $device_type)
258    {
259        // メールチェックと同等のチェックを再度行う
260        $this->lfInitMailCheckParam($objFormParam, $device_type);
261        // 秘密の質問チェックの追加
262        $objFormParam->addParam('パスワード確認用の質問', 'reminder', STEXT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK'));
263        $objFormParam->addParam('パスワード確認用の質問の答え', 'reminder_answer', STEXT_LEN, 'aKV', array('EXIST_CHECK', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
264
265        return;
266    }
267
268    /**
269     * パスワード変更お知らせメールを送信する.
270     *
271     * @param array $CONF 店舗基本情報の配列
272     * @param string $email 送信先メールアドレス
273     * @param string $customer_name 送信先氏名
274     * @param string $new_password 変更後の新パスワード
275     * @return void
276     *
277     * FIXME: メールテンプレート編集の方に足すのが望ましい
278     */
279    function lfSendMail(&$CONF, $email, $customer_name, $new_password)
280    {
281        // パスワード変更お知らせメール送信
282        $objMailText = new SC_SiteView_Ex(false);
283        $objMailText->setPage($this);
284        $objMailText->assign('customer_name', $customer_name);
285        $objMailText->assign('new_password', $new_password);
286        $toCustomerMail = $objMailText->fetch('mail_templates/forgot_mail.tpl');
287
288        $objHelperMail = new SC_Helper_Mail_Ex();
289        $objHelperMail->setPage($this);
290
291        // メール送信オブジェクトによる送信処理
292        $objMail = new SC_SendMail_Ex();
293        $objMail->setItem(
294            '' //宛先
295            , $objHelperMail->sfMakeSubject('パスワードを変更いたしました。')
296            , $toCustomerMail //本文
297            , $CONF['email03'] //配送元アドレス
298            , $CONF['shop_name'] // 配送元名
299            , $CONF['email03'] // reply to
300            , $CONF['email04'] //return_path
301            , $CONF['email04'] // errors_to
302            );
303        $objMail->setTo($email, $customer_name . ' 様');
304        $objMail->sendMail();
305
306        return;
307    }
308}
Note: See TracBrowser for help on using the repository browser.