source: branches/version-2_12-dev/data/class/pages/admin/LC_Page_Admin_Index.php @ 21420

Revision 21420, 7.9 KB checked in by Seasoft, 12 years ago (diff)

#1613 (ソース整形・ソースコメントの改善)

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