<!--#include file="Inc/syscode.asp"-->
<!--#include file="Inc/md5.asp"-->
<!--#include file="top.asp"-->
<%
if EnableUserReg<>"Yes" then
	FoundErr=true
	ErrMsg=ErrMsg & "<br><li>对不起，本站暂停新用户注册服务！</li>"
	call WriteErrMsg()
	response.end
end if

const ChannelID=2
Const ShowRunTime="Yes"
SkinID=0

dim UserName,Password,PwdConfirm,Question,Answer,Sex,Email,Homepage,QQ,MSN
UserName=trim(request("UserName"))
Password=trim(request("Password"))
PwdConfirm=trim(request("PwdConfirm"))
Question=trim(request("Question"))
Answer=trim(request("Answer"))
Sex=trim(Request("Sex"))
Email=trim(request("Email"))
Homepage=trim(request("Homepage"))
QQ=trim(request("QQ"))
MSN=trim(request("MSN"))
dim CheckNum,CheckUrl
randomize
CheckNum = int(7999*rnd+2000) '随机验证码
CheckUrl=Request.ServerVariables("HTTP_REFERER")
CheckUrl=left(CheckUrl,instrrev(CheckUrl,"/")) & "UserRegCheck.asp?Action=Check&UserName=" & UserName & "&Password=" & Password & "&CheckNum=" & CheckNum
if UserName="" or strLength(UserName)>14 or strLength(UserName)<4 then
	founderr=true
	errmsg=errmsg & "<br><li>请输入用户名(不能大于14小于4)</li>"
else
  	if Instr(UserName,"=")>0 or Instr(UserName,"%")>0 or Instr(UserName,chr(32))>0 or Instr(UserName,"?")>0 or Instr(UserName,"&")>0 or Instr(UserName,";")>0 or Instr(UserName,",")>0 or Instr(UserName,"'")>0 or Instr(UserName,",")>0 or Instr(UserName,chr(34))>0 or Instr(UserName,chr(9))>0 or Instr(UserName,"")>0 or Instr(UserName,"$")>0 then
		errmsg=errmsg+"<br><li>用户名中含有非法字符</li>"
		founderr=true
	end if
end if
if Password="" or strLength(Password)>12 or strLength(Password)<6 then
	founderr=true
	errmsg=errmsg & "<br><li>请输入密码(不能大于12小于6)</li>"
else
	if Instr(Password,"=")>0 or Instr(Password,"%")>0 or Instr(Password,chr(32))>0 or Instr(Password,"?")>0 or Instr(Password,"&")>0 or Instr(Password,";")>0 or Instr(Password,",")>0 or Instr(Password,"'")>0 or Instr(Password,",")>0 or Instr(Password,chr(34))>0 or Instr(Password,chr(9))>0 or Instr(Password,"")>0 or Instr(Password,"$")>0 then
		errmsg=errmsg+"<br><li>密码中含有非法字符</li>"

		founderr=true
	end if
end if
if PwdConfirm="" then
	founderr=true
	errmsg=errmsg & "<br><li>请输入确认密码(不能大于12小于6)</li>"
else
	if Password<>PwdConfirm then
		founderr=true
		errmsg=errmsg & "<br><li>密码和确认密码不一致</li>"
	end if
end if
if Question="" then
	founderr=true
	errmsg=errmsg & "<br><li>密码提示问题不能为空</li>"
end if
if Answer="" then
	founderr=true
	errmsg=errmsg & "<br><li>密码答案不能为空</li>"
end if
if Sex="" then
	founderr=true
	errmsg=errmsg & "<br><li>性别不能为空</li>"
else
	sex=cint(sex)
	if Sex<>0 and Sex<>1 then
		Sex=1
	end if
end if
if Email="" then
	founderr=true
	errmsg=errmsg & "<br><li>Email不能为空</li>"
else
	if IsValidEmail(Email)=false then
		errmsg=errmsg & "<br><li>您的Email有错误</li>"
   		founderr=true
	end if
end if
if QQ<>"" then
	if not isnumeric(QQ) or len(cstr(QQ))>10 then
		errmsg=errmsg & "<br><li>QQ号码只能是4-10位数字，您可以选择不输入。</li>"
		founderr=true
	end if
end if
if MSN<>"" then
	if IsValidEmail(MSN)=false then
		errmsg=errmsg & "<br><li>你的MSN有误。</li>"
		founderr=true
	end if
end if

if founderr=false then
	dim sqlReg,rsReg
	sqlReg="select * from [User] where UserName='" & Username & "'"
	set rsReg=server.createobject("adodb.recordset")
	rsReg.open sqlReg,conn,1,3
	if not(rsReg.bof and rsReg.eof) then
		founderr=true
		errmsg=errmsg & "<br><li>你注册的用户已经存在！请换一个用户名再试试！</li>"
	else
		rsReg.addnew
		rsReg("UserName")=UserName
		rsReg("Password")=md5(Password)
		rsReg("Question")=Question
		rsReg("Answer")=md5(Answer)
		rsReg("Sex")=Sex
		rsReg("Email")=Email
		rsReg("Homepage")=Homepage
		rsReg("QQ")=QQ
		rsReg("MSN")=MSN
		rsReg("RegDate")=Now()
		rsReg("CheckNum")=CheckNum
		if EmailCheckReg="Yes" then
			rsReg("UserLevel")=3000
			call SendRegEmail()
		else
			if AdminCheckReg="Yes" then
				rsReg("UserLevel")=2000
			else			
				rsReg("UserLevel")=999
				Response.Cookies("asp163")("UserName")=UserName
				Response.Cookies("asp163")("Password") =md5(Password)
				Response.Cookies("asp163")("UserLevel")=999
			end if
		end if		
		rsReg.update
	end if
	rsReg.close
	set rsReg=nothing
end if		
PageTitle="注册成功"
%>
<html>
<head>
<title><%=strPageTitle & " >> " & PageTitle%></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<!--#include file="inc/Skin_CSS.asp"-->
<% call MenuJS() %>
<link rel="stylesheet" href="1.css" type="text/css">
</head>

<body leftmargin="2" topmargin="0" marginwidth="0" marginheight="0">
<table border="0" cellpadding="0" cellspacing="0" width="762" height="620" ALIGN="CENTER" BGCOLOR="#FFFFFF" >
  <tr> 
    <td height="18" colspan="4" BGCOLOR="#FFFFFF"></td>
  </tr>
  <tr> 
    <td width="22" height="486" BACKGROUND="bg.gif"></td>
    <td width="1" height="486" valign="top">&nbsp;</td>
    <td width="717" align="center" valign=top><table width="100%" border="0" cellpadding="0" cellspacing="0" >
        <tr> 
          <td> <div align="center"><br>
              <br>
              <br>
              <br>
              <%
if founderr=false then
	call RegSuccess()
else
	call WriteErrmsg()
end if
%>
              <br>
              <br>
            </div></td>
        </tr>
      </table>
      <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
        <tr> 
          <td  height="15" align="center" valign="top"> <table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
              <tr> 
                <td height="13"></td>
              </tr>
            </table></td>
        </tr>
      </table></td>
    <td width="22" height="486" BACKGROUND="bg.gif"></td>
  </tr>
  <tr VALIGN="MIDDLE"> 
    <td height="35" colspan="4"><DIV ALIGN="CENTER"> 
        <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0">
          <TR> 
            <TD HEIGHT="35" BACKGROUND="footbg.gif">&nbsp;</TD>
          </TR>
        </TABLE>
      </DIV></td>
  </tr>
  <tr VALIGN="TOP"> 
    <td height="4" colspan="4" BORDERCOLOR="1"><TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" HEIGHT="76">
        <TR> 
          <TD WIDTH="54%" VALIGN="TOP" HEIGHT="2"><iframe frameborder=0 name=tong scrolling=no src="http://www.3niao.com/home/online/index.asp" 
            width=15 HEIGHT=15>层</iframe></TD>
          <TD WIDTH="46%" ROWSPAN="2"><DIV ALIGN="RIGHT"><IMG SRC="images/foot.gif" WIDTH="280" HEIGHT="80"></DIV></TD>
        </TR>
        <TR> 
          <TD WIDTH="54%" VALIGN="TOP" BACKGROUND="footgb1.gif" HEIGHT="53">&nbsp;</TD>
        </TR>
      </TABLE></td>
  </tr>
</table>
</html>
<%
call CloseConn

sub WriteErrMsg()
    response.write "<br><br><table align='center' width='300' border='0' cellpadding='2' cellspacing='0' class='border'>"
    response.write "<tr class='title'><td align='center' height='22'>由于以下的原因不能注册用户！</td></tr>"
    response.write "<tr class='tdbg'><td align='left' height='100'><br>" & errmsg & "<p align='center'>【<a href='javascript:onclick=history.go(-1)'>返 回</a>】<br></p></td></tr>"
	response.write "</table>" 
end sub

sub RegSuccess()
    response.write "<br><br><table align='center' width='300' border='0' cellpadding='2' cellspacing='0' class='border'>"
    response.write "<tr class='title'><td align='center' height='22'>成功注册用户！</td></tr>"
    response.write "<tr class='tdbg'><td align='left' height='100'><br>你注册的用户名：" & UserName & "<br>"
	if EmailCheckReg="Yes" then
		response.write "系统已经发送了一封确认信到你注册时填写的信箱中，你必须在收到确认信并通过确认信中链接进行确认后，你才能正式成为本站的注册用户。"
	else
		if AdminCheckReg="Yes" then
			response.write "请等待管理通过你的注册申请后，你就可以正式成为本站的注册用户了。"
		else			
			response.write "欢迎您的加入！3鸟设社需要你的支持!"
		end if
	end if		
	response.write "<p align='center'>【<a href='javascript:onclick=window.close()'>关 闭</a>】<br></p></td></tr>"
	response.write "</table>" 
end sub

sub SendRegEmail()
	dim MailtoAddress,MailtoName,Subject,MailBody,FromName,MailFrom,Priority
	MailtoAddress=Email
	MailtoName=UserName
	Subject="注册确认信"
	MailBody="这是一封注册确认信。你的验证码是：" & CheckNum & vbcrlf & "<br>请点此进行确认：<a href='" & CheckUrl & "'>" & CheckUrl & "</a>"
	FromName=SiteName
	MailFrom=WebmasterEmail
	Priority=3
	ErrMsg=SendMail(MailtoAddress,MailtoName,Subject,MailBody,FromName,MailFrom,Priority)
	if ErrMsg<>"" then FoundErr=True
end sub
%>