<!--#include file="Include/Const.Asp"-->
<!--#include file="Include/ConnSiteData.Asp"-->
<!--#include file="Include/Md5.Asp"-->
<%
Dim LoginName, LoginPassword, AdminName, Password,GroupID, GroupPurview, Working, UserName, rs, sql,RealName
LoginName = ReplaceBadChar(Trim(request.Form("UserName")))
LoginPassword = Md5(ReplaceBadChar(request.Form("password")))
CheckCode = LCase(ReplaceBadChar(Trim(Request("CheckCode"))))

If CheckCode = "" Then
    response.Write "<script language='JavaScript'>alert('验证码不能为空，请返回检查！');" & "history.back()" & "</script>"
    response.End
End If
If Trim(Session("CheckCode")) = "" Then
    response.Write "<script language='JavaScript'>alert('您登录停留的时间过长，导致验证码失效。\n请重新返回登录页面进行登录。');" & "history.back()" & "</script>"
    response.End
End If
If CheckCode <> Session("CheckCode") Then
    response.Write "<script language='JavaScript'>alert('您输入的验证码和系统产生的不一致，请重新输入。');" & "history.back()" & "</script>"
    response.End
End If

Set rs = server.CreateObject("adodb.recordset")
sql = "select * from Zqj_Members where MemName='"&LoginName&"'"
rs.Open sql, conn, 1, 3
If rs.EOF Then
    response.Write "<script language='JavaScript'>alert('无此帐号，请返回检查！');" & "history.back()" & "</script>"
    response.End
Else
    'AdminName = rs("AdminName")
    Password = rs("Password")
    GroupID = rs("GroupID")
    Working = rs("Working")
    UserName = rs("MemName")
	RealName=rs("RealName")
End If
If LoginPassword<>Password Then
    response.Write "<script language='JavaScript'>alert('密码错误，请返回检查！');" & "history.back()" & "</script>"
    response.End
End If
If Not Working Then
    response.Write "<script language='JavaScript'>alert('帐号被禁用！');" & "history.back()" & "</script>"
    response.End
End If
If LoginName = UserName And LoginPassword = Password Then
    rs("LastLoginTime") = Now()
    rs("LastLoginIP") = Request.ServerVariables("Remote_Addr")
	rs("LoginTimes")=rs("LoginTimes")+1	
    rs.update
    rs.Close
    Set rs = Nothing
	call MemGroup(GroupID)
	session("UserName")=UserName
	session("RealName")=RealName
	session("GroupPurview")=GroupPurview
	session("LoginSystem")="Succeed"
	session("GroupID")=GroupID
	session.timeout=260
    'Response.Cookies("Crmsystem")("LoginIP") = Request.ServerVariables("Remote_Addr")
	'==================================
    Dim LoginIP, LoginTime, LoginSoft
    LoginIP = Request.ServerVariables("Remote_Addr")
    LoginSoft = Request.ServerVariables("http_user_agent")
    LoginTime = Now()
    '==================================
    response.redirect "Index.Asp"
    response.End
End If

Function MemGroup(GroupID)
    Dim rs, sql
    Set rs = server.CreateObject("adodb.recordset")
    sql = "Select * From Zqj_MemGroup where GroupID='"&GroupID&"'"
    rs.Open sql, conn, 1, 1
	if rs("GroupPurview")="" then
	GroupPurview="普通用户"
	else
    GroupPurview = rs("GroupPurview")
	end if
    rs.Close
    Set rs = Nothing
End Function
%>