<%@ LANGUAGE="VBSCRIPT" %>
<!--#include file="../conn/zkconn.asp"-->
<!--#include file="bbsinc/const.asp"-->
<!--#include file="bbsinc/char.asp"-->
<!--#include file="bbsinc/grade.asp"-->
<%
	dim rs
	dim sql
	dim UserIP
	dim username
	dim userclass
	dim password
	dim article
	dim founderr
	dim errmsg
	founderr=false

	UserIP=Request.ServerVariables("REMOTE_ADDR")
	if request("username")="" then
		errmsg=errmsg+"<br>"+"<li>请输入您的用户名。"
		founderr=true
	else
		username=nohack(request("username"))
	end if
	if request("password")="" then
		errmsg=errmsg+"<br>"+"<li>请输入您的密码。"
		founderr=true
	else
		password=nohack(request("password"))
	end if
	set rs=server.createobject("adodb.recordset")
	sql="select huiyuan,password,userclass,logins,lastlogin,article from huiyuan where huiyuan='"&username&"' and lockuser=0"
	rs.open sql,conn,1,3
	if rs.bof and rs.eof then
		errmsg=errmsg+"<br>"+"<li>您输入的用户名并不存在，<a href='reg.asp'>请先注册</a><li>或者用户名已经给管理员锁定。"
		founderr=true
	else
		if rs("password")<>password then
			errmsg=errmsg+"<br>"+"<li>您输入的密码不正确。"
			founderr=true
		else
			rs("logins")=rs("logins")+1
			rs("lastlogin")=Now()
			rs.update
			article=rs("article")
			if rs("userclass")<>user_level7 and rs("userclass")<>user_level8 and rs("userclass")<>user_level9 then
				if rs("article")>=level2_point and rs("article")<level3_point then
					if rs("userclass")<>user_level2 then
						rs("userclass")=user_level2
						rs.update
					end if
				elseif rs("article")>=level3_point and rs("article")<level4_point then
					if rs("userclass")<>user_level3 then
						rs("userclass")=user_level3
						rs.update
					end if
				elseif rs("article")>=level4_point and rs("article")<level5_point then
					if rs("userclass")<>user_level4 then
						rs("userclass")=user_level4
						rs.update
					end if
				elseif rs("article")>=level5_point and rs("article")<level6_point then
					if rs("userclass")<>user_level5 then
						rs("userclass")=user_level5
						rs.update
					end if
				elseif rs("article")>=level6_point then
					if rs("userclass")<>user_level6 then
						rs("userclass")=user_level6
						rs.update
					end if
				end if
			end if
	Response.Cookies("lgcookie")("username") = rs("huiyuan")
	Response.Cookies("lgcookie")("password") = rs("password")
	Response.Cookies("lgcookie")("userclass") = rs("userclass")
	Response.Cookies("lgcookie").Expires = Now()+365
	session("huiyuan")=username
		call activeuser()

		end if
	end if

	sub activeuser()
	dim rsactiveusers,activeuser
	dim membername
	dim memberword
	dim memberclass
	membername=nohack(request.cookies("lgcookie")("username"))
	memberword=nohack(request.cookies("lgcookie")("password"))
	memberclass=nohack(request.cookies("lgcookie")("userclass"))
	set rsactiveusers=server.createobject("adodb.recordset")
	if Session.SessionID<>"" then
	activeuser="delete from bbs_online where id="&cstr(Session.SessionID)
	Conn.Execute activeuser
	end if
	activeuser="select * from bbs_online where username='"&membername&"'"
	rsactiveusers.open activeuser,conn,1,3
	if rsactiveusers.eof and rsactiveusers.bof then
		rsactiveusers.addnew
		rsactiveusers("id")=Session.SessionID
		rsactiveusers("username")=membername
		rsactiveusers("userclass")=memberclass
		rsactiveusers("ip")=Request.ServerVariables("REMOTE_HOST")
		rsactiveusers("startime")=Now()
		rsactiveusers("lastimebk")=Now()
		rsactiveusers("lastime")=DateToStr(Now())
		rsactiveusers("browser")=Request.ServerVariables("HTTP_USER_AGENT")
		rsactiveusers("stats")=Request.ServerVariables("SCRIPT_NAME")
		rsactiveusers.update
	else
		rsactiveusers("lastimebk")=Now()
		rsactiveusers("lastime")=DateToStr(Now())
		rsactiveusers("stats")=Request.ServerVariables("SCRIPT_NAME")
		rsactiveusers.update
	end if
	rsactiveusers.close
	set rsactiveusers=nothing
	end sub

	if founderr=true then
		call error()
	else
		response.redirect("index.asp")
	end if
rs.close
set rs=nothing
%>