PublicAction.class.php
2.36 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
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
class PublicAction extends Action {
public $ADMIN_KEY='';
public function __construct() {
parent::__construct();
$this->ADMIN_KEY=cookie('uid');
}
public function login(){
$ADMIN_KEY=$this->ADMIN_KEY;
if (isset($ADMIN_KEY)) {
$this->redirect('Index/index');
}
if($this->isPost()){
if (!I('post.account',null)) {
$this->error("帐号不可以为空!");
}elseif(!I('post.password',null)) {
$this->error("密码不可以为空!");
}elseif(session('verify') != md5(I('post.code'))) {
$this->error('验证码错误!');
}
$map['username'] = I('post.account');
$admin = M('Webuser')->where($map)->find();
if(empty($admin) || $admin['password'] != md5(I('post.password'))){
$this->error("帐号不存在或者密码错误!");
}elseif($admin['isshow']==0){
$this->error("账号已被禁用!");
}else{
cookie('uid',$admin['id']);
cookie('account',$admin['username']); //登录账号
cookie('username',$admin['name']);
cookie('logtime',time());
$Ad=M('Webuser');
$Ad->ltime = time();
$Ad->lip = $_SERVER['REMOTE_ADDR'];
$Ad->where('id='.$admin['id'])->save(); // 根据条件保存修改的数据
$this->success("登录成功!",U('Index/index'));
}
}else{
$this->display();
}
}
public function index(){
$this->redirect('Public/login');
}
//验证码类
public function verify() {
//ob_clean();
import ( "ORG.Util.Image" );
Image::buildImageVerify (4);
}
/**
* 用户忘记密码
*/
public function forgetPass(){
if($this->isPost()){
$m=M('Webuser');
$where['id']=array('eq',cookie('uid'));
$where['password']=array('eq',md5($_POST['oldpass']));
$onearr=$m->where($where)->field('id,password,email')->find();
if(!$onearr)
{
$this->error('原始密码错误,请重新输入');
}
if($_POST['password']!=$_POST['password2'])
{
$this->error('两次密码不一致,请重新输入');
}
$where2['id']=array('eq',$onearr['id']);
$data['password'] = md5($_POST['password']);
$row=$m->where($where2)->save($data);
if($row){
$this->success('修改成功,请重新登陆!',U('logout'),array('cid'=>I('cid'),'p'=>I('p')));
exit;
}else{
$this->error('修改失败!');
exit;
}
}
$this->display();
}
}