Index: /pro-violet-viettel/sourcecode/application/modules/frontend/controllers/home.php
===================================================================
--- /pro-violet-viettel/sourcecode/application/modules/frontend/controllers/home.php	(revision 325)
+++ /pro-violet-viettel/sourcecode/application/modules/frontend/controllers/home.php	(revision 326)
@@ -25,7 +25,12 @@
 			redirect('/frontend/lecture');
 		}else{
-			$this->load->view ( 'home');
-			if (isset($_POST['submit'])){
-				$this->signin();
+			$cookie_name = "siteCookie";
+			if(isset($_COOKIE[$cookie_name])){
+				$arr_user = parse_str($_COOKIE[$cookie_name]);
+				$user_info = array( 'username' => $arr_user['username'], "logined_in" => TRUE);
+				$this->session->set_userdata('userInfo', $user_info);
+				redirect('/frontend/lecture');
+			}else{
+				$this->load->view ( 'home');
 			}
 		}
@@ -43,51 +48,66 @@
 		$username = $this->input->post('username', TRUE);
 		$password = $this->input->post('password', TRUE);
+		$autologin = ($this->input->post('remember_me') == 'on') ? 1 : 0;
 		$token = md5($username.self::TOKENPW);
 		$this->load->model(array('user_model'));
 		$data = $this->user_model->checkLogin('violet', $token, $username, $password);
-		echo $data;
-		$arr_users = explode("&", $data);
-		$str_status = "";
-		$str_fullname = "";
-		$fullname = "";
-		for ($i=0; $i<count($arr_users); $i++)
+		if ($data == null)
 		{
-			if (strpos($arr_users[$i], 'status=') !== false)
+			$this->session->set_flashdata('login_error', TRUE);
+			redirect('/frontend/home');
+		}else{
+			$arr_users = explode("&", $data);
+			$str_status = "";
+			$str_fullname = "";
+			$fullname = "";
+			for ($i=0; $i<count($arr_users); $i++)
 			{
-				$str_status = $arr_users[$i];
+				if (strpos($arr_users[$i], 'status=') !== false)
+				{
+					$str_status = $arr_users[$i];
+				}
+				if (strpos($arr_users[$i], 'fullname=') !== false)
+				{
+					$str_fullname = $arr_users[$i];
+				}
 			}
-			if (strpos($arr_users[$i], 'fullname=') !== false)
+			$arr_status = explode("=", $str_status);
+			if ($str_fullname != ""){
+				$arr_fullname = explode("=", $str_fullname);
+				$fullname = $arr_fullname[1];
+			}
+			$status = (int)$arr_status[1];
+			switch($status)
 			{
-				$str_fullname = $arr_users[$i];
+				case 0:		
+					if($autologin == 1){
+						$cookie_name = 'siteCookie';
+						//$cookie_time = 7200;
+						$cookie_time = 3600*24*30;
+						setcookie($cookie_name, 'username='.$username, time() + $cookie_time);
+					}
+					$userdata = array('username' => $username, "logined_in" => TRUE);
+					$this->session->set_userdata('userInfo', $userdata);
+					redirect('/frontend/lecture');
+					break;
+				case 1:
+					$this->session->set_flashdata('login_error', TRUE);
+					redirect('/frontend/home');
+					break;
+				case 2:
+				case 3:
+					$this->session->set_flashdata('login_error', TRUE);
+					redirect('/frontend/home');
+					break;
+				case 4:
+					redirect('/frontend/home');
+					break;
+				case 10:
+					$this->session->set_flashdata('login_error_token', TRUE);
+					redirect('/frontend/home');
+					break;
+				default:
+					break;
 			}
-		}
-		$arr_status = explode("=", $str_status);
-		if ($str_fullname != ""){
-			$arr_fullname = explode("=", $str_fullname);
-			$fullname = $arr_fullname[1];
-		}
-		$status = (int)$arr_status[1];
-		switch($status)
-		{
-			case 0:
-				$userdata = array('username' => $username, "logined_in" => TRUE);
-				$this->session->set_userdata('userInfo', $userdata);
-				redirect('/frontend/lecture');
-				break;
-			case 1:
-				echo "Thiếu thông tin đăng nhập !";
-				break;
-			case 2:
-			case 3:
-				echo "Sai username hoặc password !";
-				break;
-			case 4:
-				echo "Tài khoản chưa được Activated";
-				break;
-			case 10:
-				echo "Sai Token";
-				break;
-			default:
-				break;
 		}
 	}
@@ -95,5 +115,9 @@
 	public function signout() 
 	{
-		
+		$this->session->sess_destroy();
+		//unset($this->session->userdata); 
+		$cookie_name = "siteCookie";
+		setcookie($cookie_name, 'username='."", time() - 3600);
+		redirect('/frontend/home');
 	}
 
Index: /pro-violet-viettel/sourcecode/application/modules/frontend/controllers/lecture.php
===================================================================
--- /pro-violet-viettel/sourcecode/application/modules/frontend/controllers/lecture.php	(revision 325)
+++ /pro-violet-viettel/sourcecode/application/modules/frontend/controllers/lecture.php	(revision 326)
@@ -13,5 +13,4 @@
 	{
 		parent::__construct();
-		$this->load->library('session');
 	}
 
@@ -19,10 +18,11 @@
 	{	
 		$user_info = $this->session->userdata('userInfo');
-		if ($user_info){
+		if (isset($user_info)){
 			$this->load->view ( 'lecture_editor');
-		}else
-		{
+
+		}else{
 			redirect('/frontend/home/');
 		}
+		
 	}
 }
Index: /pro-violet-viettel/sourcecode/application/modules/frontend/models/user_model.php
===================================================================
--- /pro-violet-viettel/sourcecode/application/modules/frontend/models/user_model.php	(revision 325)
+++ /pro-violet-viettel/sourcecode/application/modules/frontend/models/user_model.php	(revision 326)
@@ -14,5 +14,57 @@
 	{
 		$data = $this->vservices->actionExecute('login', array('src' => $src, 'token' => $token, 'username' => $username, 'password' => $password), 'user');
-		return $data;
+		//return $data;
+		$arr_users = explode("&", $data);
+		$str_status = "";
+		$str_fullname = "";
+		$str_usid = "";
+		$usid = "";
+		$fullname = "";
+		for ($i=0; $i<count($arr_users); $i++)
+		{
+			if (strpos($arr_users[$i], 'status=') !== false)
+			{
+				$str_status = $arr_users[$i];
+			}
+			
+			if (strpos($arr_users[$i], 'fullname=') !== false)
+			{
+				$str_fullname = $arr_users[$i];
+			}
+			
+			if (strpos($arr_users[$i], 'us_id=') !== false)
+			{
+				$str_usid = $arr_users[$i];
+			}
+		}
+		$arr_status = explode("=", $str_status);
+		if ($str_fullname != "")
+		{
+			$arr_fullname = explode("=", $str_fullname);
+			$fullname = $arr_fullname[1];
+		}
+		if ($str_usid !== "")
+		{
+			$arr_usid = explode("=", $str_usid);
+			$usid = $arr_usid[1];
+		}
+		
+		$status = (int)$arr_status[1];
+		if ($status == 0){
+			$us_id = (int)$usid;
+			$query = "SELECT * FROM tbluser WHERE us_id = ?";
+			$result = $this->db->query($query, array($us_id));
+			if($result->num_rows() == 1){
+				return $data;
+			}else
+			{
+				return null;
+			}
+		}else
+		{
+			return $data;
+		}
+		
+		
 	}
 	
