source: branches/camp/camp-2_13-plugin/data/class/pages/admin/LC_Page_Admin_Index.php @ 22567

Revision 22567, 8.2 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/admin/LC_Page_Admin_Ex.php';
26
27/**
28 * 管理者ログイン のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
34class LC_Page_Admin_Index extends LC_Page_Admin_Ex
35{
36
37    // }}}
38    // {{{ functions
39
40    /**
41     * Page を初期化する.
42     *
43     * @return void
44     */
45    function init()
46    {
47        parent::init();
48        $this->tpl_mainpage = 'login.tpl';
49        $this->httpCacheControl('nocache');
50    }
51
52    /**
53     * Page のプロセス.
54     *
55     * @return void
56     */
57    function process()
58    {
59        $this->action();
60        $this->sendResponse();
61    }
62
63    /**
64     * デストラクタ.
65     *
66     * @return void
67     */
68    function destroy()
69    {
70        parent::destroy();
71    }
72
73    /**
74     * Page のアクション.
75     *
76     * @return void
77     */
78    function action()
79    {
80
81        // パラメーター管理クラス
82        $objFormParam = new SC_FormParam_Ex();
83
84        switch ($this->getMode()) {
85            case 'login':
86                //ログイン処理
87                $this->lfInitParam($objFormParam);
88                $objFormParam->setParam($_POST);
89                $this->arrErr = $this->lfCheckError($objFormParam);
90                if (SC_Utils_Ex::isBlank($this->arrErr)) {
91                    $this->lfDoLogin($objFormParam->getValue('login_id'));
92
93                    SC_Response_Ex::sendRedirect(ADMIN_HOME_URLPATH);
94                } else {
95                    // ブルートフォースアタック対策
96                    // ログイン失敗時に遅延させる
97                    sleep(LOGIN_RETRY_INTERVAL);
98
99                    SC_Utils_Ex::sfDispError(LOGIN_ERROR);
100                }
101                break;
102            default:
103                break;
104        }
105
106        // 管理者ログインテンプレートフレームの設定
107        $this->setTemplate(LOGIN_FRAME);
108
109    }
110
111    /**
112     * パラメーター情報の初期化
113     *
114     * @param array $objFormParam フォームパラメータークラス
115     * @return void
116     */
117    function lfInitParam(&$objFormParam)
118    {
119        $objFormParam->addParam('ID', 'login_id', ID_MAX_LEN, '', array('EXIST_CHECK', 'ALNUM_CHECK' ,'MAX_LENGTH_CHECK'));
120        $objFormParam->addParam('PASSWORD', 'password', ID_MAX_LEN, '', array('EXIST_CHECK', 'ALNUM_CHECK', 'MAX_LENGTH_CHECK'));
121    }
122
123    /**
124     * パラメーターのエラーチェック
125     *
126     * TODO: ブルートフォースアタック対策チェックの実装
127     *
128     * @param array $objFormParam フォームパラメータークラス
129     * @return array $arrErr エラー配列
130     */
131    function lfCheckError(&$objFormParam)
132    {
133        // 書式チェック
134        $arrErr = $objFormParam->checkError();
135        if (SC_Utils_Ex::isBlank($arrErr)) {
136            $arrForm = $objFormParam->getHashArray();
137            // ログインチェック
138            if (!$this->lfIsLoginMember($arrForm['login_id'], $arrForm['password'])) {
139                $arrErr['password'] = 'ログイン出来ません。';
140                $this->lfSetIncorrectData($arrForm['login_id']);
141            }
142        }
143        return $arrErr;
144    }
145
146    /**
147     * 有効な管理者ID/PASSかどうかチェックする
148     *
149     * @param string $login_id ログインID文字列
150     * @param string $pass ログインパスワード文字列
151     * @return boolean ログイン情報が有効な場合 true
152     */
153    function lfIsLoginMember($login_id, $pass)
154    {
155        $objQuery =& SC_Query_Ex::getSingletonInstance();
156        //パスワード、saltの取得
157        $cols = 'password, salt';
158        $table = 'dtb_member';
159        $where = 'login_id = ? AND del_flg <> 1 AND work = 1';
160        $arrData = $objQuery->getRow($cols, $table, $where, array($login_id));
161        if (SC_Utils_Ex::isBlank($arrData)) {
162            return false;
163        }
164        // ユーザー入力パスワードの判定
165        if (SC_Utils_Ex::sfIsMatchHashPassword($pass, $arrData['password'], $arrData['salt'])) {
166            return true;
167        }
168        return false;
169    }
170
171    /**
172     * 管理者ログイン設定処理
173     *
174     * @param string $login_id ログインID文字列
175     * @return void
176     */
177    function lfDoLogin($login_id)
178    {
179        $objQuery =& SC_Query_Ex::getSingletonInstance();
180        //メンバー情報取得
181        $cols = 'member_id, authority, login_date, name';
182        $table = 'dtb_member';
183        $where = 'login_id = ?';
184        $arrData = $objQuery->getRow($cols, $table, $where, array($login_id));
185        // セッション登録
186        $sid = $this->lfSetLoginSession($arrData['member_id'], $login_id, $arrData['authority'], $arrData['name'], $arrData['login_date']);
187        // ログイン情報記録
188        $this->lfSetLoginData($sid, $arrData['member_id'], $login_id, $arrData['authority'], $arrData['login_date']);
189    }
190
191    /**
192     * ログイン情報セッション登録
193     *
194     * @param integer $member_id メンバーID
195     * @param string $login_id ログインID文字列
196     * @param integer $authority 権限ID
197     * @param string $login_name ログイン表示名
198     * @param string $last_login 最終ログイン日時(YYYY/MM/DD HH:ii:ss形式) またはNULL
199     * @return string $sid 設定したセッションのセッションID
200     */
201    function lfSetLoginSession($member_id, $login_id, $authority, $login_name, $last_login)
202    {
203        $objSess = new SC_Session_Ex();
204        // 認証済みの設定
205        $objSess->SetSession('cert', CERT_STRING);
206        $objSess->SetSession('member_id', $member_id);
207        $objSess->SetSession('login_id', $login_id);
208        $objSess->SetSession('authority', $authority);
209        $objSess->SetSession('login_name', $login_name);
210        $objSess->SetSession('uniqid', $objSess->getUniqId());
211        if (SC_Utils_Ex::isBlank($last_login)) {
212            $objSess->SetSession('last_login', date('Y-m-d H:i:s'));
213        } else {
214            $objSess->SetSession('last_login', $last_login);
215        }
216        return $objSess->GetSID();
217    }
218
219    /**
220     * ログイン情報の記録
221     *
222     * @param mixed $sid セッションID
223     * @param integer $member_id メンバーID
224     * @param string $login_id ログインID文字列
225     * @param integer $authority 権限ID
226     * @param string $last_login 最終ログイン日時(YYYY/MM/DD HH:ii:ss形式) またはNULL
227     * @return void
228     */
229    function lfSetLoginData($sid, $member_id, $login_id, $authority, $last_login)
230    {
231        // ログイン記録ログ出力
232        $str_log = "login: user=$login_id($member_id) auth=$authority "
233                    . "lastlogin=$last_login sid=$sid";
234        GC_Utils_Ex::gfPrintLog($str_log);
235
236        // 最終ログイン日時更新
237        $objQuery =& SC_Query_Ex::getSingletonInstance();
238        $sqlval = array();
239        $sqlval['login_date'] = date('Y-m-d H:i:s');
240        $table = 'dtb_member';
241        $where = 'member_id = ?';
242        $objQuery->update($table, $sqlval, $where, array($member_id));
243    }
244
245    /**
246     * ログイン失敗情報の記録
247     *
248     * TODO: ブルートフォースアタック対策の実装
249     *
250     * @param string $login_id ログイン失敗時に投入されたlogin_id文字列
251     * @return void
252     */
253    function lfSetIncorrectData($error_login_id)
254    {
255        GC_Utils_Ex::gfPrintLog($error_login_id . ' password incorrect.');
256    }
257}
Note: See TracBrowser for help on using the repository browser.