<!--#include file="inc/inc_syssite.asp"-->
<!--#include file="inc/md5.asp"-->
<!-- #include file="API/Class_API.asp" -->
<%
Dim P_logined_uname,P_logined_upass,P_logined_udate
P_Chklogined
dim username,password,show_login,CookieDate,fromurl,action
action=request("action")
if action<>"showindexlogin" and action<>"showjs" then
	if  oblog.checkuserlogined() then response.Redirect("user_index.asp")
end if
username=oblog.filt_badstr(trim(request.Form("username")))
password=trim(request.form("password"))
CookieDate=trim(request("CookieDate"))
fromurl=trim(request("fromurl"))
if username<>"" or request("chk")="1" then 	
	call sub_chklogin
else
	if action="showindexlogin" then
		call sub_showindexlogin()
	elseif action="showjs" then
		blogurl=oblog.setup(3,0)
		call sub_showindexlogin()
	else
		call sub_showlogin()
	end if
end if
sub sub_showlogin()
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>用户管理登陆</title>
<link href="OblogStyle/OblogStyleAdminLogin.css" rel="stylesheet" type="text/css" />
</head>
<body><form name="reg" method="post" action="login.asp?fromurl=<%=fromurl%>" >
<p class="p1"><input name="username" type="text" class="put1" size="25" />
</p>
<p class="p2"><input name="password" type="password" class="put1" size="25" />
</p>
<p class="p3">
	<input name="CookieDate" type="radio" value="0" checked="checked" title="若您不在自己的电脑登陆，请不要保存密码" />不保存
	<input type="radio" name="CookieDate" value="1" />一天
	<input type="radio" name="CookieDate" value="2" />一月
	<input type="radio" name="CookieDate" value="3" />一年</p>
<p class="p4"></p>
<div class="but">
	<input name="Submit" type="image" src="OblogStyle/OblogStyleAdminImages/login.gif" value="提交" onclick="submit()" /></div>
	<div class="code">
	<%if oblog.setup(58,0)=1 then
	%><input name="codestr" type="text" class="put2" size="6" maxlength="4" />
	<%response.Write(oblog.getcode)
	end if
	%>
	</div></p>
	</form>
</body>
</html>
<%
end sub

sub sub_chklogin()
	if oblog.chkiplock() then
		oblog.adderrstr("对不起！你的IP已被锁定,不允许登陆，！")
		oblog.showerr
		exit sub
	end if
	if oblog.setup(58,0)=1 then
		if not oblog.codepass then oblog.adderrstr("验证码错误，请刷新后重新输入！"):oblog.showerr
	end if
	if UserName="" then oblog.adderrstr("登陆用户名不能为空！")
	if Password="" then oblog.adderrstr("登陆密码不能为空！")
	if oblog.errstr<>"" then oblog.showerr:exit sub
	if CookieDate="" then CookieDate=0	else CookieDate=Clng(CookieDate)
'	password=md5(password)
	if is_ot_user=1 then
		call ot_chklogin()
	Else
		oblog.ob_chklogin UserName,MD5(password),CookieDate
		If API_Enable Then 
				Dim blogAPI
				Set blogAPI = New DPO_API_OBLOG
				blogAPI.LoadXmlFile True
				blogAPI.UserName=username
				blogAPI.PassWord=password
				blogAPI.CookieDate=CookieDate
				blogAPI.userip=oblog.userip
				Call blogAPI.ProcessMultiPing("login")
				Set blogAPI=Nothing
				Dim strUrl,i,gourl
				if fromurl<>"" Then 
					gourl=replace(fromurl,"$","&")
				Else
					gourl=oblog.comeurl
				End If
				For i=0 To UBound(aUrls)
					strUrl=Lcase(aUrls(i))
					If Left(strUrl,7)="http://" Then
						Response.write("<script src="""&strUrl&"?syskey="&MD5(UserName&oblog_Key)&"&username="&UserName&"&password="&MD5(PassWord)&"&savecookie="&CookieDate&"""></script>")
						Response.Flush
					End If
				Next
				response.write"<script language=JavaScript>"
				response.write"setTimeout(""window.location='"&gourl&"'"",0);"
				response.write"</script>"
		End If
	end If
	If API_Enable=False Then 
		if fromurl<>"" then
			response.Redirect(replace(fromurl,"$","&"))
		else
			if action="showindexlogin" then
				if instr(oblog.comeurl,"/err.asp")>0 then
					response.Redirect("index.asp")
				else
					response.Redirect(oblog.comeurl)
			
				end if
			else
				response.Redirect("user_index.asp")
			end if
		end If
	End If 
end sub



sub ot_chklogin()
	dim sql,rs,rsreg
	if not IsObject(ot_conn) then link_database
	sql="select * from "&ot_usertable&" where "&ot_username&"='"& username & "' and "&ot_password&" ='" & password &"'"
	set rs=ot_conn.execute(sql)
	if rs.bof and rs.eof then
		set rs=nothing
		if isobject(ot_conn) then ot_conn.close:set ot_conn=nothing
		oblog.adderrstr("用户名或密码错误，请重新输入！"):oblog.showerr
		exit sub
	else
		set rsreg=server.CreateObject("adodb.recordset")
		rsreg.open "select * from [oblog_user] where username='"& username &"'",conn,1,3
		if rsreg.eof then
			dim reguserlevel
			if oblog.setup(16,0)=1 then	reguserlevel=6 else reguserlevel=7
			set rsreg=server.CreateObject("adodb.recordset")
			rsreg.open "select top 1 * from [oblog_user]",conn,1,3
			rsreg.addnew
			rsreg("username")=username
			rsreg("password")="othertable"
			rsreg("user_dir")=oblog.setup(30,0)
			rsreg("user_level")=reguserlevel
			rsreg("lockuser")=0
			rsreg("en_blogteam")=1
			rsreg("adddate")=now()
			rsreg.update
			oblog.execute("update oblog_user set user_folder=userid where username='"&username&"'")
			oblog.execute("update oblog_setup set user_count=user_count+1")
			rsreg.close
			set rsreg=nothing
			oblog.SaveCookie username,password,0," "
			oblog.CreateUserDir username,1
			set rs=nothing
			oblog.showok "您是第一次激活blog系统，请完善blog资料!","user_setting.asp"
			response.End()
		else
			rsreg("LastLoginIP")=Request.ServerVariables("REMOTE_ADDR")
			rsreg("LastLoginTime")=now()
			rsreg("LoginTimes")=rsreg("LoginTimes")+1
			rsreg.update			
		end if
		rsreg.close
		set rsreg=nothing
		set rs=nothing
		if isobject(ot_conn) then ot_conn.close:set ot_conn=nothing
		oblog.SaveCookie username,password,CookieDate,""
		if action="showindexlogin" then
			'response.Redirect(oblog.comeurl)
			response.Redirect("user_index.asp")
		else
			response.Redirect("user_index.asp")
		end if	
	end if
end sub

sub sub_showindexlogin()
	dim show_userlogin
	if oblog.CheckUserLogined()=False then
		show_userlogin="<form action="""&blogurl&"login.asp?action=showindexlogin&chk=1"" method='post' name='UserLogin'>" 
    	show_userlogin=show_userlogin&"<table align='center' width='100%' border='0' cellspacing='0' cellpadding='0' style=""font-size:12px"">" 
        show_userlogin=show_userlogin & "<tr><td height='25' class=login>用户名：<input name='UserName' type='text' id='UserName' size='12' maxlength='20'></td></tr>" 
        show_userlogin=show_userlogin & "<tr><td height='25' class=login >密　码：<input name='Password' type='password' id='Password' size='12' maxlength='20'></td></tr>" 
		if oblog.setup(58,0)=1 then
			show_userlogin=show_userlogin&"<tr><td height='25' >验证码：<input name=""codestr"" type=""text"" size=""4"" maxlength=""4"" />"&oblog.getcode&"</td></tr>"
		end if
        show_userlogin=show_userlogin & "<tr><td height='25'>　　　　<input type=""checkbox"" name=""CookieDate"" value=""3"">记住密码</td></tr>" 
		
		show_userlogin=show_userlogin & "<tr><td height='25'><input name='Login' type='submit' id='Login' value='登录'> " 
        show_userlogin=show_userlogin & "<a href='"&blogurl&"reg.asp'>用户注册</a>&nbsp;<a href='"&blogurl&"lostpassword.asp'>忘记密码</a><br></td>"       
        show_userlogin=show_userlogin & "</tr></table></form>" 
	else
		show_userlogin="--欢迎您," & oblog.logined_uname & "--<br />"
		show_userlogin= show_userlogin&"您的身份："
		if oblog.logined_ulevel=7 then
			show_userlogin= show_userlogin&"注册用户"
		elseif oblog.logined_ulevel=8 then
			show_userlogin= show_userlogin&"VIP用户"
		elseif oblog.logined_ulevel=9 then
			show_userlogin= show_userlogin& "前台管理员"
		end if
		'show_userlogin= show_userlogin& "<br><b>用户控制面板：</b><br>" & vbcrlf
		show_userlogin= show_userlogin& "<br /><a href="&blogurl&"blog.asp?name="&oblog.logined_uname&" target='_blank'>我的首页</a>"
		show_userlogin= show_userlogin& "&nbsp;&nbsp;<a href='"&blogurl&"user_index.asp' target='_blank'>管理中心</a><br />" 
		show_userlogin= show_userlogin& "<a href='"&blogurl&"user_index.asp?url=user_post.asp' target='_blank'>发表日志</a>&nbsp;&nbsp;"
		show_userlogin= show_userlogin& "<a href='"&blogurl&"user_index.asp?t=logout&re=1'>注销登录</a><br />" 
	end if
	Response.Write oblog.htm2js_div(show_userlogin,"ob_login")
end Sub

Function P_Chklogined()
	Dim Logined
	Logined = True
	If Session("syskey")="" Or Session("username")="" Or Session("password")="" Then Logined = False 
	P_logined_uname = oblog.filt_badstr(Session("username"))
	P_logined_upass = oblog.filt_badstr(Session("password"))
	P_logined_udate = oblog.filt_badstr(Session("cookiedate"))
	If P_logined_uname = "" Then
		Logined = False
	End If
	If P_logined_upass = "" Then
		Logined = False
	End If
	If P_logined_udate=0 Or P_logined_udate="" Then P_logined_udate=1
	P_Chklogined=Logined
	if oblog.CheckUserLogined()=False then
		oblog.SaveCookie P_logined_uname, P_logined_upass, P_logined_udate, ""
	End If 
	Session("syskey")=""
	Session("username")=""
	Session("password")=""
	Session("cookiedate")=""
End Function 
%>

