<?php 
class CActionLogin extends CActionBase
{
	function doAction()
	{
		$ret = -1;
		$job = $_POST["job"];
		$user_name = $_POST["user_name"];
		$user_pwd = $_POST["user_pwd"];
			
		$sql = "select a.*, b.role_grade from tb_user a, tb_role b where user_name='".$user_name."' and a.role_id=b.role_id";
	
		$this->db->ExeQuerySql($sql);
		if($this->db->FetchRow())
		{			
			if($user_pwd != $this->db->Get("user_pwd"))
				$ret = -2;
			else
			{
				$ret = 0;
			
				if($job == "login")
				{
					$user_id = $this->db->Get("user_id");
					
					PhpSetCookie("UID", 	$user_id);
					PhpSetCookie("UNAME", $user_name);
					PhpSetCookie("RNAME", $this->db->Get("real_name"));
					PhpSetCookie("ROLE", $this->db->Get("role_grade"));
					PhpSetCookie("LOGIN", 1);
					GotoWeb("../index.php");
				}
			}
		}
		$this->db->FreeResult();
		
		return $ret;
	}	
};
?>
