<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%option explicit%>
<!--#include file="../Conn.asp"-->
<!--#include file="../Task/TaskConfig.asp"-->
<!--#include file="../Plus/md5.asp"-->
<!--#include file="../HSK_Cls/HSK.MemberCls.asp"-->
<!--#include file="../API/cls_api.asp"-->
<!--#include file="../HSK_Cls/HSK.Label.CommonCls.asp"-->
<!--#include file="../HSK_Cls/HSK.EscapeCls.asp"-->
<%
Response.Addheader "Content-Type", "text/html; charset=gb2312"
Response.Charset = "gb2312"

Dim KSCls
Set KSCls = New Admin_GetPass
	KSCls.HSK_Run()
Set KSCls = Nothing

Class Admin_GetPass
        Private KS,KSUser
		Private Sub Class_Initialize()
		  Set KS=New PublicCls
		  Set KSUser = New UserCls
		End Sub
        Private Sub Class_Terminate()
		 Set KS=Nothing
		 Set KSUser=Nothing
		End Sub
		%>
		<!--#include file="../HSK_Cls/UserFunction.asp"-->
		<%
       Public Sub loadMain()
		Call KSUser.Head()
		If KS.S("GetPassType") <> "2" Then
			Call KSUser.InnerLocation("找回登录密码")
		Else
			Call KSUser.InnerLocation("找回安全密码")
		End If
		
		  Dim RS, UserName, Answer, Verifycode, MobileVerifyCode, GetPassType
		  
		  Dim Step:Step=KS.ChkClng(KS.S("Step"))
		  IF Step=0 Then Step=1
		  If KS.S("GetPassType") = "2" And Step = 1 Then
		  	  Step=2
		  ElseIf KS.S("GetPassType") <> "2" Then
		  	 If CBool(KSUser.UserLoginChecked) = True Then
				 Response.Write "<script>alert('抱歉！您已登录，无须找回登录密码！');history.back();</script>"
				 Exit Sub
			 End If
		  End If
		  IF Step=2 Then
			 If KS.S("GetPassType") = "2" Then
			 	 If CBool(KSUser.UserLoginChecked) = False Then
					 GCls.ComeUrl = GCls.GetUrl()
					 Response.Write "<script>alert('请先登录后再来找回安全密码!');location.href='Login/';</script>"
					 Exit Sub
				 Else
				 	 UserName = KSUser.UserName
				 End If
			 Else
				 UserName=Left(Trim(KS.CheckXSS(KS.R(KS.S("UserName")))),30)
			 End If
			 If UserName = "" Then
				 Response.Write("<script>alert('请输入用户名!');history.back();</script>")
				 Response.End
              End IF
			 
             Set RS=Server.CreateObject("Adodb.RecordSet")
			  RS.Open "Select Top 1 Question,Mobile From KS_User Where UserName='" & UserName & "'",Conn,1,1
			  IF RS.Eof And RS.Bof Then
			  	 Response.Write("<script>alert('抱歉！您输入的用户名不存在！');history.back();</script>")
				 Response.End
			  Else
		     %>
			 	<script language = "JavaScript">
				function CheckForm()
				{
				<%If Not KS.IsNul(RS("Question")) Then%>
				if (document.myform.Answer.value=="")
				  {
					alert("请输入问题答案！");
					document.myform.Answer.focus();
					return false;
				  }
				<%End If%>
				<%If Not KS.IsNul(RS("Mobile")) Then%>
				if (document.myform.MobileVerifyCode.value=="")
				  {
					alert("请输入手机验证码！");
					document.myform.MobileVerifyCode.focus();
					return false;
				  }
				<%End If%>
				if (document.myform.Verifycode.value=="")
				  {
					alert("请输入验证码！");
					document.myform.Verifycode.focus();
					return false;
				  }
	              return true;
				  }
				var showverifycode = false;
				function getCode()
				{
					if(showverifycode==false){
						showverifycode=true;
						$("#showVerify").html("<img style='cursor:pointer' src='../plus/verifycode.asp?n='+Math.random() onClick='this.src=\"../plus/verifycode.asp?n=\"+ Math.random();' align='absmiddle'>");	
					}
				}
				function SendSMS(){
					var ajaxchk;
					var ajaxstr;
					<%If Not KS.IsNul(RS("Question")) Then%>
					if (document.myform.Answer.value =="")
						{
						alert("请先填写问题答案！");
						document.myform.Answer.focus();
						return false;
					}
					<%End If%>
					if (document.myform.Verifycode.value =="")
						{
						alert("请先填写验证码！");
						document.myform.Verifycode.focus();
						return false;
					}
					document.myform.Send_bt.disabled=true;
					$.ajax({type:"post",url:"/Plus/Ajax_SMS.asp",data:"Action=SendSMS&UserName="+ escape("<%=UserName%>") +"&N=1<%If KS.S("GetPassType")="2" Then KS.Echo "&M=1&ME=1"%>&Flag=GetPassword&V="+ document.myform.Verifycode.value +"&VC=1&anticache=" + Math.floor(Math.random()*1000),cache:false,dataType:"html",success:function(d){
					var s=unescape(d);
					ajaxchk=s.split('|')[0];
					ajaxstr=s.split('|')[1];
					if (ajaxstr!=null){
						if (ajaxchk=='ok'){alert(ajaxstr);}
						else{alert(ajaxstr);document.myform.Send_bt.disabled=false;}
					}
				} });
				}
				</script>
                  <br>
					  <table width="96%"  border="0" align="center" cellpadding="0" cellspacing="1" class="border">
					 	<form name="myform" method="post" action="?Step=3" onSubmit="return CheckForm();">
                            <input type="hidden" value="<%=UserName%>" name="UserName">
                            <tr class="title">
                                <td height="30" colspan=2 align="center" style="color:red; font-weight:bold">取回<%If KS.S("GetPassType")="2" Then KS.Echo "安全"%>密码<%If KS.S("GetPassType")<>"2" Then KS.Echo "第二步"%> 填写验证信息</td>
                            </tr>
                            <tr>
                                <td height="10" colspan=2 align="center"></td>
                            </tr>
                            <tr class="tdbg">
                              <td height="40" colspan="2" align="center" style="color:blue"><strong>
                              <input type="radio" name="GetPassType" id="GetPassType" value="1"<%If KS.S("GetPassType")<>"2" Then KS.Echo " checked=""checked""" Else KS.Echo " disabled=""disabled"""%> />找回登录密码 &nbsp; 
                              <input type="radio" name="GetPassType" id="GetPassType" value="2"<%If KS.S("GetPassType")="2" Then KS.Echo " checked=""checked""" Else KS.Echo " disabled=""disabled"""%> />找回安全密码</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                            </tr>
                            <tr class="tdbg">
                              <td width="40%" height="40" align="right"><strong> 用户名：</strong></td>
                              <td width="60%"><font color="red"><%=UserName%></font></td>
                            </tr>
                        	<%If Not KS.IsNul(RS("Question")) Then%>
                            <tr class="tdbg">
                              <td width="40%" height="40" align="right"><strong> 密码问题：</strong></td>
                              <td width="60%"><%=RS("Question")%></td>
                            </tr>
                            <tr class="tdbg">
                              <td width="40%" height="40" align="right"><strong> 您的答案：</strong></td>
                              <td width="60%"><input name="Answer" type="text" id="Answer" size="25" class="textbox" value="<%=Session("GetPassAnswer")%>" autocomplete="off" /></td>
                            </tr>
                            <%End If%>
                            <%If Not KS.IsNul(RS("Mobile")) Then%>
                            <tr class="tdbg">
                              <td width="40%" height="40" align="right"><strong> 短信接收手机号：</strong></td>
                              <td width="60%"><%=Left(RS("Mobile"),3) & "*****" & Right(RS("Mobile"),3)%></td>
                            </tr>
                            <tr class="tdbg">
                            <td width="40%" height="40" align="right"><strong> 手机验证码：</strong></td>
                            <td><input class="textbox" style="width:100px;" type="text" name="MobileVerifyCode" id="MobileVerifyCode" size="30" maxlength="6" onKeyUp="this.value=this.value.replace(/\D/g,'')"  onafterpaste="this.value=this.value.replace(/\D/g,'')" value="<%=Session("GetPassMobileCode")%>" />&nbsp; <input class="button" name="Send_bt" id="Send_bt" type="button" <%If KS.S("GetPassType")="2" Then KS.Echo "value=""获取短信验证码(" & KS.GetN(SMS_Price,2) & "元/条)"" title=""从您账户余额中扣取" & KS.GetN(SMS_Price,2) & "元/条""" Else KS.Echo "value="" 免费获取手机短信验证码 """%> onclick="SendSMS()" /></td>
                           </tr>
                           <%End If%>
                        <tr class="tdbg">
                              <td width="40%" height="40" align="right"><strong> 验证码：</strong></td>
                              <td width="60%"><input name="Verifycode" onfocus="this.value='';getCode()" type="text" id="Verifycode" size="8" class="textbox" />
							  <span id="showVerify"><font color="red">点击输入框显示验证码</font></span>
							  </td>
                            </tr>
                            <tr class="tdbg">
                              <td colspan=2 height="52" align="center"><%
							  If KS.IsNul(RS("Question")) And KS.IsNul(RS("Mobile")) Then
							  	KS.Echo "请联系客服人员找回密码"
							  Else
							  %><input class="button" name="Submit2" type="submit" value=" 下一步 " />
                              <%End If%>
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td>
                            </tr>
							</form>
                        </table>
						
                    
		  <%   End IF
		  ElseIF Step=3 Then
		  	 GetPassType = KS.F("GetPassType")
			 Answer = Trim(Left(KS.F("Answer"),30))
             Verifycode = Trim(KS.F("Verifycode"))
			 MobileVerifyCode = Trim(KS.F("MobileVerifyCode"))
			 UserName = Left(Trim(KS.CheckXSS(KS.R(KS.F("UserName")))),30)

			IF Trim(Verifycode)<>Trim(Session("Verifycode")) then 
		   		Response.Write("<script>alert('验证码有误，请重新输入！');history.back();</script>")
		    	Response.End
			End IF
			
			Dim RSC:Set RSC=Conn.Execute("Select Top 1 Question,Answer,Mobile,RndPassWord,CheckNum From KS_User Where UserName='" & UserName & "'")
			IF RSC.EOF AND RSC.Bof Then
			  	 Response.Write("<script>alert('抱歉！不存在该用户！');history.back();</script>")
				 Set RSC = Nothing
				 Response.End
			Else
				If Not KS.IsNul(RSC("Question")) Then
					If Md5(Answer, 16) <> RSC("Answer") Then
						Response.Write("<script>alert('抱歉！问题的答案不正确！');history.back();</script>")
						Set RSC = Nothing
						Response.End
					End If
				End If
				Session("GetPassAnswer") = Answer
				If Not KS.IsNul(RSC("Mobile")) Then
					If RSC("CheckNum") <> MobileVerifyCode Then
						Response.Write("<script>alert('抱歉！手机验证码不正确！');history.back();</script>")
						Set RSC = Nothing
						Response.End
					End If
				End If
				Session("GetPassMobileCode") = MobileVerifyCode
			 %>			 
			 <script language = "JavaScript">
				function CheckForm()
				{
				if (document.myform.PassWord.value==""||document.myform.PassWord.value.length<6)
				  {
					alert("请输入6位以上的新<%If KS.S("GetPassType")="2" Then KS.Echo "安全"%>密码！");
					document.myform.PassWord.focus();
					return false;
				  }
				if (document.myform.RePassWord.value=="")
				  {
					alert("请输入确认<%If KS.S("GetPassType")="2" Then KS.Echo "安全"%>密码！");
					document.myform.RePassWord.focus();
					return false;
				  }
				if (document.myform.PassWord.value!=document.myform.RePassWord.value)
				  {
					alert("两次输入的密码不一致！");
					document.myform.PassWord.focus();
					return false;
				  }
	              return true;
				  }
				</script>
				<br>
                   <table width="96%"  border="0" align="center" cellpadding="0" cellspacing="1" class="border">
                    <form name="myform" method="post" action="?Step=4" onsubmit="return CheckForm();">
                        <input type="hidden" value="<%=Answer%>" name="answer">
                        <input type="hidden" value="<%=MobileVerifyCode%>" name="MobileVerifyCode">
                        <input type="hidden" value="<%=UserName%>" name="UserName">
                        <input type="hidden" value="<%=GetPassType%>" name="GetPassType">
                        <tr class="title">
                            <td height="30" colspan=2 align="center" style="color:red; font-weight:bold">取回<%If KS.S("GetPassType")="2" Then KS.Echo "安全"%>密码第三步 设置新<%If KS.S("GetPassType")="2" Then KS.Echo "安全"%>密码 </td>
                        </tr>
                        <tr>
                            <td height="10" colspan=2 align="center"></td>
                        </tr>
                        <tr class="tdbg">
                          <td width="40%" height="40" align="right"> <strong>用户名：</strong></td>
                          <td width="60%"><font color="red"><%=UserName%></font></td>
                        </tr>
                        <tr class="tdbg">
                          <td width="40%" height="40" align="right"> <strong>新<%If KS.S("GetPassType")="2" Then KS.Echo "安全"%>密码：</strong></td>
                          <td width="60%"><input name="PassWord" type="password" id="PassWord" size="20" class="textbox" /></td>
                        </tr>
                        <tr class="tdbg">
                          <td width="40%" height="40" align="right"> <strong>确认<%If KS.S("GetPassType")="2" Then KS.Echo "安全"%>密码：</strong></td>
                          <td width="60%"><input name="RePassWord" type="password" id="RePassWord" size="20" class="textbox" /></td>
                        </tr>
                        <tr class="tdbg">
                          <td height="52" align="center" colspan=2><input  class="button" name="Submit22" type="submit" value=" 完 成 " />
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td>
                        </tr>
                    </form>
                   </table>
					
			<% End IF
		  ElseIF Step=4 Then
		     If KS.CheckOuterUrl=True Or Trim(Request.ServerVariables("HTTP_REFERER"))="" Then
				Response.Write "<script>alert('非法操作！');history.back();</script>"
				Response.end
			 End If
			 If Instr(lcase(Request.ServerVariables("HTTP_REFERER")),"step=3")<=0 Then
				Response.Write "<script>alert('非法操作1！');history.back();</script>"
				Response.end
			 End If
			 GetPassType = KS.F("GetPassType")
			 Answer = Trim(Left(KS.F("Answer"),30))
			 MobileVerifyCode = Trim(KS.F("MobileVerifyCode"))
			 UserName = Left(Trim(KS.CheckXSS(KS.R(KS.DelSql(Request.Form("UserName"))))),30)

		  	 Dim PassWord:PassWord=Left(Trim(KS.CheckXSS(KS.R(KS.DelSql(Request.Form("PassWord"))))),30)
			 Dim RePassWord:RePassWord=Left(Trim(KS.CheckXSS(KS.R(KS.DelSql(Request.Form("RePassWord"))))),30)
			 If UserName="" Then
				 Response.Write("<script>alert('操作非法!');history.back();</script>")
				 Response.End
			 End If
			 If PassWord = "" Then
				 Response.Write("<script>alert('请先输入密码!');history.back();</script>")
				 Response.End
			 ElseIF RePassWord="" Then
				 Response.Write("<script>alert('请先输入确认密码');history.back();</script>")
				 Response.End
			 ElseIF PassWord<>RePassWord Then
				 Response.Write("<script>alert('两次输入的密码不一致');history.back();</script>")
				 Response.End
			 End If

             Set RS=Server.CreateObject("Adodb.RecordSet")
			 RS.Open "Select Top 1 PassWord,Question,Answer,Mobile,RndPassWord,CheckNum,KS_SecurityCode From KS_User Where UserName='" & UserName & "'",Conn,1,3
			 If Not RS.Eof Then
			  	If Not KS.IsNul(RS("Question")) Then
					If Md5(Answer, 16) <> RS("Answer") Then
						Response.Write("<script>alert('操作非法！');history.back();</script>")
						RS.Close:Set RS=Nothing
						Response.End
					End If
				End If
				If Not KS.IsNul(RS("Mobile")) Then
					If RS("CheckNum") <> MobileVerifyCode Then
						Response.Write("<script>alert('操作非法！');history.back();</script>")
						RS.Close:Set RS=Nothing
						Response.End
					End If
				End If
				 
				 If GetPassType = "2" Then
				     RS("KS_SecurityCode") = MD5(PassWord, 16)
				 Else
					 RS("PassWord") = MD5(PassWord, 16)
				 End If
				 RS("CheckNum") = KS.MakeRandom(6)
				 RS.Update
				 RS.Close:Set RS=Nothing
				 Session("GetPassAnswer") = Null
				 Session("GetPassMobileCode") = Null
			  Else
			  	 RS.Close:Set RS=Nothing
				 Response.Write("<script>alert('操作失败，请重新找回密码!');history.back();</script>")
				 Response.End
			  End If
			 '-----------------------------------------------------------------
				'系统整合
				'-----------------------------------------------------------------
				Dim API_KS,API_SaveCookie,SysKey
				If API_Enable Then
					Set API_KS = New API_Conformity
					API_KS.NodeValue "action","update",0,False
					API_KS.NodeValue "username",KS.S("UserName"),1,False
					Md5OLD = 1
					SysKey = Md5(API_KS.XmlNode("username") & API_ConformKey,16)
					Md5OLD = 0
					API_KS.NodeValue "syskey",SysKey,0,False
					API_KS.NodeValue "password",PassWord,1,False
					API_KS.SendHttpData
					If API_KS.Status = "1" Then
						Response.Write "<script>alert('" &  API_KS.Message  & "');</script>"
						Exit Sub
					End If
					Set API_KS = Nothing
				End If
				'-----------------------------------------------------------------
			 
		  %>
		  <br>
              <table width="96%"  border="0" align="center" cellpadding="0" cellspacing="1" class="border">
                  <tr class="title">
                      <td height="30" align="center" style="color:red; font-weight:bold">取回<%If KS.S("GetPassType")="2" Then KS.Echo "安全"%>密码成功</td>
                  </tr>
                   <tr class="tdbg">
                      <td height="150" align="center"><img src="Images/regok.jpg" width="48" height="48" align="absmiddle" /> &nbsp; 恭喜你，<%If KS.S("GetPassType")="2" Then KS.Echo "安全"%>密码取回成功！您的新<%If KS.S("GetPassType")="2" Then KS.Echo "安全"%>密码是：<span style="color:green;font-weight:bold; font-size:20px;"><%=PassWord%></span><%If KS.S("GetPassType")="2" Then%> &nbsp;请牢记！<%Else%> &nbsp;请用新密码登录。
                        <p>&nbsp;</p>
                     <p><a href="/user/login/" style="color:blue; font-size:14px; font-weight:bold">我要登录&gt;&gt;</a></p><%End If%></td>
                </tr>
                </table>                       
		  <%
           Else
		   %>
		   <script language = "JavaScript">
				function CheckForm()
				{
				if (document.myform.UserName.value=="")
				  {
					alert("请输入用户名！");
					document.myform.UserName.focus();
					return false;
				  }
	              return true;
				  }
				</script>
			 <br><br>
	   <form name="myform" method="post" action="?Step=2" onSubmit="return CheckForm();">
         <table width="96%"  border="0" align="center" cellpadding="0" cellspacing="1" class="border">
              <tr class="title">
                <td height="30" align="center" colspan="2" style="color:red; font-weight:bold">取回<%If KS.S("GetPassType")="2" Then KS.Echo "安全"%>密码第一步 &nbsp;输入注册时填写的用户名 </td>
              </tr>
              <TR class="tdbg">
                    <TD width="40%" height=10 align="right"></TD>
                    <TD width="60%" height=10></TD>
             </TR>
              <TR class="tdbg">
                <TD width="40%" height=40 align="right"> <strong>您的用户名：</strong></TD>
                <TD width="60%" height=40><input name="UserName" type="text" id="UserName" class="textbox" size="20"></TD>
              </TR>
              <TR class="tdbg">
                <TD  colspan="2" height=52 align="center"> 
                <input  class="button" name="Submit" type="submit" value=" 下一步 ">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </TD>
              </TR>
   		</TABLE>
	  </form>
		<%
		 Session("GetPassAnswer") = Null
		 Session("GetPassMobileCode") = Null
		 End IF
		 
  End Sub
End Class
%> 
