using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace RedGlovePermission.Web.Admin
{
    public partial class ChangePassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
                btn_save.Attributes.Add("onclick","return checksubmit()");
        }

        protected void btn_save_Click(object sender, EventArgs e)
        {
            if (OldPassword.Text != "" && NewPassword.Text != "" && RePassword.Text != "" && (NewPassword.Text == RePassword.Text))
            {
                RedGlovePermission.BLL.Users bll = new RedGlovePermission.BLL.Users();
                int id = SessionBox.GetUserSession().LoginId;
                if (bll.VerifyPassword(id,RedGlovePermission.Lib.SecurityEncryption.MD5(OldPassword.Text.Trim(), 32)))
                {
                    if (bll.ChangePassword(id, RedGlovePermission.Lib.SecurityEncryption.MD5(RePassword.Text.Trim(), 32)))
                    {
                        ScriptManager.RegisterClientScriptBlock(CustomPanel1, this.GetType(), "", "alert('更新成功!');", true);
                    }
                    else
                    {
                        ScriptManager.RegisterClientScriptBlock(CustomPanel1, this.GetType(), "", "alert('更新操作失败!');", true);
                    }
                }
                else
                {
                    ScriptManager.RegisterClientScriptBlock(CustomPanel1, this.GetType(), "", "alert('原密码错误!');", true);
                }
            }
        }
    }
}
