Exemple #1
0
        private void ModifyAdmin()
        {
            AdministratorInfo administratorByAdminId = Administrators.GetAdministratorByAdminId(BasePage.RequestInt32("AdminId"));

            if (string.IsNullOrEmpty(this.TxtPassword.Text.Trim()))
            {
                administratorByAdminId.AdminPassword = this.ViewState["Password"].ToString();
            }
            else
            {
                administratorByAdminId.AdminPassword = StringHelper.MD5(this.TxtPassword.Text);
            }
            if ((!administratorByAdminId.EnableModifyPassword && (administratorByAdminId.AdminPassword != this.ViewState["Password"].ToString())) && !PEContext.Current.Admin.IsSuperAdmin)
            {
                AdminPage.WriteErrMsg("没有修改密码的权限!");
            }
            if (administratorByAdminId.AdminPassword != this.ViewState["Password"].ToString())
            {
                administratorByAdminId.LastModifyPasswordTime = new DateTime?(DateTime.Now);
            }
            if (string.Compare(this.TxtUserName.Text.Trim(), this.ViewState["UserName"].ToString(), StringComparison.OrdinalIgnoreCase) != 0)
            {
                UserInfo usersByUserName = Users.GetUsersByUserName(this.TxtUserName.Text.Trim());
                if (usersByUserName.IsNull)
                {
                    AdminPage.WriteErrMsg("此前台用户名不存在!");
                }
                if (!Administrators.GetAdministratorByUserName(usersByUserName.UserName).IsNull)
                {
                    AdminPage.WriteErrMsg("此前台用户已经被添加为管理员了!");
                }
            }
            administratorByAdminId.UserName             = this.TxtUserName.Text.Trim();
            administratorByAdminId.IsLock               = this.ChkIsLock.Checked;
            administratorByAdminId.EnableModifyPassword = this.ChkEnableModifyPassword.Checked;
            administratorByAdminId.EnableMultiLogOn     = this.ChkEnableMultiLogin.Checked;
            if (Administrators.Update(administratorByAdminId))
            {
                if (this.RadPurview1.Checked)
                {
                    RoleMembers.AddMemberToRoles(administratorByAdminId.AdminId, "0");
                }
                else
                {
                    RoleMembers.AddMemberToRoles(administratorByAdminId.AdminId, this.HdnBelongToRole.Value);
                }
                AdminPage.WriteSuccessMsg("修改管理员成功!", "AdministratorManage.aspx");
            }
            else
            {
                AdminPage.WriteErrMsg("修改管理员失败!");
            }
        }
Exemple #2
0
        private void AddAdmin()
        {
            UserInfo usersByUserName = Users.GetUsersByUserName(this.TxtUserName.Text.Trim());

            if (usersByUserName.IsNull)
            {
                AdminPage.WriteErrMsg("此前台用户名不存在!");
            }
            AdministratorInfo adminInfo = new AdministratorInfo();

            adminInfo.AdminName            = this.TxtAdminName.Text.Trim();
            adminInfo.UserName             = this.TxtUserName.Text.Trim();
            adminInfo.IsLock               = this.ChkIsLock.Checked;
            adminInfo.EnableModifyPassword = this.ChkEnableModifyPassword.Checked;
            if (string.IsNullOrEmpty(this.TxtPassword.Text.Trim()))
            {
                AdminPage.WriteErrMsg("管理员密码不能为空");
            }
            else
            {
                adminInfo.AdminPassword = StringHelper.MD5(this.TxtPassword.Text);
            }
            adminInfo.EnableMultiLogOn = this.ChkEnableMultiLogin.Checked;
            if (Administrators.IsExist(adminInfo.AdminName))
            {
                AdminPage.WriteErrMsg("已经存在同样的管理员名!");
            }
            if (!Administrators.GetAdministratorByUserName(usersByUserName.UserName).IsNull)
            {
                AdminPage.WriteErrMsg("此前台用户已经被添加为管理员了!");
            }
            if (Administrators.Add(adminInfo))
            {
                if (this.RadPurview1.Checked)
                {
                    RoleMembers.AddMemberToRoles(adminInfo.AdminId, "0");
                }
                else
                {
                    RoleMembers.AddMemberToRoles(adminInfo.AdminId, this.HdnBelongToRole.Value);
                }
                AdminPage.WriteSuccessMsg("添加管理员成功!", "AdministratorManage.aspx");
            }
            else
            {
                AdminPage.WriteErrMsg("添加管理员失败!");
            }
        }