<%@ LANGUAGE = VBScript.Encode %>
<!--#include file="../Include/conn.asp"-->
<!--#include file="../Include/ConnDatabase.asp"-->

<%
'=====================================
'天天企业网站管理系统  TianTianCMS
'天天网络科技工作室版权所有
'官方客服中心 http://www.ip126.com
'微信公众号 ip126com
'QQ:530051328 mail:bbfhq@163.com
'=====================================
%>
<%
dim LoginName,LoginPassword,LoginCode,AdminName,Password,AdminPurview,Working,UserName,rs,sql
LoginName=ReplaceBadChar(trim(request.form("LoginName")))
LoginPassword=Md5(ReplaceBadChar(request.form("LoginPassword")))
LoginCode=ReplaceBadChar(request.form("LoginCode"))
If request.form("GetCode")<>"" Then  GetCode = Int(ReplaceBadChar(Trim(Request.Form("GetCode"))))
If LoginCode="" And EnableSiteManageCode = True Then
   response.Write "<script language=javascript>alert('后台认证码不能为空，请返回检查!');location.replace('Admin_Login.asp');</script>"
   response.end 
End If
If LoginCode<>AdminLoginCode And EnableSiteManageCode=True Then
response.Write "<script language=javascript>alert('您输入的后台验证码和系统设置的不一致，请重新输入!');location.replace('Admin_Login.asp');</script>"
   response.end
End If
If GetCode = "" Then
response.Write "<script language=javascript>alert('验证码不能为空，请返回检查!');location.replace('Admin_Login.asp');</script>"
   response.end
End If
If Trim(Session("GetCode")) = "" Then
response.Write "<script language=javascript>alert('您在管理登录停留的时间过长，导致验证码失效。\n请重新返回登录页面进行登录!');location.replace('Admin_Login.asp');</script>"
   response.end
End If
If GetCode <> Session("GetCode") Then
response.Write "<script language=javascript>alert('您输入的验证码和系统产生的不一致，请重新输入!');location.replace('Admin_Login.asp');</script>"
   response.end
End If
set rs = server.createobject("adodb.recordset")
sql="select * from TianTianCMS_Admin where AdminName='"&LoginName&"'"
rs.open sql,conn,1,3
if rs.eof Then
response.Write "<script language=javascript>alert('无此帐号，请返回检查!');location.replace('Admin_Login.asp');</script>"
   response.end
else
   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('Admin_Login.asp');</script>"
   response.end
end if
if session("VerifyCode")<>request("VerifyCode") And EnableSiteManageCode = True Then
response.Write "<script language=javascript>alert('验证码错误，请返回检查!');location.replace('Admin_Login.asp');</script>"
   response.end
end if
if not Working Then
response.Write "<script language=javascript>alert('帐号被禁用!');location.replace('Admin_Login.asp');</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
   session("AdminName")=AdminName
   session("UserName")=UserName
   session("AdminPurview")=AdminPurview
   session("LoginSystem")="Succeed"
   session.timeout=60''设置后台停留时间为分钟
   Response.Cookies("AdminLoginCode")=AdminLoginCode
   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 TianTianCMS_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
%> 