<%@ Control Language="C#" %>
<%@ Import Namespace="Kesion.Cache" %>
<%@ Import Namespace="Kesion.Publics" %>
<%@ Import Namespace="Kesion.BLL" %>
<%@ Import Namespace="Kesion.Config" %>
<%@ Import Namespace="Kesion.Components" %>
<%@ Import Namespace="Kesion.HtmlTags" %>
<%@ Import Namespace="Kesion.UCenter" %>
<%@ Import Namespace="Kesion.XML" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Xml" %>
<script runat="server" type="text/C#">

    dynamic __user = HttpContext.Current.Items["user"];                //初始化用户信息
    bool isLoadPage = true;  //定义页面是否加载

    protected void Page_Load(object sender, EventArgs e)
    {
        if (KSCMS.S("action") == "dosave")
        {
            isLoadPage = false;
            DoSave();
            return;
        }
    }

    private void DoSave()
    {
        #region 保存修改密码

        string ValidateCode = KSCMS.S("VerifyCode");
		
		if (!Utils.IsValidVerifyCode(ValidateCode))
         {
            Msg.Alert("验证码错误！");
            return;
         }
		
       
        string salt = __user.Salt;
        string password = string.Empty;
        if (!string.IsNullOrEmpty(salt))
        {
            password = Utils.MD5(KSCMS.S("OldPass")+salt, 32);
        }else
        {
            password =Utils.MD5(KSCMS.S("OldPass"), 16);
        }

        if (__user.IsApi != 1 && DataFactoryUser.Exists("KS_User", "userid=" + __user.UserID + " and password='" + password + "'") == false)
        {
            Msg.Alert("输入的旧密码不正确！");
            return;
        }
        else
        {
            if (KSCMS.S("OldPass").Trim() == KSCMS.S("PassWord").Trim())
            {
                Msg.Alert("新密码不能和旧密码一样！");
                return;
            }
            password = KSCMS.S("PassWord");
            string repass = KSCMS.S("RePassWord");
            if (password != repass)
            {
                Msg.Alert("两次输入的密码不一致！");
                return;
            }
            else
            {

                #region 整合Ucenter
                if (MyCache.GetShopCommonConfig(84) == "1")
                {
                    new ucenter().UpataPass(__user.UserName, string.Empty, KSCMS.S("PassWord"), string.Empty);
                }
                #endregion

                UserManage.UpdatePass(__user.UserID, password);
                CheckUserLogin.UserLoginOut(); //退出
                Msg.AlertDoFun("恭喜，密码修改成功,请重新登录！", "top.location.href='" + Kesion.HtmlTags.BasicField.GetRewriteUrl("userlogin") + "';");
            }
        }
        #endregion
    }
</script>
<%
    if (!isLoadPage) return;
%>
<script>
    function checkform() {
        if ($("#OldPass").val() == '') {
            KesionJS.Alert('请输入您的旧密码！', "$('#OldPass').focus()");
            return false;
        }
        if ($("#PassWord").val() == '') {
            KesionJS.Alert('请输入您的新密码！', "$('#PassWord').focus()");
            return false;
        }
        if ($("#PassWord").val().length < 6) {
            KesionJS.Alert('新密码长度不能少于六位！', "$('#PassWord').focus()");
            return false;
       }
       if ($("#PassWord").val() == $("#OldPass").val()) {
            KesionJS.Alert('新密码和旧密码不能设置一样！', "$('#PassWord').focus()");
            return false;
        }

        if ($("#RePassWord").val() == '') {
            KesionJS.Alert('请输入您的确认密码！', "$('#RePassWord').focus()");
            return false;
        }
        if ($("#PassWord").val() != $("#RePassWord").val()) {
            KesionJS.Alert('两次输入的密码不一致，请重输！', "$('#PassWord').focus()");
            return false;
        }
        if ($("#VerifyCode").val() == '') {
            KesionJS.Alert('请输入验证码！', "$('#VerifyCode').focus()");
            return false;
        }
    }
</script>

	<div class="t_tybox nomar">
        <div class="r_title ty_title pd0">
            <h4 class="ep-pl20">修改密码</h4>
            <div class="tabs">	
              <ul class="clearfix">
                   <%if (__user.GroupID==4) { %>
                    <li><a href="<%=BasicField.GetUserUrl("teacher/teacher") %>">我的资料</a></li>
                    <%}
                      else if (__user.GroupID == 3){ %>
                    <li><a href="<%=BasicField.GetUserUrl("School/UserEnterprise") %>">基本资料</a></li>
                    <%}else { %>
                     <li><a href="<%=BasicField.GetUserUrl("basic/editinfo") %>">修改我的资料</a></li>
                     <%} %>
                    <li ><a href="<%=BasicField.GetUserUrl("basic/userface") %>">上传头像</a></li>
                     <li class='puton'><a href="<%=BasicField.GetUserUrl("basic/editpass") %>">修改密码</a></li>
                    <% if (__user.GroupID==3) {%>
                    <li ><a href="<%=BasicField.GetUserUrl("school/userepintroduce") %>">机构介绍</a></li>
                    <li ><a href="<%=BasicField.GetUserUrl("school/userepbank") %>">银行账户</a></li>
                    <% } 
                    %>
                   
                    <li ><a href="<%=BasicField.GetUserUrl("basic/editquestion") %>">修改安全问题</a></li>
                    <li><a href="<%=BasicField.GetUserUrl("basic/mobilebind") %>">第三方绑定</a></li>
                    <li><a href="<%=BasicField.GetUserUrl("Shop/MyAddress") %>">收货人地址</a></li>
            
              </ul>
            </div>
        </div>

      <iframe src="about:blank" name="hidframe" style="display:none;width:0px;height:0px"></iframe>
      <form name="myform" action="{$GetCurrUrl}" method="post" id="myform" target="hidframe">
      <input type="hidden" name="action" value="dosave"/>
 		<table  cellspacing="1" cellpadding="3" class="border" width="100%" align="center" border="0">

                          <%if (__user.IsApi == 1)
                            { %>
                            <tr class="tdbg">
                            <td colspan="2" style="font-size:14px;color:green;height:80px; text-align:left;line-height:30px;padding:10px;">温馨提示：您是通过第三方网站账号登录本站的，您可以设置新密码，下次就可以直接使用用户名 <span style="color:Red"><%=__user.UserName %></span> 和以下设置的密码登录本站了。</td>
                          </tr>
                          <%}
                            else
                            { %>
                          <tr class="tdbg">
                            <td  class="lefttd w120">旧 密 码：</td>
                            <td style="text-align:left;"><input type="password" class="textbox" name="OldPass" id="OldPass" maxlength="50"> <span style="color: red">* </span><span class="tips">您的旧登录密码，必须正确填写。</span></td>
                          </tr>
                          <%} %>
                          <tr class="tdbg">
                            <td class="lefttd w120"> 新 密 码：</td>
                            <td style="text-align:left;"><input type="password" class="textbox" name="PassWord" id="PassWord" maxlength="50"> <span style="color: red">* </span><span class="tips">请输入您的新密码！</span>
                           </td>
                          </tr>
                          <tr class="tdbg w120">
                            <td class="lefttd">确认密码：</td>
                            <td style="text-align:left;"><input type="password" class="textbox" name="RePassWord" id="RePassWord" maxlength="50"> <span style="color: red">* </span><span class="tips">同上。</span>
                            </td>
                          </tr>
                          <tr class="tr-nobor">
                            <td class="lefttd">验 证 码：</td>
                            <td style="text-align:left;">
                                <input type="text" class="textbox" name="VerifyCode" id="VerifyCode" maxlength="50">
                              <span style="color: red">*  </span>
                                <img src="/plus/ValidateCode.aspx" onclick="this.src=this.src+'?'+Math.random()" style="vertical-align: middle;"/>

                            </td>
                          </tr>

       
            </table>

        <div class="cz_btn ">
            <div class="d-inline-block">
                <span><input type="submit" onclick="return(checkform());" ID="Button1" class="green-bt bt-w-auto button"  value="OK!确定修改" /></span>
                <span><input type="reset" class="grey-bt button" value=" 重 置 " /></span>
            </div>
        </div>
<div class="clear"></div>
         </form>

  </div>  