<!-- #include file=../inc/BBSsetup.asp -->
<!-- #include file=../inc/User_Setup.asp -->
<!-- #include file=../inc/Board_Popfun.asp -->
<!-- #include file=inc/UserTopic.asp -->

<%
Response.Expires = 0 
Response.ExpiresAbsolute = DEF_Now - 1
Response.AddHeader "pragma","no-cache"
Response.AddHeader "cache-control","private" 
Response.CacheControl = "no-cache"

DEF_BBS_HomeUrl = "../"
OpenDatabase
GBL_UserID = CheckPass

SiteHead(DEF_SiteNameString & " - 用户会员区")

UserTopicTopInfo
DisplayUserNavigate("用户登录")

UpdateOnlineUserAtInfo GBL_board_ID,"登录"
	
If GBL_CHK_Flag=1 and Request("R")<>"Yes" Then		
	If GBL_CHK_LastWriteTime < DEF_WriteEventSpace Then
		Response.Write "<br><p align=left><font color=ff0000 class=RedFont><b>登录太频，稍候再试!</b></font>"
	Else		
		UpdateUserLevel
		LoginAccuessFul
		Rem 己有更新，特不必重复写入
		'If CheckSupervisorUserName = 0 Then
		'	Con.ExeCute("Update LeadBBS_User Set LastWriteTime=" & GetTimeValue(DEF_Now) & " where ID=" & GBL_UserID)
		'	GBL_DBNum = GBL_DBNum + 1
		'	UpdateSessionValue 13,GetTimeValue(DEF_Now),0
		'End If
	End If
Else%>
	<table width=96%>
	<tr>
	<td>
	<%
	If Request("submitflag")="" Then
		Response.Write "<br><b>请先登录</b>"
	Else
		Response.Write "<br><p align=left><font color=ff0000 class=RedFont><b>" & GBL_CHK_TempStr & "</b></font>"
	End If
	DisplayLoginForm
	Response.Write "</p>"%>
	</td>
	</tr>
	</table>
	<%
End If
UserTopicBottomInfo
closeDataBase
SiteBottom
If GBL_ShowBottomSure = 1 Then Response.Write GBL_SiteBottomString

Function LoginAccuessFul%>

<table width="97%" border="0" cellspacing="0" cellpadding="0">
<tr>
	<td>
	<br>
	<br>
	<font style="background-color:#cccccc" color="#000000">欢迎您登录！5秒钟后系统自动返回首页，您现在仍可选择：</font>
	<p><br>
	- <a href=<%=DEF_BBS_HomeUrl%>>返回论坛首页</a>
	<br><br>
	<table border="0" cellspacing="0" cellpadding="0">
	<tr><td>-&nbsp;</td><td>
	<!-- #include file=../inc/IncHtm/BoardJump.asp -->
	</td></tr></table>
	<%If Request("u") <> "" Then
	%><br>
	- 返回<a href="<%=Request("u")%>"><%=htmlencode(Request("u"))%></a><%End If%>
	<meta http-equiv=refresh content="5;URL=<%
	Dim u
	u = Request.QueryString("u")
	If Left(u,1) <> "/" and Left(u,1) <> "\" then u = ""
	If u <> "" Then
		Response.Write htmlencode(u)
	Else
		Response.Write "../Boards.asp"
	End If%>">
	<br><br>
	<br><font style="background-color:#cccccc" color="#000000">登录后，一切行为无需输入密码
	<%If DEF_RepeatLoginTimeOut > 0 and DEF_RepeatLoginTimeOut < DEF_UserOnlineTimeOut Then
		Response.write "<br>已开启防重登录功能。登录后，其它人无权再使用您的用户名登陆。"
	End If%></font>
            </td>
        </tr>
      </table>
    
<%End Function

Rem 当用户登录时，需要更新一些信息，比如最后登录时间等
Function UpdateUserLevel

	Dim Temp_N,IP,SessionID,Prevtime
	Dim Rs
	IP = GBL_IPAddress
	SessionID = session.sessionid
	Prevtime = GetTimeValue(DEF_Now)

	If GBL_CHK_ShowFlag = 1 and DEF_EnableUserHidden = 1 Then
		Temp_N = "隐身会员"
	Else
		If GBL_UserID > 0 Then
			Temp_N = GBL_CHK_User
		Else
			Temp_N = ""
		End If
	End If
	Dim OnlineID,CountFlag,TmpSessionID,OnlineUserID,tmp,i
	
	If GBL_CHK_ShowFlag = 1 and DEF_EnableUserHidden = 1 Then
		i = "隐身会员"
		tmp = 0
	Else
		If GBL_UserID > 0 Then
			i = GBL_CHK_User
			tmp = GBL_CHK_UserLimit
		Else
			I = ""
			tmp = 0
		End If
	End If
	Set Rs = Con.ExeCute("select top 2 id,SessionID from LeadBBS_onlineUser where UserID=" & GBL_UserID)
	GBL_DBNum = GBL_DBNum + 1
	If Not Rs.Eof Then
		OnlineID = cCur(Rs(0))
		TmpSessionID = Rs(1)
		Rs.MoveNext
		If Not Rs.Eof Then
			CountFlag = 1
		Else
			CountFlag = 0
		End If
		Rs.Close
		Set Rs = Nothing
		If CountFlag = 1 Then
			UpdateOnlineUserInfo("from LeadBBS_onlineUser where UserID=" & GBL_UserID & " and ID<>" & OnlineID)
			SetActiveUserCount
		End if

		If GBL_UserID > 0 and OnlineID > 0 Then
			con.execute("Update LeadBBS_onlineUser set sessionID=" & cCur(SessionID) & ",HiddenFlag=" & GBL_CHK_UserLimit & ",UserID=" & GBL_UserID & ",UserName='" & Replace(Temp_N,"'","''") & "',LastDoingTime=" & GetTimeValue(DEF_Now) & ",IP='" & GBL_IPAddress & "' where ID=" & OnlineID)
			GBL_DBNum = GBL_DBNum + 1
			UpdateSessionValue 17,GBL_IPAddress,0
			UpdateSessionValue 18,GetTimeValue(DEF_Now),0
		End If
	Else
		Rs.Close
		Set Rs = Nothing
		Set Rs = Con.ExeCute("select top 1 UserID,LastDoingTime,sessionID,ID from LeadBBS_onlineUser where IP='" & Replace(GBL_IPAddress,"'","''") & "' and UserID=0")
		GBL_DBNum = GBL_DBNum + 1
		If Rs.Eof Then
			Rs.close
			Set Rs = Nothing
			UpdateOnlineUserInfo("from LeadBBS_onlineUser where SessionID=" & cCur(SessionID))
			con.execute("insert into LeadBBS_onlineUser(SessionID,UserID,LastDoingTime,IP,StartTime,AtBoardID,AtUrl,AtInfo,Browser,System,UserName,HiddenFlag,LastRndNumber) values(" & cCur(SessionID) & "," & cCur(GBL_UserID) & "," & GetTimeValue(DEF_Now) & ",'" & GBL_IPAddress & "'," & GetTimeValue(DEF_Now) & ",0,'" & Replace(Left(Request.Servervariables("SCRIPT_NAME") & "?" & Request.QueryString,255),"'","''") & "','其它页面','" & Left(Replace(GetSBInfo(Request.ServerVariables("HTTP_USER_AGENT"),1),"'","''"),30) & "','" & Left(Replace(GetSBInfo(Request.ServerVariables("HTTP_USER_AGENT"),2),"'","''"),30) & "','" & Replace(i,"'","''") & "'," & cCur(tmp) & "," & (Fix(Timer) mod 9999) & ")")
			GBL_DBNum = GBL_DBNum + 1

			If GBL_CHK_User <> "" and GBL_UserID > 0 and CheckSupervisorUserName = 1 Then
				Con.ExeCute("insert into LeadBBS_Log(LogType,LogTime,LogInfo,UserName,IP,BoardID) Values(51," & GetTimeValue(DEF_Now) & ",'管理员登录论坛.','" & Replace(Replace(htmlencode(Left(GBL_CHK_User,14)),"\","\\"),"'","''") & "','" & Replace(GBL_IPAddress,"'","''") & "'," & GBL_Board_ID & ")")
				GBL_DBNum = GBL_DBNum + 1
			End If

			Application.Lock
			application(DEF_MasterCookies & "ActiveUsers") = application(DEF_MasterCookies & "ActiveUsers") + 1
			Application.UnLock
			OnlineID = 0
		Else
			OnlineID = cCur(Rs(3))
			Rs.Close
			Set Rs = Nothing	
			If GBL_UserID > 0 and OnlineID > 0 Then
				con.execute("Update LeadBBS_onlineUser set sessionID=" & cCur(SessionID) & ",HiddenFlag=" & GBL_CHK_UserLimit & ",UserID=" & GBL_UserID & ",UserName='" & Replace(Temp_N,"'","''") & "',LastDoingTime=" & GetTimeValue(DEF_Now) & ",IP='" & GBL_IPAddress & "' where ID=" & OnlineID)
				GBL_DBNum = GBL_DBNum + 1
			End If
		End If
	End If

	con.ExeCute ("Update LeadBBS_User set IP='" & Replace(IP,"'","''") & "',SessionID='" &_
		Replace(SessionID,"'","''") & "',Prevtime=" & Prevtime & ",LastDoingTime=" & GetTimeValue(DEF_Now) & ",LastWriteTime=" & GetTimeValue(DEF_Now) & " where id=" & GBL_UserID)
	UpdateSessionValue 11,Prevtime,0
	UpdateSessionValue 13,GetTimeValue(DEF_Now),0
	GBL_DBNum = GBL_DBNum + 1

	UpdateUserLevel = 1
	GBL_CHK_Flag = 1	

End Function
%>