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

Revision 23605, 4.4 KB checked in by kimoto, 10 years ago (diff)

#2448 typo修正・ソース整形・ソースコメントの改善 for 2.13.3

Scrutinizer Auto-Fixes

This patch was automatically generated as part of the following inspection:
 https://scrutinizer-ci.com/g/nobuhiko/EC-CUBE/inspections/d8722894-69a6-4b1b-898d-43618035c60d

Enabled analysis tools:

  • PHP Analyzer
  • PHP PDepend
  • PHP Similarity Analyzer
  • PHP Change Tracking Analyzer
  • 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-2014 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    public $login_id;
29
30    /** ユーザ権限 */
31    public $authority;
32
33    /** 認証文字列(認証成功の判定に使用) */
34    public $cert;
35
36    /** セッションID */
37    public $sid;
38
39    /** ログインユーザの主キー */
40    public $member_id;
41
42    /** ページ遷移の正当性チェックに使用 */
43    public $uniqid;
44
45    /* コンストラクタ */
46    public 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    public function IsSuccess()
69    {
70        if ($this->cert == CERT_STRING) {
71            $masterData = new SC_DB_MasterData_Ex();
72            $admin_path = strtolower(preg_replace('/\/+/', '/', $_SERVER['SCRIPT_NAME']));           
73            $arrPERMISSION = array_change_key_case($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
81            return SUCCESS;
82        }
83
84        return ACCESS_ERROR;
85    }
86
87    /* セッションの書き込み */
88
89    /**
90     * @param string $key
91     */
92    public function SetSession($key, $val)
93    {
94        $_SESSION[$key] = $val;
95    }
96
97    /* セッションの読み込み */
98
99    /**
100     * @param string $key
101     */
102    public function GetSession($key)
103    {
104        return $_SESSION[$key];
105    }
106
107    /* セッションIDの取得 */
108    public function GetSID()
109    {
110        return $this->sid;
111    }
112
113    /** ユニークIDの取得 **/
114    public function getUniqId()
115    {
116        // ユニークIDがセットされていない場合はセットする。
117        if (empty($_SESSION['uniqid'])) {
118            $this->setUniqId();
119        }
120
121        return $this->GetSession('uniqid');
122    }
123
124    /** ユニークIDのセット **/
125    public function setUniqId()
126    {
127        // 予測されないようにランダム文字列を付与する。
128        $this->SetSession('uniqid', SC_Utils_Ex::sfGetUniqRandomId());
129    }
130
131    // 関連セッションのみ破棄する。
132    public function logout()
133    {
134        unset($_SESSION['cert']);
135        unset($_SESSION['login_id']);
136        unset($_SESSION['authority']);
137        unset($_SESSION['member_id']);
138        unset($_SESSION['uniqid']);
139        // トランザクショントークンを破棄
140        SC_Helper_Session_Ex::destroyToken();
141        // ログに記録する
142        GC_Utils_Ex::gfPrintLog('logout : user='.$this->login_id.' auth='.$this->authority.' sid='.$this->sid);
143    }
144}
Note: See TracBrowser for help on using the repository browser.