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

Revision 22567, 12.4 KB checked in by shutta, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.12.4)
Zend Framework PHP 標準コーディング規約のコーディングスタイルへ準拠。
classおよびfunctionの開始波括弧「{」のスタイルを修正。

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