<%
'**************************************
'* 最后更新 2013-05-31 by 56770.Kingdge
'* Copyright www.56770.com
'*************************************
Dim regok,other_main,sql,user_id,user_mail,user_name,pass1,pass2,password,city,user_tel,user_adds,user_postalcode,fax,fapiao_company,fapiao_adds,fapiao_zip,regerror,error_type,verifycode,user_oicq,user_question,user_answer,CookiesId,user_mobile,birthday,birthday_y,birthday_m,birthday_d,path
Showpath = "<a href='"& Eshop_url & LangPath &"'>"& Lebi_word(0) &"</a> → "& Lebi_user(25)
CookiesId = CheckNum(request.cookies(cookiesname&"_user")("cookiesid"),GetUserId())
path=trim(request.form("path"))
user_mail=Safereplace(trim(request.form("user_mail")))
user_id=Safereplace(trim(request.form("user_id")))
user_name=Safereplace(trim(request.form("user_name")))
pass1=Safereplace(trim(request.form("ps1")))
pass2=Safereplace(trim(request.form("ps2")))
password=pass2
city=Safereplace(trim(request.form("city")))
user_tel=Safereplace(trim(request.form("user_tel")))
user_adds=Safereplace(trim(request.form("user_adds")))
user_postalcode=Safereplace(trim(request.form("user_postalcode")))
fax=Safereplace(trim(request.form("fax")))
fapiao_company=Safereplace(trim(request.form("fapiao_company")))
fapiao_adds=Safereplace(trim(request.form("fapiao_adds")))
fapiao_zip=Safereplace(trim(request.form("fapiao_zip")))
sex=Safereplace(trim(request.form("sex")))
user_oicq = Safereplace(trim(request.form("user_oicq")))
user_question = Safereplace(trim(request.form("user_question")))
user_answer = Safereplace(trim(request.form("user_answer")))
If user_question = "" Then user_question = user_id
If user_answer = "" Then user_answer = password
user_mobile = Safereplace(trim(request.form("user_mobile")))
birthday = Safereplace(trim(request.form("birthday")))
birthday_y = Safereplace(trim(request.form("birthday_y")))
birthday_m= Safereplace(trim(request.form("birthday_m")))
birthday_d = Safereplace(trim(request.form("birthday_d")))
If birthday = "" And birthday_y <> "" Then
		birthday = birthday_y &"-"& birthday_m &"-"& birthday_d
End If
country = checknum(trim(request.form("country")),0)
state = Safereplace(trim(request.form("state")))
user_adds2 = Safereplace(trim(request.form("user_adds2")))
If user_id = "" Then
		regerror=True
		error_type = error_type &",11,"
End If
rem	<-{ 验证码判断 2008-3-8 by 56770.WangLei
if CInt(Config_Lebi_Eshop(11)) = 1 Then
		verifycode	= request.form("verifycode")
		If verifycode <> cstr(Session("verifycode")) Then
		regerror=True
		error_type = error_type &",13,"
		End If
End If
rem	}->
If Len(user_id)<2 Or Len(user_id)>20 Then
		If not check_name(user_id) Then
			   regerror=True
			   error_type = error_type &",1,"
		Else
			   regerror=True
			   error_type = error_type &",2,"
		End If
End if
If pass1="" Or Len(pass1)<6 Or Len(pass1)>16 Then
		regerror=True
		error_type = error_type &",3,"
End If
If pass2="" Then
		regerror=True
		error_type = error_type &",12,"
End If
If pass1<>pass2 Then
		regerror=True
		error_type = error_type &",4,"
End If
If Len(user_name)<2 Or Len(user_name)>20 Then
		regerror=True
		error_type = error_type &",5,"
End If
'        If IsValidEmail(user_mail)=false Then
'                regerror=True
'                error_type = error_type &",7,"
'        End If
'        If Len(user_tel)<6 Or Len(user_tel)>50 Then
'                regerror=True
'                error_type = error_type &",6,"
'        End If
'        If Len(user_postalcode)>7 Then
'                regerror=True
'                error_type = error_type &",8,"
'        End If
'        If Len(user_adds)<3 Or Len(user_adds)>50 Then
'                regerror=True
'                error_type = error_type &",9,"
'        End If

If LCase(user_id) = "admin" Then
		regerror=True
		error_type = error_type &",10,"
End If

set rs=server.createobject("ADODB.Recordset")
sql="select * from [Lebi_user] where user_id='"&user_id&"'"
rs.open sql,conn,1,3
if not(rs.eof or rs.bof) Then
		regerror=True
		error_type = error_type &",10,"
End if
If regerror=true Then
		response.redirect Eshop_url & PagePath(1) &"?action=reg&error_type="& error_type
		response.End
Else
		'-----------------------------------------------------------------
		'系统整合
		'-----------------------------------------------------------------
		Dim API_LEBI,API_SaveCookie,SysKey
		If API_Enable Then
				Set API_LEBI = New API_Conformity
				API_LEBI.NodeValue "action","reguser",0,False
				API_LEBI.NodeValue "username",user_id,1,False
				Md5OLD = 1
				SysKey = Md5(API_LEBI.XmlNode("username") & API_ConformKey)
				Md5OLD = 0
				API_LEBI.NodeValue "syskey",SysKey,0,False
				API_LEBI.NodeValue "password",password,0,False
				API_LEBI.NodeValue "email",user_mail,1,False
				API_LEBI.NodeValue "question",user_question,1,False
				API_LEBI.NodeValue "answer",user_answer,1,False
				API_LEBI.NodeValue "truename",user_name,1,False
				If sex = "女士" Then
					API_LEBI.NodeValue "gender",0,0,False
				Else
					API_LEBI.NodeValue "gender",1,0,False
				End If
				API_LEBI.NodeValue "qq",user_oicq,1,False
				API_LEBI.NodeValue "mobile",user_mobile,1,False
				API_LEBI.NodeValue "address",user_adds,1,False
				API_LEBI.NodeValue "zipcode",user_postalcode,1,False
				API_LEBI.NodeValue "telephone",user_tel,1,False
				API_LEBI.SendHttpData
				If API_LEBI.Status = "1" Then
						Response.Write "<script>alert('" &  API_LEBI.Message  & "');javascript:history.back();</script>"
						response.End
				Else
						Dim usercookies:usercookies=1
						API_SaveCookie = API_LEBI.SetCookie(SysKey,user_id,md5(password),usercookies)
				End If
				Set API_LEBI = Nothing
		End If
		'-----------------------------------------------------------------
		set rs=server.createobject("ADODB.Recordset")
		sql="select * from [Lebi_user]"
		rs.open sql,conn,1,3
				rs.addnew
				rs("user_id")=user_id
				rs("user_adds")=user_adds
				rs("user_mail")=user_mail
				rs("user_password")=md5(password)
				rs("user_postalcode")=user_postalcode
				rs("user_name")=user_name
				rs("fax")=fax
				rs("sex")=sex
				rs("user_tel")=user_tel
				rem	<-{   2008-3-7  by 56770.WangLei
				If Not IsNull(Config_Lebi_Eshop(1)) And IsNumeric(Config_Lebi_Eshop(1)) Then
					rs("user_grade")=CInt(Config_Lebi_Eshop(1))
				Else
					rs("user_grade")= 1
				End If
				rs("jifen")=Config_Lebi_Eshop(0)
				rem	}->
				rs("regdate")=now()
				rs("lastlogintime")=now()
				rs("lastloginip")=GetIp()
				rs("regip")=GetIp()
				rs("locksj")=now()
				rs("logins")=1
				rs("usermoney")=0
				rs("sumpay")=0
				rs("ifpay")=0
				rs("shenqing")=0
				rs("city")=city
				rs("lock")=1             '锁定状态
				'增加发票信息
				rs("fapiao_company")=fapiao_company
				rs("fapiao_adds")=fapiao_adds
				rs("fapiao_zip")=fapiao_zip
				rs("oicq") = user_oicq
				rs("user_question") = user_question
				If user_answer <> "" Then rs("user_answer") = md5(user_answer)
				rs("user_mobile") = user_mobile
				rs("birthday") = birthday
				rs("LangName") = LangName
				rs("LangTxt") = LangTxt
				rs("RndPass") = md5(md5(password))
				If UnionApi = "1" Then
					rs("u_parent") = GetUnionId()
				End If 
				rs("user_adds2") = user_adds2
				rs("country") = country
				rs("state") = state
				rs.Update
				Dim cookies_path
				cookies_path = replace(lcase(Request.ServerVariables("URL")),"reg.asp","")
				Response.cookies(cookiesname&"_user")("user_id") = rs("user_id")
				Response.cookies(cookiesname&"_user")("user_grade") = rs("user_grade")
				Response.cookies(cookiesname&"_user")("user_key") = md5(md5(password))
				Response.Cookies(cookiesname&"_user").Expires = Date() + 1
				'Response.Cookies(cookiesname&"_user").path = cookies_path
				session(cookiesname&"_user"&"user_id")=rs("user_id")
				session(cookiesname&"_user"&"user_grade")=rs("user_grade")
				session(cookiesname&"_user"&"user_key") = md5(md5(password))
		rs.close
		Set rs=Nothing
		'-----------------------------------------------------------------
		'系统整合
		'-----------------------------------------------------------------
		If API_Enable Then
				regok = regok & API_SaveCookie
				Response.Flush
		End If
		'-----------------------------------------------------------------
		If SMS_State = "1" Then
				Dim LoadSMSInfo,SMSMsg
				LoadSMSInfo = LoadStyle(Eshop_url&"include/lebi_data/SMS"& LangTxt &".data")
				If CheckMobile(user_mobile) Then
						If InStr(","& SMS_SendMode &",",",1,") > 0 Then
								SMSMsg = splits(Split(LoadSMSInfo,"@@@")(0))
								ReplaceStyle "user_id",user_id,SMSMsg
								ReplaceStyle "user_name",user_name,SMSMsg
								ReplaceStyle "user_password",pass2,SMSMsg
								session("SMSMsg0") = SMSMsg
								Call RedirectSendSMS(user_mobile,SMSMsg,0,"",sms_sendtype)
						End If
				End If
				If CheckMobile(sms_receiveno) Then
						If InStr(","& SMS_SendMode &",",",8,") > 0 Then
								SMSMsg = splits(Split(LoadSMSInfo,"@@@")(7))
								ReplaceStyle "user_id",user_id,SMSMsg
								ReplaceStyle "user_name",user_name,SMSMsg
								Call RedirectSendSMS(sms_receiveno,SMSMsg,1,"",sms_sendtype)
						End If
				End If
		End If
		'发送注册邮件
		If jmail_regon=1 And jmail_type<>0 Then
		Dim useremail,topic,mailbody,sendmsg,LoadMailInfo
		rem 增加自定义邮件内容 2008-1-21 by 56770.kingdge
		LoadMailInfo = LoadStyle(Eshop_url&"include/lebi_data/E-mail"& LangTxt &".data")
		useremail=user_mail
		topic=splits(Split(LoadMailInfo,"@@@")(0))
		ReplaceStyle "user_id",user_id,topic
		mailbody = Split(LoadMailInfo,"@@@")(1)
		ReplaceStyle "user_id",user_id,mailbody
		ReplaceStyle "user_password",pass2,mailbody
		Dim Email_Lebi
		Set Email_Lebi = New Dv_SendMail
		Email_Lebi.SendObject = jmail_type
		Email_Lebi.ServerLoginName = jmail_sendmail
		Email_Lebi.ServerLoginPass = jmail_sendpass
		Email_Lebi.SendSMTP = jmail_smtp
		Email_Lebi.SendFromEmail = jmail_frommail
		Email_Lebi.SendFromName = jmail_sendname
		If Email_Lebi.ErrCode = 0 Then
			Email_Lebi.SendMail useremail,topic,splits(mailbody)
			If jmail_sendmail<>"" And jmail_sendpass<>"" And jmail_smtp<>"" Then
				sendmsg = Lebi_user(177)
			Else
			    sendmsg = Lebi_user(178)
			End If
		Else
			sendmsg= Lebi_user(178)
		End If
		Set Email_Lebi = Nothing
		End If

        regok = regok &"<table width=""100%"" cellpadding=""0"" cellspacing=""0"" align=""center"" class=""MyUserInfo"">"
		regok = regok &"<tr><td height=""25"" class=""headmenu"">"& sitename &"&nbsp;&nbsp;〖"& Lebi_user(25) &"〗</td></tr>"
        If jmail_regon=1 Then
                regok = regok &"<tr><td height=""25"" class=""list"">"& sendmsg &"</td></tr>"
		End If
        regok = regok &"<tr><td height=""25"" class=""list""><strong>"& Lebi_user(164) &"：</strong></td></tr>"
        regok = regok &"<tr><td height=""25"" class=""list"">"& user_id &"，"& Lebi_user(165) &"</td></tr>"
		regok = regok &"<tr><td height=""25"" class=""list"">"& Lebi_user(171) &"</td></tr>"
'        regok = regok &"<tr><td height=""25"" class=""list"">&nbsp;&nbsp;1. <a href='"& Eshop_url & LangPath &"'>"& Lebi_user(166) &"</a></td></tr>"
        regok = regok &"<tr><td height=""25"" class=""list"">"
        '判断返回页面
		If path = "" Then
				Dim lsbuy
				set rs = conn.execute("select cpid,color,chima from [Lebi_lsbuy] where sessionid="& CookiesId &"")
				If rs.eof Then
						regok = regok &"<a href='"& Eshop_url & LangPath &"'>"&Lebi_user(167)&"</a> (<font color=red><span id=""backtime"">0</span></font>)"
						If session("oldUrl")="" Then
								m_u = Eshop_url & LangPath
						Else
								m_u = session("oldUrl")
						End If
				Else
						regok = regok &"<a href='"& Eshop_url & PagePath(3) &"'>"&Lebi_user(168)&"</a> (<font color=red><span id=""backtime"">0</span></font>)"
						m_u = Eshop_url & PagePath(3)
						Do While Not rs.eof
								Set lsbuy = server.CreateObject("adodb.recordset")
								lsbuy.open "select user_id from [Lebi_lsbuy] where sessionid="& CookiesId &" and user_id = '"& user_id &"' and cpid = "& rs(0) &" and color= '"& rs(1) &"' and chima = '"& rs(2) &"'",conn,1,3
								If Not lsbuy.eof Then
										lsbuy(0) = user_id
										lsbuy.update
								End If
								lsbuy.close
						rs.movenext
						Loop
				End If
				rs.Close : Set rs=Nothing
		Else
				If InStr(LCase(path),"/login")>0 Or InStr(LCase(path),"/error")>0 Then
						If session("oldUrl")="" Then
								m_u = Eshop_url & LangPath
						Else
								m_u = session("oldUrl")
						End If
				Else
						m_u = path
				End If
				regok = regok &"<font color=red><span id=""backtime"">0</span></font> <a href='"& m_u &"'>"&Lebi_user(75)&"</a>"
		End If
		m_time = 3
        regok = regok &"</td></tr>"
		regok = regok &"<tr><td height=""25"" class=""list""><strong>"& Lebi_user(169) &"：</strong></td></tr>"
		regok = regok &"<tr><td height=""25"" class=""list"">"& Lebi_user(170) &"</td></tr>"
		regok = regok &"<tr><td height=""25"" class=""list"">"& Lebi_user(172) &"</td></tr>"
		regok = regok &"</table>"
		regok = regok &"<script language=""JavaScript"">Url="""&m_u&""";if (!Url){Url=document.referrer}function countDown(secs){document.getElementById(""backtime"").innerHTML=secs;if(--secs>0) {setTimeout(""countDown(""+secs+"")"",1000);}else {window.location.href=Url;}}countDown("&m_time&");</script>"
		other_main = regok
		User_jifen_product_state()
End If
%>