<%
Class User_Reg_Update
	Private Reg_User_Err,Reg_Pass_Err,Reg_Pass2_Err,Reg_Caty_Err,Reg_Mail_Err,Reg_BlogTitle_Err
	Private Reg_BlogName_Err,Reg_BlogClass_Err,Reg_Url_Err,Reg_Info_Err,Reg_Code_Err,IsRegTrue
	Private TBUser_Name,TBUser_Pass,TBUser_Sex,TBUser_Mail,TBBlog_Url,TBBlog_Name,TBBlog_Title
	Private TBBlog_Class,TBBlog_Info,TBBlog_Data,TBBlog_Caty,LoginErr
	
	
	Rem 变量初始化
	Private Sub Class_Initialize() 
		Reg_User_Err=" 4-12位，数字，中英文,下划线即可!"
		Reg_Pass_Err=" 6-14位，数字，字母及下划线组成!"
		Reg_Pass2_Err=" 再次输入密码!"
		Reg_Caty_Err=" 请选择您的城市!"
		Reg_Mail_Err=" 输入您的电子邮箱!"
		Reg_BlogName_Err=" 您博客的名称!如：我的博客"
		Reg_BlogTitle_Err=" 您博客的标题!如：记录我的一切"
		Reg_BlogClass_Err=" 选择您博客的分类!"
		Reg_Url_Err=" 您的二级域名(数字，字母下划线组合)!"
		Reg_Code_Err=" 看不清请点击左图!"
		LoginErr="User Login: 输入您的用户名和密码进入登入！"
		IsRegTrue=True
	End Sub 
	
	Private Function Public_Check_str(Strings)
		Dim CheckStr,CheckStrArr,jjj
		CheckStr="&,%,$,!,~,*,^,',(,),/,\,<,>,?,:,|,"&Chr(34)&""
		Public_Check_str=true
		CheckStrArr=split(CheckStr,",")
		For jjj=0 to ubound(CheckStrArr)
			if instr(Strings,CheckStrArr(jjj))>0 then
				Public_Check_str=False
				Exit for
			End If
		Next
	End Function

	'检测邮箱函数
	Private function IsValidEmail(email)
		dim emailnames, emailname, emaili, emailc
		IsValidEmail = true
		emailnames = Split(email, "@")
		if UBound(emailnames) <> 1 then
		   IsValidEmail = false
		   exit function
		end if
		for each emailname in emailnames
		   if Len(emailname) <= 0 then
			 IsValidEmail = false
			 exit function
		   end if
		   for emaili = 1 to Len(emailname)
			 emailc = Lcase(Mid(emailname, emaili, 1))
			 if InStr("abcdefghijklmnopqrstuvwxyz_-.", emailc) <= 0 and not IsNumeric(emailc) then
			   IsValidEmail = false
			   exit function
			 end if
		   next
		   if Left(emailname, 1) = "." or Right(emailname, 1) = "." then
			  IsValidEmail = false
			  exit function
		   end if
		next
		if InStr(emailnames(1), ".") <= 0 then
		   IsValidEmail = false
		   exit function
		end if
		emaili = Len(emailnames(1)) - InStrRev(emailnames(1), ".")
		if emaili <> 2 and emaili <> 3 then
		   IsValidEmail = false
		   exit function
		end if
		if InStr(email, "..") > 0 then
		   IsValidEmail = false
		end if
	End function 

    Private Function Chkdomain(domain)
        Dim name, ii, cc
        name = domain
        chkdomain = True
        If Len(name) <= 0 Then
            chkdomain = False
            Exit Function
        End If
        For ii = 1 To Len(name)
            cc= LCase(Mid(name, ii, 1))
            If InStr("abcdefghijklmnopqrstuvwxyz-", cc) <= 0 And Not IsNumeric(cc) Then
               chkdomain = False
            Exit Function
            End If
       Next
    End Function
	'是否为双字节
	Private function isChinese(para)
		on error resume next
		isChinese=true
		if isNUll(para) or len(para)>24 then 
			isChinese=false
			exit function
		end if
		str=cstr(para)
		if trim(str)="" then
			isChinese=false
			exit function
		end if
		FOR I=1 TO LEN(STR)
			IF Asc(Mid(Str,i,1))<=0 THEN
				isChinese=false 
				exit function
			END IF
		NEXT
		if err.number<>0 then err.clear
	End function
	
	Public Function IsBlogUrl(BlogUrl)
		BlogUrl=Server.HTMLEncode(Trim(BlogUrl))
		IF BlogUrl="" Then
			Reg_Url_Err=" <strong class=""f00"">错误:二级域名不能为空!</strong>"
			IsRegTrue=FALSE
			Exit Function
		End IF
		IF Not Chkdomain(BlogUrl) Then
			Reg_Url_Err=" <strong class=""f00"">错误:二级域名必须是英文!</strong>"
			IsRegTrue=FALSE
			Exit Function
		End IF
		
		IF isChinese(BlogUrl) Then
			Reg_Url_Err=" <strong class=""f00"">错误:二级域名请用半角输入!</strong>"
			IsRegTrue=FALSE
			Exit Function
		End IF
		
		Dim Arr,jjj
		Arr=split(CheckDom,",")
		For jjj=0 to ubound(Arr)
			If BlogUrl=Arr(jjj) Then
				Reg_Url_Err=" <strong class=""f00"">错误:此二级域名已经有人使用!</strong>"
				IsRegTrue=FALSE
				EXIT FUNCTION
			End if
		Next
		
		DIM CheckRs
		CheckRS=CONN.EXECUTE("select Count(ID) FROM TB_USER WHERE Blog_url='"& BlogUrl &"'")(0)
		SqlCount=SqlCount+1
		IF CheckRS>0 THEN
			Reg_Url_Err=" <strong class=""f00"">错误:此二级域名已经有人使用!</strong>"
			IsRegTrue=FALSE
			Exit Function
		END IF
		Reg_Url_Err=" <strong class=""f099"">正确</strong>"
		TBBlog_Url=BlogUrl
	End Function
	
	Public Function IsEmail(Email)
		Email=Server.HTMLEncode(Trim(Email))
		IF Not IsValidEmail(Email) Then
			Reg_Mail_Err=" <strong class=""f00"">错误:Email格式不正确!</strong>"
			IsRegTrue=FALSE
		Else
			Reg_Mail_Err=" <strong class=""f099"">正确</strong>"
			TBUser_Mail=Email	
		End if
	End Function
	
	Public Function IsBlogName(BlogName,BlogTitle)
		BlogName=Server.HTMLEncode(Trim(BlogName))
		BlogTitle=Server.HTMLEncode(Trim(BlogTitle))
		IF Len(BlogName)<2 OR Len(BlogName)>40 Then
			Reg_BlogName_Err=" <strong class=""f00"">错误:博客名称不允超过40个字符!</strong>"
			IsRegTrue=FALSE
		Else
			Reg_BlogName_Err=" <strong class=""f099"">正确</strong>"
			TBBlog_Name=BlogName
		End If
		
		IF Len(BlogTitle)<2 OR Len(BlogTitle)>50 Then
			Reg_BlogTitle_Err=" <strong class=""f00"">错误:博客标题不允超过50个字符!</strong>"
			IsRegTrue=FALSE
		Else
			Reg_BlogTitle_Err=" <strong class=""f099"">正确</strong>"
			TBBlog_Title=BlogTitle
		End If
	End Function
	
	Public Function IsCode
		IF NOT CBlogObj.CodeIsTrue() Then
			Reg_Code_Err=" <strong class=""f00"">错误:验证码错误!</strong>"
			IsRegTrue=FALSE
			Exit FunCtion
		End If	
	End Function
	
	Public Function IsUser(UserName)
		UserName=Trim(Server.HTMLEncode(UserName))
		Dim Arr,jjj
		Arr=split(CheckUserName,",")
		For jjj=0 to ubound(Arr)
			If UserName=Arr(jjj) Then
				Reg_User_Err=" <strong class=""f00"">错误:此用户已经有人使用!</strong>"
				IsRegTrue=FALSE
				EXIT FUNCTION
			End if
		Next
		IF UserName="" Then 
			Reg_User_Err=" <strong class=""f00"">错误:用户名不能为空!</strong>"
			IsRegTrue=FALSE
			Exit FunCtion
		End IF
		
		IF Not Public_Check_str(UserName) Then
			Reg_User_Err=" <strong class=""f00"">错误:用户名中含有非法字符!</strong>"
			IsRegTrue=FALSE
			Exit FunCtion
		End IF
		
		IF lEN(UserName)>24 OR len(UserName)<2 Then
			Reg_User_Err=" <strong class=""f00"">错误:用户名长度应在2-24位之间!</strong>"
			IsRegTrue=FALSE
			Exit FunCtion
		End IF
		Dim CheckRs
		CheckRS=CONN.EXECUTE("select Count(ID) FROM TB_USER WHERE USER_NAME='"& UserName &"'")(0)
		SqlCount=SqlCount+1
		IF CheckRS>0 THEN
			Reg_User_Err=" <strong class=""f00"">错误:此用户名已被注册,请换一个用户名!</strong>"
			IsRegTrue=FALSE
			Exit FunCtion
		END IF
		Reg_User_Err=" <strong class=""f099"">正确</strong>"
		TBUser_Name=UserName
	End Function
	
	Public Function IsBlogClass(BlogClass)
		BlogClass=Trim(Server.HTMLEncode(BlogClass))
		IF BlogClass="" Then
			Reg_BlogClass_Err=" <strong class=""f00"">错误:请选择你的博客分类!</strong>"
			IsRegTrue=FALSE
			Exit FunCtion
		Else
			TBBlog_Class=BlogClass
		End if
	End Function
	
	Public Function IsPassWord(PassWord,PassWord2)
		PassWord=Trim(PassWord)
		PassWord2=Trim(PassWord2)
		IF PassWord="" Then 
			Reg_Pass_Err=" <strong class=""f00"">错误:密码不能为空!</strong>"
			IsRegTrue=FALSE
			Exit FunCtion
		End IF
		
		IF lEN(PassWord)>14 OR len(PassWord)<4 Then
			Reg_Pass_Err=" <strong class=""f00"">错误:密码长度应在4-14位之间!</strong>"
			IsRegTrue=FALSE
			Exit FunCtion
		End IF
		
		IF PassWord<> PassWord2 Then
			Reg_Pass2_Err=" <strong class=""f00"">错误:两次输入的密码不一样!</strong>"
			IsRegTrue=FALSE
			Exit FunCtion
		End IF
		Reg_Pass_Err=" <strong class=""f099"">正确</strong>"
		Reg_Pass2_Err=" <strong class=""f099"">正确</strong>"
		TBUser_Pass=PassWord
		
	End Function

	Public Function RegUserOk()
		IF IsRegTrue THEN
			TBBlog_Info=Server.HTMLEncode(CBlogObj.FormRequest("BlogInfo"))
			TBBlog_Info=Replace(TBBlog_Info,chr(13)&chr(10),"<br/>")
			TBBlog_Info=Replace(TBBlog_Info,chr(10)&chr(13),"<br/>")
			TBBlog_Info=Replace(TBBlog_Info,chr(10),"<br/>")
			TBBlog_Info=Replace(TBBlog_Info,chr(13),"<br/>")
			TBBlog_Caty=Server.HTMLEncode(CBlogObj.FormRequest("Caty"))
			TBBlog_Data=Date()
			TBUser_Sex=Server.HTMLEncode(CBlogObj.FormRequest("Sex"))
			IF TBBlog_Info="" Then
				TBBlog_Info="欢迎光临我的博客!"
			End if
			Dim IsPassCheck
			IF IsCheck=False Then
				IsPassCheck=1
			Else
				IsPassCheck=0
			End IF
			CONN.EXECUTE ("INSERT INTO [Tb_User] ( [User_Name],[User_Pass],[User_Sex],[User_Mail],[Blog_Url],[Blog_Name],[Blog_Title],[Blog_class],[Blog_Info],[User_Date],[Blog_Caty],[UpFileSize],[IsCheck]) VALUES ('"& TBUser_Name &"','"& TBUser_Pass &"','"& TBUser_Sex &"','"& TBUser_Mail &"','"& TBBlog_Url &"','"& TBBlog_Name &"','"& TBBlog_Title &"','"& TBBlog_Class &"','"& TBBlog_Info &"','"&TBBlog_Data&"','"&TBBlog_Caty&"',"& UpFileSize &","& IsPassCheck &")")
			Dim UserID
			UserID=CONN.EXECUTE("SELECT @@IDENTITY FROM TB_USER")(0)
			SqlCount=SqlCount+2
			Dim BlogTopTitle
			'Response.Write UserID
			'RESPONSE.END
			UserID=Clng(UserID)
			CBlogObj.CreateFolder(CityBlogDir & "User" & Cint(UserID/800) & "/")
			CBlogObj.CreateFolder(CityBlogDir & "UserUpLoad/User" & Cint(UserID/800) & "/")
			CBlogObj.Copyfile CityBlogDir & "inc/uploaddir/", CBlogObj.GetUpLoadDir(UserID)
			CBlogObj.Copyfile CityBlogDir & "inc/default/", CBlogObj.GetDir(UserID)
			BlogTopTitle=CBlogObj.FormRequest("BlogTitle")
			IF IsDom Then 
				BlogTopTitle=BlogTopTitle & "  http://" & TBBlog_Url & "." & WebHost
			End IF
			TBBlog_Name=TBBlog_Name & "(" & TBUser_Name & "'S Blog)"
			Dim RegExpObj,BodyText
			BodyText=CBlogObj.GetTxt(CityBlogDir & "inc/usersetup.inc")
			Set RegExpObj=new RegExp
			RegExpObj.IgnoreCase =true
			RegExpObj.Global=True
			RegExpObj.Pattern="(#UserID#)"
			BodyText=RegExpObj.Replace(BodyText,UserID)
			RegExpObj.Pattern="(#UserBlogTitle#)"
			BodyText=RegExpObj.Replace(BodyText,BlogTopTitle)
			RegExpObj.Pattern="(#BlogName#)"
			BodyText=RegExpObj.Replace(BodyText,TBBlog_Name)
			RegExpObj.Pattern="(#PageSize#)"
			BodyText=RegExpObj.Replace(BodyText,10)
			RegExpObj.Pattern="(#photo#)"
			BodyText=RegExpObj.Replace(BodyText,"../../img/default.jpg")
			RegExpObj.Pattern="(#UserName#)"
			BodyText=RegExpObj.Replace(BodyText,TBUser_Name)
			RegExpObj.Pattern="(#Sex#)"
			BodyText=RegExpObj.Replace(BodyText,TBUser_Sex)
			RegExpObj.Pattern="(#Date#)"
			BodyText=RegExpObj.Replace(BodyText,TBBlog_Data)
			RegExpObj.Pattern="(#Email#)"
			BodyText=RegExpObj.Replace(BodyText,TBUser_Mail)
			RegExpObj.Pattern="(#City#)"
			BodyText=RegExpObj.Replace(BodyText,TBBlog_Caty)
			RegExpObj.Pattern="(#Announcement#)"
			BodyText=RegExpObj.Replace(BodyText,TBBlog_Info)
			RegExpObj.Pattern="(#mp3#)"
			BodyText=RegExpObj.Replace(BodyText,"")
			Set RegExpObj=nothing
			CBlogObj.WriteStream CBlogObj.GetDir(UserID) & "/setup.asp",BodyText
			CblogObj.DelCahe("New_User")
			Response.Redirect("Okreg.asp?UserID=" & UserID & "&Url=" & TBBlog_Url & "")
		End IF
	End Function
	
	Public Function UpdateUserOk()
		IF IsRegTrue THEN
			TBBlog_Info=Server.HTMLEncode(CBlogObj.FormRequest("BlogInfo"))
			TBBlog_Info=Replace(TBBlog_Info,chr(13)&chr(10),"<br/>")
			TBBlog_Info=Replace(TBBlog_Info,chr(10)&chr(13),"<br/>")
			TBBlog_Info=Replace(TBBlog_Info,chr(10),"<br/>")
			TBBlog_Info=Replace(TBBlog_Info,chr(13),"<br/>")
			TBBlog_Caty=Server.HTMLEncode(CBlogObj.FormRequest("Caty"))
			TBUser_Sex=Server.HTMLEncode(CBlogObj.FormRequest("Sex"))
			IF TBBlog_Info="" Then
				TBBlog_Info="欢迎光临我的博客!"
			End if
			Dim PageZ,Photo
			PageZ=CBlogObj.FormRequest("PageZ")
			IF NOT IsNumeric(PageZ) Then
				PageZ=10
			End IF
			Dim mp3
			mp3=Replace(CBlogObj.FormRequest("mp3"),chr(13),"")
			mp3=Replace(mp3,chr(10),"")
			mp3=Replace(mp3,chr(34),"")
			IF mid(mp3,1,1)="|" Then
				mp3=mid(mp3,2)
			End IF
			Photo=CBlogObj.FormRequest("Photo")
			Conn.ExeCute("Update [Tb_User] Set User_Pass='"& TBUser_Pass &"',User_Sex='"& TBUser_Sex &"',Blog_Name='"& TBBlog_Name &"',Blog_Title='"& TBBlog_Title &"',User_Mail='"& TBUser_Mail &"',Blog_class='"& TBBlog_Class &"',Blog_Info='"& TBBlog_Info &"',Blog_Caty='"& TBBlog_Caty &"',User_Photo='"& Photo &"',mp3='"& mp3 &"' Where ID="& Session("UserID") &"")
			SqlCount=SqlCount+1
			Dim BlogTopTitle
			BlogTopTitle=CBlogObj.FormRequest("BlogTitle")
			IF IsDom Then 
				BlogTopTitle=BlogTopTitle & " http://" & CBlogObj.FormRequest("url") & "." & WebHost
			End IF
			TBBlog_Name=TBBlog_Name & "(" & Session("UserName") & "'S Blog)"
			Dim RegExpObj,BodyText
			BodyText=CBlogObj.GetTxt(CityBlogDir & "inc/usersetup.inc")
			IF Mp3<>"" Then
				Mp3="<object type=""""application/x-shockwave-flash"""" data=""""../../dewplayer-multi.swf"""" height=""""18"""" width=""""172""""><param value=""""../../dewplayer-multi.swf?mp3="& Mp3 &""""" name=""""movie""""></object>"
			End IF
			Set RegExpObj=new RegExp
			RegExpObj.IgnoreCase =true
			RegExpObj.Global=True
			RegExpObj.Pattern="(#UserID#)"
			BodyText=RegExpObj.Replace(BodyText,Session("UserID"))
			RegExpObj.Pattern="(#UserBlogTitle#)"
			BodyText=RegExpObj.Replace(BodyText,BlogTopTitle)
			RegExpObj.Pattern="(#BlogName#)"
			BodyText=RegExpObj.Replace(BodyText,TBBlog_Name)
			RegExpObj.Pattern="(#PageSize#)"
			BodyText=RegExpObj.Replace(BodyText,PageZ)
			RegExpObj.Pattern="(#photo#)"
			BodyText=RegExpObj.Replace(BodyText,Photo)
			RegExpObj.Pattern="(#UserName#)"
			BodyText=RegExpObj.Replace(BodyText,Session("UserName"))
			RegExpObj.Pattern="(#Sex#)"
			BodyText=RegExpObj.Replace(BodyText,TBUser_Sex)
			RegExpObj.Pattern="(#Date#)"
			BodyText=RegExpObj.Replace(BodyText,TBBlog_Data)
			RegExpObj.Pattern="(#Email#)"
			BodyText=RegExpObj.Replace(BodyText,TBUser_Mail)
			RegExpObj.Pattern="(#City#)"
			BodyText=RegExpObj.Replace(BodyText,TBBlog_Caty)
			RegExpObj.Pattern="(#Announcement#)"
			BodyText=RegExpObj.Replace(BodyText,TBBlog_Info)
			RegExpObj.Pattern="(#mp3#)"
			BodyText=RegExpObj.Replace(BodyText,mp3)
			Set RegExpObj=nothing
			CBlogObj.WriteStream CBlogObj.GetDir(Session("UserID")) & "/setup.asp",BodyText
			CblogObj.GetHttpUrl("")
			GetErrInfo=" <div class=""doen"">【操作成功提示:修改资料成功! 】</div>"
		End IF
	End Function
		
		
	Public Sub UserLogin()
		IF CBlogObj.FormRequest("Login")="true" Then
			IF NOT CBlogObj.CodeIsTrue() Then
				LoginErr="出错了:您的验证码错误!"
				Exit Sub
			End If
			Set Rs=Conn.execute("Select ID,User_Pass,Blog_class,Blog_Name,UpFileSize,IsCheck From Tb_User Where User_Name='"& CBlogObj.FormRequest("UserName") &"'")
			IF Rs.eof Then
				LoginErr="出错了:您输入的用户名不存在!"
				Rs.Close:Set Rs=Nothing
				Exit Sub
			Else
				IF IsNull(Rs(5)) Or Rs(5)=False Then
					LoginErr="出错了:您还没有通过审核!目前不能登陆!"
					Rs.Close:Set Rs=Nothing
					Exit Sub
				End IF
				IF Rs(1)<>CBlogObj.FormRequest("PassWord") Then
					LoginErr="出错了:您输入的用户名或密码出错!"
					Rs.Close:Set Rs=Nothing
					Exit Sub
				Else
					Session("UserID")=Rs(0):Session("UserName")=CBlogObj.FormRequest("UserName"):SESSION("User_Class")=rs(2):Session("Blog_Name")=rs(3):Session("UpFileSize")=rs(4)
					IF CBlogObj.FormRequest("Cookie")="true" Then
						Response.Cookies("cixiblog")("User_Name")=CBlogObj.FormRequest("UserName")
						Response.Cookies("cixiblog")("User_ID")=Rs(0)
						Response.Cookies("cixiblog")("User_PASS")=RS(1)
						Response.Cookies("cixiblog").expires=date+365
					End if
					LoginErr="正在登入....请稍候......"
					Response.Redirect("UserManage/default.asp")
					RS.Close:Set Rs=Nothing
				End IF
			End IF
		End IF	
	End Sub
	
	Public Sub Reg_User
		Response.write Reg_User_Err
	End Sub
	
	Public Sub Reg_Pass
		Response.write Reg_Pass_Err
	End Sub
	
	Public Sub Reg_Pass2
		Response.write Reg_Pass2_Err
	End Sub
	
	Public Sub Reg_Mail
		Response.write Reg_Mail_Err
	End Sub
	
	Public Sub Reg_BlogName
		Response.write Reg_BlogName_Err
	End Sub
	
	Public Sub Reg_BlogTitle
		Response.write Reg_BlogTitle_Err
	End Sub
	
	Public Sub Reg_BlogClass
		Response.write Reg_BlogClass_Err
	End Sub
	
	Public Sub Reg_Url
		Response.write Reg_Url_Err
	End Sub
	
	Public Sub Reg_Code
		Response.write Reg_Code_Err
	End Sub
	
	Public Sub Login_Err
		Response.write LoginErr
	End Sub
	
	Public Sub CatyList(Caty)
		response.write "<input type=""text"" name=""Caty"" class=""txtinput"" value="""&Caty&""" />"
	End Sub

	Private Sub Class_Terminate() 
		
	End Sub 
End Class
Righttrue=False
Dim Re
Set Re=New User_Reg_Update
IF CBlogObj.FormRequest("Reg")="next" Then
	Re.IsCode
	Re.IsUser CBlogObj.FormRequest("UserName")
	Re.IsPassWord CBlogObj.FormRequest("PassWord"),CBlogObj.FormRequest("PassWord2")
	Re.IsBlogName CBlogObj.FormRequest("BlogName"),CBlogObj.FormRequest("BlogTitle")
	Re.IsEmail CBlogObj.FormRequest("mail")
	IF IsDom Then Re.IsBlogUrl CBlogObj.FormRequest("blogurl")
	Re.IsBlogClass CBlogObj.FormRequest("BlogClass")
	Re.RegUserOk
End IF
IF CBlogObj.QUERY_STRING="quit" Then
	Session.Contents.RemoveAll()
	Response.Cookies("cixiblog")("User_Name")=empty
	Response.Cookies("cixiblog")("User_ID")=empty
	Response.Cookies("cixiblog")("User_PASS")=empty
	Response.Cookies("cixiblog").Expires=Date+0
End IF
Re.UserLogin
%>