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

Revision 22856, 9.3 KB checked in by Seasoft, 11 years ago (diff)

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

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