<!--#include file="../conn.asp"-->
<!--#include file="../inc/md5.asp"-->
<!--#include file="../inc/function.asp"-->
<%
dim act
act=Trim(Request.Form("act"))
Dim AskD,inHtml
Set AskD = Server.CreateObject("KwAsk.FunAsk")
	opendb
	set AskD.myConn =conn
	AskD.myPredb =predb
	AskD.Getsetting()
	AskD.GetUserRole()
	siteinfo=AskD.siteinfo
	setting=AskD.setting
	UserRole=AskD.UserRole

if act="1" then
  call login()
else 
	AskD.GetTemplate("user/T-login.html")
    inHtml=RexHtml(AskD.tempbody)
    inHtml=RexHtml_IF(inHtml)
    Response.Write(inHtml)
end if
set AskD.myConn =Nothing
closedb
Set AskD = Nothing

sub login()
Dim Rs,Sql,Userid,Userpass,Verycode,curl,ismem
  Userid=Trim(Request.Form("userid"))
  Userpass=Trim(Request.Form("userpass"))
  Verycode=Trim(Request.Form("verycode"))
  curl=Trim(Request.Form("curl"))
  ismem=Trim(Request.Form("ismem"))
  IF ismem="" Then ismem=0
  if curl="" then curl="../"
  
  'IF Verycode="" Then Response.Write("<script>var a = new parent.xWin(""1"",240,100,"""&siteInfo(4)&""",""出于安全考虑，请重新登录一次。谢谢合作！"");setTimeout(""window.parent.location.reload()"",2000);</scr"&"ipt>"):Response.End()
  'If Verycode<>Session("SafeCode") Then Response.Write("<script>var a = new parent.xWin(""1"",240,100,"""&siteInfo(4)&""",""出于安全考虑，请重新登录一次。谢谢合作！"");setTimeout(""window.parent.location.reload()"",2000);</scr"&"ipt>"):Response.End()
	 
	 If Userid="" or Userpass="" Then
	    Response.Write "<script>var a = new parent.xWin(""1"",240,100,"""&siteInfo(4)&""",""用户名或密码不能为空！"");</script>"
		Response.End()
	 End If

  Set Rs= Server.CreateObject("Adodb.Recordset")
  Rs.CursorLocation = 3
  Sql="Select * from "&predb&"User where Userid='"&Userid&"' And Userpass='"&Md5(Userpass,16)&"'"
  
  Rs.open Sql,conn,1,3
  If Rs.Bof And Rs.Eof Then
	 Response.Write "<script>var a = new parent.xWin(""1"",240,100,"""&siteInfo(4)&""",""用户名或密码错误！"");</script>"
     Response.End()
  Else
'      IF rs("isLock")=1 then
'		 Response.Write("<script language=javascript>alert('该用户被锁定，请联系管理员！');history.go(-1);</scr"&"ipt>")
'		 Response.End()
'      ElseIf rs("isLock")=2 Then
'		 Response.Write("<script language=javascript>alert('该用户尚未审核，请联系管理员！');history.go(-1);</scr"&"ipt>")
'		 Response.End()
'	   End IF
      IF rs("Score")=0 Then
	     Call AskD.Score(Rs("ID"),setting(11),"首次登陆") '第一次登陆加20分
	  End If
      If DateDiff("h",rs("Lasttime"),now())>Hour(now()) Then
	     Call AskD.Score(Rs("ID"),setting(12),"每天第一次登陆")  '每天第一次登陆加5分
	  End If
dim cip
CIP=Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If CIP="" then
   CIP=Request.ServerVariables("REMOTE_ADDR")
End If
      rs("PreviousIP")=rs("Lastip")
	  rs("PreviousTime")=rs("Lasttime")
	  rs("Lastip")=cip
	  rs("Lasttime")=now()
	  rs.update
	  Response.Cookies("Muser")=Rs("ID")
	  Response.Cookies("Musername")=Rs("userID")
	  Response.Cookies("MuserPass")=Md5(Userpass,16)
	  Response.Cookies("Grade")=Rs("grade")
	  Response.Cookies("islock")=Rs("islock")
	  IF ismem=1 Then
	     Response.Cookies("Memname")=Rs("userID")
		 Response.Cookies("Memname").Expires=Date()+30
	  Else
	     Response.Cookies("Memname")=""
		 Response.Cookies("Memname").Expires=Date()-1
	  End IF
	  '记录登录状态
	  'Response.Cookies("loginuser")=Rs("ID")
      'If Trim(Request.Form("Muser"))="1" then
		 'Response.Cookies("loginuser").Expires=Date+30
	  'End If
       Response.Write("<script language=javascript>parent.location.href='"&curl&"';</script>")
  End if
  Rs.Close
  Set Rs=Nothing
end sub
%>