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

Revision 21693, 11.5 KB checked in by h_yoshimoto, 12 years ago (diff)

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