<% Option Explicit %>
<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312" />
<META NAME="Keywords" CONTENT="" />
<META NAME="Description" CONTENT="" />
<TITLE>检查后台登录</TITLE>
</HEAD>
<!--#include file="../Include/Const.asp" -->
<!--#include file="../Include/Conn1.asp" -->
<!--#include file="../include/Md5.asp"-->
<BODY>
<%
dim LoginName,LoginPassword,AdminName,Password,AdminPurview,Working,UserName,rs,sql,UserId
LoginName=trim(request.form("LoginName"))
LoginPassword=Md5(request.form("LoginPassword"))
set rs = server.createobject("adodb.recordset")
sql="select * from Angel_Admin where AdminName='"&LoginName&"'"
rs.open sql,conn,1,3

if rs.eof then
   response.write "<script language=javascript> alert('管理员名称不正确，请重新输入。');location.replace('index.html');</script>"
   response.end
Else
   UserId   =rs("ID")  
   AdminName=rs("AdminName")
   Password=rs("Password")
   AdminPurview=rs("AdminPurview")
   Working=rs("Working")
   UserName=rs("UserName")
end if

if LoginPassword<>Password then
   response.write "<script language=javascript> alert('管理员密码不正确，请重新输入。');location.replace('index.html');</script>"
   response.end
end if 

if CStr(Session("GetCode"))<>CStr(trim(request.Form("code"))) then
   response.write "<script language=javascript> alert('您输入验证码错误，"&Session("GetCode")&"请返回重新登录！');location.replace('index.html');</script>"
   response.end
end if

if not Working then
   response.write "<script language=javascript> alert('不能登录，此管理员帐号已被锁定。');location.replace('index.html');</script>"
   response.end
end if 
 
if LoginName=AdminName and LoginPassword=Password then
   rs("LastLoginTime")=now()
   rs("LastLoginIP")=Request.ServerVariables("Remote_Addr")
   rs.update
   rs.close
   set rs=nothing 
   Response.Cookies("Angelasp")("UserId")=UserId
   Response.Cookies("Angelasp")("UserName")=UserName
   Response.Cookies("Angelasp")("AdminName")=AdminName
   Response.Cookies("Angelasp")("LoginSystem")="Succeed"
   '==================================
   dim LoginIP,LoginTime,LoginSoft
   LoginIP=Request.ServerVariables("Remote_Addr")
   LoginSoft=Request.ServerVariables("Http_USER_AGENT")
   LoginTime=now()
   '====================================
   set rs = server.createobject("adodb.recordset")
   sql="select * from Angel_AdminLog"
   rs.open sql,conn,1,3
   rs.addnew
   rs("AdminName")=AdminName
   rs("UserName")=UserName
   rs("LoginIP")=LoginIP
   rs("LoginSoft")=LoginSoft
   rs("LoginTime")=LoginTime
   rs.update
   rs.close
   set rs=nothing 
   '========================================
   response.redirect "main.asp"
   response.end
end if
%>
</BODY>
</HTML>