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

Revision 21743, 10.0 KB checked in by AMUAMU, 12 years ago (diff)

#1754 (exit;を個別の処理でしない) #1692 (プラグイン機能) 各ファイルでフックポイントの呼出を書かないで、自動的にフックポイントを呼び出すように修正。

  • 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        // モードによって分岐
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                    $loginFailFlag = false;
116                    if (SC_Display_Ex::detectDevice() === DEVICE_TYPE_MOBILE) {
117                        // モバイルサイト
118                        if (!$objCustomer->getCustomerDataFromMobilePhoneIdPass($arrForm['login_pass']) &&
119                            !$objCustomer->getCustomerDataFromEmailPass($arrForm['login_pass'], $arrForm['login_email'], true)
120                        ) {
121                            $loginFailFlag = true;
122                        }
123                    } else {
124                        // モバイルサイト以外
125                        if (!$objCustomer->getCustomerDataFromEmailPass($arrForm['login_pass'], $arrForm['login_email'])) {
126                            $loginFailFlag = true;
127                        }
128                    }
129
130                    // ログイン処理
131                    if ($loginFailFlag == false) {
132                        if (SC_Display_Ex::detectDevice() === DEVICE_TYPE_MOBILE) {
133                            // ログインが成功した場合は携帯端末IDを保存する。
134                            $objCustomer->updateMobilePhoneId();
135
136                            /*
137                             * email がモバイルドメインでは無く,
138                             * 携帯メールアドレスが登録されていない場合
139                             */
140                            $objMobile = new SC_Helper_Mobile_Ex();
141                            if (!$objMobile->gfIsMobileMailAddress($objCustomer->getValue('email'))) {
142                                if (!$objCustomer->hasValue('email_mobile')) {
143
144                                    SC_Response_Ex::sendRedirectFromUrlPath('entry/email_mobile.php');
145                                    SC_Response_Ex::actionExit();
146                                }
147                            }
148                        }
149
150                        // --- ログインに成功した場合
151                        if (SC_Display_Ex::detectDevice() === DEVICE_TYPE_SMARTPHONE) {
152
153                            echo SC_Utils_Ex::jsonEncode(array('success' => $_POST['url']));
154                        } else {
155
156                            SC_Response_Ex::sendRedirect($_POST['url']);
157                        }
158                        SC_Response_Ex::actionExit();
159                    } else {
160                        // --- ログインに失敗した場合
161                        $arrForm['login_email'] = strtolower($arrForm['login_email']);
162                        $objQuery = SC_Query_Ex::getSingletonInstance();
163                        $where = '(email = ? OR email_mobile = ?) AND status = 1 AND del_flg = 0';
164                        $exists = $objQuery->exists('dtb_customer', $where, array($arrForm['login_email'], $arrForm['login_email']));
165                        // ログインエラー表示 TODO リファクタリング
166                        if ($exists) {
167                            if (SC_Display_Ex::detectDevice() === DEVICE_TYPE_SMARTPHONE) {
168                                echo $this->lfGetErrorMessage(TEMP_LOGIN_ERROR);
169                                SC_Response_Ex::actionExit();
170                            } else {
171                                SC_Utils_Ex::sfDispSiteError(TEMP_LOGIN_ERROR);
172                                SC_Response_Ex::actionExit();
173                            }
174                        } else {
175                            if (SC_Display_Ex::detectDevice() === DEVICE_TYPE_SMARTPHONE) {
176                                echo $this->lfGetErrorMessage(SITE_LOGIN_ERROR);
177                                SC_Response_Ex::actionExit();
178                            } else {
179                                SC_Utils_Ex::sfDispSiteError(SITE_LOGIN_ERROR);
180                                SC_Response_Ex::actionExit();
181                            }
182                        }
183                    }
184                } else {
185                    // XXX 到達しない?
186                    // 入力エラーの場合、元のアドレスに戻す。
187                    SC_Response_Ex::sendRedirect($_POST['url']);
188                    SC_Response_Ex::actionExit();
189                }
190
191                break;
192            case 'logout':
193                // --- ログアウト
194
195                // ログイン情報の解放
196                $objCustomer->EndSession();
197                // 画面遷移の制御
198                $mypage_url_search = strpos('.'.$_POST['url'], 'mypage');
199                if ($mypage_url_search == 2) {
200
201                    // マイページログイン中はログイン画面へ移行
202                    SC_Response_Ex::sendRedirectFromUrlPath('mypage/login.php');
203                } else {
204
205                    // 上記以外の場合、トップへ遷移
206                    SC_Response_Ex::sendRedirect(HTTP_URL);
207                }
208                SC_Response_Ex::actionExit();
209
210                break;
211            default:
212                break;
213        }
214
215    }
216
217    /**
218     * デストラクタ.
219     *
220     * @return void
221     */
222    function destroy() {
223        parent::destroy();
224    }
225
226    /**
227     * パラメーター情報の初期化.
228     *
229     * @param SC_FormParam $objFormParam パラメーター管理クラス
230     * @return void
231     */
232    function lfInitParam(&$objFormParam) {
233        $objFormParam->addParam('記憶する', 'login_memory', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
234        $objFormParam->addParam('メールアドレス', 'login_email', MTEXT_LEN, 'a', array('EXIST_CHECK', 'MAX_LENGTH_CHECK'));
235        $objFormParam->addParam('パスワード', 'login_pass', PASSWORD_MAX_LEN, '', array('EXIST_CHECK', 'MAX_LENGTH_CHECK'));
236    }
237
238    /**
239     * エラーメッセージを JSON 形式で返す.
240     *
241     * TODO リファクタリング
242     * この関数は主にスマートフォンで使用します.
243     *
244     * @param integer エラーコード
245     * @return string JSON 形式のエラーメッセージ
246     * @see LC_PageError
247     */
248    function lfGetErrorMessage($error) {
249        switch ($error) {
250            case TEMP_LOGIN_ERROR:
251                $msg = "メールアドレスもしくはパスワードが正しくありません。\n本登録がお済みでない場合は、仮登録メールに記載されているURLより本登録を行ってください。";
252                break;
253            case SITE_LOGIN_ERROR:
254            default:
255                $msg = 'メールアドレスもしくはパスワードが正しくありません。';
256        }
257        return SC_Utils_Ex::jsonEncode(array('login_error' => $msg));
258    }
259}
Note: See TracBrowser for help on using the repository browser.