source: branches/version-2_13-dev/data/class/SC_Session.php @ 22856

Revision 22856, 4.2 KB checked in by Seasoft, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.13.0)

  • 主に空白・空白行の調整。もう少し整えたいが、一旦現状コミット。
  • 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/* セッション管理クラス */
25class SC_Session
26{
27    /** ログインユーザ名 */
28    var $login_id;
29
30    /** ユーザ権限 */
31    var $authority;
32
33    /** 認証文字列(認証成功の判定に使用) */
34    var $cert;
35
36    /** セッションID */
37    var $sid;
38
39    /** ログインユーザの主キー */
40    var $member_id;
41
42    /** ページ遷移の正当性チェックに使用 */
43    var $uniqid;
44
45    /* コンストラクタ */
46    function __construct()
47    {
48        // セッション情報の保存
49        if (isset($_SESSION['cert'])) {
50            $this->sid = session_id();
51            $this->cert = $_SESSION['cert'];
52            $this->login_id  = $_SESSION['login_id'];
53            // 管理者:0, 店舗オーナー:1, 閲覧:2, 販売担当:3 (XXX 現状 0, 1 を暫定実装。2, 3 は未実装。)
54            $this->authority = $_SESSION['authority'];
55            $this->member_id = $_SESSION['member_id'];
56            if (isset($_SESSION['uniq_id'])) {
57                $this->uniqid    = $_SESSION['uniq_id'];
58            }
59
60            // ログに記録する
61            GC_Utils_Ex::gfPrintLog('access : user='.$this->login_id.' auth='.$this->authority.' sid='.$this->sid);
62        } else {
63            // ログに記録する
64            GC_Utils_Ex::gfPrintLog('access error.');
65        }
66    }
67    /* 認証成功の判定 */
68    function IsSuccess()
69    {
70        if ($this->cert == CERT_STRING) {
71            $masterData = new SC_DB_MasterData_Ex();
72            $admin_path = preg_replace('/\/+/', '/', $_SERVER['SCRIPT_NAME']);
73            $arrPERMISSION = $masterData->getMasterData('mtb_permission');
74            if (isset($arrPERMISSION[$admin_path])) {
75                // 数値が自分の権限以上のものでないとアクセスできない。
76                if ($arrPERMISSION[$admin_path] < $this->authority) {
77                    return AUTH_ERROR;
78                }
79            }
80            return SUCCESS;
81        }
82
83        return ACCESS_ERROR;
84    }
85
86    /* セッションの書き込み */
87    function SetSession($key, $val)
88    {
89        $_SESSION[$key] = $val;
90    }
91
92    /* セッションの読み込み */
93    function GetSession($key)
94    {
95        return $_SESSION[$key];
96    }
97
98    /* セッションIDの取得 */
99    function GetSID()
100    {
101        return $this->sid;
102    }
103
104    /** ユニークIDの取得 **/
105    function getUniqId()
106    {
107        // ユニークIDがセットされていない場合はセットする。
108        if (empty($_SESSION['uniqid'])) {
109            $this->setUniqId();
110        }
111
112        return $this->GetSession('uniqid');
113    }
114
115    /** ユニークIDのセット **/
116    function setUniqId()
117    {
118        // 予測されないようにランダム文字列を付与する。
119        $this->SetSession('uniqid', SC_Utils_Ex::sfGetUniqRandomId());
120    }
121
122    // 関連セッションのみ破棄する。
123    function logout()
124    {
125        unset($_SESSION['cert']);
126        unset($_SESSION['login_id']);
127        unset($_SESSION['authority']);
128        unset($_SESSION['member_id']);
129        unset($_SESSION['uniqid']);
130        // トランザクショントークンを破棄
131        SC_Helper_Session_Ex::destroyToken();
132        // ログに記録する
133        GC_Utils_Ex::gfPrintLog('logout : user='.$this->login_id.' auth='.$this->authority.' sid='.$this->sid);
134    }
135}
Note: See TracBrowser for help on using the repository browser.