[Svn-src-all:1227] [version-2_5-dev 20115] #961 ([管理画面]ログイン/ホーム リファクタリング) ログイン、ログアウトの修正
AMUAMU
admin @ mail.ec-cube.net
2011年 2月 9日 (水) 06:02:49 JST
Subversion committed to /home/svn/open 20115
http://svn.ec-cube.net/open_trac/changeset/20115
┌────────────────────────────┐
│更新者 : AMUAMU │
│更新日時: 2011-02-09 06:02:48 +0900 (水, 09 2月 2011)│
└────────────────────────────┘
Log:
--------------------------------------------------------
#961 ([管理画面]ログイン/ホーム リファクタリング) ログイン、ログアウトの修正
#783 (ページ間の遷移方法の改善) login.phpの削除。
Changed: [U:修正,A:追加,D:削除]
--------------------------------------------------------
U branches/version-2_5-dev/data/Smarty/templates/admin/login.tpl
U branches/version-2_5-dev/data/class/pages/admin/LC_Page_Admin_Index.php
D branches/version-2_5-dev/data/class/pages/admin/LC_Page_Admin_Login.php
U branches/version-2_5-dev/data/class/pages/admin/LC_Page_Admin_Logout.php
D branches/version-2_5-dev/html/admin/login.php
変更: branches/version-2_5-dev/data/Smarty/templates/admin/login.tpl
===================================================================
--- branches/version-2_5-dev/data/Smarty/templates/admin/login.tpl 2011-02-08 13:18:07 UTC (rev 20114)
+++ branches/version-2_5-dev/data/Smarty/templates/admin/login.tpl 2011-02-08 21:02:48 UTC (rev 20115)
@@ -29,7 +29,9 @@
<div id="login-form" class="clearfix">
<h1><img src="<!--{$TPL_URLPATH}-->img/contents/admin_login_logo.jpg" width="140" height="150" alt="EC-CUBE管理画面" /></h1>
<div id="input-form">
- <form name="form1" id="form1" method="post" action="login.php">
+ <form name="form1" id="form1" method="post" action="?">
+ <input type="hidden" name="mode" value="login" />
+ <input type="hidden" name="<!--{$smarty.const.TRANSACTION_ID_NAME}-->" value="<!--{$transactionid}-->" />
<p><label for="login_id">ID</label></p>
<input type="text" name="login_id" size="20" class="box25" />
<p><label for="password">PASSWORD</label></p>
変更: branches/version-2_5-dev/data/class/pages/admin/LC_Page_Admin_Index.php
===================================================================
--- branches/version-2_5-dev/data/class/pages/admin/LC_Page_Admin_Index.php 2011-02-08 13:18:07 UTC (rev 20114)
+++ branches/version-2_5-dev/data/class/pages/admin/LC_Page_Admin_Index.php 2011-02-08 21:02:48 UTC (rev 20115)
@@ -44,6 +44,7 @@
function init() {
parent::init();
$this->tpl_mainpage = 'login.tpl';
+ $this->httpCacheControl('nocache');
}
/**
@@ -52,27 +53,194 @@
* @return void
*/
function process() {
- parent::process();
$this->action();
$this->sendResponse();
}
/**
+ * デストラクタ.
+ *
+ * @return void
+ */
+ function destroy() {
+ parent::destroy();
+ }
+
+ /**
* Page のアクション.
*
* @return void
*/
function action() {
+ // 不正アクセスチェック
+ if ($_SERVER["REQUEST_METHOD"] == "POST") {
+ if (!SC_Helper_Session_Ex::isValidToken()) {
+ SC_Utils_Ex::sfDispError(LOGIN_ERROR);
+ }
+ }
+ // パラメータ管理クラス
+ $objFormParam = new SC_FormParam();
+
+ switch ($this->getMode()) {
+ case 'login':
+ //ログイン処理
+ $this->lfInitParam($objFormParam);
+ $objFormParam->setParam($_POST);
+ $this->arrErr = $this->lfCheckError($objFormParam);
+ if (SC_Utils_Ex::isBlank($this->arrErr)) {
+ $this->lfDoLogin($objFormParam->getValue('login_id'));
+ SC_Response_Ex::sendRedirect(ADMIN_HOME_URLPATH);
+ }else{
+ SC_Utils_Ex::sfDispError(LOGIN_ERROR);
+ }
+ break;
+ default:
+ break;
+ }
+ // トランザクションID
+ $this->transactionid = SC_Helper_Session_Ex::getToken();
+ // 管理者ログインテンプレートフレームの設定
$this->setTemplate(LOGIN_FRAME);
}
-
+
/**
- * デストラクタ.
+ * パラメーター情報の初期化
*
+ * @param array $objFormParam フォームパラメータークラス
* @return void
*/
- function destroy() {
- parent::destroy();
+ function lfInitParam(&$objFormParam) {
+ $objFormParam->addParam('ID', 'login_id', ID_MAX_LEN, '', array('EXIST_CHECK', 'ALNUM_CHECK' ,'MAX_LENGTH_CHECK'));
+ $objFormParam->addParam('PASSWORD', 'password', ID_MAX_LEN, '', array('EXIST_CHECK', 'ALNUM_CHECK', 'MAX_LENGTH_CHECK'));
}
+
+ /**
+ * パラメーターのエラーチェック
+ *
+ * TODO: ブルートフォースアタック対策チェックの実装
+ *
+ * @param array $objFormParam フォームパラメータークラス
+ * @return array $arrErr エラー配列
+ */
+ function lfCheckError(&$objFormParam) {
+ // 書式チェック
+ $arrErr = $objFormParam->checkError();
+ if(SC_Utils_Ex::isBlank($arrErr)) {
+ $arrForm = $objFormParam->getHashArray();
+ // ログインチェック
+ if(!$this->lfIsLoginMember($arrForm['login_id'], $arrForm['password'])) {
+ $arrErr['password'] = "ログイン出来ません。";
+ $this->lfSetIncorrectData($arrForm['login_id']);
+ }
+ }
+ return $arrErr;
+ }
+
+ /**
+ * 有効な管理者ID/PASSかどうかチェックする
+ *
+ * @param string $login_id ログインID文字列
+ * @param string $pass ログインパスワード文字列
+ * @return boolean ログイン情報が有効な場合 true
+ */
+ function lfIsLoginMember($login_id, $pass) {
+ $objQuery =& SC_Query::getSingletonInstance();
+ //パスワード、saltの取得
+ $cols = "password, salt";
+ $table = "dtb_member";
+ $where = "login_id = ? AND del_flg <> 1 AND work = 1";
+ $arrData = $objQuery->getRow($cols, $table, $where, array($login_id));
+ if (SC_Utils_Ex::isBlank($arrData)) {
+ return false;
+ }
+ // ユーザー入力パスワードの判定
+ if (SC_Utils_Ex::sfIsMatchHashPassword($pass, $arrData['password'], $arrData['salt'])) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * 管理者ログイン設定処理
+ *
+ * @param string $login_id ログインID文字列
+ * @return void
+ */
+ function lfDoLogin($login_id) {
+ $objQuery =& SC_Query::getSingletonInstance();
+ //メンバー情報取得
+ $cols = "member_id, authority, login_date, name";
+ $table = "dtb_member";
+ $where = "login_id = ?";
+ $arrData = $objQuery->getRow($cols, $table, $where, array($login_id));
+ // セッション登録
+ $sid = $this->lfSetLoginSession($arrData['member_id'], $login_id, $arrData['authority'], $arrData['name'], $arrData['login_date']);
+ // ログイン情報記録
+ $this->lfSetLoginData($sid, $arrData['member_id'], $login_id, $arrData['authority'], $arrData['login_date']);
+ }
+
+ /**
+ * ログイン情報セッション登録
+ *
+ * @param integer $member_id メンバーID
+ * @param string $login_id ログインID文字列
+ * @param integer $authority 権限ID
+ * @param string $login_name ログイン表示名
+ * @param string $last_login 最終ログイン日時(YYYY/MM/DD HH:ii:ss形式) またはNULL
+ * @return string $sid 設定したセッションのセッションID
+ */
+ function lfSetLoginSession($member_id, $login_id, $authority, $login_name, $last_login) {
+ $objSess = new SC_Session();
+ // 認証済みの設定
+ $objSess->SetSession('cert', CERT_STRING);
+ $objSess->SetSession('member_id', $member_id);
+ $objSess->SetSession('login_id', $login_id);
+ $objSess->SetSession('authority', $authority);
+ $objSess->SetSession('login_name', $login_name);
+ $objSess->SetSession('uniqid', $objSess->getUniqId());
+ if(SC_Utils_Ex::isBlank($last_login)) {
+ $objSess->SetSession('last_login', date("Y-m-d H:i:s"));
+ }else{
+ $objSess->SetSession('last_login', $last_login);
+ }
+ return $objSess->GetSID();
+ }
+
+ /**
+ * ログイン情報の記録
+ *
+ * @param mixed $sid セッションID
+ * @param integer $member_id メンバーID
+ * @param string $login_id ログインID文字列
+ * @param integer $authority 権限ID
+ * @param string $last_login 最終ログイン日時(YYYY/MM/DD HH:ii:ss形式) またはNULL
+ * @return void
+ */
+ function lfSetLoginData($sid, $member_id, $login_id, $authority, $last_login) {
+ // ログイン記録ログ出力
+ $str_log = "login: user=$login_id($member_id) auth=$authority "
+ . "lastlogin=$last_login sid=$sid";
+ GC_Utils_Ex::gfPrintLog($str_log);
+
+ // 最終ログイン日時更新
+ $objQuery =& SC_Query::getSingletonInstance();
+ $sqlval = array();
+ $sqlval['login_date'] = date("Y-m-d H:i:s");
+ $table = "dtb_member";
+ $where = "member_id = ?";
+ $objQuery->update($table, $sqlval, $where, array($member_id));
+ }
+
+ /**
+ * ログイン失敗情報の記録
+ *
+ * TODO: ブルートフォースアタック対策の実装
+ *
+ * @param string $login_id ログイン失敗時に投入されたlogin_id文字列
+ * @return void
+ */
+ function lfSetIncorrectData($error_login_id) {
+ GC_Utils_Ex::gfPrintLog($error_login_id . " password incorrect.");
+ }
}
?>
削除: branches/version-2_5-dev/data/class/pages/admin/LC_Page_Admin_Login.php
===================================================================
--- branches/version-2_5-dev/data/class/pages/admin/LC_Page_Admin_Login.php 2011-02-08 13:18:07 UTC (rev 20114)
+++ branches/version-2_5-dev/data/class/pages/admin/LC_Page_Admin_Login.php 2011-02-08 21:02:48 UTC (rev 20115)
@@ -1,156 +0,0 @@
-<?php
-/*
- * This file is part of EC-CUBE
- *
- * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved.
- *
- * http://www.lockon.co.jp/
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-// {{{ requires
-require_once(CLASS_REALDIR . "pages/admin/LC_Page_Admin.php");
-
-/**
- * 管理者ログイン のページクラス.
- *
- * @package Page
- * @author LOCKON CO.,LTD.
- * @version $Id$
- */
-class LC_Page_Admin_Login extends LC_Page_Admin {
-
- // {{{ properties
-
- /** SC_Session インスタンス */
- var $objSess;
-
- // }}}
- // {{{ functions
-
- /**
- * Page を初期化する.
- *
- * @return void
- */
- function init() {
- parent::init();
- }
-
- /**
- * Page のプロセス.
- *
- * @return void
- */
- function process() {
- $this->action();
- $this->sendResponse();
- }
-
- /**
- * Page のアクション.
- *
- * @return void
- */
- function action() {
- $objQuery = new SC_Query();
- $this->objSess = new SC_Session();
- $ret = false;
-
- if (!isset($_POST['login_id'])) $_POST['login_id'] = "";
- if (!isset($_POST['password'])) $_POST['password'] = "";
-
- // 入力判定
- if(strlen($_POST{'login_id'}) > 0 && strlen($_POST{'password'}) >= ID_MIN_LEN && strlen($_POST{'password'}) <= ID_MAX_LEN) {
- // 認証パスワードの判定
- $ret = $this->fnCheckPassword($objQuery);
- }
-
- if($ret) {
- // 成功
- SC_Response_Ex::sendRedirect(ADMIN_HOME_URLPATH);
- exit;
- } else {
- // エラーページの表示
- SC_Utils_Ex::sfDispError(LOGIN_ERROR);
- exit;
- }
- }
-
- /**
- * デストラクタ.
- *
- * @return void
- */
- function destroy() {
- parent::destroy();
- }
-
- /* 認証パスワードの判定 */
- function fnCheckPassword(&$objQuery) {
- $sql = "SELECT member_id, password, salt, authority, login_date, name FROM dtb_member WHERE login_id = ? AND del_flg <> 1 AND work = 1";
- $arrcol = array ($_POST['login_id']);
- // DBから暗号化パスワードを取得する。
- $data_list = $objQuery->getAll($sql ,$arrcol);
- // パスワードの取得
- $password = $data_list[0]['password'];
- // saltの取得
- $salt = $data_list[0]['salt'];
- // ユーザ入力パスワードの判定
- if (SC_Utils_Ex::sfIsMatchHashPassword($_POST['password'], $password, $salt)) {
- // セッション登録
- $this->fnSetLoginSession($data_list[0]['member_id'], $data_list[0]['authority'], $data_list[0]['login_date'], $data_list[0]['name']);
- // ログイン日時の登録
- $this->fnSetLoginDate();
- return true;
- }
-
- // パスワード
- GC_Utils_Ex::gfPrintLog($_POST['login_id'] . " password incorrect.");
- return false;
- }
-
- /* 認証セッションの登録 */
- function fnSetLoginSession($member_id,$authority,$login_date, $login_name = '') {
-
- // 認証済みの設定
- $this->objSess->SetSession('cert', CERT_STRING);
- $this->objSess->SetSession('login_id', $_POST{'login_id'});
- $this->objSess->SetSession('authority', $authority);
- $this->objSess->SetSession('member_id', $member_id);
- $this->objSess->SetSession('login_name', $login_name);
- $this->objSess->SetSession('uniqid', $this->objSess->getUniqId());
-
- if(strlen($login_date) > 0) {
- $this->objSess->SetSession('last_login', $login_date);
- } else {
- $this->objSess->SetSession('last_login', date("Y-m-d H:i:s"));
- }
- $sid = $this->objSess->GetSID();
- // ログに記録する
- GC_Utils_Ex::gfPrintLog("login : user=".$_SESSION{'login_id'}." auth=".$_SESSION{'authority'}." lastlogin=". $_SESSION{'last_login'} ." sid=".$sid);
- }
-
- /* ログイン日時の更新 */
- function fnSetLoginDate() {
- $objQuery = new SC_Query();
- $sqlval['login_date'] = date("Y-m-d H:i:s");
- $member_id = $this->objSess->GetSession('member_id');
- $where = "member_id = " . $member_id;
- $ret = $objQuery->update("dtb_member", $sqlval, $where);
- }
-}
-?>
変更: branches/version-2_5-dev/data/class/pages/admin/LC_Page_Admin_Logout.php
===================================================================
--- branches/version-2_5-dev/data/class/pages/admin/LC_Page_Admin_Logout.php 2011-02-08 13:18:07 UTC (rev 20114)
+++ branches/version-2_5-dev/data/class/pages/admin/LC_Page_Admin_Logout.php 2011-02-08 21:02:48 UTC (rev 20115)
@@ -51,13 +51,31 @@
* @return void
*/
function process() {
- $objSess = new SC_Session();
- $objSess->logout();
+ $this->action();
+ }
+ /**
+ * Page のアクション.
+ *
+ * @return void
+ */
+ function action() {
+ $this->lfDoLogout();
+ // ログイン画面に遷移
SC_Response_Ex::sendRedirectFromUrlPath(ADMIN_DIR . DIR_INDEX_PATH);
}
/**
+ * ログアウト処理
+ *
+ * @return void
+ */
+ function lfDoLogout() {
+ $objSess = new SC_Session();
+ $objSess->logout();
+ }
+
+ /**
* デストラクタ.
*
* @return void
削除: branches/version-2_5-dev/html/admin/login.php
===================================================================
--- branches/version-2_5-dev/html/admin/login.php 2011-02-08 13:18:07 UTC (rev 20114)
+++ branches/version-2_5-dev/html/admin/login.php 2011-02-08 21:02:48 UTC (rev 20115)
@@ -1,34 +0,0 @@
-<?php
-/*
- * This file is part of EC-CUBE
- *
- * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved.
- *
- * http://www.lockon.co.jp/
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-// {{{ requires
-require_once './require.php';
-require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Login_Ex.php';
-
-// }}}
-// {{{ generate page
-
-$objPage = new LC_Page_Admin_Login_Ex();
-register_shutdown_function(array($objPage, 'destroy'));
-$objPage->init();
-$objPage->process();
-?>
Svn-src-all メーリングリストの案内