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

Revision 21514, 12.3 KB checked in by Seasoft, 12 years ago (diff)

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

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