Index: pro-violet-viettel/sourcecode/application/modules/frontend/controllers/home.php
===================================================================
--- pro-violet-viettel/sourcecode/application/modules/frontend/controllers/home.php	(revision 439)
+++ pro-violet-viettel/sourcecode/application/modules/frontend/controllers/home.php	(revision 447)
@@ -34,11 +34,4 @@
 				$this->load->view ( 'home');
 			}
-		}
-	}
-	
-	public function test()
-	{
-		if (isset($_POST['submit'])){
-			$this->signin();
 		}
 	}
@@ -80,5 +73,6 @@
 			switch($status)
 			{
-				case 0:		
+				case 0:
+				case 4:
 					if($autologin == 1){
 						$cookie_name = 'siteCookie';
@@ -100,7 +94,6 @@
 					redirect('/frontend/home');
 					break;
-				case 4:
-					redirect('/frontend/home');
-					break;
+				//case 4:
+					//redirect('/frontend/home');
 				case 10:
 					$this->session->set_flashdata('login_error_token', TRUE);
@@ -121,5 +114,18 @@
 		redirect('/frontend/home');
 	}
-
+	public function register()
+	{
+		$this->load->model('user_model');
+		$sentNumber = '0979947802';
+		$serviceID = 1;
+		$receiveID = '0985685735';
+		$commandcode = 'commandcode1';
+		$info = 'ABCD';
+		//$receiveTime = time();
+		$receiveTime = date("Y-m-d H:i:s");
+		$data = $this->user_model->register($sentNumber, $receiveID, $serviceID, $commandcode, $info, $receiveTime);
+		echo $data;
+	}
+	
 }
 
Index: pro-violet-viettel/sourcecode/application/modules/frontend/models/user_model.php
===================================================================
--- pro-violet-viettel/sourcecode/application/modules/frontend/models/user_model.php	(revision 439)
+++ pro-violet-viettel/sourcecode/application/modules/frontend/models/user_model.php	(revision 447)
@@ -1,6 +1,8 @@
-﻿<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
 class User_model extends CI_Model
 {
+	
+	const TOKENPW = 'violet';
 	
 	function __construct(){
@@ -48,5 +50,5 @@
 		}
 		$status = (int)$arr_status[1];
-		if ($status == 0){
+		if ($status == 0 || $status = 4){
 			$us_id = (int)$usid;
 			$query = "SELECT * FROM tbluser WHERE us_id = ?";
@@ -64,5 +66,6 @@
 	}
 
-	function register ($sentNumber, $receiverID, $serviceID, $commandcode, $info, $receiveTime) {
+	function register ($sentNumber, $receiverID, $serviceID, $commandcode, $info, $receiveTime)
+	{
 		//1. check collaborator info if $receiverID existed
 		//2. insert new user to database
@@ -72,5 +75,4 @@
 		$username = '';
 		$collaborator = '';
-		
 		if (is_null($receiverID) || $receiverID == '') {
 			$username = $sentNumber;
@@ -80,6 +82,54 @@
 			$collaborator = $sentNumber;
 		}
-		
-		
+		$user = array();
+		$smslog = array();
+		$password = $this->create_random_password();
+		$src = 'SBG';
+		$token = md5($username.self::TOKENPW);
+		$phone = $username;
+		$data = $this->vservices->actionExecute('update', array('src'=>$src, 'username'=>$username, 'password'=>$password, 'fullname'=>" ", 'phone'=>$username, 'token'=>$token), 'user');
+		$status = substr($data, 7, 1);
+		$sms = "";
+		switch($status)
+		{
+			case "0":
+				$us_id = (int)substr($data, 12);
+				$user['created_time'] = $receiveTime;
+				$user['updated_time'] = $receiveTime;
+				$user['us_id'] = $us_id;
+				$user['cellphone'] = $username;
+				$user['collaborator'] = $collaborator;
+				$this->db->insert('tbluser', $user);
+				$smslog['sender'] = $sentNumber;
+				$smslog['us_id'] = $us_id;
+				$smslog['service_id'] = $serviceID;
+				$smslog['commandcode'] = $commandcode;
+				$smslog['info'] = $info;
+				$smslog['created_time'] = $receiveTime;
+				$this->db->insert('tblsmslog', $smslog);
+				$sms = "Chuc mung Qui vi da dang ky thanh cong tai khoan Soan Bai giang Online.
+					Hay dang nhap vao http://soanbaigiang.smas.vn/ voi ten truy nhap [".$username."], mat khau [".$password."] de su dung.";
+				return $sms;
+			case "2":
+				$sms = "Tai khoan cua Qui vi da duoc dang ky !";			
+				return $sms;
+			case "4":
+				$sms = "So dien thoai cá»§a Qui vi da duoc dang ky !";
+				return $sms;
+			default:
+				break;
+		}
+	}
+	
+	function create_random_password()
+	{
+		$alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
+		$pass = array();
+		$alphaLength = strlen($alphabet) - 1;
+		for ($i = 0; $i < 6; $i++) {
+			$n = rand(0, $alphaLength);
+			$pass[] = $alphabet[$n];
+		}
+		return implode($pass);
 	}
 }
Index: pro-violet-viettel/sourcecode/application/modules/frontend/views/home.php
===================================================================
--- pro-violet-viettel/sourcecode/application/modules/frontend/views/home.php	(revision 439)
+++ pro-violet-viettel/sourcecode/application/modules/frontend/views/home.php	(revision 447)
@@ -185,5 +185,5 @@
 						required: true,
 					},
-					account: {
+					username: {
 						required: true
 					}
@@ -191,5 +191,5 @@
 		
 				messages: {
-					account: {
+					username: {
 						required: "Vui lÃ²ng nháº­p tÃ i khoáº£n hoáº·c sá» Äiá»n thoáº¡i",
 					},
