<!--#include file="../conn.asp"-->
<!--#include file="../inc/md5.asp"-->
<!--#include file="../inc/function.asp"-->
<!--#include file="../inc/Language.asp"-->
<%
Dim AskD,inHtml
Set AskD = Server.CreateObject("KwAsk.FunAsk")
	opendb
	set AskD.myConn =conn
	AskD.myPredb =predb
	AskD.Getsetting()
	AskD.GetUserRole()
	siteinfo=AskD.siteinfo
	setting=AskD.setting
    UserRole=AskD.UserRole
	regForm=AskD.regForm
dim act
act=Trim(Request.Form("act"))
if act="1" then
  call reg()
else 
	AskD.GetTemplate("user/T-reg.html")
    inHtml=RexHtml(AskD.tempbody)
    inHtml=RexHtml_IF(inHtml)
    Response.Write(inHtml)
end if
set AskD.myConn =Nothing
Call Closedb()
Set AskD = Nothing

sub reg()
Dim Userid,Userpsd1,Userpsd2,Nicheng,Usermail,Sex,regquestion,regans,truename,qq,msn,tel,info,verycode,curl,cip
    Userid=Trim(Request.Form("userid"))
    Userpsd1=Trim(Request.Form("userpass1"))
    Userpsd2=Trim(Request.Form("userpass2"))
    Nicheng=Trim(Request.Form("Nicheng"))
    Usermail=Trim(Request.Form("usermail"))
    Sex=Trim(Request.Form("sex"))
	regquestion=Trim(Request.Form("regquestion"))
	regans=Trim(Request.Form("regans"))
	truename=Trim(Request.Form("truename"))
	qq=Trim(Request.Form("qq"))
	msn=Trim(Request.Form("msn"))
	tel=Trim(Request.Form("tel"))
	info=Trim(Request.Form("info"))
	verycode=Trim(Request.Form("verycode"))
    curl=Trim(Request.Form("curl"))
    if curl="" then curl="../"
	
	if len(UserID)<clng(regForm(5)) or len(UserID)>clng(regForm(6)) then
	  Response.Write "<script>var a = new parent.xWin(""1"",240,100,"""&siteInfo(4)&""","""&regForm(5)&"用户名位数不正确！"");</script>"
      Response.End()
	end if
	
	
CIP=Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If CIP="" then
   CIP=Request.ServerVariables("REMOTE_ADDR")
End If
	
If Request.Cookies("kwreg")="" Then
   Response.Cookies("kwreg")=0
End If

IF instr(","&regForm(7)&",",","&Userid&",")>0 then
	  Response.Write "<script>var a = new parent.xWin(""1"",240,100,"""&siteInfo(4)&""",""该用户名禁止注册！"");</script>"
	  Response.End()
End IF
IF instr(vbcrlf&regForm(8)&vbcrlf,vbcrlf&cip&vbcrlf)>0 then
	  Response.Write "<script>var a = new parent.xWin(""1"",240,100,"""&siteInfo(4)&""",""该IP禁止注册！"");</script>"
      Response.End()
End IF
IF instr(siteInfo(12),"passcode2")>0 and verycode<>Cstr(session("SafeCode")) then
	  Response.Write "<script>var a = new parent.xWin(""1"",240,100,"""&siteInfo(4)&""",""您的验证码填写错误！"");</script>"
      Response.End()
End IF

IF Clng(regForm(4))=0 Or Clng(Request.Cookies("kwreg")) < Clng(regForm(4)) Then  '每天只允许注册 次
 Dim Rs,Sql,rs1,rsID,Activat
  Set Rs=server.CreateObject("adodb.recordset")
      Rs.CursorLocation = 3
	  IF regForm(2)=1 Then Sql=" or Usermail='"&Usermail&"'"
      Sql ="Select * from "&predb&"User where Userid='"&Userid&"'"&sql
      Rs.open Sql,Conn,1,3
	If Rs.Bof And Rs.Eof Then
	   Rs.AddNew
	   Rs("Userid")=Userid
	   Rs("Userpass")=Md5(Userpsd1,16)
	   Rs("Nicheng")=Nicheng
	   Rs("Usermail")=Usermail
	   Rs("Sex")=Sex
	   Rs("regquestion")=regquestion
	   Rs("regans")=md5(regans,16)
	   Rs("truename")=truename
	   Rs("qq")=qq
	   Rs("msn")=msn
	   Rs("tel")=tel
	   Rs("info")=info
	   Rs("Grade")=1
	   Rs("Regtime")=Now()
	   Rs("Lasttime")=Now()
	   Rs("Lastip")=cip
	   Rs("Score")=setting(11)
	   Rs("islock")=0
	   IF regForm(1)=0 then
	      Rs("islock")=2
	   End IF
	   IF regForm(3)=0 Then
	      Activat=Md5(Userid&Userpsd1&Usermail&AskD.Activated,16)
	      Rs("islock")=3
		  Rs("Activated")=Activat
	   End IF
	   Rs.UpDate
	   
	     Response.Cookies("Muser")=Rs("ID")
	     Response.Cookies("Musername")=Rs("userID")
	     Response.Cookies("MuserPass")=Md5(Userpsd1,16)
		 Response.Cookies("Grade")=1
		 Response.Cookies("islock")=Rs("islock")
         Response.Cookies("kwreg")=Request.Cookies("kwreg")+1
         Response.Cookies("kwreg").Expires=Date+1
	   Rs.Close:Set Rs=Nothing	
	    
	   IF regForm(3)=0 then
	     Dim From,FromName,Topic,MailBody,ToMail,SmtpName,SmtpPass,MailSmtp
				Topic=siteInfo(4)&" - "&Lan1
				MailBody=Lan2&" <a target='_blank' href='"&siteInfo(0)&siteInfo(1)&"User/Activated.asp?ID="&Request.Cookies("Muser")&"&Activated="&Activat&"'>"&siteInfo(0)&siteInfo(1)&"User/Activated.asp?ID="&Request.Cookies("Muser")&"&Activated="&Activat&"</a>"
				ToMail=Usermail
				MailSmtp=setting(39)
				SmtpName=setting(40)
				SmtpPass=setting(41)
				From=setting(42)
				FromName=siteInfo(4)
		 '发送激活邮件
		    Call AskD.SendMail(From,FromName,Topic,MailBody,ToMail,SmtpName,SmtpPass,MailSmtp)
			IF AskD.Isgo then 
				 Response.Write "<script>var a = new parent.xWin(""1"",240,100,"""&siteInfo(4)&""",""激活邮件已经发送到你的邮箱，请激活！"");</script>"
				 Response.Write("<script language=javascript>setTimeout(""parent.location.href='"&curl&"'"",2000);</script>")
			Else
				 Response.Write "<script>var a = new parent.xWin(""1"",240,100,"""&siteInfo(4)&""",""激活邮件发送失败，请联系管理员激活！"");</script>"
				 Response.Write("<script language=javascript>setTimeout(""parent.location.href='"&curl&"'"",2000);</script>")
			End IF
	   End IF
	   IF regForm(1)=0 and regForm(3)=1 then
	     Response.Write "<script>var a = new parent.xWin(""1"",240,100,"""&siteInfo(4)&""",""恭喜，注册成功了！请等待审核。"");</script>"
		 Response.Write("<script language=javascript>setTimeout(""parent.location.href='"&curl&"'"",2000);</script>")
	   End IF
	   
	   IF regForm(1)=1 and regForm(3)=1 Then
	     Response.Write "<script>var a = new parent.xWin(""1"",240,100,"""&siteInfo(4)&""",""恭喜，注册成功了！"");</script>"
		 Response.Write("<script language=javascript>setTimeout(""parent.location.href='"&curl&"'"",2000);</script>")
	   End IF
	 Else
	     Response.Write "<script>var a = new parent.xWin(""1"",240,100,"""&siteInfo(4)&""",""该用户名或邮箱已经被注册，请重新选择！"");</script>"
	     Rs.Close:Set Rs=Nothing	
	 End If

Else
	     Response.Write "<script>var a = new parent.xWin(""1"",240,100,"""&siteInfo(4)&""",""每日允许注册"&regForm(4)&"次，请明天注册！"");</script>"
		 Response.Write("<script language=javascript>setTimeout(""parent.location.href='"&curl&"'"",2000);</script>")
End If	
end sub

%>