<!--#include file="inc/conn.asp"-->
<%




dim Action, ErrStr



dim s_Usr,s_Pwd,s_Chk
Randomize timer
Action = UCase(Trim(Request.QueryString("action")))
if Action="LOGIN" then 
	s_Usr = YeSqlStr(Trim(Request.form("usr")),0)
	s_Pwd = YeSqlStr(Trim(Request.form("pwd")),0)
	s_Chk = Trim(Request.form("chk"))
	If not isnumeric(s_Chk) or s_Chk="" then
	ErrStr="验证码错误,请重试!"
	elseif s_Chk <> Session("GetCode")  then
	ErrStr="验证码错误,请重试!"
	else
		If s_Usr <> "" And s_Pwd <> "" Then
	    	call ConnectionDatabase
			set Rs=GrateRs("select * from H_admin where username like '"&trim(s_Usr)&"'",3)
			If Not Rs.Eof Then
				If Rs("password") = md5(s_Pwd) Then

					If Rs("diqu") <> "0" and Instr(showCountry(getIP()),Rs("diqu"))=0 Then
					ErrStr="所在地区禁止访问!"
					else
					response.Cookies("Admin_Name")=s_Usr
					response.Cookies("Admin_Name").expires=date+330

					response.Cookies("Admin_UserName")=s_Usr
					response.Cookies("Admin_UserName").expires=date+330

					response.Cookies("Admin_PassWord")=md5(s_Pwd)
					response.Cookies("Admin_PassWord").expires=date+330

					Response.Cookies("log")(CacheName&"admik")=Rs("limit")	'记录登录用户权限
					response.Cookies("log").expires=date+330

					Rs("lasttime")=now()
					Rs("lastip")=getIP()
					Rs.update
					End If
				Else

					ErrStr="密码不正确!"
				End If
			Else


				ErrStr="用户不存在!"
			End If

			log_Txt=ErrStr
			if log_Txt="" then log_Txt="登陆成功!"
			Call WriteLog(""&log_Txt&"",2)


			call DBConnEnd
		Else
			ErrStr="用户名和密码不能为空!"
		End If

	end if



	if ErrStr="" then 
	response.Redirect "main.asp"
	else
		response.write "<script>alert('"&ErrStr&" 请返回重新登录');window.location.href='/';</script>"
	end if





	
	end if

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>后台管理登陆</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<LINK href="/images/userlogin/public.css" type=text/css rel=stylesheet>
<LINK href="/images/userlogin/login.css" type=text/css rel=stylesheet>
<STYLE type=text/css>
</STYLE>
<script>
function fCheck(frm)
{
	if(frm.Usr.value == "") 
	{
		alert("请填写用户名");
		return false;
	}
	if(frm.Pwd.value  == "") 
	{
		alert("请填写密码");
		return false;
	}
	if(frm.Chk.value  == "") 
	{
		alert("请填写验证码");
		return false;
	}
	return true;
}
</script>
</HEAD>
<BODY>

<DIV id=div1>
  <TABLE id=login height="100%" cellSpacing=0 cellPadding=0 width=800 align=center>
  <form method=POST action="index.asp?action=login" onSubmit="return fCheck(this)">
    <TBODY>
      <TR id=main>
        <TD>
          <TABLE height="100%" cellSpacing=0 cellPadding=0 width="100%">
            <TBODY>
              <TR>
                <TD colSpan=4>&nbsp;</TD>
              </TR>
              <TR height=30>
                <TD width=380>&nbsp;</TD>
                <TD>&nbsp;</TD>
                <TD>&nbsp;</TD>
                <TD>&nbsp;</TD>
              </TR>

<%if request.cookies("Admin_UserName") <>"" then%>
               <TR height=40>
                <TD rowSpan=4>&nbsp;</TD>
                <TD><%=request.cookies("Admin_UserName")%></TD>
                <TD>
                  <a href="/main.asp">[管理中心]</a>
                  <a href="/logout.asp?action=logout">[退出]</a>
                </TD>
                <TD width=120>&nbsp;</TD>
              </TR>
<%else%>


              <TR height=40>
                <TD rowSpan=4>&nbsp;</TD>
                <TD>用户名：</TD>
                <TD>
                  <INPUT class=textbox id=txtUserName name=Usr value="<%=request.cookies("Admin_Name")%>">
                </TD>
                <TD width=120>&nbsp;</TD>
              </TR>
              <TR height=40>
                <TD>密　码：</TD>
                <TD>
                  <INPUT class=textbox id=txtUserPassword type=password name=Pwd>
                </TD>
                <TD width=120>&nbsp;</TD>
              </TR>
              <TR height=40>
                <TD>验证码：</TD>
                <TD vAlign=center colSpan=2>
                  <INPUT id=txtSN size=4 name=Chk class=codebox>
                  &nbsp; <IMG src="code.asp" border=0 align="absmiddle"></TD>
              </TR>
              <TR height=40>
                <TD></TD>
                <TD align=right>
                  <INPUT id=btnLogin type=submit value=" 登 录 " name=btnLogin>
                </TD>
                <TD width=120>&nbsp;</TD>
              </TR>
<%end if%>
              <TR height=110>
                <TD colSpan=4>&nbsp;</TD>
              </TR>
            </TBODY>
          </TABLE>
        </TD>
      </TR>


      <TR id=root height=104>
        <TD align="right" style="font-family:Verdana;padding-right:55px;">Copyright &copy; 2009 6117.Com , All right reserved
</TD>
      </TR>
    </TBODY>
  </form>
  </TABLE>
</DIV>
<DIV id=div2 style="DISPLAY: none"></DIV>
</CONTENTTEMPLATE>
</BODY>
</HTML>
