source: branches/version-2_12-dev/data/class/pages/frontparts/LC_Page_FrontParts_LoginCheck.php @ 21804

Revision 21804, 10.2 KB checked in by h_yoshimoto, 12 years ago (diff)

#1791 htmlspecialchars処理を追加

  • 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 * TODO mypage/LC_Page_Mypage_LoginCheck と統合
31 *
32 * @package Page
33 * @author LOCKON CO.,LTD.
34 * @version $Id:LC_Page_FrontParts_LoginCheck.php 15532 2007-08-31 14:39:46Z nanasess $
35 */
36class LC_Page_FrontParts_LoginCheck extends LC_Page_Ex {
37
38    // }}}
39    // {{{ functions
40
41    /**
42     * Page を初期化する.
43     *
44     * @return void
45     */
46    function init() {
47        parent::init();
48
49    }
50
51    /**
52     * Page のプロセス.
53     *
54     * @return void
55     */
56    function process() {
57        $this->action();
58        $this->sendResponse();
59    }
60
61    /**
62     * Page のアクション.
63     *
64     * @return void
65     */
66    function action() {
67
68        // 会員管理クラス
69        $objCustomer = new SC_Customer_Ex();
70        // クッキー管理クラス
71        $objCookie = new SC_Cookie_Ex(COOKIE_EXPIRE);
72        // パラメーター管理クラス
73        $objFormParam = new SC_FormParam_Ex();
74
75        // パラメーター情報の初期化
76        $this->lfInitParam($objFormParam);
77
78        // リクエスト値をフォームにセット
79        $objFormParam->setParam($_POST);
80       
81        $url = htmlspecialchars($_POST['url']);
82
83        // モードによって分岐
84        switch ($this->getMode()) {
85            case 'login':
86                // --- ログイン
87
88                // 入力値のエラーチェック
89                $objFormParam->trimParam();
90                $objFormParam->toLower('login_email');
91                $arrErr = $objFormParam->checkError();
92
93                // エラーの場合はエラー画面に遷移
94                if (count($arrErr) > 0) {
95                    if (SC_Display_Ex::detectDevice() === DEVICE_TYPE_SMARTPHONE) {
96                        echo $this->lfGetErrorMessage(TEMP_LOGIN_ERROR);
97                        SC_Response_Ex::actionExit();
98                    } else {
99                        SC_Utils_Ex::sfDispSiteError(TEMP_LOGIN_ERROR);
100                        SC_Response_Ex::actionExit();
101                    }
102                }
103
104                // 入力チェック後の値を取得
105                $arrForm = $objFormParam->getHashArray();
106
107                // クッキー保存判定
108                if ($arrForm['login_memory'] == '1' && $arrForm['login_email'] != '') {
109                    $objCookie->setCookie('login_email', $arrForm['login_email']);
110                } else {
111                    $objCookie->setCookie('login_email', '');
112                }
113               
114                // 遷移先の制御
115                if (count($arrErr) == 0) {
116                    // ログイン判定
117                    $loginFailFlag = false;
118                    if (SC_Display_Ex::detectDevice() === DEVICE_TYPE_MOBILE) {
119                        // モバイルサイト
120                        if (!$objCustomer->getCustomerDataFromMobilePhoneIdPass($arrForm['login_pass']) &&
121                            !$objCustomer->getCustomerDataFromEmailPass($arrForm['login_pass'], $arrForm['login_email'], true)
122                        ) {
123                            $loginFailFlag = true;
124                        }
125                    } else {
126                        // モバイルサイト以外
127                        if (!$objCustomer->getCustomerDataFromEmailPass($arrForm['login_pass'], $arrForm['login_email'])) {
128                            $loginFailFlag = true;
129                        }
130                    }
131
132                    // ログイン処理
133                    if ($loginFailFlag == false) {
134                        if (SC_Display_Ex::detectDevice() === DEVICE_TYPE_MOBILE) {
135                            // ログインが成功した場合は携帯端末IDを保存する。
136                            $objCustomer->updateMobilePhoneId();
137
138                            /*
139                             * email がモバイルドメインでは無く,
140                             * 携帯メールアドレスが登録されていない場合
141                             */
142                            $objMobile = new SC_Helper_Mobile_Ex();
143                            if (!$objMobile->gfIsMobileMailAddress($objCustomer->getValue('email'))) {
144                                if (!$objCustomer->hasValue('email_mobile')) {
145
146                                    SC_Response_Ex::sendRedirectFromUrlPath('entry/email_mobile.php');
147                                    SC_Response_Ex::actionExit();
148                                }
149                            }
150                        }
151
152                        // --- ログインに成功した場合
153                        if (SC_Display_Ex::detectDevice() === DEVICE_TYPE_SMARTPHONE) {
154                            echo SC_Utils_Ex::jsonEncode(array('success' => $url));
155                        } else {
156                            SC_Response_Ex::sendRedirect($url);
157                        }                       
158                        SC_Response_Ex::actionExit();
159                    } else {
160                        // --- ログインに失敗した場合
161
162                        // ブルートフォースアタック対策
163                        // ログイン失敗時に遅延させる
164                        sleep(LOGIN_RETRY_INTERVAL);
165
166                        $arrForm['login_email'] = strtolower($arrForm['login_email']);
167                        $objQuery = SC_Query_Ex::getSingletonInstance();
168                        $where = '(email = ? OR email_mobile = ?) AND status = 1 AND del_flg = 0';
169                        $exists = $objQuery->exists('dtb_customer', $where, array($arrForm['login_email'], $arrForm['login_email']));
170                        // ログインエラー表示 TODO リファクタリング
171                        if ($exists) {
172                            if (SC_Display_Ex::detectDevice() === DEVICE_TYPE_SMARTPHONE) {
173                                echo $this->lfGetErrorMessage(TEMP_LOGIN_ERROR);
174                                SC_Response_Ex::actionExit();
175                            } else {
176                                SC_Utils_Ex::sfDispSiteError(TEMP_LOGIN_ERROR);
177                                SC_Response_Ex::actionExit();
178                            }
179                        } else {
180                            if (SC_Display_Ex::detectDevice() === DEVICE_TYPE_SMARTPHONE) {
181                                echo $this->lfGetErrorMessage(SITE_LOGIN_ERROR);
182                                SC_Response_Ex::actionExit();
183                            } else {
184                                SC_Utils_Ex::sfDispSiteError(SITE_LOGIN_ERROR);
185                                SC_Response_Ex::actionExit();
186                            }
187                        }
188                    }
189                } else {
190                    // XXX 到達しない?
191                    // 入力エラーの場合、元のアドレスに戻す。
192                    SC_Response_Ex::sendRedirect($url);
193                    SC_Response_Ex::actionExit();
194                }
195
196                break;
197            case 'logout':
198                // --- ログアウト
199
200                // ログイン情報の解放
201                $objCustomer->EndSession();
202                // 画面遷移の制御
203                $mypage_url_search = strpos('.'.$url, 'mypage');
204                if ($mypage_url_search == 2) {
205
206                    // マイページログイン中はログイン画面へ移行
207                    SC_Response_Ex::sendRedirectFromUrlPath('mypage/login.php');
208                } else {
209
210                    // 上記以外の場合、トップへ遷移
211                    SC_Response_Ex::sendRedirect(HTTP_URL);
212                }
213                SC_Response_Ex::actionExit();
214
215                break;
216            default:
217                break;
218        }
219
220    }
221
222    /**
223     * デストラクタ.
224     *
225     * @return void
226     */
227    function destroy() {
228        parent::destroy();
229    }
230
231    /**
232     * パラメーター情報の初期化.
233     *
234     * @param SC_FormParam $objFormParam パラメーター管理クラス
235     * @return void
236     */
237    function lfInitParam(&$objFormParam) {
238        $objFormParam->addParam('記憶する', 'login_memory', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
239        $objFormParam->addParam('メールアドレス', 'login_email', MTEXT_LEN, 'a', array('EXIST_CHECK', 'MAX_LENGTH_CHECK'));
240        $objFormParam->addParam('パスワード', 'login_pass', PASSWORD_MAX_LEN, '', array('EXIST_CHECK', 'MAX_LENGTH_CHECK'));
241    }
242
243    /**
244     * エラーメッセージを JSON 形式で返す.
245     *
246     * TODO リファクタリング
247     * この関数は主にスマートフォンで使用します.
248     *
249     * @param integer エラーコード
250     * @return string JSON 形式のエラーメッセージ
251     * @see LC_PageError
252     */
253    function lfGetErrorMessage($error) {
254        switch ($error) {
255            case TEMP_LOGIN_ERROR:
256                $msg = "メールアドレスもしくはパスワードが正しくありません。\n本登録がお済みでない場合は、仮登録メールに記載されているURLより本登録を行ってください。";
257                break;
258            case SITE_LOGIN_ERROR:
259            default:
260                $msg = 'メールアドレスもしくはパスワードが正しくありません。';
261        }
262        return SC_Utils_Ex::jsonEncode(array('login_error' => $msg));
263    }
264}
Note: See TracBrowser for help on using the repository browser.