<?php
require_once('tgydapicommon.php');
//************************执行代码开始*************************
if($_POST['do']=='login'){
	$user=safestr($_POST['user']);
	$pwd=safestr($_POST['pwd']);
	$ip=getip();
	if(!$user || !$pwd){
		$msg="账号密码不能为空";
	}elseif(strlen($user) < 5){
		$msg="用户名太短";
	}elseif(strlen($pwd) < 5){
		$msg="密码太简单";//exit("<script language='javascript'>alert('密码太简单！');history.go(-1);</script>");
	}else{
		$pwd=md5(md5($pwd).md5('815856515'));
		if(is_numeric($user)){
			$where="(user='$user' or phone='$user') and pwd='$pwd'";
		}else{
			$where="(user='$user' or mail='$user') and pwd='$pwd'";
		}
		if($row=$db->get_row("select uid,user from ".C('DB_PREFIX')."users where {$where} limit 1")){
			$sid=md5(uniqid().rand(1,1000));
			$now=date("Y-m-d H:i:s");
			$ip=getip();
			$db->query("update ".C('DB_PREFIX')."users set sid='$sid',lasttime='$now',lastip='$ip' where uid='{$row[uid]}'");
			setcookie("klsf_sid",$sid,time()+3600*24*14,'/');
			$ntime=date("G"); //取得现在的时间
	if($ntime>=0 and $ntime<4){exit("<script language='javascript'>alert('{$row[user]}，午夜好！');window.location.href='/mgmt';</script>");}
	if($ntime>=4 and $ntime<11){exit("<script language='javascript'>alert('{$row[user]}，早上好！');window.location.href='/mgmt';</script>");}
	if($ntime>=11 and $ntime<14){exit("<script language='javascript'>alert('{$row[user]}，中午好！');window.location.href='/mgmt';</script>");}
	if($ntime>=14 and $ntime<18){exit("<script language='javascript'>alert('{$row[user]}，下午好！');window.location.href='/mgmt';</script>");}
	if($ntime>=18 and $ntime<24){exit("<script language='javascript'>alert('{$row[user]}，晚上好！');window.location.href='/mgmt';</script>");}
		}else{
			$msg="Email/用户名/手机号与密码不匹配";
		}
	}
}
//************************执行代码结束**************************
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<link href="/indexs/css/pace-theme-flash.css" rel="stylesheet" type="text/css" media="screen"/>
<link href="/indexs/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<link href="/indexs/css/bootstrap-theme.min.css" rel="stylesheet" type="text/css"/>
<link href="/indexs/css/font-awesome.css" rel="stylesheet" type="text/css"/>
<link href="/indexs/css/animate.min.css" rel="stylesheet" type="text/css"/>
<!-- END CORE CSS FRAMEWORK -->
<!-- BEGIN CSS TEMPLATE -->
<link href="/indexs/css/style.css" rel="stylesheet" type="text/css"/>
<link href="/indexs/css/responsive.css" rel="stylesheet" type="text/css"/>
<link href="/indexs/css/magic_space.css" rel="stylesheet" type="text/css"/>
<link href="/indexs/css/custom-icon-set.css" rel="stylesheet" type="text/css"/>
<body class="error-body no-top lazy" style="background: url(/index/img/hero-bg.jpg);background-size: cover;"> 
<title>系统登陆 - <?=C('webname')?></title>
<body class="error-body no-top">

<div class="container">
  <div class="row login-container column-seperation">  
        <div class="col-md-5 col-md-offset-1">
          <h2><?=C('webname')?></h2>
          <p>目前,已经实现了更快捷的方式.<br>
            如果你已经登陆, <a href="/mgmt" class="btn btn-primary btn-cons" type="submit">请点击到用户中心</a> 如果你无法进行登录,试试下面的按钮.</p>
          <br>
		   <a href="/findpwd.php" class="btn btn-block col-md-8" type="button">
            <span class="pull-left"><i class="fa fa-mail-forward"></i></span>
            <span class="bold">密码找回</span> </a>
		   <a href="/reg.php" class="btn btn-block btn-success col-md-8" type="button">
            <span class="pull-left"><i class="fa fa-key"></i></span>
            <span class="bold">用户注册</span> </a>
        </div>
        <div class="col-md-5 "> <br>
		 <form class="login-form" action="?" method="post">
		 <input type="hidden" name="do" value="login"/>
		<input type="hidden" name="type" value="1"/>
<div class="alert alert-info"><div class="alert-content"><?php if(stripslashes(C('web_control_gg'))==''){echo("暂无公告");}?><?php if($msg){?><div class="alert alert-warning alert-dismissable"><div>提示:<?=$msg?></div></div><?php }?></div></div>		 <div class="row">
		 <div class="form-group col-md-10">
            <label class="form-label">用户名Username</label>
            <div class="controls">
				<div class="input-with-icon  right">
					<i class=""></i>
					<input type="text" name="user" id="txtusername" class="form-control" placeholder="用户名/邮箱/手机号/QQ均可登录" required autofocus>
				</div>
            </div>
          </div>
          </div>
		  <div class="row">
          <div class="form-group col-md-10">
            <label class="form-label">密码Password</label>
            <span class="help"></span>
            <div class="controls">
				<div class="input-with-icon  right">
					<i class=""></i>
					<input type="password" name="pwd" id="txtpassword" class="form-control" placeholder="输入密码" required>
				</div>
            </div>
          </div>
          </div>
          <div class="row">
            <div class="col-md-10">
              <button class="btn btn-primary btn-cons pull-right" type="submit">登录Login</button>
            </div>
          </div>
		  </form>
        </div>
     
    
  </div>
</div>

<script src="/indexs/js/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="/indexs/js/bootstrap.min.js" type="text/javascript"></script>
<script src="/indexs/js/pace.min.js" type="text/javascript"></script>
<script src="/indexs/js/jquery.validate.min.js" type="text/javascript"></script>
<script src="/indexs/js/login.js" type="text/javascript"></script>

</body>
</html>