<?php
/*
　* @$Id
　* @
　* @Ver: 2.0
　* @Create: 2009-11-18 8:10
　* @Modify: 
　* @Author: CPWEB http://www.cpweb.net.cn
　* @Copyright (C) 2008 www.cpweb.net.cn. All Rights Reserved.
　* @License CPWEB is free software and use is subject to license terms
　*/
class PublicAction extends Action{
	private $USER=array();
	function _initialize()
	{
		$this->USER['id']=intval(Session::get(C('USER_AUTH_KEY')));
		$this->USER['username']=Session::get('username');
	}
	public function login()
	{
		if(!$this->USER['id'])
		{
			$this->display();
		}else{
			$this->assign("jumpUrl","__APP__/Index/index/");
			$this->assign("waitSecond",3);
			$this->error(L('CPWEB_LOGIN'));
		}
	}	
	public function checkLogin()
	{
		$username=trim(dhtml($_POST['username']));
		$password=trim(dhtml($_POST['password']));
		$seccode=trim($_POST['seccode']);
		if($username=='')
		{
			$this->ajaxReturn(0,L('CPWEB_ERROR_MEMBER_NAME'),0);
		}elseif($password==''){
			$this->ajaxReturn(0,L('CPWEB_ERROR_MEMBER_PASSWORD'),0);
		}elseif(md5($seccode)!=$_SESSION['cpweb']){
			$this->ajaxReturn(0,L('CPWEB_ERROR_MEMBER_SECCODE'),0);
		}
		$Ures=M('Member');
		$map['username']=$username;
		$this->USER=$Ures->where($map)->find();
		if($this->USER){
			if($this->USER['password']==md5($password)){
				if($this->USER['ischecked']==1){
					Session::set(C('USER_AUTH_KEY'),$this->USER['id']);
					Session::set('username',$this->USER['username']);
					Session::set('lastlogintime',$this->USER['lastlogintime']);
					$Ures->setINC('logintimes','id='.$this->USER['id']);
					$ii= getdate();
					$Ures->setField('lastlogintime',$ii[0],'id='.$this->USER['id']);
					$this->ajaxReturn(0,$this->USER['username'].L('CPWEB_SUCCESS_LOGIN'),1);
				}else{
					$this->ajaxReturn(0,L('CPWEB_ERROR_MEMBER_ISCHECKED'),0);
				}
			}else{
				$this->ajaxReturn(0,L('CPWEB_ERROR_MEMBER_PASSWORD_O'),0);
			}
		}else{
			$this->ajaxReturn(0,L('CPWEB_ERROR_MEMBER_NAME_O'),0);
		}
	}
	public function verify(){
		import("ORG.Util.Image");
		Image::buildImageVerify(4,1,'png',50,22,'cpweb');
	}

	public function authorizationstop() 
	{
		$this->display();
	}
	public function logout() 
    {

        if(isset($this->USER['id'])) {
			Session::destroy();
			$this->assign("jumpUrl","__APP__/Public/login/");
			$this->assign("waitSecond",3);
            $this->assign("message",L('CPWEB_SUCCESS_LOGIN_O'));
        }else {
            $this->assign('error',L('CPWEB_LOGIN_O'));
			$this->assign("waitSecond",3);
			$this->assign("jumpUrl","__APP__/Public/login/");
        }
        $this->success();
    }
}
?>