<!--#include file="Conn.asp" -->
<!--#include file="inc/const.asp" -->
<!--#include file="inc/chan_const.asp"-->
<!--#include file="inc/chkinput.asp" -->
<!--#include file="inc/Upiconfig.asp"-->
<!--#include file="inc/md5.asp" -->
<!--#include file="inc/dv_clsother.asp"-->
<!--#include file="inc/Email_Cls.asp"-->
<%
'完整调用形式：
'<script src="Interface.asp?action=操作类型&name=用户名&Md5Info=验证串&pass=密码&lock=是否锁定&question=提示问题&answer=答案&email=电子邮件&sex=性别&save=Cookies保存选项"
'action、name、Md5Info是必填参数
'删除用户时不需要其它参数
'更新资料时，提供所要更新的信息即可
'注意：这里传递的用户密码为32位MD5加密
Dim Action,UpiUserName,UpiUserPass,UpiMd5Info,UpiQuestion,UpiAnswer,UpiEmail,UpiUserLock,UpiUserSex,UpiSaveCookies
Dim HLMd5Info
Dim TruePassword,OldPassword

Action = Trim(Request("action"))
session("SecurityKey")=SecurityKey
UpiUserName = Dvbbs.CheckStr(Trim(Request("name")))

UpiUserName = Replace(UpiUserName,"'","")
UpiUserPass = Replace(Trim(Request("pass")),"'","")
If Len(UpiUserPass) = 32 Then UpiUserPass = Mid(UpiUserPass,9,16)
UpiUserPass = Dvbbs.CheckStr(UpiUserPass)
UpiMd5Info = UCase(Trim(Request("Md5Info")))
UpiQuestion = Dvbbs.CheckStr(Trim(Request("question")))
UpiAnswer = Trim(Request("answer"))
If Len(UpiAnswer)=32 then UpiAnswer=Mid(UpiAnswer,9,16)
UpiEmail = Dvbbs.CheckStr(Trim(Request("email")))
UpiUserSex = Trim(Request("sex"))
UpiUserLock = Trim(Request("lock"))
UpiSaveCookies = Trim(Request("save"))
OldPassword=Dvbbs.CheckStr(Trim(Request("oldpass")))
If Len(OldPassword) = 32 Then OldPassword = Mid(OldPassword,9,16)
If Action="LogoutUser" then Call LogoutUser()'直接退出登录

If Not (Action = "" or UpiUserName = "" or UpiMd5Info = "") And HLIntegration = True Then
          Md5OLD=0          '整合中文同步设置兼容PHP
	   HLMd5Info = MD5(UpiUserName&SecurityKey,32)	
	If UpiMd5Info <> UCase(HLMd5Info) Then	
	   Md5OLD=1          '整合中文同步设置不兼容PHP
 	   HLMd5Info = MD5(UpiUserName&SecurityKey,32)
	   If UpiMd5Info <> UCase(HLMd5Info) Then
	      Response.End()
	   End IF
	End IF
	Select Case Action
		Case "AddUser"		
			Call AddUser()			
		Case "LoginUser"
			Call LoginUser()
		Case "LogoutUser"
			Call LogoutUser()
		Case "ModifyInfo"
			Call ModifyUserInfo()
			Case"ModifyPsw"
session("777")="123456"
		    Call ModifyUserPsw()
		Case "DelUser"
			Call DelUser()
	End Select
End If

Sub AddUser()
   
	Dvbbs.Stats = "用户注册"
	On Error Resume Next
	If UpiQuestion = "" Then UpiQuestion = "答案为您的密码"
	If UpiAnswer = "" Then UpiAnswer = UpiUserPass
	If UpiEmail = "" Then UpiEmail = UpiUserName & "@PowerEasy.cn"
	If UpiUserSex = "" Then UpiUserSex = 0
	If Not IsNumeric(UpiUserSex) Then UpiUserSex = 0
	If UpiUserSex < 0 or UpiUserSex > 1 Then UpiUserSex = 0
	If UpiUserLock = "" Then UpiUserLock = 0
	If Not IsNumeric(UpiUserLock) Then UpiUserLock = 0
	Dim UpiUserExist
	UpiUserExist = True
	
	Dvbbs.LoadTemplates("login")
	'通行注册要产生的字段
	Dim RegUserFace,RegTitlePic,RegClassName
	'随机产生用户头像
	Dim ForumAllFace,FaceTotalNum,RegUserFaceNum
	ForumAllFace = Split(Dvbbs.Forum_userface,"|||")
	FaceTotalNum = Ubound(ForumAllFace)-1
	Randomize
	RegUserFaceNum = Int(Rnd * FaceTotalNum)
	RegUserFace = ForumAllFace(0)&ForumAllFace(RegUserFaceNum)
	'产生随机密码
	Dim TruePassword
	TruePassword = Dvbbs.Createpass
	'判断用户所属用户组
	Dim TempRs
	Set TempRs = Dvbbs.Execute("Select UserTitle,GroupPic,UserGroupID,IsSetting,ParentGID From Dv_UserGroups Where ParentGID=3 Order By MinArticle")
	RegTitlePic=TempRs(1)
	RegClassName=TempRs(0)
	Dvbbs.UserGroupID = TempRs(2)
	TempRs.Close
	Set TempRs = Nothing
	
	Set TempRs = Server.CreateObject("Adodb.Recordset")
	TempRs.Open "SELECT * FROM Dv_User WHERE UserName='" & UpiUserName & "'",Conn,1,3
	If TempRs.Eof and TempRs.Bof Then
		UpiUserExist = False
		'插入新记录
		TempRs.addnew
		TempRs("UserName")=UpiUserName
		TempRs("UserPassword")=UpiUserPass
		TempRs("UserEmail")=UpiEmail
		TempRs("Userclass")=RegClassName
		TempRs("TitlePic")=RegTitlePic
		TempRs("UserQuesion")=UpiQuestion
		TempRs("UserAnswer")=UpiAnswer
		TempRs("TruePassWord")=TruePassword
		TempRs("UserIM")="||||||||||||||||||"
		TempRs("UserPost")=0
		TempRs("Usersex")=UpiUserSex
		TempRs("Lockuser")=0
		If UpiUserLock = 1 Then
			TempRs("UserGroupID")=5
		Else
			TempRs("UserGroupID")=Dvbbs.UserGroupID
		End If
		TempRs("JoinDate")=NOW()
		TempRs("UserFace")=RegUserFace
		TempRs("UserWidth")=32
		TempRs("Usertoday")="0|0|0|0|0"
		TempRs("UserHeight")=32
		TempRs("UserLogins")=1
		TempRs("LastLogin")=NOW()
		TempRs("userWealth")=dvbbs.Forum_user(0)
		TempRs("userEP")=dvbbs.Forum_user(5)
		TempRs("usercP")=dvbbs.Forum_user(10)
		TempRs("UserInfo")="||||||||||||||||||||||||||||||||||||||||||"
		TempRs("Usersetting")="||||||1"
		TempRs("UserPower")=0
		TempRs("UserDel")=0
		TempRs("UserIsbest")=0
		TempRs("UserFav")="陌生人,我的好友,黑名单"
		TempRs("IsChallenge")=0
		TempRs("UserHidden")=0
		TempRs("UserLastIP")=Request.ServerVariables("REMOTE_ADDR")
		'TempRs("UserMsg")="0||0||null"
		TempRs.update
	End If
	TempRs.close
	
	If Not UpiUserExist Then
		Dvbbs.execute("UpDate Dv_Setup Set Forum_UserNum=Forum_UserNum+1,Forum_lastUser='"&Dvbbs.HtmlEncode(UpiUserName)&"'")
		Dvbbs.ReloadSetupCache UpiUserName,14
		Dvbbs.ReloadSetupCache (CLng(Dvbbs.CacheData(10,0))+1),10 
		Set TempRs=Dvbbs.execute("select top 1 userid from [Dv_user] order by userid desc")
			Dvbbs.userid=rs(0)
		TempRs.close
		
		Set TempRs=nothing
		If Dvbbs.Forum_Setting(23) = 1 Then Dvbbs.Forum_Setting(47) = 1 'EMAIL通知密码当然要发邮件 2005-11-9 Dv.Yz
	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"&fname)
		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,sqlstr,rs,sqlstr2
		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))
		sqlstr="insert into dv_message(incept,sender,title,content,sendtime,flag,issend) values('"&UpiUserName&"','"&sender&"','"&title&"','"&body&"','"&NOW()&"',0,1)"
		
		Dvbbs.Execute(sqlstr)
		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	
		sqlstr2="UPDATE [Dv_User] Set UserMsg='"&Dvbbs.CheckStr(UserMsg)&"' WHERE UserName='"&Dvbbs.CheckStr(UpiUserName)&"'"
		Dvbbs.Execute(sqlstr2)		
	End If
	
		If Not (cint(Dvbbs.Forum_Setting(23))=1 and  CInt(Dvbbs.Forum_Setting(25))=1) Then
			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
			Response.Cookies(Dvbbs.Forum_sn)("usercookies") = 0
			Response.Cookies(Dvbbs.Forum_sn)("username") = UpiUserName
			Response.Cookies(Dvbbs.Forum_sn)("password") = TruePassWord
			Response.Cookies(Dvbbs.Forum_sn)("userclass") = RegClassName
			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=UpiUserName
			Dvbbs.userhidden=2
			Dvbbs.MemberClass=RegClassName
		End If
		'如果开邮件发送密码或认证则不是登录状态 2005-11-9 Dv.Yz
	If Cint(Dvbbs.Forum_Setting(23)) = 1 Or CInt(Dvbbs.Forum_Setting(25)) = 1 Then
		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") = ""
		If EnabledSession Then
			Session(Dvbbs.CacheName & "UserID") = Empty
		End If
		Set Dvbbs.UserSession = Nothing
	End If
	session("regtime")=now()
		Call LoginUser()
	End If
	If link=1 then Call RegSiteID()
	
End Sub '注册新用户

Sub LoginUser()
	Dim i
	If UpiSaveCookies = "" Then UpiSaveCookies=0
	
	'产生随机密码
	TruePassword = Dvbbs.Createpass
	
	'判断更新cookies目录
	Dim cookies_path_s,cookies_path_d,cookies_path
	cookies_path_s=split(Request.ServerVariables("PATH_INFO"),"/")
	cookies_path_d=ubound(cookies_path_s)
	cookies_path="/"
	For i=1 to cookies_path_d-1
		If not (cookies_path_s(i)="upload" or cookies_path_s(i)="admin") Then cookies_path=cookies_path&cookies_path_s(i)&"/"
	Next
	If dvbbs.cookiepath<>cookies_path Then
		cookies_path=replace(cookies_path,"'","")
		Dvbbs.execute("update dv_setup set Forum_Cookiespath='"&cookies_path&"'")
		Dim setupData 
		Dvbbs.CacheData(26,0)=cookies_path
		Dvbbs.Name="setup"
		Dvbbs.value=Dvbbs.CacheData
	End If
	'判断用户是否登录
    Call ChkUserLogin(UpiUserName, UpiUserPass, "", UpiSaveCookies, 1)
End Sub

Sub LogoutUser()
	If Not IsObject(Conn) Then ConnectionDatabase
	Dim activeuser,TempNum
	If Not CLng(DVbbs.UserSession.documentElement.selectSingleNode("userinfo/@userid").text)=0 Then
		activeuser="delete from Dv_online where userid= "& DVbbs.UserSession.documentElement.selectSingleNode("userinfo/@userid").text
		Conn.Execute activeuser,TempNum
		'更新缓存总用户在线数据
		MyBoardOnline.Forum_UserOnline = MyBoardOnline.Forum_UserOnline - TempNum
		Dvbbs.Name="Forum_UserOnline"
		Dvbbs.value=MyBoardOnline.Forum_UserOnline
	Else
		If IsNumeric(DVbbs.UserSession.documentElement.selectSingleNode("userinfo/@statuserid").text) Then 
			activeuser="delete from Dv_online where id="& DVbbs.UserSession.documentElement.selectSingleNode("userinfo/@statuserid").text
			Conn.Execute activeuser,TempNum
			'更新缓存总用户在线数据
			MyBoardOnline.Forum_GuestOnline = MyBoardOnline.Forum_GuestOnline - TempNum
			Dvbbs.Name="Forum_GuestOnline"
			Dvbbs.value=MyBoardOnline.Forum_GuestOnline
		End If 
	End If
	MyBoardOnline.Forum_Online = MyBoardOnline.Forum_Online - TempNum
	Dvbbs.Name="Forum_Online"
	Dvbbs.value=MyBoardOnline.Forum_Online
	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")=""
	If EnabledSession Then	
		Session(Dvbbs.CacheName & "UserID")=Empty
	End If
	Set Dvbbs.UserSession=Nothing 
	Session("flag")=Empty
End Sub

Sub ModifyUserInfo()

	On Error Resume Next
	Dim tempSQL
	tempSQL = "UPDATE Dv_User Set "
	If UpiUserPass <> "" and Len(UpiUserPass) = 16 Then
		tempSQL = tempSQL & "UserPassWord='" & UpiUserPass & "'"
	Else
		tempSQL = tempSQL & "UserPassword=UserPassword"
	End If
	If UpiQuestion <> "" Then
		tempSQL = tempSQL & ",UserQuesion='" & UpiQuestion & "'"
	End If
	If UpiAnswer <> "" and Len(UpiAnswer) = 16 Then
		tempSQL = tempSQL & ",UserAnswer='" & UpiAnswer & "'"
	End If
	If UpiEmail <> "" Then
		tempSQL = tempSQL & ",UserEmail='" & UpiEmail & "'"
	End If
	If UpiUserSex <> "" and IsNumeric(UpiUserSex) Then
		If UpiUserSex <0 or UpiUserSex > 1 Then UpiUserSex = 0
		tempSQL = tempSQL & ",UserSex=" & UpiUserSex
	End If
	If UpiUserLock <> "" and IsNumeric(UpiUserLock) Then
		If UpiUserLock <0 or UpiUserLock > 1 Then UpiUserLock = 0
		tempSQL = tempSQL & ",lockuser=" & UpiUserLock
	End If

	tempSQL = tempSQL & " WHERE UserName='" & UpiUserName & "' and UserPassword='"&UpiUserPass&"'"

	Dvbbs.Execute(TempSQL)
	
End Sub
Sub ModifyUserPsw()
Dim Rs,sql,i
Set Rs=Dvbbs.Execute("Select H_Content From Dv_Help Where H_ID=1")
	set	rs=server.createobject("adodb.recordset")
	sql="select	* from Dv_User where username='"&UpiUserName&"'and UserPassword='"&OldPassword&"'"
	rs.open sql,conn,1,3
	If not rs.eof then
	rs("UserPassword")=UpiUserPass
	rs.update
	rs.close
	set rs=nothing
	end if
end sub

Sub DelUser()
Dim DleoneName,j,DelName
DleoneName = Split(UpiUserName, ",")
For j = 0 To UBound(DleoneName)
DelName=Trim(DleoneName(j))
    On Error Resume Next
    Dvbbs.Execute("update dv_message set delR=1 where incept='"&trim(DelName)&"' and delR=0")
    Dvbbs.Execute("update dv_message set delS=1 where sender='"&trim(DelName)&"' and delS=0 and issend=0")
    Dvbbs.Execute("update dv_message set delS=1 where sender='"&trim(DelName)&"' and delS=0 and issend=1")
    Dvbbs.Execute("delete from dv_message where incept='"&DelName&"' and delR=1") 
    Dvbbs.Execute("update dv_message set delS=2 where sender='"&trim(DelName)&"' and delS=1")
    Dvbbs.Execute("delete from dv_friend where F_username='"&DelName&"'") 
    Dvbbs.Execute("delete from dv_bookmark where username='"&DelName&"'") 

    '删除用户的帖子和精华
    Dvbbs.Execute("delete from dv_topic where PostUserName='" & DelName & "'")
	'--------------------替换部分--------------------
    'for i=0 to ubound(allposttable)
    '    Dvbbs.Execute("delete from "&allposttable(i)&" where PostUserID in ("&replace(request("userid"),"'","")&")")
    'next
	'--------------------替换部分--------------------
	Dim AllPostTable
    Dim Trs
    Set Trs=Dvbbs.Execute("select * from [Dv_TableList]")
    AllPostTable=""
    Do While Not TRs.EOF
        If AllPostTable=""  Then 
            AllPostTable=TRs("TableName")
        Else
            AllPostTable=AllPostTable&"|"&TRs("TableName")
        End If
    TRs.MoveNext
    Loop 
    Trs.Close
    AllPostTable=Split(AllPostTable,"|")
    Dim iNum
    For iNum = 0 to Ubound(AllPostTable)
        Dvbbs.Execute("DELETE FROM " & AllPostTable(iNum) & " WHERE UserName='" & DelName & "'")
    Next
	'--------------------替换部分--------------------
    Dvbbs.Execute("delete from dv_besttopic where PostUserName='" & DelName & "'")
    '删除用户上传表
    Dvbbs.Execute("delete from dv_upfile where F_Username='" & DelName & "'")
    Dvbbs.Execute("delete from [dv_user] where UserName='" & DelName & "'")
Next
End Sub

Sub RegSiteID()'===================注册网站ID

dim str_1,RegSiteIds,rs_1
 
set rs_1=server.CreateObject("adodb.recordset")'检查是否有注册目标系统reg_site包含注册系统的id
    str_1="select reg_site,id from hl_user where username='"&UpiUserName&"'"
	RegSiteIds=replace(request("RegSiteId"),"'","")
	rs_1.open str_1,conns,1,3
	if InStr(rs_1("reg_site"),RegSiteIds)>0 then
	response.End()
	else
	RegSiteIds=rs_1("reg_site")&","&RegSiteIds
	rs_1("reg_site")=RegSiteIds
	rs_1.update
	rs_1.close
	set rs_1=nothing
    end if
End sub


	

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,OLDuserhidden

	FoundGrade=False
	lastip=Dvbbs.UserTrueIP
	userhidden=request.form("userhidden")
	If userhidden <> "1" Then userhidden=2
	ChkUserLogin=false
	If mobile<>"" Then
		sqlstr=" Passport='"&mobile&"'"
	Else
		sqlstr=" UserName='"&username&"'"
	End If
	Sql="Select UserID,UserName,UserPassword,UserEmail,UserPost,UserTopic,UserSex,UserFace,UserWidth,UserHeight,JoinDate,LastLogin,lastlogin as cometime , LastLogin as activetime,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,userid as boardid"
	Sql=Sql & " From [Dv_User] Where "&sqlstr&""

	set rsUser=Dvbbs.Execute(sql)
	If rsUser.eof and rsUser.bof Then
		ChkUserLogin=False
		Exit Function
	Else
		If rsUser("Lockuser") =1 Or rsUser("UserGroupID") =5 Then
			ChkUserLogin=False
			Exit Function
		Else
			If Trim(password)=Trim(rsUser("UserPassword")) Then
				ChkUserLogin=True
				Dvbbs.UserID=RsUser("UserID")
				RegName = RsUser("UserName")
				Article= RsUser("UserPost")
				UserLastLogin = RsUser("cometime")
				UserClass = RsUser("Userclass")		
				GroupID = RsUser("userGroupID")
				OLDuserhidden=RsUser("UserHidden")
				TitlePic = RsUser("UserTitle")
				If Article < 0  Then Article=0
				Set Dvbbs.UserSession=Dvbbs.RecordsetToxml(rsUser,"userinfo","xml")
				Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@cometime").text=Now()
				Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@activetime").text=DateAdd("s",-3600,Now())
				Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@boardid").text=0
				Dvbbs.UserSession.documentElement.selectSingleNode("userinfo").attributes.setNamedItem(Dvbbs.UserSession.createNode(2,"isuserpermissionall","")).text=Dvbbs.FoundUserPermission_All()
				If OLDuserhidden <> CLng(userhidden) Then
					Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@userhidden").text=userhidden
					Dvbbs.Execute("update Dv_user set userhidden="&userhidden&" where UserId=" & Dvbbs.UserID)
				End If
				Dim BS
				Set Bs=Dvbbs.GetBrowser()
				Dvbbs.UserSession.documentElement.appendChild(Bs.documentElement)
				If EnabledSession Then 	Session(Dvbbs.CacheName & "UserID")=Dvbbs.UserSession.xml
			Else
				ChkUserLogin=False
				Exit Function
			End If
		End If
	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
	Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@truepassword").text= TruePassWord
	Dvbbs.Membername=Dvbbs.Checkstr(regname)
	Dvbbs.Memberclass=Dvbbs.Checkstr(userclass)
	Dvbbs.UserGroupID=GroupID
	End If
End Function
%>