<!--#include file="Conn.asp"-->
<!-- #include file="inc/const.asp" -->
<!--#include file="inc/chan_const.asp"-->
<!--#include file="inc/chkinput.asp"-->
<!--#include file="inc/Email_Cls.asp"-->
<!--#include file="inc/md5.asp"-->
<%
Dim Selectinfo(5)
Dim Stats,ErrCodes
session("flag")=empty
If Request("t")="1" Then
ChkReg_Main()
Else
Reg_Main()
End If

Sub Reg_Main()
Dim PageSid
PageSid = Dvbbs.Skinid
Dvbbs.LoadTemplates("usermanager")
Dvbbs.Skinid = PageSid
Selectinfo(0)=chk_select("",template.Strings(11))
Selectinfo(1)=chk_select("",template.Strings(12))
Selectinfo(2)=chk_select("",template.Strings(13))
Selectinfo(3)=chk_select("",template.Strings(14))
Selectinfo(4)=Chk_KidneyType("character","",template.Strings(15))
Selectinfo(5)=chk_select("",template.Strings(16))
Dvbbs.LoadTemplates("login")
Stats=Split(template.Strings(25),"||")
Dvbbs.Stats=Stats(0)
Dvbbs.Nav()
Dvbbs.ActiveOnline
If Cint(dvbbs.Forum_Setting(37))=0 Then
ErrCodes=ErrCodes+"<li>"+template.Strings(26)
Else
If request("action")="apply" Then
Dvbbs.stats=Stats(2)
Dvbbs.Head_var 0,0,Stats(0),"xyfzc.asp"
reg_2()
ElseIf request("action")="save" Then
Dvbbs.stats=Stats(3)
Dvbbs.Head_var 0,0,Stats(0),"xyfzc.asp"
reg_3()
ElseIf request("action")="redir" Then
Dvbbs.stats=Stats(3)
Dvbbs.Head_var 0,0,Stats(0),"xyfzc.asp"
redir()
Else
Dvbbs.stats=Stats(1)
Dvbbs.Head_var 0,0,Stats(0),"xyfzc.asp"
reg_1()
End If
End If
Dvbbs.Showerr()
If ErrCodes<>"" Then Response.redirect "showerr.asp?ErrCodes="&ErrCodes&"&action=OtherErr"

Dvbbs.Footer()
End Sub

Sub reg_1()
Dim TempLateStr
TempLateStr=template.html(12)
TempLateStr=Replace(TempLateStr,"{$Forum_Name}",Dvbbs.Forum_Info(0))
Response.Write TempLateStr
End Sub

Sub reg_2()
Dim grouploopinfo,TempLateStr,Rs
TempLateStr=template.html(13)
If Dvbbs.forum_setting(78)="0" Then
TempLateStr=Replace(TempLateStr,"{$getcode}","")
Else
template.html(24)=Replace(template.html(24),"{$codestr}",Dvbbs.GetCode())
TempLateStr=Replace(TempLateStr,"{$getcode}",template.html(24))
End If
Set Rs=Dvbbs.Execute("select * from DV_GroupName")
If Rs.eof and Rs.bof Then
grouploopinfo="<option value=""尚未加入"">尚未加入</option>"
Else
do while not Rs.eof
grouploopinfo=grouploopinfo & "<option value="""&rs("Groupname")&""">"&rs("GroupName")&"</option>"
Rs.movenext
loop
End If
Rs.close:Set Rs=Nothing
Dim userregface,i,Forum_userface,FaceDefault
Forum_userface = split(Dvbbs.Forum_userface,"|||")
FaceDefault=Forum_userface(0)&Forum_userface(1)
For i = 1 to Ubound(Forum_userface)-1
userregface = userregface & "<option value="""&Forum_userface(0)&Forum_userface(i)
userregface = userregface & """>" & Forum_userface(i) & "</option>"
Next
TempLateStr=Replace(TempLateStr,"{$color}",Dvbbs.mainsetting(1))
TempLateStr=Replace(TempLateStr,"{$FaceDefault}",FaceDefault)
TempLateStr=Replace(TempLateStr,"{$Face_select}",userregface)
TempLateStr=Replace(TempLateStr,"{$FaceMaxWidth}",Dvbbs.Forum_Setting(38))
TempLateStr=Replace(TempLateStr,"{$FaceMaxHeight}",Dvbbs.Forum_Setting(39))
TempLateStr=Replace(TempLateStr,"{$ForumFaceMax}",Dvbbs.Forum_Setting(57))
TempLateStr=Replace(TempLateStr,"{$NameLimLength}",Dvbbs.Forum_Setting(40))
TempLateStr=Replace(TempLateStr,"{$NameMaxLength}",Dvbbs.Forum_Setting(41))
TempLateStr=Replace(TempLateStr,"{$Forum_Setting7}",Dvbbs.Forum_UploadSetting(0))
TempLateStr=Replace(TempLateStr,"{$Forum_Setting23}",Dvbbs.Forum_Setting(23))
TempLateStr=Replace(TempLateStr,"{$Forum_Setting32}",Dvbbs.Forum_Setting(32))
TempLateStr=Replace(TempLateStr,"{$Forum_Setting54}",Dvbbs.Forum_Setting(54))
TempLateStr=Replace(TempLateStr,"{$Forum_Setting42}",Dvbbs.Forum_Setting(42))
TempLateStr=Replace(TempLateStr,"{$grouploopinfo}",grouploopinfo)
TempLateStr=Replace(TempLateStr,"{$user_blood}",chk_select("","A,B,AB,O"))
TempLateStr=Replace(TempLateStr,"{$user_shengxiao}",Selectinfo(0))
TempLateStr=Replace(TempLateStr,"{$user_occupation}",Selectinfo(1))
TempLateStr=Replace(TempLateStr,"{$user_marital}",Selectinfo(2))
TempLateStr=Replace(TempLateStr,"{$user_education}",Selectinfo(3))
TempLateStr=Replace(TempLateStr,"{$user_character}",Selectinfo(4))
TempLateStr=Replace(TempLateStr,"{$user_belief}",Selectinfo(5))
Response.Write TempLateStr
End Sub

'下拉菜单转换输出
Function Chk_select(str1,str2)
Dim k
str2=Split(str2,",")
If  str1="" Then chk_select="<option value="""" selected=""selected"">...</option>"
For k=0 to ubound(str2)
chk_select=chk_select & "<option value=""" & str2(k)&""""
If str2(k)=str1 Then chk_select=chk_select &" selected=""selected"" "
chk_select=chk_select & " >" & str2(k) &"</option>"
Next
End Function

'多项选取转换输出
Function Chk_KidneyType(str0,str1,str2)
Dim k
str2=split(str2,",")
For k = 0 to ubound(str2)
chk_KidneyType=chk_KidneyType+"<input type=""checkbox"" name="""&str0&""" value="""&trim(str2(k))&""" " 
If instr(str1,trim(str2(k)))>0 Then '如果有此项
chk_KidneyType=chk_KidneyType + "checked" 
End If 
chk_KidneyType=chk_KidneyType + ">"&trim(str2(k))&" "
If ((k+1) mod 5)=0 Then chk_KidneyType=chk_KidneyType +  "<br>"  '每行显示六个性格进行换行
Next
End Function

Sub reg_3()
Dim username,sex,pass1,pass2,password
Dim useremail,face,width,height
Dim sign,showRe,birthday,UserIM
Dim mailbody,sendmsg,rndnum,num1
Dim quesion,answer,topic
Dim userinfo,usersetting
Dim userclass,UserJoinTime
Dim rs,sql,i,TempLateStr
Dim Qq
'判断同一IP注册间隔时间
If Not Isnull(Session("regtime")) Or Clng(Dvbbs.Forum_Setting(22)) > 0 Then
If DateDiff("s",Session("regtime"),Now()) < Clng(Dvbbs.Forum_Setting(22)) Then
ErrCodes = ErrCodes + "<li>" + Replace(Template.Strings(27), "{$RegTime}", Dvbbs.Forum_Setting(22))
Exit Sub
End If
End If
If Dvbbs.chkpost=false Then
Dvbbs.AddErrCode(16)
Exit sub
End If
If Trim(Request.form("name"))="" or strLength(Request.form("name"))>Cint(Dvbbs.Forum_Setting(41)) or strLength(Request.form("name"))<Cint(Dvbbs.Forum_Setting(40)) Then
TempLateStr=template.Strings(28)
TempLateStr=Replace(TempLateStr,"{$RegMaxLength}",Dvbbs.Forum_Setting(41))
TempLateStr=Replace(TempLateStr,"{$RegLimLength}",Dvbbs.Forum_Setting(40))
ErrCodes=ErrCodes+"<li>"+TempLateStr
TempLateStr=""
Exit Sub
Else
username=Dvbbs.CheckStr(Request.form("name"))
End If

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 or Instr(username,"|")>0 Then
Dvbbs.AddErrCode(19)
Exit sub
End If
If Dvbbs.forum_setting(78)="1" Then
If Not Dvbbs.CodeIsTrue() Then
 Response.redirect "showerr.asp?ErrCodes=<li>验证码校验失败，请返回刷新页面后再输入验证码。&action=OtherErr"
End If
End If
Dim RegSplitWords
If Trim(Dvbbs.cachedata(1,0))<>"" Then
RegSplitWords=split(Dvbbs.cachedata(1,0),"|||")(4)
RegSplitWords=split(RegSplitWords,",")
For i = 0 to ubound(RegSplitWords)
If Trim(RegSplitWords(i))<>"" Then
If instr(username,RegSplitWords(i))>0 Then
Dvbbs.AddErrCode(19)
Exit sub
End If
End If 
next
End If 
If Request.form("sex")=0 or Request.form("sex")=1 Then
sex=Cint(Request.form("sex"))
Else
sex=1
End If

If Request.form("showRe")=0 or Request.form("showRe")=1 Then
showRe=Request.form("showRe")
Else
showRe=1
End If

If Cint(Dvbbs.Forum_Setting(23))=1 Then
Randomize
Do While Len(rndnum)<8
num1=CStr(Chr((57-48)*rnd+48))
rndnum=rndnum&num1
loop
password=md5(rndnum,16)
Else
If Request.form("psw")="" or len(Request.form("psw"))>10 or len(Request.form("psw"))<6 Then
ErrCodes=ErrCodes+"<li>"+template.Strings(13)
Else
pass1=Request.form("psw")
End If
If Request.form("pswc")="" or strLength(Request.form("pswc"))>10 or len(Request.form("pswc"))<6 Then
ErrCodes=ErrCodes+"<li>"+template.Strings(13)
Else
pass2=Request.form("pswc")
End If
If pass1<>pass2 Then
ErrCodes=ErrCodes+"<li>"+template.Strings(29)
Else
password=md5(pass2,16)
End If
End If

If Request.form("quesion")="" Then
ErrCodes=ErrCodes+"<li>"+template.Strings(11)
Else
quesion=Request.form("quesion")
End If
If Request.form("answer")="" Then
  ErrCodes=ErrCodes+"<li>"+template.Strings(11)
ElseIf Request.form("answer")=Request.form("oldanswer") Then
answer=Request.form("answer")
Else
answer=md5(Request.form("answer"),16)
End If

If IsValidEmail(Trim(Request.form("e_mail")))=false Then
ErrCodes=ErrCodes+"<li>"+template.Strings(30)
Else
If not Isnull(Dvbbs.Forum_Setting(52)) and Dvbbs.Forum_Setting(52)<>"" and Dvbbs.Forum_Setting(52)<>"0" Then
Dim SplitUserEmail
SplitUserEmail=Split(Dvbbs.Forum_Setting(52),"|")
For i=0 to Ubound(SplitUserEmail)
If Instr(Request.form("e_mail"),SplitUserEmail(i))>0 Then
ErrCodes=ErrCodes+"<li>"+template.Strings(31)
Exit Sub
End If
Next
End If
useremail=Dvbbs.CheckStr(Trim(Request.form("e_mail")))
End If

If Request.form("myface")<>"" and Cint(Dvbbs.Forum_Setting(54))=0 Then
If Request.form("width")="" or Request.form("height")="" Then
ErrCodes=ErrCodes+"<li>"+template.Strings(32)
ElseIf Not IsNumeric(Request.form("width")) or not IsNumeric(Request.form("height")) Then
Dvbbs.AddErrCode(18)
Exit Sub
ElseIf Cint(Request.form("width"))>Cint(Dvbbs.Forum_Setting(57)) Then
ErrCodes=ErrCodes+"<li>"+template.Strings(33)
ElseIf Cint(Request.form("height"))>Cint(Dvbbs.Forum_Setting(57)) Then
ErrCodes=ErrCodes+"<li>"+template.Strings(33)
Else
If Cint(Dvbbs.Forum_Setting(55))=0 Then
If instr(lcase(Request.form("myface")),"http://")>0 or instr(lcase(Request.form("myface")),"www.")>0 Then
ErrCodes=ErrCodes+"<li>"+template.Strings(34)
End If
End If
face=Request.form("myface")
End If
Else
If Request.form("face")<>"" Then
face=Request.form("face")
End If
End If
face=Server.htmlencode(face)
face=replace(face,"|","")
width=Request.form("width")
height=Request.form("height")
If width="" Or Not IsNumeric(width) Then width=CInt(Dvbbs.forum_setting(57))
If height="" Or Not IsNumeric(height) Then height=CInt(Dvbbs.forum_setting(57))
width=CInt(width)
height=CInt(height)
If Width > CInt(Dvbbs.forum_setting(57)) Then width=CInt(Dvbbs.forum_setting(57))
If height > CInt(Dvbbs.forum_setting(57)) Then height=CInt(Dvbbs.forum_setting(57))
birthday=Dvbbs.Checkstr(Trim(Request.Form("birthday")))
If not Isdate(birthday) Then birthday=""
'防止填写QQ号码为非数字类型 2005-3-22 Dv.Yz
If Isnumeric(Request.Form("OICQ")) Then
Qq = Int(Request.Form("OICQ"))
Else
Qq = ""
End If
userinfo=checkreal(Request.Form("realname")) & "|||" & checkreal(Request.Form("character")) & "|||" & checkreal(Request.Form("personal")) & "|||" & checkreal(Request.Form("country")) & "|||" & checkreal(Request.Form("province")) & "|||" & checkreal(Request.Form("city")) & "|||" & Request.Form("shengxiao") & "|||" & Request.Form("blood") & "|||" & Request.Form("belief") & "|||" & Request.Form("occupation") & "|||" & Request.Form("marital") & "|||" & Request.Form("education") & "|||" & checkreal(Request.Form("college")) & "|||" & checkreal(Request.Form("userphone")) & "|||" & checkreal(Request.Form("address"))
usersetting=Request.Form("setuserinfo") & "|||" & Request.Form("setusertrue") & "|||" & showRe
UserIM=checkreal(Request.form("homepage")) &"|||" & Qq & "|||"& checkreal(Request.form("ICQ")) &"|||"& checkreal(Request.form("msn")) &"|||"& checkreal(Request.form("yahoo")) &"|||"& checkreal(Request.form("aim")) &"|||"& checkreal(Request.form("uc"))
UserIM=Server.htmlencode(UserIM)
If ErrCodes<>"" Then Exit Sub
If Dvbbs.ErrCodes<>"" Then Exit Sub
Dim titlepic
Dim TruePassWord
TruePassWord=Dvbbs.Createpass
Set Rs=Dvbbs.Execute("Select UserTitle,GroupPic,UserGroupID,IsSetting,ParentGID From Dv_UserGroups Where ParentGID=3 Order By MinArticle")
UserClass=rs(0)
TitlePic=rs(1)
Dvbbs.UserGroupID = Rs(2)
Set Rs=Server.CreateObject("Adodb.RecordSet")
If Request("Forum_Passport")<>"" And Cint(Dvbbs.Forum_Setting(24))=1 Then
Sql="Select * From [Dv_user] Where UserName='"&UserName&"' Or UserEmail='"&UserEmail&"' Or Passport='"&Dvbbs.CheckStr(Request("Forum_Passport"))&"'"
ElseIf Request("Forum_Passport")<>"" Then
Sql="Select * From [Dv_user] Where UserName='"&UserName&"' Or Passport='"&Dvbbs.CheckStr(Request("Forum_Passport"))&"'"
ElseIf Cint(Dvbbs.Forum_Setting(24))=1 Then
Sql="Select * From [Dv_user] Where Username='"&UserName&"' or useremail='"&UserEmail&"'"
Else
Sql="Select * From [Dv_user] Where Username='"&UserName&"'"
End If
'Response.Write sql
'response.end
Rs.Open Sql,Conn,1,3
If Not Rs.Eof And Not Rs.Bof Then
If Request("Forum_Passport")<>"" And Cint(Dvbbs.Forum_Setting(24))=1 Then
Response.redirect "showerr.asp?ErrCodes=<li>您填写的用户名已经被注册或者已经有用户使用了您填写的电子邮件地址。<li>或者您选择了填写了超贴通行证帐号，但所使用的通行证在本超贴已经被使用，您可以选择使用该<a href=login.asp>通行证登录超贴</a>。&action=OtherErr"
ElseIf Request("Forum_Passport")<>"" Then
Response.redirect "showerr.asp?ErrCodes=<li>您填写的用户名已经被注册。<li>或者您选择了填写了超贴通行证帐号，但所使用的通行证在本超贴已经被使用，您可以选择使用该<a href=login.asp>通行证登录超贴</a>。&action=OtherErr"
ElseIf Cint(Dvbbs.Forum_Setting(24))=1 Then
Response.redirect "showerr.asp?ErrCodes=<li>您填写的用户名已经被注册或者已经有用户使用了您填写的电子邮件地址。&action=OtherErr"
Else
Response.redirect "showerr.asp?ErrCodes=<li>您填写的用户名已经被注册。&action=OtherErr"
End If
Exit Sub
Else
Rs.AddNew
UserJoinTime = Now()
Rs("UserName")=username
Rs("UserPassword")=password
Rs("UserEmail")=useremail
Rs("Userclass")=userclass
Rs("TitlePic")=titlepic
Rs("UserQuesion")=quesion
Rs("UserAnswer")=answer
Rs("TruePassWord")=TruePassWord
Rs("UserIM")=UserIM
If Request.Form("Signature")<>"" Then Rs("UserSign")=Dvbbs.Htmlencode(Trim(Request.Form("Signature")))
Rs("UserPost")=0
If Dvbbs.Forum_Setting(25)="1" Then
Rs("UserGroupID")=5
Else
   Rs("UserGroupID")=Dvbbs.UserGroupID
End If
Rs("Lockuser")=0
Rs("UserSex")=sex
If birthday<>"" Then rs("UserBirthday")=birthday
Rs("UserGroup")=Request.form("UserGroup")
Rs("JoinDate")=UserJoinTime
If Request.form("myface")<>"" Then
Rs("UserFace")=replace(face,"'","")
Else
Rs("UserFace")=replace(face,"'","")
End If
Rs("UserWidth")=Width
Rs("Usertoday")="0|0|0|0|0"
Rs("UserHeight")=height
Rs("UserLogins")=1
Rs("LastLogin")=UserJoinTime
Rs("userWealth")=dvbbs.Forum_user(0)
Rs("userEP")=dvbbs.Forum_user(5)
Rs("usercP")=dvbbs.Forum_user(10)
Rs("UserInfo")=userinfo
Rs("UserSetting")=usersetting
Rs("UserPower")=0
Rs("UserDel")=0
Rs("UserIsbest")=0
Rs("UserMoney")=0
Rs("UserTicket")=0
Rs("UserFav")="陌生人,我的好友,黑名单"
Rs("IsChallenge")=0
Rs("UserHidden")=0
Rs("UserLastIP")=Dvbbs.UserTrueIP
Rs.Update
Dvbbs.Execute("UpDate Dv_Setup Set Forum_UserNum=Forum_UserNum+1,Forum_lastUser='"&Dvbbs.HtmlEncode(username)&"'")

End If
rs.close
Dvbbs.ReloadSetupCache username,14
Dvbbs.ReloadSetupCache (CLng(Dvbbs.CacheData(10,0))+1),10 
Dim facename
Set rs=Dvbbs.execute("select top 1 userid,UserFace from [Dv_user] order by userid desc")
Dvbbs.userid=rs(0)
facename=rs(1)
rs.close
set rs=nothing

'******************
'对上传头象进行过滤与改名
If Cint(Dvbbs.Forum_UploadSetting(0))=1 Then 
on error resume next
Dim objFSO,upface,newfilename
facename=Replace(facename,"\","/")
facename=Replace(facename,"//","/")
facename=Replace(facename,"..","")
facename=Replace(facename,"^","")
facename=Replace(facename,"@","")
facename=Replace(facename,"%","")
If instr(Lcase(facename),"uploadface/") Then
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
facename=objFSO.GetFileName(facename)
upface="uploadFace/"&facename
newfilename="uploadFace/"&Dvbbs.userid&"_"&facename
if objFSO.fileExists(Server.MapPath(upface)) Then
objFSO.movefile ""&Server.MapPath(upface)&"",""&Server.MapPath(newfilename)&""
If Not Err Then
Dvbbs.execute("update [Dv_user] set UserFace='"&replace(newfilename,"'","")&"' Where userid="&Dvbbs.userid)
End If
End If
set objFSO=nothing
End If
End If
'对上传头象进行过滤与改名结束
'****************
If Dvbbs.Forum_Setting(47)=1 and Cint(Dvbbs.Forum_Setting(2))>0 Then
'on error resume next
'发送注册邮件
Dim getpass
topic=Replace(template.Strings(35),"{$Forumname}",Dvbbs.Forum_Info(0))
If Cint(Dvbbs.Forum_Setting(23))=1 Then
getpass=rndnum
Else
getpass=Request.form("psw")
End If
mailbody = template.html(17)
mailbody = Replace(mailbody,"{$username}",Dvbbs.HtmlEncode(username))
mailbody = Replace(mailbody,"{$password}",getpass)
mailbody = Replace(mailbody,"{$copyright}",Dvbbs.Forum_Copyright)
mailbody = Replace(mailbody,"{$version}",Dvbbs.Forum_Version)
Dim DvEmail
Set DvEmail = New Dv_SendMail
DvEmail.SendObject = Cint(Dvbbs.Forum_Setting(2))'设置选取组件 1=Jmail,2=Cdonts,3=Aspemail
DvEmail.ServerLoginName = Dvbbs.Forum_info(12)'您的邮件服务器登录名
DvEmail.ServerLoginPass = Dvbbs.Forum_info(13)'登录密码
DvEmail.SendSMTP = Dvbbs.Forum_info(4)'SMTP地址
DvEmail.SendFromEmail = Dvbbs.Forum_info(5)'发送来源地址
DvEmail.SendFromName = Dvbbs.Forum_info(0)'发送人信息
If DvEmail.ErrCode = 0 Then
DvEmail.SendMail useremail,topic,mailbody'执行发送邮件
If DvEmail.Count>0 Then
If Cint(Dvbbs.Forum_Setting(23))=1 Then
sendmsg=template.Strings(38)
Else
sendmsg=template.Strings(39)
End If
Else
sendmsg=template.Strings(37)
End If
Else
sendmsg=template.Strings(37)
End If
Set DvEmail = Nothing
Else
sendmsg = template.Strings(36)
End If

If Dvbbs.Forum_Setting(46)="1" Then
'发送注册短信
Dim sender,title,body,UserMsg,MsgID
sender=Dvbbs.Forum_Info(0)
title=Dvbbs.lanstr(2)&Dvbbs.Forum_Info(0)
body = template.html(18)
body = Replace(body,"{$Forumname}",Dvbbs.Forum_Info(0))
sql="insert into dv_message(incept,sender,title,content,sendtime,flag,issend) values('"&username&"','"&sender&"','"&title&"','"&body&"',"&SqlNowString&",0,1)"
Dvbbs.Execute(sql)
Set rs=Dvbbs.execute("select top 1 ID from [Dv_message] order by ID desc")
MsgID=rs(0)
Rs.close:Set Rs=Nothing
UserMsg="1||"& MsgID &"||"& sender
Dvbbs.execute("UPDATE [Dv_User] Set UserMsg='"&Dvbbs.CheckStr(UserMsg)&"' WHERE UserID="&Dvbbs.userid)
End If

If Not (cint(Dvbbs.Forum_Setting(23))=1 and  CInt(Dvbbs.Forum_Setting(25))=1) Then
If EnabledSession Then
Set Dvbbs.UserSession = Nothing 
Session(Dvbbs.CacheName & "UserID")= empty
End If
Dim StatUserID,UserSessionID
StatUserID = Dvbbs.checkStr(Trim(Request.Cookies(Dvbbs.Forum_sn)("StatUserID")))
If IsNumeric(StatUserID) = 0 or StatUserID = "" Then
StatUserID = Replace(Dvbbs.UserTrueIP,".","")
UserSessionID = Replace(Startime,".","")
If IsNumeric(StatUserID) = 0 or StatUserID = "" Then StatUserID = 0
StatUserID = Ccur(StatUserID) + Ccur(UserSessionID)
End If
StatUserID = Ccur(StatUserID)
Dvbbs.Execute("delete from dv_online where username='"&dvbbs.membername&"' Or id="&StatUserID&"")
Response.Cookies(Dvbbs.Forum_sn)("StatUserID") = StatUserID
select case request("usercookies")
 case 0
Response.Cookies(Dvbbs.Forum_sn)("usercookies") = request("usercookies")
Case 1
Response.Cookies(Dvbbs.Forum_sn).Expires=Date+1
Response.Cookies(Dvbbs.Forum_sn)("usercookies") = request("usercookies")
Case 2
Response.Cookies(Dvbbs.Forum_sn).Expires=Date+31
Response.Cookies(Dvbbs.Forum_sn)("usercookies") = request("usercookies")
    case 3
Response.Cookies(Dvbbs.Forum_sn).Expires=Date+365
Response.Cookies(Dvbbs.Forum_sn)("usercookies") = request("usercookies")
end select
Response.Cookies(Dvbbs.Forum_sn)("username") = username
Response.Cookies(Dvbbs.Forum_sn)("password") = TruePassWord
Response.Cookies(Dvbbs.Forum_sn)("userclass") = userclass
Response.Cookies(Dvbbs.Forum_sn)("userid") = Dvbbs.userid
Response.Cookies(Dvbbs.Forum_sn)("userhidden") = 2
Response.Cookies(Dvbbs.Forum_sn).path=Dvbbs.cookiepath
Dvbbs.membername=username
Dvbbs.userhidden=2
Dvbbs.MemberClass=userclass

End If
Session("regtime")=now()

'前往官方超贴通行证验证
If Request("Forum_Passport")<>"" Then
'Get_ChallengeWord
'生成订单号:01+yyyyMMddhhmmss+六位随机数
'生成日期字串
Dim NowTimes,PayMonth,PayDay,PayHour,PayMin,PaySe,PayDayStr,RandomizeStr,num2
Dim PayCode,PayCodeEnCode
NowTimes = Now()
PayMonth = Month(NowTimes)
If Len(PayMonth)=1 Then PayMonth = "0" & PayMonth
PayDay = Day(NowTimes)
If Len(PayDay)=1 Then PayDay = "0" & PayDay
PayHour = Hour(NowTimes)
If Len(PayHour)=1 Then PayHour = "0" & PayHour
PayMin = Minute(NowTimes)
If Len(PayMin)=1 Then PayMin = "0" & PayMin
PaySe = Second(NowTimes)
If Len(PaySe)=1 Then PaySe = "0" & PaySe
PayDayStr = Year(NowTimes) & PayMonth & PayDay & PayHour & PayMin & PaySe
'生成随机字串
Randomize
Do While Len(RandomizeStr)<5
num2 = CStr(Chr((57-48)*rnd+48))
RandomizeStr = RandomizeStr & num2
Loop
PayCode = PayDayStr & RandomizeStr & Left(MD5(Dvbbs.Forum_ChanSetting(4)&Dvbbs.Forum_ChanSetting(6),32),8)
Session("challengeWord_key") = MD5(PayCode & ":" & MD5(answer & ":" & FormatDateTime(UserJoinTime,2),32),32)
Session("challengeUserID") = Dvbbs.UserID
Response.Write Replace(template.html(14),"{$Forumname}",Dvbbs.Forum_Info(0))
If not IsObject(Application(Dvbbs.CacheName & "_iplist")) Then
SendData()
ElseIf DateDiff("D",Application(Dvbbs.CacheName & "_iplist").documentElement.selectSingleNode("@date").text,Date())<> 0 Then
SendData()
End If
%>
<form name="redir" action="xyfzc.asp" method="post">
<INPUT type=hidden name="password" value="">
<INPUT type=hidden name="passport" value="<%=request("Forum_Passport")%>">
<INPUT type=hidden name="username" value="<%=username%>">
<INPUT type=hidden name="userid" value="<%=Dvbbs.UserID%>">
<INPUT type=hidden name="email" value="<%=useremail%>">
<INPUT type=hidden name="forumname" value="<%=Dvbbs.Forum_Info(0)%>">
<INPUT type=hidden name="forumurl" value="<%=Dvbbs.Get_ScriptNameUrl%>">
<input type=hidden value="<%=PayCode%>" name="seqno">
<input type=hidden value="<%=Dvbbs.Get_ScriptNameUrl%>xyfzc.asp?action=redir" name="backurl">
</form>
<script LANGUAGE=javascript>
<!--
redir.submit();
//-->
</script>
<%
Else
TempLateStr=template.html(15)
TempLateStr=Replace(TempLateStr,"{$Forumname}",Dvbbs.Forum_Info(0))
TempLateStr=Replace(TempLateStr,"{$sendmsg}",sendmsg)
Response.Write TempLateStr
End If
End Sub

Function strAnsi2Unicode(asContents)
Dim len1,i,varchar,varasc
strAnsi2Unicode = ""
len1=LenB(asContents)
If len1=0 Then Exit Function
  For i=1 to len1
  varchar=MidB(asContents,i,1)
  varasc=AscB(varchar)
  If varasc > 127  Then
  If MidB(asContents,i+1,1)<>"" Then
  strAnsi2Unicode = strAnsi2Unicode & chr(ascw(midb(asContents,i+1,1) & varchar))
  End If
  i=i+1
     Else
     strAnsi2Unicode = strAnsi2Unicode & Chr(varasc)
     End If
  Next
End Function
Sub SendData()
Dim xmlhttp,xml,DataToSend,xmlserverurl
  On Error Resume Next
  Set xmlhttp = Server.CreateObject("MSXML2.ServerXMLHTTP"&MsxmlVersion)
xmlserverurl="http://server.sg188.com/dvbbs/iplist.asp"
xmlhttp.setTimeouts 65000, 65000, 65000, 65000
  xmlhttp.Open "POST",xmlserverurl,false
  xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
  xmlhttp.send
  Set XML=Server.CreateObject("Msxml2.FreeThreadedDOMDocument"& MsxmlVersion)
  If XML.loadxml(strAnsi2Unicode(xmlhttp.responseBody)) Then
  Xml.documentElement.selectSingleNode("@date").text=Date()
Set Application(Dvbbs.CacheName & "_iplist")=Xml.cloneNode(true)
End If
Set xmlhttp = Nothing
End Sub

Function redir()
Dim ErrorCode,ErrorMsg
Dim remobile,rechallengeWord,retokerWord
Dim challengeWord_key,rechallengeWord_key
ErrorCode=trim(request("ErrorCode"))
ErrorMsg=trim(request("ErrorMsg"))
remobile=trim(Dvbbs.CheckStr(request("passport")))
rechallengeWord=trim(Dvbbs.CheckStr(request("seqno")))
retokerWord=trim(request("token"))

If Session("challengeUserID") = "" Then Response.Redirect "index.asp"

If ErrorCode = "1" Then
challengeWord_key = Session("challengeWord_key")
If challengeWord_key = retokerWord Then
Dvbbs.Execute("Update [Dv_User] Set Passport='"&remobile&"',IsChallenge=1 Where UserID = " & Session("challengeUserID"))
Else
ErrCodes=ErrCodes+"<li>本地验证失败，可能的原因有：网络超时、非法的提交请求。"
Exit Function
End If
Else
Response.redirect "showerr.asp?ErrCodes="&ErrorMsg&"&action=OtherErr"
Exit Function
End If
Session("challengeWord_key") = Empty
Session("challengeUserID") = Empty
Response.Write Replace(Replace(template.html(15),"{$Forumname}",Dvbbs.Forum_Info(0)),"{$sendmsg}",ErrorMsg)
End Function

Function checkreal(v)
Dim w
If not isnull(v) Then
w=replace(v,"|","")
checkreal=w
End If
End Function

Sub ChkReg_Main()
Dvbbs.LoadTemplates("login")
Dim Stats,TempLateStr
Dim username,i,sql,Rs,useremail
Stats=split(template.Strings(25),"||")
Dvbbs.Stats=Stats(0)
dvbbs.head()
ErrCodes=""
If Request.form("username")="" Then ErrCodes=ErrCodes+"<li>"+template.Strings(6)
If strLength(Request.form("username"))>Cint(Dvbbs.Forum_Setting(41)) or strLength(Request.form("username"))<Cint(Dvbbs.Forum_Setting(40)) Then
TempLateStr=template.Strings(28)
TempLateStr=Replace(TempLateStr,"{$RegMaxLength}",Dvbbs.Forum_Setting(41))
TempLateStr=Replace(TempLateStr,"{$RegLimLength}",Dvbbs.Forum_Setting(40))
ErrCodes=ErrCodes+"<li>"+TempLateStr
TempLateStr=""
Else
username=Dvbbs.CheckStr(Trim(Request.form("username")))
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
ErrCodes=ErrCodes+"<li>"+template.Strings(46)
End If
Dim RegSplitWords
RegSplitWords=split(Dvbbs.forum_setting(4),",")
for i = 0 to ubound(RegSplitWords)
If instr(username,RegSplitWords(i))>0 Then
ErrCodes=ErrCodes+"<li>"+template.Strings(46)
End If
next
End If
If Request("action")="" Then
If IsValidEmail(trim(Request.form("email")))=false then
   ErrCodes=ErrCodes+"<li>"+template.Strings(30)
Else 
useremail=Dvbbs.checkStr(Request.form("email"))
End If
End If
If ErrCodes<>"" Then Showerr()
if ErrCodes="" then
If cint(Dvbbs.Forum_Setting(24))=1 Then
If Request("action")="" Then
sql="select username,useremail from [Dv_user] where username='"&username&"' or useremail='"&useremail&"'"
Else
sql="select username,useremail from [Dv_user] where username='"&username&"'"
End If
Else 
sql="select username,useremail from [Dv_user] where username='"&username&"'"
End If
Set Rs=Dvbbs.execute(sql)
If Not rs.eof and not rs.bof then
If cint(Dvbbs.Forum_Setting(24))=1 And Rs("useremail")=useremail Then
If Request("action")="" Then
ErrCodes=ErrCodes+"<li>"+template.Strings(44)
Else
ErrCodes=ErrCodes+"<li>"+template.Strings(43)
End If
Else 
ErrCodes=ErrCodes+"<li>"+template.Strings(44)
End If
End If 
Rs.close:Set Rs=Nothing

If ErrCodes="" Then 
ErrCodes=template.Strings(45)
End If
Response.Write Replace(template.html(16),"{$Reportmsg}",ErrCodes)
End If
Dvbbs.Footer()
End Sub
Sub Showerr()
Dim Show_Errmsg
If ErrCodes<>"" Then 
Show_Errmsg=Dvbbs.mainhtml(14)
ErrCodes=Replace(ErrCodes,"{$color}",Dvbbs.mainSetting(1))
Show_Errmsg=Replace(Show_Errmsg,"{$color}",Dvbbs.mainSetting(1))
Show_Errmsg=Replace(Show_Errmsg,"{$errtitle}",Dvbbs.Forum_Info(0)&"-"&Dvbbs.Stats)
Show_Errmsg=Replace(Show_Errmsg,"{$action}",Dvbbs.Stats)
Show_Errmsg=Replace(Show_Errmsg,"{$ErrString}",ErrCodes)
End If
Response.write Show_Errmsg
End Sub
%>