<!--#include file="inc/inc_syssite.asp"-->
<!--#include file="inc/md5.asp"-->
<%
Response.Charset = "GB2312"

'Oblog4.0 AJAX Server

Dim Action
action=LCase(Request("action"))

Select Case action
	Case "chkcode"
	Case "chkmail"
	Case "chkuser"
	Case "autosave"
End Select

'此节用于处理邀请码
Sub CheckObCode()
	Dim obCode,rs
	obCode=Trim(Request("obcode"))
	If obCode<>"" Then
		If oblog.CheckObCode(obcode,0) Then
			Response.Write "邀请码可用"
		Else
			Response.Write "邀请码不存在或已经被使用，请更换其它邀请码"
		End If
		Response.End	
	End If
End Sub

'此节用于处理Email
Sub CheckEmail()
	Dim sEmail
	sEmail=Request("email")
	If sEmail<>"" Then
		sEmail=Replace(Replace(Replace(oblog.filt_badstr(sEmail)," ",""),"%",""),"'","")
		Set rs=oblog.Execute("Select userid From oblog_user Where useremail='" & sEmail & "'")
		If Not rs.Eof Then
			Response.Write sEmail & " 已经被使用，请更换邮箱"
		Else
			Response.Write sEmail & " 可用"
		End If
		rs.Close
		Response.End
	End If
End Sub
Sub CheckUser()
	'此节用于处理用户名
	Dim regusername, user_domain, user_domainroot
	regusername = oblog.filt_badstr(Trim(request("username")))
	user_domain = oblog.filt_badstr(Trim(request("domain")))
	user_domainroot = oblog.filt_badstr(Trim(request("domainroot")))
	If regusername = "" Or oblog.strLength(regusername) > 14 Or oblog.strLength(regusername) < 4 Then oblog.adderrstr ("用户名不能为空(不能大于14小于4)！")
	If oblog.chk_regname(regusername) Then oblog.adderrstr ("用户名系统不允许注册！")
	If oblog.chk_badword(regusername) > 0 Then oblog.adderrstr ("用户名中含有系统不允许的字符！")
	If en_nameisnum = 0 And IsNumeric(regusername) Then oblog.adderrstr ("用户名不允许全部为数字！")
	If oblog.chkdomain(regusername) = False Then oblog.adderrstr ("用户名不合规范，只能使用小写字母，数字！")
	If oblog.CacheConfig(5) <> "" And oblog.CacheConfig(6) = 1 Then
	    If user_domain = "" Or oblog.strLength(user_domain) > 20 Then oblog.adderrstr ("域名不能为空(不能大于14个字符)！")
	    If user_domain <> request("old_userdomain") And oblog.strLength(user_domain) < 4 Then oblog.adderrstr ("域名不能小于4个字符！")
	    If oblog.chk_regname(user_domain) Then oblog.adderrstr ("此域名系统不允许注册！")
	    If oblog.chk_badword(user_domain) > 0 Then oblog.adderrstr ("域名中含有系统不允许的字符！")
	    If oblog.chkdomain(user_domain) = False Then oblog.adderrstr ("域名不合规范，只能使用小写字母，数字及下划线！")
	    If user_domainroot = "" Then oblog.adderrstr ("域名根不能为空！")
	End If
	If oblog.errstr <> "" Then
	    Dim errmsg, errmsg1, i
	    errmsg = Split(oblog.errstr, "_")
	    For i = 0 To UBound(errmsg)
	        If i = 0 Then
	            errmsg1=errmsg1&"<li>"&errmsg(i)
	        Else
	            errmsg1=errmsg1&"<br><li>"&errmsg(i)
	        End If
	    Next
	    Response.Write (errmsg1)
	Else
	    set rs=oblog.execute("select userid from oblog_user where username='"&regusername&"'")
	    If Not rs.EOF Then
	        Response.Write("<li><strong>"&regusername&"</strong>此用户名已存在,请更换！</li>")
	    Else
	        Response.Write("<li><strong>"&regusername&"</strong>此用户名可使用</li>")
	    End If
	    If oblog.CacheConfig(5) <> "" And oblog.CacheConfig(6) = 1 Then
	        set rs=oblog.execute("select userid from oblog_user where user_domain='"&user_domain&"' and user_domainroot='"&user_domainroot&"'")
	        If Not rs.EOF Then
	            Response.Write("<li><strong>"&user_domain&"."&user_domainroot&"</strong>此域名已存在,请更换！</li>")
	        Else
	            Response.Write("<li><strong>"&user_domain&"."&user_domainroot&"</strong>此域名可使用！</li>")
	        End If
	    End If
	    Set rs = Nothing
	End If
End Sub

'此节用于处理自动保存
Sub AutoSave()
	Dim ,sContent,sFileName,oStream
	dim FileName,From_url,Serv_url,oStream
	sFileName="draft/tmp_" & oblog.l_uid &".txt"
	Set oStream = Server.CreateObject("ADODB.Stream")
	With oStream
		.Type = 2
		.Mode = 3
		.Open
		.Charset = "gb2312"
		.Position = oStream.Size
		.WriteText=BytesToBstr(Request.BinaryRead(Request.TotalBytes),"gb2312")
		.SaveToFile Server.MapPath(FileName),2
		.Close
	End With
	Set oStream = NoThing
	If Err.Number=0 then
		Response.Write "<span style=""background-color: #FFDD3E;"">&nbsp;"&formatdatetime(now,4)&":"&Right("0"&second(now),2)&"<a href="&sFileName&" target=""_blank"" style=""text-decoration: none;"">自动保存成功</a>&nbsp;</span>"
	Else
		Response.Write "<span style=""background-color: #FFDD3E;"">&nbsp;"&formatdatetime(now,4)&"保存失败&nbsp;"&Err.Number&Err.description&"</span>"
	End If
End Sub
%>