CommonAction.class.php
1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
class CommonAction extends BaseAction {
public function __construct() {
parent::__construct();
header('Content-Type:text/html; charset=utf-8');
$this->checkLog();
//去除反斜梗
if (get_magic_quotes_gpc()){
$_POST = array_map('stripslashes_deep', $_POST);
$_GET = array_map('stripslashes_deep', $_GET);
$_COOKIE = array_map('stripslashes_deep', $_COOKIE);
}
}
public function _initialize()
{
parent::_initialize();
if((MODULE_NAME !="Index" || (MODULE_NAME =="Index" && !in_array(ACTION_NAME,array('index','main','menu','delcache','outlogin')))) && (MODULE_NAME !="Public" || (MODULE_NAME == 'Public' && !in_array(ACTION_NAME,array('login','index','verify')))))
{
import('ORG.Util.Auth');//加载类库
$auth=new Auth();
// var_dump($auth->check(strtolower(MODULE_NAME).'-'.strtolower(ACTION_NAME),cookie('uid')));
// exit;
if(!$auth->check(strtolower(MODULE_NAME).'-'.strtolower(ACTION_NAME),cookie('uid'))){
$this->error('你没有权限');
}
}
}
/**
* 判断用户是否登录
* @return [bool]
*/
public function checkLog() {
if(!cookie('uid') || !cookie('account')){
$this->clearlog();
exit('<script>alert("当前用户未登录或登录超时,请重新登录");top.location.href="'.U('Public/login').'";</script>');
}
}
/**
* 清除登录所生成的cookie
*/
protected function clearLog(){
cookie('uid',null);
cookie('account',null);
cookie('username',null);
cookie('logtime',null);
}
/**
* 用户退出登录
*/
public function outlogin(){
$this->clearLog();
$this->success('退出成功!',U('Public/index'));
}
/**
* 获取用户权限
* 防止 authlist 走出cookie限制
* @return array
*/
protected function getPower(){
//获取用户权限
import('ORG.Util.Auth');//加载类库
$auth=new Auth();
$authlist=$auth->getAuthList(cookie('uid'));
return $authlist;
}
}