<?php
require_once('tgydapicommon.php');
//************************执行代码开始*************************
if($_POST['do']=='register'){
	session_start();
	$user=safestr($_POST['user']);
	$email=safestr($_POST['email']);
	$pwd=safestr($_POST['pwd']);
	$code=safestr($_POST['code']);
	$qq=safestr($_POST['qq']);
	$ip=getip();
	if(!$user || !$email || !$pwd || !$qq || !$code){
		$msg="每一项都必须填写";
	}elseif(strlen($user) < 5){
		$msg="用户名太短";
	}elseif(!$code || strtolower($_SESSION['klsf_code'])!=strtolower($code)){
		$msg="验证码错误";//exit("<script language='javascript'>alert('验证码错误');history.go(-1);</script>");
	}elseif(strlen($pwd) < 5){
		$msg="密码太简单";//exit("<script language='javascript'>alert('密码太简单！');history.go(-1);</script>");
	}elseif(!preg_match("/^[a-z0-9][a-z0-9\.\_\-]+@[a-z0-9]+\.[a-z]{2,4}$/i",$email)){ 
		$msg="邮箱地址不正确";//exit("<script language='javascript'>alert('邮箱地址不正确');history.go(-1);</script>");
	}elseif($db->get_row("select uid from ".C('DB_PREFIX')."users where mail='{$email}' limit 1")){
		$msg="此邮箱已经注册过";//exit("<script language='javascript'>alert('此邮箱已经注册过');history.go(-1);</script>");
	}elseif($db->get_row("select uid from ".C('DB_PREFIX')."users where user='{$user}' limit 1")){
		$msg="用户名已存在";//exit("<script language='javascript'>alert('用户名已存在！');history.go(-1);</script>");
	}else{
		$_SESSION['klsf_code'] =md5(rand(100,500).time());
		$sid=md5(uniqid().rand(1,1000));
		$pwd=md5(md5($pwd).md5('815856515'));
		$now=date("Y-m-d H:i:s");
		$city=get_ip_city($ip);
		$active=1;
		$peie=C('regpeie');
		$rmb=C('regrmb');
		if ($db->query("insert into  ".C('DB_PREFIX')."users (user,pwd,sid,active,peie,rmb,mail,qq,city,regip,lastip,regtime,lasttime) values ('$user','$pwd','$sid','$active','$peie','$rmb','$email','$qq','$city','$ip','$ip','$now','$now')")) {
			$msg="√注册成功！<a href='login.php'>马上登录</a>";
		}else{
			$msg="注册失败，".mysql_error();
		}
	}
}
//************************执行代码结束**************************
?>
<!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>
<div class="container">
  <div class="row login-container animated fadeInUp">  
        <div class="col-md-8 col-md-offset-2 tiles white no-padding">
		 <div class="p-t-30 p-l-40 p-b-20 xs-p-t-10 xs-p-l-10 xs-p-b-10"> 
         <h2 class="normal"><?php if($msg){?><?=$msg?><?php }else{echo '<h2 class="normal">欢迎注册加入我们';}?></h2>
		  <p>目前,已经实现了更快捷的注册方式.</p>
          <p>所有项必填，资料一经填写无法修改（除密码外）</p>
		  </div>
		<div class="tiles grey p-t-20 p-b-20 text-black">
		<form action="?" class="form-sign" method="post">
		<input type="hidden" name="do" value="register" class="form-sign">
                    <div class="row form-row m-l-20 m-r-20 xs-m-l-10 xs-m-r-10">
                      <div class="col-md-6 col-sm-6">
                        <input name="user" type="text"  class="form-control" placeholder="用户名Username">
                      </div>
                      <div class="col-md-6 col-sm-6">
                        <input name="pwd" type="password"  class="form-control" placeholder="密码Password">
                      </div>
                    </div>	
                    <div class="row form-row m-l-20 m-r-20 xs-m-l-10 xs-m-r-10">
                      <div class="col-md-6 col-sm-6">
                        <input name="qq" type="tel"  class="form-control" placeholder="QQ号">
                      </div>
					  <div class="col-md-6 col-sm-6">
                        <input name="email" type="email"  class="form-control" placeholder="邮箱Email">
                      </div>
                    </div>		
                    <div class="row form-row m-l-20 m-r-20 xs-m-l-10 xs-m-r-10">
                      <div class="col-md-6 col-sm-6">
                        <input name="code" type="text"  class="form-control" placeholder="验证码Code">
                      </div>
                      <div class="col-md-3 col-sm-3">

<img title="点击刷新" src="code.php" onclick="javascript:this.src='code.php?'+Math.random();"></img>
                      </div>
 <div class="col-md-3 col-sm-3">
<input type="submit" class="btn btn-primary" name="submit" value="注册Register"></input></div>
 </div>
                    <div class="row form-row m-l-20 m-r-20 xs-m-l-10 xs-m-r-10">
<div class="col-md-4 col-sm-4">
</div>
				  <div class="control-group  col-md-10">
					<div class="checkbox checkbox check-success"> <a href="/login.php">已经注册成功?点击登录</a>
					</div>
				  </div>
			</form>
		</div> 


