<!--#include file="Conn.asp"-->
<!--#include file="inc/const.asp"-->
<!--#include file="inc/dv_clsother.asp"-->
<!--#include file="inc/chan_const.asp"-->
<!--#include file="inc/chkinput.asp"-->
<!--#include file="inc/Email_Cls.asp"-->
<!--#include file="inc/md5.asp"-->
<!--#include file="inc/UpiConfig.asp"-->
<%
Dim comeurl
Dim TruePassWord

Dvbbs.LoadTemplates("login")
Dvbbs.stats=template.Strings(1)
Dvbbs.Nav()
Dvbbs.Head_var 0,0,template.Strings(0),"login.asp"
TruePassWord=Dvbbs.Createpass
Select Case request("action")
Case "chk"
	Dvbbs_ChkLogin
	Dvbbs.Showerr()
Case "redir"
	redir
	Dvbbs.Showerr()
Case "save_redir_reg"
	call save_redir_reg()
	Dvbbs.Showerr()
Case Else
	Main
End Select
Dvbbs.ActiveOnline
Dvbbs.Footer()

Function Main()
	Dim TempStr
	TempStr = template.html(0)
	If Dvbbs.forum_setting(79)="0" Then
		TempStr = Replace(TempStr,"{$getcode}","")
	Else
		Template.html(23)=Replace(template.html(23),"{$codestr}",Dvbbs.GetCode())
		TempStr = Replace(TempStr,"{$getcode}",template.html(23))
	End If
	If Dvbbs.Forum_ChanSetting(0)=1 And Dvbbs.Forum_ChanSetting(10)=1 Then
		TempStr = Replace(TempStr,"{$rayuserlogin}",template.html(1))
	Else
		TempStr = Replace(TempStr,"{$rayuserlogin}","")
	End If
	Dim Comeurl,tmpstr
	If Request("f")<>"" Then
		Comeurl=Request("f")
	ElseIf Request.ServerVariables("HTTP_REFERER")<>"" Then 
		tmpstr=split(Request.ServerVariables("HTTP_REFERER"),"/")
		Comeurl=tmpstr(UBound(tmpstr))
	Else
		Comeurl="index.asp"
	End If
	TempStr = Replace(TempStr,"{$comeurl}",Comeurl)
	Response.Write TempStr
	TempStr=""
End Function

Function Dvbbs_ChkLogin
	Dim username
	Dim password
	Dim usercookies

	username = Trim(Request("username"))
	password = Trim(Request("password"))
	usercookies = Trim(Request("CookieDate"))

	If ComeUrl <> "" Then
		ComeUrl = Replace(Lcase(Request.ServerVariables("SCRIPT_NAME")),"login.asp",ComeUrl)
		ComeUrl = "http://" & Lcase(Request.ServerVariables("HTTP_HOST")) & ComeUrl
	Else
		ComeUrl = Replace(Lcase(Request.ServerVariables("SCRIPT_NAME")),"login.asp","")
		ComeUrl = "http://" & Lcase(Request.ServerVariables("HTTP_HOST")) & ComeUrl
		ComeUrl = ComeUrl & Dvbbs.Forum_Info(11)
	End If

	Response.Write "<form name='upiform' id='upiform' action='"&PE_Url&"User/User_ChkLogin.asp' method='post'>" & vbCrLf
	Response.Write "	<input type='hidden' name='UserName' value='"&username&"'>" & vbCrLf
	Response.Write "	<input type='hidden' name='UserPassword' value='"&password&"'>" & vbCrLf
	Response.Write "	<input type='hidden' name='CookieDate' value='"&usercookies&"'>" & vbCrLf
	Response.Write "	<input type='hidden' name='ComeUrl' value='"&ComeUrl&"'>" & vbCrLf
	Response.Write "</form>" & vbCrLf
	Response.Write "<script language='JavaScript' type='text/javascript'>" & vbCrLf
	Response.Write "<!--//Powered by PowerEasy Inc." & vbCrLf
	Response.Write "	upiform.submit();" & vbCrLf
	Response.Write "//-->" & vbCrLf
	Response.Write "</script>" & vbCrLf

End Function

'全网认证
Function challenge_check(mobile,password)
	If Not(Dvbbs.Forum_ChanSetting(0)=1 And Dvbbs.Forum_ChanSetting(10)=1) Then
		Dvbbs.AddErrCode(13)
		Exit Function
	End If
	Dim rs
	Dim MyForumID
	Dim PostChanWord
	Set Rs=Dvbbs.Execute("select top 1 * from Dv_ChallengeInfo")
	MyForumID=rs("D_ForumID")
	PostChanWord=Get_ChallengeWord
	Dim FoundMobile
	Set Rs=Dvbbs.Execute("Select UserMobile From Dv_User Where UserMobile = '"&Dvbbs.CheckStr(Mobile)&"'")
	If Rs.Eof And Rs.Bof Then
		FoundMobile = False
	Else
		FoundMobile = True
	End If
	Rs.Close
	Set Rs=Nothing

	Dim TempStr,TempArray
	TempArray = Split(template.html(19),"||")
	TempStr = TempArray(0)
	TempStr = Replace(TempStr,"{$Dvbbs_Server}",Dvbbs_Server_Url)
	TempStr = Replace(TempStr,"{$mobile}",mobile)
	'TempStr = Replace(TempStr,"{$password}",password)
	TempStr = Replace(TempStr,"{$MyForumID}",MyForumID)
	TempStr = Replace(TempStr,"{$serverurl}",Dvbbs.Get_ScriptNameUrl())
	TempStr = Replace(TempStr,"{$PostChanWord}",PostChanWord)
	TempStr = Replace(TempStr,"{$remobile}",left(mobile,3)&"xxx"&right(mobile,5))
	TempStr = Replace(TempStr,"{$usermobile}",left(mobile,3)&"xxx"&right(mobile,5))
	If FoundMobile Then
		TempStr = Replace(TempStr,"{$ifpassnull}","，您正在进行手机用户<B>快速登录</B>。请点击下一步继续。")
		TempStr = Replace(TempStr,"{$ifpassnull1}","如果您希望用此手机号重新注册新用户，请在登录论坛后修改当前用户绑定的手机。")
	Else
		TempStr = Replace(TempStr,"{$ifpassnull}","，您正在进行手机用户<B>快速注册</B>，请点击下一步继续。")
		TempStr = Replace(TempStr,"{$ifpassnull1}","本操作将引导您在本论坛注册，并且同步您在手机无线服务器上的用户基本信息。")
	End If
	Response.Write TempStr
	TempStr = ""
	set rs=nothing
End Function

Function redir()

	Dim ErrorCode,ErrorMsg
	Dim remobile,rechallengeWord,retokerWord,reuserpassword
	Dim resex,reqq,reemail,reusername
	Dim challengeWord_key,rechallengeWord_key
	Dim userclass
	Dim rs

	ErrorCode=trim(request("ErrorCode"))
	ErrorMsg=trim(request("ErrorMsg"))
	remobile=trim(Dvbbs.CheckStr(request("mobile")))
	reuserpassword=trim(Dvbbs.CheckStr(request("password")))
	rechallengeWord=trim(Dvbbs.CheckStr(request("seqno")))
	retokerWord=trim(request("token"))
	'resex=trim(Dvbbs.CheckStr(request("sex")))
	'If resex="F" Then 
	'	resex=1
	'Else
	'	resex=0
	'End If
	'reqq=trim(Dvbbs.CheckStr(request("qq")))
	'reemail=trim(Dvbbs.CheckStr(request("email")))
	'reusername=trim(Dvbbs.CheckStr(request("username")))

	Session("re_challenge_reg_temp")=checkreal(remobile) & "|||" & checkreal(reuserpassword)

	If ErrorCode = "1" Then
		challengeWord_key=session("challengeWord_key")
		If challengeWord_key=retokerWord Then
			set rs=Dvbbs.Execute("select UserMobile,IsChallenge,userid,userclass,username,UserPassword from [Dv_User] where UserMobile='"&remobile&"' and IsChallenge=1")
			If rs.eof and rs.bof Then
				'不是本论坛高级用户，引导其注册
				Call redir_reg_1()
				Exit Function
			Else
				'Dvbbs.Execute("update [Dv_User] set UserPassword='"&md5(reuserpassword,16)&"' where UserMobile='"&remobile&"'")
				Dvbbs.UserID=rs(2)
				userclass=Rs(5)
				reusername=rs(4)
			End If
		Else
			'Response.Write session("challengeWord")&"||"&rechallengeWord
			'Response.End
			Dvbbs.AddErrCode(14)
			'challengeWord_key & "," & retokerWord & "," & md5(Session("challengeWord") & ":" & "raynetwork",32) & "<br>原始随机数："&Session("challengeWord")&",返回随机数："&rechallengeWord&""
			Exit Function
		End If
	Else
		Response.redirect "showerr.asp?ErrCodes=<li>"&ErrorMsg&"&action=OtherErr"
		Exit Function
	End If

	Dim TempStr
	TempStr = template.html(20)
	If Dvbbs.Forum_ChanSetting(0)=1 And Dvbbs.Forum_ChanSetting(10)=1 And Dvbbs.Forum_ChanSetting(12)=1 Then
		TempStr = Replace(TempStr,"{$ray_logininfo}",template.html(3))
	Else
		TempStr = Replace(TempStr,"{$ray_logininfo}","")
	End If
	TempStr = Replace(TempStr,"{$reuserpassword}",reuserpassword)
	TempStr = Replace(TempStr,"{$forumname}",Dvbbs.Forum_Info(0))
	Response.Write TempStr
	TempStr=""
	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)
	'客人=SessionID+活动时间+发贴时间+版面ID
	'Session(Dvbbs.CacheName & "UserID") = Split(StatUserID & "_" & Now & "_" & Now & "_" & Dvbbs.BoardID,"_")
	'Response.Cookies(Dvbbs.Forum_sn).Expires=DateAdd("s",3600,Now())
	'Response.Cookies(Dvbbs.Forum_sn).path=Dvbbs.cookiepath
	'Response.Cookies(Dvbbs.Forum_sn)("StatUserID") = StatUserID
	'Response.Cookies(Dvbbs.Forum_sn)("usercookies") = "0"
	'Response.Cookies(Dvbbs.Forum_sn)("username") = reusername
	'Response.Cookies(Dvbbs.Forum_sn)("userid") = dvbbs.UserID
	'Response.Cookies(Dvbbs.Forum_sn)("password") = TruePassWord
	'Response.Cookies(Dvbbs.Forum_sn)("userclass") = userclass
	'Response.Cookies(Dvbbs.Forum_sn)("userhidden") = 2
	rem 清除图片上传数的限制
	'response.cookies("upNum")=0
	If ChkUserLogin(reusername,userclass,"",0,1) Then userclass=""
	
End Function

sub redir_reg_1()

	If Session("re_challenge_reg_temp")="" Then
		Dvbbs.AddErrCode(14)
		exit sub
	End If

	Dim re_challenge_reg_temp
	re_challenge_reg_temp=split(Session("re_challenge_reg_temp"),"|||")

	Dim TempStr
	TempStr = template.html(21)
	TempStr = Replace(TempStr,"{$maxuserlength}",Dvbbs.Forum_Setting(41))
	TempStr = Replace(TempStr,"{$minuserlength}",Dvbbs.Forum_Setting(40))
	TempStr = Replace(TempStr,"{$reusername}",Left(re_challenge_reg_temp(0),3) & Right(re_challenge_reg_temp(0),4))
	TempStr = Replace(TempStr,"{$width}",Dvbbs.mainsetting(0))
	Response.Write TempStr
end sub

sub save_redir_reg()
	If Session("re_challenge_reg_temp")="" Then
		Dvbbs.AddErrCode(14)
		exit sub
	End If

	Dim username,sex,pass1,pass2,password
	Dim useremail,face,width,height
	Dim oicq,sign,showRe,birthday
	Dim mailbody,sendmsg,rndnum,num1
	Dim quesion,answer,topic
	Dim userinfo,usersetting
	Dim userclass,UserIM
	Dim re_challenge_reg_temp
	Dim rs,sql,i,namebadword,SplitWords
	re_challenge_reg_temp=split(Session("re_challenge_reg_temp"),"|||")

	If Request("name")="" or strLength(Request("name"))>Cint(Dvbbs.Forum_Setting(41)) or strLength(Request("name"))<Cint(Dvbbs.Forum_Setting(40)) Then
		Dvbbs.AddErrCode(17)
	Else
		username=Dvbbs.CheckStr(Trim(Request("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 Then
		Dvbbs.AddErrCode(19)
	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 For
				End If
			End If 
		next
	End If 
	sex=1
	password=md5(re_challenge_reg_temp(1),16)
	useremail=re_challenge_reg_temp(0) & "@dvbbs.net"
	showRe=1
	face="images/userface/image1.gif"
	width=32
	height=32

	If request.Form("birthyear")="" or request.form("birthmonth")="" or request.form("birthday")="" Then
		birthday=""
	Else
		birthday=trim(Request.Form("birthyear"))&"-"&trim(Request.Form("birthmonth"))&"-"&trim(Request.Form("birthday"))
		If not isdate(birthday) Then birthday=""
	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

	If Dvbbs.ErrCodes<>"" Then Exit Sub
	Dim titlepic,iUserGroupID
	set rs=Dvbbs.Execute("select usertitle,grouppic,UserGroupID from Dv_UserGroups where ParentGID=3 order by minarticle")
	userclass=rs(0)
	titlepic=rs(1)
	iUserGroupID=rs(2)
	UserIM = "||||||||||||||||||"
	set rs=server.createobject("adodb.recordset")
	sql="select * from [Dv_User] where username='"&username&"' or usermobile='"&re_challenge_reg_temp(0)&"'"
	rs.open sql,conn,1,3
	If not rs.eof and not rs.bof Then
		Dvbbs.AddErrCode(21)
		Exit Sub
	Else
		rs.addnew
		rs("IsChallenge")=1
		rs("username")=username
		rs("userpassword")=password
		rs("TruePassWord")=TruePassWord
		rs("useremail")=useremail
		rs("userclass")=userclass
		rs("titlepic")=titlepic
		rs("UserMobile")=re_challenge_reg_temp(0)
		Rs("UserIM")=UserIM
		Rs("UserPost")=0
		Rs("usergroupid")=iUserGroupID
		rs("lockuser")=0
		Rs("Usersex")=sex
		rs("JoinDate")=NOW()
		rs("Userface")=replace(face,"'","")
		rs("UserWidth")=width
		rs("UserHeight")=height
		rs("UserLogins")=1
		Rs("lastlogin")=NOW()
		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("UserFav")="陌生人,我的好友,黑名单"
		rs.update
		Dvbbs.Execute("update Dv_Setup set Forum_usernum=Forum_usernum+1,Forum_lastuser='"&username&"'")
	End If
	rs.close
	set rs=Dvbbs.Execute("select top 1 userid from [Dv_User] order by userid desc")
	dvbbs.userid=rs(0)
	set rs=nothing
	Dvbbs.ReloadSetupCache username,14
	Dvbbs.ReloadSetupCache (CLng(Dvbbs.CacheData(10,0))+1),10 
	'ReloadSetup

	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))
		mailbody = template.html(17)
		mailbody = Replace(mailbody,"{$username}",Dvbbs.HtmlEncode(username))
		mailbody = Replace(mailbody,"{$password}",password)
		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
		Dvbbs.ErrCodes=""
	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.Forum_info(0)&"欢迎您的到来"

		body = template.html(18)
		body = Replace(body,"{$Forumname}",Dvbbs.Forum_Info(0))
		'response.write body
		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 cint(Dvbbs.Forum_Setting(25))=1 Then

	Else
		Response.Cookies(Dvbbs.Forum_sn).path=dvbbs.cookiepath
		Response.Cookies(Dvbbs.Forum_sn)("username")=""
		Response.Cookies(Dvbbs.Forum_sn)("password")=""
		Response.Cookies(Dvbbs.Forum_sn)("userclass")=""
		Response.Cookies(Dvbbs.Forum_sn)("userid")=""
		Response.Cookies(Dvbbs.Forum_sn)("userhidden")=""
		Response.Cookies(Dvbbs.Forum_sn)("usercookies")=""
		

		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)
		'客人=SessionID+活动时间+发贴时间+版面ID
		Session(Dvbbs.CacheName & "UserID") = Split(StatUserID & "_" & Now & "_" & Now & "_" & Dvbbs.BoardID,"_")
		'Response.Cookies(Dvbbs.Forum_sn).Expires=DateAdd("s",3600,Now())
		Response.Cookies(Dvbbs.Forum_sn).path=Dvbbs.cookiepath
		Response.Cookies(Dvbbs.Forum_sn)("StatUserID") = StatUserID
 		Response.Cookies(Dvbbs.Forum_sn)("usercookies") = "0"
		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
		Dvbbs.Execute("delete from dv_online where username='"&dvbbs.membername&"' Or id="&StatUserID&"")
	End If

	Dim TempStr
	TempStr = template.html(22)
	If Dvbbs.Forum_ChanSetting(0)=1 And Dvbbs.Forum_ChanSetting(10)=1 And Dvbbs.Forum_ChanSetting(12)=1 Then
		TempStr = Replace(TempStr,"{$ray_logininfo}",template.html(3))
	Else
		TempStr = Replace(TempStr,"{$ray_logininfo}","")
	End If
	TempStr = Replace(TempStr,"{$reuserpassword}",re_challenge_reg_temp(1))
	TempStr = Replace(TempStr,"{$sendmsg}",sendmsg)
	TempStr = Replace(TempStr,"{$forumname}",Dvbbs.Forum_Info(0))
	Response.Write TempStr
	TempStr=""
	Session("re_challenge_reg_temp")=""
End Sub

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


Rem ==========论坛登录函数=========
Rem 判断用户登录
Function ChkUserLogin(username,password,mobile,usercookies,ctype)

	Dim rsUser,article,userclass,titlepic
	Dim userhidden,lastip,UserLastLogin
	Dim GroupID,ClassSql,FoundGrade
	Dim regname,iMyUserInfo
	Dim sql,sqlstr

	FoundGrade=False
	lastip=Dvbbs.UserTrueIP
	userhidden=request.form("userhidden")
	If not isnumeric(userhidden) and userhidden="" Then userhidden=2
	ChkUserLogin=false
	If mobile<>"" Then
		sqlstr=" UserMobile='"&mobile&"'"
	Else
		sqlstr=" UserName='"&username&"'"
	End If
	'Session(CacheName & "UserID")用户资料=0dvbbs+1刷新时间+2发帖时间+3所在版面ID+4用户ID+5用户名+6用户密码+7用户邮箱+8用户文章数+9用户主题数+10用户性别+11用户头像+12用户头像宽+13用户头像高+14用户注册时间+15用户最后登陆时间+16用户登陆次数+17用户状态+18用户等级+19用户组ID+20用户组名+21用户金钱+22用户积分UserEp+23用户魅力UserCp+24用户威望+25用户生日+26最后登陆IP+27用户被删除数+28用户精华数+29用户隐身状态+30用户短信情况+31用户阳光会员+32用户手机+33用户组图标+34用户头衔+35验证密码+36用户今日信息+37用户金币+38用户点券+	39跟踪用户ID+40VIP登记时间+41VIP截止时间+42是否存在全局自定义权限+43是否有多属性用户组+44临时数据+45Dvbbs
	Sql="Select UserID,UserName,UserPassword,UserEmail,UserPost,UserTopic,UserSex,UserFace,UserWidth,UserHeight,JoinDate,LastLogin,UserLogins,Lockuser,Userclass,UserGroupID,UserGroup,userWealth,userEP,userCP,UserPower,UserBirthday,UserLastIP,UserDel,UserIsBest,UserHidden,UserMsg,IsChallenge,UserMobile,TitlePic,UserTitle,TruePassWord,UserToday,UserMoney,UserTicket,FollowMsgID,Vip_StarTime,Vip_EndTime"
	Sql=Sql+" From [Dv_User] Where "&sqlstr&""
	set rsUser=Dvbbs.Execute(sql)
	If rsUser.eof and rsUser.bof Then
		ChkUserLogin=false
		Exit Function
	Else
		iMyUserInfo=rsUser.GetString(,1, "|||", "", "")
		rsUser.Close:Set rsUser = Nothing
	End If
	iMyUserInfo = "Dvbbs|||"& Now & "|||" & Now &"|||"& Dvbbs.BoardID &"|||"& iMyUserInfo &"|||"&Dvbbs.FoundUserPermission_All()&"|||0||||||Dvbbs"
	'iMyUserInfo = "Dvbbs|||"& Now & "|||" & Now &"|||"& Dvbbs.BoardID &"|||"& iMyUserInfo &"||||||Dvbbs"
	iMyUserInfo = Split(iMyUserInfo,"|||")
	If Trim(password)<>Trim(iMyUserInfo(6)) Then
		ChkUserLogin=false
	ElseIf iMyUserInfo(17)=1 Then
		ChkUserLogin=false
	ElseIf iMyUserInfo(19)=5 Then
		ChkUserLogin=false
	Else
		ChkUserLogin=True
		Session(Dvbbs.CacheName & "UserID") = iMyUserInfo
		Dvbbs.UserID = iMyUserInfo(4)
		RegName = iMyUserInfo(5)
		Article = iMyUserInfo(8)
		UserLastLogin = iMyUserInfo(15)
		UserClass = iMyUserInfo(18)			
		GroupID = iMyUserInfo(19)
		TitlePic = iMyUserInfo(34)
		If Article<0 Then Article=0
	End If

	If ChkUserLogin Then
	REM 判断用户组(等级)资料，当用户级别为跟随文章数增长则自动更新用户组(等级)
	REM 自动更新用户数据
	REM 如果属于系统或特殊或多属性组
	Set rsUser=Dvbbs.Execute("Select MinArticle,IsSetting,ParentGID,UserTitle,GroupPic From Dv_UserGroups Where UserGroupID="&GroupID)
	If Not (rsUser.Eof And rsUser.Bof) Then
		If rsUser(2)=1 Or rsUser(2)=2 Or rsUser(2)=4 Or rsUser(2)=5 Then
			'用户等级不按照文章升级，用户为系统或特殊或多属性组
			UserClass=rsUser(3)
			TitlePic=rsUser(4)
			FoundGrade=True
		End If
	End If
	If Not FoundGrade Then
		'如果不属于系统或特殊或多属性组,则将该用户属于注册用户组且按照其文章数自动更新其用户组(等级)
		Set rsUser=Dvbbs.Execute("Select Top 1 usertitle,GroupPic,UserGroupID From Dv_UserGroups Where ParentGID=3 And Minarticle<="&Article&" Order By MinArticle Desc,UserGroupID")
		If Not (rsUser.Eof And rsUser.Bof) Then
			UserClass=rsUser(0)
			TitlePic=rsUser(1)
			GroupID=rsUser(2)
			FoundGrade=True
		End If
	End If
	Set rsUser=nothing
	If Not FoundGrade Then Response.Redirect "showerr.asp?ErrCodes=<li>系统没有找到您的注册用户组资料，请联系管理员进行修正。&action=OtherErr"
	select case ctype
	case 1
		If Datediff("d",UserLastLogin,Now())=0 Then
			sql="update [Dv_User] set LastLogin="&SqlNowString&",UserLogins=UserLogins+1,UserLastIP='"&lastip&"',userclass='"&userclass&"',titlepic='"&titlepic&"',UserGroupID="&GroupID&",TruePassWord='"&TruePassWord&"' where userid="&dvbbs.UserID
		Else
			sql="update [Dv_User] set userWealth=userWealth+"&Dvbbs.Forum_user(4)&",userEP=userEP+"&Dvbbs.Forum_user(9)&",userCP=userCP+"&Dvbbs.Forum_user(14)&",LastLogin="&SqlNowString&",UserLogins=UserLogins+1,UserLastIP='"&lastip&"',userclass='"&userclass&"',titlepic='"&titlepic&"',UserGroupID="&GroupID&",TruePassWord='"&TruePassWord&"' where userid="&dvbbs.UserID
		End If
	case 2
		sql="update [Dv_User] set UserPost=UserPost+1,UserTopic=UserTopic+1,userWealth=userWealth+"&Dvbbs.Forum_user(1)&",userEP=userEP+"&Dvbbs.Forum_user(6)&",userCP=userCP+"&Dvbbs.Forum_user(11)&",LastLogin="&SqlNowString&",UserLastIP='"&lastip&"',userclass='"&userclass&"',titlepic='"&titlepic&"',UserGroupID="&GroupID&",TruePassWord='"&TruePassWord&"' where userid="&dvbbs.UserID
	case 3
		sql="update [Dv_User] set UserPost=UserPost+1,userWealth=userWealth+"&Dvbbs.Forum_user(2)&",userEP=userEP+"&Dvbbs.Forum_user(7)&",userCP=userCP+"&Dvbbs.Forum_user(12)&",LastLogin="&SqlNowString&",UserLastIP='"&lastip&"',userclass='"&userclass&"',titlepic='"&titlepic&"',UserGroupID="&GroupID&",TruePassWord='"&TruePassWord&"' where userid="&dvbbs.UserID
	end select
	Dvbbs.Execute(sql)
	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  id="&StatUserID&"")
	If trim(username)<>trim(Dvbbs.membername) Then
		Response.Cookies(Dvbbs.Forum_sn)("username")=""
		Response.Cookies(Dvbbs.Forum_sn)("password")=""
		Response.Cookies(Dvbbs.Forum_sn)("userclass")=""
		Response.Cookies(Dvbbs.Forum_sn)("userid")=""
		Response.Cookies(Dvbbs.Forum_sn)("userhidden")=""
		Response.Cookies(Dvbbs.Forum_sn)("usercookies")=""
		Dvbbs.Execute("delete from dv_online where username='"&Dvbbs.membername&"'")
	End If
	If isnull(usercookies) or usercookies="" Then usercookies="0"
	select case usercookies
	case "0"
		Response.Cookies(Dvbbs.Forum_sn)("usercookies") = usercookies
	case 1
   		Response.Cookies(Dvbbs.Forum_sn).Expires=Date+1
		Response.Cookies(Dvbbs.Forum_sn)("usercookies") = usercookies
	case 2
		Response.Cookies(Dvbbs.Forum_sn).Expires=Date+31
		Response.Cookies(Dvbbs.Forum_sn)("usercookies") = usercookies
	case 3
		Response.Cookies(Dvbbs.Forum_sn).Expires=Date+365
		Response.Cookies(Dvbbs.Forum_sn)("usercookies") = usercookies
	end select
	Response.Cookies(Dvbbs.Forum_sn).path = Dvbbs.cookiepath
	Response.Cookies(Dvbbs.Forum_sn)("username") = regname
	Response.Cookies(Dvbbs.Forum_sn)("userid") = Dvbbs.UserID
	Response.Cookies(Dvbbs.Forum_sn)("password") = TruePassWord
	Response.Cookies(Dvbbs.Forum_sn)("userclass") = userclass
	Response.Cookies(Dvbbs.Forum_sn)("userhidden") = userhidden
	rem 清除图片上传数的限制
	Response.Cookies("upNum")=0
	Dim iUserInfo
	iUserInfo = Session(Dvbbs.CacheName & "UserID")
	iUserInfo(35) = TruePassWord
	Session(Dvbbs.CacheName & "UserID") = iUserInfo
	End If
End Function
%>