PublicAction.class.php 2.36 KB
<?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();
	}
}