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

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