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

Revision 23256, 9.5 KB checked in by Seasoft, 10 years ago (diff)

#2427 (SC_SessionFactory_UseRequest#initSession URLパスでリダイレクトしている)
#2445 (TOPページのURLに揺らぎがある)
#2446 (HTTP へ復帰すべき画面遷移でも HTTPS が維持される)

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