PublicAction.class.php
2.17 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
68
69
70
<?php
// 本类由系统自动生成,仅供测试用途
class PublicAction extends Action {
public $ADMIN_KEY='';
public function __construct() {
parent::__construct();
$this->ppFirewall();
$this->ADMIN_KEY=cookie('ADMIN_KEY');
}
public function login(){
$ADMIN_KEY=$this->ADMIN_KEY;
if (isset($ADMIN_KEY)) {
$this->redirect('Index/index');
}
if($this->isPost()){
if (empty($_POST['username'])) {
$this->error("帐号不可以为空!");
}else if (empty($_POST['password'])) {
$this->error("密码不可以为空!");
}else if(session('verify') != md5($_POST["verify"])) {
$this->error('验证码错误!');
}
$map['username']=$_POST["username"];
$map['password']=md5($_POST["password"]);
$admin = M('Admin')->where($map)->find();
if(empty($admin)){
$this->error("帐号不存在或者密码错误!");
}elseif($admin['isshow']==0){
$this->error("账号已被禁用!");
}else{
$pp_life_time=0;
cookie('ADMIN_KEY',$admin['id'],$pp_life_time);
cookie('ADMIN_NAME',$admin['name'],$pp_life_time);
cookie('LOGIN_TIME',time());
//获取用户权限
import('ORG.Util.Auth');//加载类库
$auth=new Auth();
$authlist=$auth->getAuthList($admin['id']);
cookie('pp_authlist',$authlist,$pp_life_time);
$Ad=M('Admin');
$Ad->ltime = time();
$Ad->lip = $_SERVER['REMOTE_ADDR'];
$Ad->where('id='.$admin['id'])->save(); // 根据条件保存修改的数据
$this->success("登录成功!",U('Index/index'));
//echo '<script>alert("当前用户未登录或登录超时,请重新登录");top.location.href="'.U('Public/login').'";</script>';
}
}else{
$this->display();
}
}
public function index(){
$this->redirect('Public/login');
}
//验证码类
public function verify() {
//ob_clean();
import ( "ORG.Util.Image" );
Image::buildImageVerify (4);
}
//防火墙验证
protected function ppFirewall(){
if(!$_COOKIE['pro_ppfirewall']){
header('Content-Type:text/html; charset=utf-8');
exit('您无权限操作');
}
}
}