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

Revision 20076, 7.8 KB checked in by yomoro, 13 years ago (diff)

#986 リファクタリング

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id Revision Date
  • 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-2010 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_REALDIR . "pages/LC_Page.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 {
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        // URLチェック
68        $this->lfCheckValidAccess();
69       
70        // 会員管理クラス
71        $objCustomer = new SC_Customer();
72        // クッキー管理クラス
73        $objCookie = new SC_Cookie(COOKIE_EXPIRE);
74        // パラメータ管理クラス
75        $this->objFormParam = new SC_FormParam();
76       
77        // パラメータ情報の初期化
78        $this->lfInitParam($this->objFormParam);
79       
80        // リクエスト値をフォームにセット
81        $objFormParam->setParam($this->lfConvertParam($_POST));
82       
83        // モードによって分岐
84        switch ($this->getMode()) {
85        case 'login':
86            // ログイン
87            $this->lfLogin($objCustomer, $objCookie);
88            break;
89        case 'logout':
90            // ログアウト
91            $this->lfLogout($objCustomer);
92            break;
93        default:
94            break;
95        }
96       
97    }
98
99    /**
100     * デストラクタ.
101     *
102     * @return void
103     */
104    function destroy() {
105        parent::destroy();
106    }
107
108    /**
109     * 正常なアクセスかチェックする.
110     *
111     * @return void
112     */
113    function lfCheckValidAccess() {
114       
115        // 不正なURLがPOSTされた場合はエラー表示
116        if (!SC_Helper_Session_Ex::isValidToken()) {
117            GC_Utils_Ex::gfPrintLog('invalid access :login_check.php $POST["url"]=' . $_POST['url']);
118            SC_Utils_Ex::sfDispSiteError(PAGE_ERROR);
119        }
120       
121    }
122
123    /**
124     * パラメータ情報の初期化.
125     *
126     * @param SC_FormParam $objFormParam パラメータ管理クラス
127     * @return SC_FormParam $objFormParam 初期化したパラメータ管理クラスを返す
128     */
129    function lfInitParam(&$objFormParam) {
130        $objFormParam->addParam('記憶する', 'login_memory', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
131        $objFormParam->addParam('メールアドレス', 'login_email', MTEXT_LEN, 'a', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'EMAIL_CHECK', 'NO_SPTAB' ,'EMAIL_CHAR_CHECK'));
132        $objFormParam->addParam('パスワード', 'login_pass', PASSWORD_LEN1, '', array('EXIST_CHECK'));
133        $objFormParam->addParam('パスワード', 'login_pass1', PASSWORD_LEN1, '', array('EXIST_CHECK', 'MIN_LENGTH_CHECK'));
134        $objFormParam->addParam('パスワード', 'login_pass2', PASSWORD_LEN2, '', array('EXIST_CHECK', 'MAX_LENGTH_CHECK'));
135        return $objFormParam;
136    }
137
138    /**
139     * リクエスト値の整形.
140     *
141     * @param array $arrRequest リクエスト
142     * @return array $arrRequest 整形したリクエストを返す
143     */
144    function lfConvertParam($arrRequest) {
145        // パスワード・Eメールにある空白をトリム
146        $arrRequest['login_email'] = preg_replace('/^[  \r\n]*(.*?)[  \r\n]*$/u', '$1', $arrRequest['login_email']);
147        $arrRequest['login_pass'] = trim($arrRequest['login_pass']); //認証用
148        $arrRequest['login_pass1'] = $arrRequest['login_pass'];      //最小桁数比較用
149        $arrRequest['login_pass2'] = $arrRequest['login_pass'];      //最大桁数比較用
150        return $arrRequest;
151    }
152
153    /**
154     * ログイン.
155     *
156     * @param SC_Customer $objCustomer 会員管理クラス
157     * @param SC_Cookie $objCookie クッキー管理クラス
158     * @return void
159     */
160    function lfLogin($objCustomer, $objCookie) {
161        // 入力値のエラーチェック
162        $this->objFormParam->toLower('login_email');
163        $arrErr = $this->objFormParam->checkError();
164       
165        // エラーの場合はエラー画面に遷移
166        if (count($arrErr) > 0) {
167            SC_Utils_Ex::sfDispSiteError(TEMP_LOGIN_ERROR);
168        }
169       
170        // 入力チェック後の値を取得
171        $arrForm = $this->objFormParam->getHashArray();
172       
173        // クッキー保存判定
174        if ($arrForm['login_memory'] == '1' && $arrForm['login_email'] != '') {
175            $objCookie->setCookie('login_email', $arrForm['login_email']);
176        } else {
177            $objCookie->setCookie('login_email', '');
178        }
179       
180        // 遷移先の制御
181        if (count($arrErr) == 0) {
182            // ログイン処理
183            if ($objCustomer->getCustomerDataFromEmailPass($arrForm['login_pass'], $arrForm['login_email'], true)) {
184                // --- ログインに成功した場合
185                SC_Response_Ex::sendRedirect(HTTP_URL);
186                exit;
187            } else {
188                // --- ログインに失敗した場合
189                $arrForm['login_email'] = strtolower($arrForm['login_email']);
190                $objQuery = SC_Query::getSingletonInstance();
191                $where = '(email = ? OR email_mobile = ?) AND status = 1 AND del_flg = 0';
192                $ret = $objQuery->count("dtb_customer", $where, array($arrForm['login_email'], $arrForm['login_email']));
193                // ログインエラー表示
194                if($ret > 0) {
195                    SC_Utils_Ex::sfDispSiteError(TEMP_LOGIN_ERROR);
196                } else {
197                    SC_Utils_Ex::sfDispSiteError(SITE_LOGIN_ERROR);
198                }
199            }
200        } else {
201            // 入力エラーの場合、元のアドレスに戻す。
202            // FIXME $_POST['url'] には、URL ではなく、url-path が渡るもよう。HTTPS 利用に関わる問題も考えられるので、URL が渡るように改善した方が良いように感じる。
203            SC_Response_Ex::sendRedirect($_POST['url']);
204            exit;
205        }
206    }
207
208    /**
209     * ログアウト.
210     *
211     * @param SC_Customer $objCustomer 会員管理クラス
212     * @return void
213     */
214    function lfLogout($objCustomer) {
215        // ログイン情報の解放
216        $objCustomer->EndSession();
217       
218        // 画面遷移の制御
219        $mypage_url_search = strpos('.'.$_POST['url'], 'mypage');
220        if ($mypage_url_search == 2) {
221            // マイページログイン中はログイン画面へ移行
222            SC_Response_Ex::sendRedirectFromUrlPath('mypage/login.php');
223        } else {
224            // 上記以外の場合、トップへ遷移
225            SC_Response_Ex::sendRedirect(HTTP_URL);
226        }
227       
228        exit;
229    }
230
231}
232?>
Note: See TracBrowser for help on using the repository browser.