<!--#include file="../Index_Setting.asp"-->
<!--#include file="../Inc/Cl_ClsCount.asp"-->
<!--#include file="../Inc/Cl_Md5.asp"-->
<!--#include file="../inc/upiconfig.asp"-->
<%
Dim Action,ComeUrl
Action=Trim(Request("Action"))
Cl.Title="用户登录--" & Cl.Title
if Action="CheckLogin" then
	Call User_CheckLogin()
else
	Response.write Cl.ReplaceAllFlag(User_ShowLogin())
end if

Function User_ShowLogin()
	if Cl.ChkUserLogin then response.Redirect "User_Index.asp"
	ComeUrl=Trim(request("ComeUrl"))
	if ComeUrl="" then
		ComeUrl=Request.ServerVariables("HTTP_REFERER")
		if ComeUrl="" or INstr(Lcase(ComeUrl),"showerr")>0 then ComeUrl="Index.asp"
	end if
	'if UserTableType = "Dvbbs" then
	'User_ShowLogin=Replace(Template.html(7),"{%loginaction%}",BbsDir&"login.asp?action=chk")
	'else
	User_ShowLogin=Replace(Template.html(7),"{%loginaction%}","Login.asp?Action=CheckLogin")
	'end if
	if Cl.Web_Setting(39)="Yes" then
	User_ShowLogin=Replace(User_ShowLogin,"{%getcode%}",Replace(Template.html(16),"{%getcode%}",Cl.GetCode("GetCode")))
	else
	User_ShowLogin=Replace(User_ShowLogin,"{%getcode%}","")
	end if
	User_ShowLogin=Replace(User_ShowLogin,"{%comeurl%}",ComeUrl)
End Function

Sub User_CheckLogin()
	Dim UserName,Password,CookieDate
	Dim TruePassWord,sValidDays,sUserInfo
	Dim RsGroup,sAddPoint,i,MsgInfo,sMewMsgN
	TruePassWord	= Cl.Createpass(16)
	UserName		= Cl.CheckStr(Trim(Request("UserName")))
	IF HLIntegration= True Then
	Password		= Cl.CheckStr(Trim(Request("Password")))
	Else
	Password		= Md5(Cl.CheckStr(Trim(Request("Password"))),16)
	End IF
	CookieDate		= Cl.ChkClng(Request("CookieDate"))
	ComeUrl			= Trim(Request("ComeUrl"))
   	if ComeUrl="" then
		ComeUrl=Trim(Request.ServerVariables("HTTP_REFERER"))
		if ComeUrl="" then ComeUrl="User_Index.asp?Action=MyInfo"
	end if
	ComeUrl=LCase(ComeUrl)
	if instr(ComeUrl,"reg")>0 or instr(ComeUrl,"User_")>0 then ComeUrl="Index.asp"
	if instr(ComeUrl,"login")>0 or instr(ComeUrl,"reg")>0 or instr(ComeUrl,"User_")>0 then ComeUrl="Index.asp"
    IF HLIntegration= True Then'----------恒浪(Howave.NET)整合开始------------------
	Response.Write "<form name='upiform' id='upiform' action='"&HL_Url&Manage_Url&"User_ChkLogin.asp' method='post'>" & vbCrLf
	Response.Write "	<input type='hidden' name='UserName' value='"&UserName&"'>" & vbCrLf
	Response.Write "	<input type='hidden' name='UserPassword' value='"&Password&"'>" & vbCrLf
	Response.Write "	<input type='hidden' name='CookieDate' value='"&CookieDate&"'>" & vbCrLf
	Response.Write "	<input type='hidden' name='ComeUrl' value='"&ComeUrl&"'>" & vbCrLf
	Response.Write "</form>" & vbCrLf
	Response.Write "<script language='JavaScript' type='text/javascript'>" & vbCrLf
	Response.Write "	upiform.submit();" & vbCrLf
	Response.Write "</script>" & vbCrLf'-----------恒浪整合结束------------------
	End If
	If Cl.Web_Setting(39)="Yes" Then
		 if Not Cl.CodeIsTrue(Request("CodeStr"),"GetCode") then Call Cl.OutMsg("验证码校验失败。","Login.Asp?ComeUrl=" & ComeUrl)
	end if
	if UserName="" or Password="" then
		Call Cl.OutMsg("用户名或密码或验证码不能为空！","Login.Asp?ComeUrl=" & ComeUrl)
	end if
    SQL="Select " & Db.UserID & "," & Db.UserName & "," & Db.UserPassWord & ","&Db.UserReName&"," & Db.UserEmail & "," & Db.UserSex & "," & Db.UserFace & "," & Db.UserFaceWidth & "," & Db.UserFaceHeight & "," & Db.UserIM & "," & Db.UserJoinDate & "," & Db.UserLastLogin & "," & Db.UserLogins & "," & Db.UserQuestion & "," & Db.UserAnswer & "," & Db.UserLastIP & "," & Db.UserDataNum & "," & Db.UserLevel & "," & Db.UserPoint & "," & Db.UserMoney & "," & Db.ChargeType & "," & Db.BeginDate & "," & Db.ValidNum & "," & Db.UserTPassWord & "," & Db.WaitReceive & "," & Db.Received & "," & Db.UserMsg & " From " & Db.UserTable & " where " & Db.UserLock & "=0 and " & Db.UserName & "='" & UserName & "'"
	Set Rs=Cl.Execute_U(SQL)
	if Rs.bof and Rs.eof then
		Rs.close : set Rs=Nothing
		Call Cl.OutMsg("用户名或密码错误！！！","Login.Asp?ComeUrl=" & ComeUrl)
	End if
	if Password<>Rs(2) then
		Rs.close : set Rs=Nothing
		Call Cl.OutMsg("用户名或密码错误！！！","Login.Asp?ComeUrl=" & ComeUrl)
	End if
	if Rs(17)=6 or Rs(17)=7 then
		Rs.close : set Rs=Nothing
		Call Cl.OutMsg("对不起，你尚未通过认证，不能登录！","Index.asp") 
	End if
	Set RsGroup=Cl.Execute("Select GroupName,GroupImg,LoginPoint,Purview,Purview_Other,arrClassView,arrClassInput,arrClassCheck,arrClassMaster From Cl_UserGroup Where ID="&Rs(17)&"")
	if RsGroup.Bof and RsGroup.Eof then
		Rs.close : Set Rs=Nothing
		RsGroup.Close : Set RsGroup = Nothing
		Call Cl.OutMsg("对不起，数据库中找不到您的用户组，请联系管理员解决。你的用户组ID为("&Rs(17)&")！","Index.asp") 
	End if
	sMewMsgN = Cl.newincept(UserName)
	If sMewMsgN>0 Then
		MsgInfo =sMewMsgN & "||" & Cl.inceptid(1,UserName) & "||" & Cl.inceptid(2,UserName)
	Else
		MsgInfo = "0||0||null"
	End If
	Cl.Execute_U("Update " & Db.UserTable & " Set " & Db.UserMsg & "='"&Cl.CheckStr(MsgInfo)&"' Where " & Db.UserID & "="&Clng(Rs(0))&"")
	if DateDiff("D",Rs(11),Now)>0 then
		'添加积分
		Cl.Execute_U("Update " & Db.UserTable & " Set " & Db.UserLastIP & "='" & Cl.UserTrueIP & "'," & Db.UserLastLogin & "='" & Now & "'," & Db.UserLogins & "=" & Db.UserLogins & "+1," & Db.UserPoint & "=" & Db.UserPoint & "+"&RsGroup(2)&","&Db.UserTPassWord&"='"&TruePassWord&"' Where "&Db.UserID&"=" & Rs(0) & "")
	else
		Cl.Execute_U("Update " & Db.UserTable & " Set " & Db.UserLastIP & "='" & Cl.UserTrueIP & "'," & Db.UserLastLogin & "='" & Now & "'," & Db.UserLogins & "=" & Db.UserLogins & "+1,"&Db.UserTPassWord&"='"&TruePassWord&"' Where "&Db.UserID&"=" & Rs(0) & "")
	end if
	if Cl.UserID=0 then
		Set Count = New Cls_Count
		Count.DelOnline 0, Cl.UserID, Session(Cl.CacheName & "UserID")(0)
		Set Count = Nothing
	end if
	'Response.Cookies(Cl.Web_Cookies).path			= InstallDir
	Response.Cookies(Cl.Web_Cookies)("UserID")		= Rs(0)
	Response.Cookies(Cl.Web_Cookies)("UserName")	= UserName
	Response.Cookies(Cl.Web_Cookies)("Password")	= PassWord
	Response.Cookies(Cl.Web_Cookies)("TruePassWord")= TruePassWord
	Response.Cookies(Cl.Web_Cookies)("UserLevel")	= Rs(17)
	Select Case CookieDate
	Case 1 : Response.Cookies(Cl.Web_Cookies).Expires=Date+1
	Case 2 : Response.Cookies(Cl.Web_Cookies).Expires=Date+31
	Case 3 : Response.Cookies(Cl.Web_Cookies).Expires=Date+365
	End Select
	sValidDays=Rs(22)-DateDiff("D",Rs(21),now())
	if sValidDays<0 then sValidDays=0
	sUserInfo	= "ClCMS@@@"& Now & "@@@" & Now & "@@@" & Cl.ScriptName
	For i=0 to 26
	sUserInfo	= sUserInfo & "@@@" & Rs(i)
	Next
	For i=0 to 8
	sUserInfo	= sUserInfo & "@@@" & RsGroup(i)
	Next
	sUserInfo	= sUserInfo & "@@@" & sValidDays & "@@@ClCMS"
	Cl.User_Info=Split(sUserInfo,"@@@")
	Session(Cl.CacheName & "UserID") = Cl.User_Info
	Rs.Close : Set Rs = Nothing
	RsGroup.Close : Set RsGroup = Nothing
	if UserTableType = "Dvbbs" then
		if request("CLCMS")<>"Y" then
		Response.Write "<meta http-equiv=""refresh"" content=""3;URL=" & ComeUrl & """>" & vbCrLf
		Response.Write "<iframe id='LoginUser' width='100%' height='0' frameborder='0' src='" & BbsDir & "Login.Asp?action=chk&Username=" & UserName & "&password=" & Request("Password") & "&CookieDate=" & CookieDate & "&CLCMS=Y'></iframe>" & vbCrLf
		Response.Write "<span style='font-size:9pt'>正在登陆，请稍等，3秒后自动<a href='"&ComeUrl&"'>返回</a>...</span>" & vbCrLf
		end if
		Response.end
	end if
	response.redirect ComeUrl
End Sub
%>
<%
'===================================================
' CreateLive CMS VeRsion 3.1
'							Powered by Aspoo.CoM
'===================================================
' Mail: aspoo@126.com, Info@aspoo.cn
' Q  Q: 3315263, 596197794
' Msn : aspoo@126.com, Clw866@hotmail.com
' Web : http://www.aspoo.com, http://www.aspoo.net
' Bbs : http://bbs.aspoo.com, http://bbs.aspoo.net
' Copyright (C) 2005 Aspoo.CoM All Rights Reserved.
'===================================================
%>