<script language=javascript>
function checkreg()
{
  if (document.UserReg.UserName.value=="")
	{
	alert("亲爱的，怎么忘了输入用户名！");
	document.UserReg.UserName.focus();
	return false;
	}
  else
    {
	document.reg.username.value=document.UserReg.UserName.value;
	var popupWin = window.open('CheckReg.asp', 'CheckReg', 'scrollbars=no,width=400,height=150');
	document.reg.submit();
	}
}
</script>
<%
dim action
action=trim(request("action"))
if action="apply" then
	start="填写资料"
else
	start="用户注册"
end if

if usery<>"yes" then
response.write"<SCRIPT language=JavaScript>alert('目前"&webname&"网站已暂停新用户注册，谢谢你的支持 ！\n\n如果想成为本站用户请联系本站。');"
response.write "JavaScript:window.close()</SCRIPT>"
response.end
end if
if UserLogined=True then  response.redirect "user_main.asp"

'=================================================
'过程名：user_reg
'作  用：注册条款、表单
'参  数：无
'=================================================
sub user_reg()
if action<>"apply" then
Response.write "<table Border='0' Cellspacing='10' Cellpadding='0' width='95%' align='Center'>"
Response.write "<TR><TD>"
Response.write "<p align='center' valign='top'>〓<strong>"&webname&"用户注册条款</strong>〓</p>"
Response.write "<li>欢迎您注册成为"&webname&"用户！</li>"
Response.write "<li>注册成为我们的会员请仔细阅读以下条款。</li>"
Response.write "<li>一、请遵守国家网络安全相关条例。</li>"
Response.write "<li>二、不得利用本站程序漏洞对本站进行破坏。</li>"
Response.write "<li>三、我们有权在不通知会员情况下更改会员权限，锁定会员。</li>"
Response.write "<li>四、如果你已经认真的阅读完了以上条款，并且确认同意和遵守了，请点击下一步。<BR></li>"
Response.write "<p align='center'><form action='?action=apply' method='post'>"
Response.write "<input name='Submit' type='submit' value='下一步' style=""cursor:hand;"" class='button'>&nbsp;&nbsp;&nbsp;<input type='button' value='不同意' onclick=""window.location.href='index.asp'"" style=""cursor:hand;"" class='button'></form></p>"
Response.write "</TD></TR>"
Response.write "</table>"
else
%>
<table width="95%"  border="0" align="center" cellpadding="0" cellspacing="10">
<tr>
<td align="center" valign="top">〓<strong>新用户注册添写资料</strong>〓</td>
</tr>
</table>
<table bgcolor="#ffffff" borderColor="#F0F0F0" Border="1" Cellspacing="3" Cellpadding="3" width="95%" align="Center" style="border-collapse: collapse">
<FORM name='UserReg' action='UserRegPost.asp' method='post'>
          <TR valign="top"> 
            <TD width="15%"><b>用户名：</b></TD>
            <TD width="85%"><INPUT maxLength=14 size=20 name='UserName' class="INPUT"> 
              <font color="#FF0000">*</font> 
            <input name="Check" type="button" id="Check" value="检查用户名" onClick="checkreg();" class="INPUT">≤12个字符（6个汉字）</TD>
          </TR>
          <TR> 
            <TD width="15%"><B>密   码：</B></TD>
            <TD width=85%"><INPUT type=password maxLength=12 size=30 name='Password' class="INPUT"> 
            <font color="#FF0000">*</font> (至少6位)</TD>
          </TR>
          <TR> 
            <TD width="15%"><strong>确认密码：</strong></TD>
            <TD width="85%"><INPUT type=password maxLength=12 size=30 name='PwdConfirm' class="INPUT"> 
            <font color="#FF0000">*</font> (至少6位)</TD>
          </TR>
          <TR> 
            <TD width="15%"><strong>密码问题：</strong></TD>
            <TD width="85%"><input type=text maxlength=50 size=30 name="Question" class="INPUT"> 
            <font color="#FF0000">*</font> </TD>
          </TR>
          <TR> 
            <TD width="15%"><strong>问题答案：</strong></TD>
            <TD width="85%"><INPUT type=text maxLength=20 size=30 name="Answer" class="INPUT"> 
            <font color="#FF0000">*</font> </TD>
          </TR>
          <TR> 
            <TD width="15%"><strong>性别：</strong></TD>
            <TD width="85%"><INPUT type=radio CHECKED value="男" name=sex >
              男 &nbsp;&nbsp; <INPUT type=radio value="女" name=sex>
            女</TD>
          </TR>
          <TR> 
            <TD width="15%"><strong>Email：</strong></TD>
            <TD width="85%"><INPUT maxLength=50 size=30 name='Email' class="INPUT"> <font color="#FF0000">*</font></TD>
          </TR>
          <TR> 
            <TD width="15%"><strong>主页：</strong></TD>
            <TD width="85%"><INPUT maxLength=100 size=30 name='homepage' value="http://" class="INPUT"></TD>
          </TR>
          <TR> 
            <TD width="15%"><strong>QQ号码：</strong></TD>
            <TD width="85%"><INPUT maxLength=20 size=30 name='QQ' class="INPUT"></TD>
          </TR>
          <TR align="center"><input type='hidden' name='regpost' value='ok'> 
            <TD height="30" colspan="2"> <input type=submit value=" 注 册 " name=Submit2 class="INPUT"> 
            &nbsp; <input name=Reset type=reset id="Reset" value=" 清 除 " class="INPUT">            
            </TD>
          </TR>
         <%if mailkg="2" then%>
          <TR align="center"><TD height="30" colspan="2">友情提示：本系统开启了“邮箱验证发送密码”功能，请用真实邮箱注册，否则你将无法登陆！</TD>
          </TR>
         <%end if%>
        </form>
          <form name='reg' action='checkreg.asp' method='post' target='CheckReg'>
          <input type='hidden' name='username' value=''>
        </form>
</TABLE>
<%
end if
end sub

'=================================================
'过程名：reg_post
'作  用：注册验证
'参  数：无
'=================================================
sub reg_post()
if request.form("regpost")<>"ok" then
    Response.Redirect "show_error.asp?eid=传值参数非法!"
    Response.End
end if
if not post_chk() then
    Response.Write("<script language=javascript>alert('您提交的数据不合法，请不要从外部提交注册。');this.location.href='/index.asp';</script>") 
    response.end   
end if
dim UserName,Password,PwdConfirm,Question,Answer,Sex,Email,Homepage,QQ,MSN,userlock,founderr,ErrMsg,sendMsg
UserName=trim(request.form("UserName"))
Password=trim(request.form("Password"))
PwdConfirm=trim(request.form("PwdConfirm"))
Question=CheckStr(request.form("Question"))
Answer=CheckStr(request.form("Answer"))
Sex=CheckStr(Request.form("Sex"))
Email=CheckStr(request.form("Email"))
Homepage=CheckStr(request.form("Homepage"))
QQ=trim(request.form("QQ"))
founderr=false
if UserName="" or strLength(UserName)>12 or strLength(UserName)<4 then
	founderr=true
	errmsg=errmsg & "<br><li>请输入用户名(不能大于12小于4)</li>"
else
        if not checkname(UserName) then
  	        errmsg=errmsg+"<br><li>用户名中含有非法字符</li>"
		founderr=true
	end if
end if
if Password="" or strLength(Password)>12 or strLength(Password)<6 then
	founderr=true
	errmsg=errmsg & "<br><li>请输入密码(不能大于12小于6)</li>"
else
	if not checkname(Password) then
		errmsg=errmsg+"<br><li>密码中含有非法字符</li>"
		founderr=true
	end if
end if
if PwdConfirm="" then
	founderr=true
	errmsg=errmsg & "<br><li>请输入确认密码(不能大于12小于6)</li>"
else
	if Password<>PwdConfirm then
		founderr=true
		errmsg=errmsg & "<br><li>密码和确认密码不一致</li>"
	end if
end if
if Question="" then
	founderr=true
	errmsg=errmsg & "<br><li>密码提示问题不能为空</li>"
end if

if Answer="" then
	founderr=true
	errmsg=errmsg & "<br><li>密码答案不能为空</li>"
end if
if Sex="" then
	founderr=true
	errmsg=errmsg & "<br><li>性别不能为空</li>"
else
	sex=sex
end if
if Email="" then
	founderr=true
	errmsg=errmsg & "<br><li>Email不能为空</li>"
else
	if IsValidEmail(Email)=false then
		errmsg=errmsg & "<br><li>您的Email有错误</li>"
   		founderr=true
	end if
end if
if QQ<>"" then
	if not isnumeric(QQ) or len(cstr(QQ))>10 then
		errmsg=errmsg & "<br><li>QQ号码只能是4-10位数字，您可以选择不输入。</li>"
		founderr=true
	end if
end if

if upass="1" then
	userlock=2
else
	userlock=0
end if
'生成随即密码
if mailkg="2" then
randomize 
Password= Int((89999999 * Rnd) + 10000000)  
end if
if badReg<>"" then
badwords=split(badReg,"|")
for z=0 to ubound(badwords)
if instr(UserName,badwords(z))>0 then
founderr=true
errmsg=errmsg & "<br><li>你的用户名含有网站禁止注册的字词</li>"
exit for
end if
next
end if
if founderr=false then
   dim sqlReg,rsReg
   sqlReg="select * from [User] where UserName='" & Username & "' or Email='" & Email & "'"
   set rsReg=server.createobject("adodb.recordset")
   rsReg.open sqlReg,conn,1,3
   if not(rsReg.bof and rsReg.eof) then
      founderr=true
      errmsg=errmsg & "<br><li>您填写的用户名已经被注册</li><br><li>或者已经有用户使用了您填写的电子邮件地址。</li>"
   else
        rsReg.addnew
        rsReg("UserName")=UserName
        rsReg("Password")=md5(Password)
        rsReg("Question")=Question
        rsReg("Answer")=md5(Answer)
	rsReg("Sex")=Sex
	rsReg("Email")=Email
	rsReg("Homepage")=Homepage
	rsReg("QQ")=QQ
	rsReg("RegDate")=Now()
	rsReg("userlock")=userlock
        rsReg.update
	rsReg.close
	set rsReg=nothing
'发送欢迎信
if fsMessage="yes" then
        title="『"&webname&"』欢迎您的到来"
        sql="insert into Message(sender,incept,title,content,sendtime) values('『"&webname&"』','"&UserName&"','"&title&"','"&bodyMessage&"','"&now()&"')"
        conn.execute(sql)
end if
'发送注册邮件
if mailkg<>"0" then
dim emailto,emailtopic,emailbody
    emailto=Email
    emailtopic="您在"&webname&"的注册资料"
    emailbody=""&vbCrlf&""&UserName&", 您好!"
    emailbody=emailbody & ""&vbCrlf&""&vbCrlf&"欢迎您注册"&webname&"会员，我们将提供给您最好的服务！"
    emailbody=emailbody & ""&vbCrlf&"下面是您在"&webname&"的注册信息："
    emailbody=emailbody & ""&vbCrlf&"注册名："&UserName&""
    emailbody=emailbody & ""&vbCrlf&"密  码："&Password&""
    emailbody=emailbody & ""&vbCrlf&"本站地址："&weburl
    emailbody=emailbody & ""&vbCrlf&""&vbCrlf&"============================================"
    emailbody=emailbody & ""&vbCrlf&"再次感谢您注册"&webname&"！"&vbCrlf&""&weburl&""&vbCrlf&""&vbCrlf&""
%>
<!-- #include file="email_inc.asp" -->
<%
if SendMail="OK" then
    if mailkg="2" then
	sendmsg="本站启用邮箱验证功能，随机密码已发往您的邮箱，请查收后登陆。"
    else
	sendmsg="您的注册信息已经同时发往您的邮箱，请注意查收。"
    end if
else
	sendmsg="由于系统设置错误，给您邮箱发送的注册资料未成功。"
end if
end if
'更新会员统计
sql="select * from allcount"
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,3 
   rs("usercount")=rs("usercount")+1
   rs.update
   rs.close
   set rs=nothing
end if
end if		
if founderr=false then
response.write "<br><br><table align='center' width='500' border='0' cellpadding='2' cellspacing='0' class='border'>"
response.write "<tr><td align='center' height='22'>注册成功！欢迎您的加入！！</td></tr>"
response.write "<tr><td align='left' height='100'><br>你注册的用户名：" & UserName & "<br>"
if upass=1 then
response.write "本站系统开启了会员注册审核功能，请等待管理员验证通过……<br>"
response.Write ""&sendmsg&"<br>"
else
response.Write ""&sendmsg&"<br>"
response.write "登录后请进入『用户中心』修改您的其它相关信息。"
response.write "<p align='center'>【 请使用左边的登录面板进行登录! 】<br></p>"
end if
response.write "</td></tr></table>"
else
response.write "<BR><table align='center' width='300' border='0' cellpadding='2' cellspacing='0' class='border'>"
response.write "<tr><td align='center' height='22'>由于以下的原因不能注册用户！</td></tr>"
response.write "<tr><td align='left' height='100'>" & errmsg & "<p align='center'>【<a href='javascript:onclick=history.go(-1)'>返 回</a>】<br></p></td></tr>"
response.write "</table>"
end if
end sub
%>

