<?php
include_once("common/config.php");
include_once("common/publicfun.php");
include_once("classes/dbclass.php");
include_once("conn.php");
include_once("common/checkpost.php");

$username=flc_request(trim($_POST["username"]));
$password=flc_request(trim($_POST["pwd"]));
$password=md5($password);
$ip=GetUserIP();

$reurl=flc_request(trim($_GET["reurl"]));

//滑动验证
if ($_SESSION['tncode_check']!='ok'){
   $response_arr = array("status" => 0,"message"  => '验证未通过,请重新验证!');
   echo json_encode($response_arr);
   exit;
}

unset($_SESSION['tncode_check']);

//审核用户允许登录
$sql   ="select * from {$tablepre}scuser where UserName='".$username."' and AdminType=0 and isCheck=1";
$row   = $db->get_row($sql);
if (empty($row)){
   $response_arr = array("status" => 0,"message"  => '用户名不正确或已被禁用！');
   echo json_encode($response_arr);
   exit;
}
else{
      $uid=$row["ID"];
	  $uname=$row["UserName"];
	  $pwd=$row["Password"];
	  if ($pwd==$password && $uname==$username){
	      $_SESSION["uid"]=$uid;
		  $_SESSION["UserName"]=$uname;
	      $_SESSION["pwd"]=$pwd;
		  //$_SESSION["errorcount"]=0;
		  $sql="update {$tablepre}scuser set LastLoginTime='".$getnow."',LastLoginIP='".$ip."',LoginTimes=LoginTimes+1 where UserName='".$username."'";
          $db->exec($sql);
		  
		  $response_arr = array("status" => 1,"message"  => '登录成功!',"reurl"  => $reurl);
          echo json_encode($response_arr);
          exit;

	  }
	  else{
	      $_SESSION["errorcount"]=$_SESSION["errorcount"]+1;
		  $response_arr = array("status" => 0,"message"  => '登录密码不正确！');
          echo json_encode($response_arr);
          exit;
	  }
}
?>