zoukankan      html  css  js  c++  java
  • 视频教程:小型登陆系统(五)

    管理员修改用户

     

      查看更多精彩图片查看更多精彩图片



    这里是修改用户信息类似于前面用户修改,这里多了个修改核准IsApproved用于设定是否允许登陆。

    如果是管理员不能被禁止登陆。

     
     
     

    管理员修改用户代码

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;

    namespace RegeditOfAdoDotnet
    {
        public partial class AdminModifyUser : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                Response.Buffer = true;
                Response.ExpiresAbsolute = System.DateTime.Now.AddSeconds(-1);
                Response.Expires = 0;
                Response.CacheControl = "no-cache";
                Response.AddHeader("Pragma", "No-Cache");
                if (!IsPostBack)
                {
                    string userName = Request.QueryString["user"].ToString();
                    lblUserName.Text = userName;
                    MembershipUser user = Membership.GetUser(lblUserName.Text);//获取当前用户
                    if (user.IsApproved)
                    {
                        ckbLicense.Checked = true;
                    }
                    else
                    {
                        ckbLicense.Checked = false;
                    }
                }
            }

            /// <summary>
            /// 确定
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            protected void btnConfirm_Click(object sender, EventArgs e)
            {
                if (Page.IsValid)
                {
                    try
                    {
                        MembershipUser user = Membership.GetUser(lblUserName.Text);//获取当前用户
                        string oldPassWord = user.GetPassword();//获取当前用户密码
                        if (!string.IsNullOrEmpty(txtPassWord.Text.ToString()))
                        {
                            string newPassWord = txtPassWord.Text.ToString();//获取新密码
                            user.ChangePassword(oldPassWord, newPassWord);//修改密码
                        }
                        if (!string.IsNullOrEmpty(txtEmail.Text.ToString()))
                        {
                            user.Email = txtEmail.Text.ToString();//获取新邮箱
                        }
                        //判断用户是否是Admin
                        if (Roles.IsUserInRole(lblUserName.Text, "Admin"))
                        {
                            ckbLicense.Checked = true;
                            ClientScript.RegisterStartupScript(this.GetType(), "myscript", "<script>alert('" + lblUserName.Text.ToString() + "是管理员,不能被禁止登陆!');</script>");
                        }
                        else
                        {
                            if (!ckbLicense.Checked)
                            {
                                user.IsApproved = false;
                            }
                            else
                            {
                                user.IsApproved = true;
                            }
                        }
                        Membership.UpdateUser(user);//更新当前用户注册信息
                    }
                    catch (Exception exp)
                    {
                        Response.Write(exp.Message); //输出错误信息
                    }
                    finally
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "myscript", "<script>alert('修改成功!');</script>");
                    }
                }
            }


            /// <summary>
            /// 返回
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            protected void btnBack_Click(object sender, EventArgs e)
            {
                Response.Redirect("~/Admin/AdminInfo.aspx");
            }


            /// <summary>
            /// 添加用户
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            protected void btnAddUser_Click(object sender, EventArgs e)
            {
                Response.Redirect("~/Admin/AdminAddUser.aspx");
            }


            /// <summary>
            /// 退出
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            protected void btnExit_Click(object sender, EventArgs e)
            {
                Session.Clear();
                FormsAuthentication.SignOut();
                Response.Redirect("~/Goodby.aspx");
            }
        }
    }

  • 相关阅读:
    递归算法的时间复杂度分析
    MongoDB入门简单介绍
    关于用例须要多少文档以及业务用例等等
    Java连接redis的使用演示样例
    C++ String 转 char*
    MySQL和PostgreSQL 导入数据对照
    SSL连接建立过程分析(1)
    XTU OJ 1210 Happy Number (暴力+打表)
    Codeforces Round #258 (Div. 2)[ABCD]
    CreateFont具体解释
  • 原文地址:https://www.cnblogs.com/Gemgin/p/3136378.html
Copyright © 2011-2022 走看看