<?
// クラス、設定読み込み
require_once ("../user_include.inc");

ErrorLogger::doOutput("Koala...ajax_user_login.php....Start.", 0);

$mobile = ParamUtil::getRequestString("mobile");
$verifycode = ParamUtil::getRequestString("verifycode");

ErrorLogger::doOutput("Koala...ajax_user_login.php....mobile=" . $mobile, 0);
ErrorLogger::doOutput("Koala...ajax_user_login.php....verifycode=" . $verifycode, 0);

//获取不到手机号码
if(empty($mobile)) {
	responseNG("手机号码错误！");
}

//获取不到验证码
if(empty($verifycode)) {
	responseNG("验证码错误！");
}

//检测验证码
$verification_code = @$_SESSION['verificationCode'];
if(empty($verification_code) || $verification_code != $verifycode) {
	responseNG("验证码错误！");
}

//检测用户是否已经注册
$param = array();
$param["delete_flg"] = false;
$param["mobile"] = $mobile;
$user_list = UserMst::getList($param);
//存在的情况下，注册一条数据
if(empty($user_list)) {	
	responseNG("手机号码不存在！");
}

//清除验证码
if(isset($_SESSION['verificationCode'])) {
	unset($_SESSION['verificationCode']);
}
//设定到session中保持
$_SESSION['_user_'] = $user_list[0];

ErrorLogger::doOutput("Koala...ajax_user_login.php....End.", 0);

responseOK("登陆成功！");

function responseNG($message) {
	$result = array("status"=>"NG", "message"=>$message);
	print json_encode($result);
	exit;
}
function responseOK($message) {
	$result = array("status"=>"OK", "message"=>$message);
	print json_encode($result);
	exit;
}

?>