Exemplo n.º 1
0
        public override void Submit_OnClick(object sender, EventArgs e)
        {
            var isChanged = false;

            try
            {
                var allRoles = EPredefinedRoleUtils.GetAllPredefinedRoleName();
                foreach (var roleName in allRoles)
                {
                    DataProvider.AdministratorsInRolesDao.RemoveUserFromRole(_userName, roleName);
                }
                DataProvider.AdministratorsInRolesDao.AddUserToRole(_userName, DdlPredefinedRole.SelectedValue);

                DataProvider.AdministratorDao.UpdateSiteIdCollection(_userName,
                                                                     EPredefinedRoleUtils.Equals(EPredefinedRole.SystemAdministrator, DdlPredefinedRole.SelectedValue)
                        ? ControlUtils.SelectedItemsValueToStringCollection(CblSiteId.Items)
                        : string.Empty);

                AuthRequest.AddAdminLog("设置管理员权限", $"管理员:{_userName}");

                SuccessMessage("权限设置成功!");
                isChanged = true;
            }
            catch (Exception ex)
            {
                FailMessage(ex, "权限设置失败!");
            }

            if (isChanged)
            {
                var redirectUrl = PageAdministrator.GetRedirectUrl();
                LayerUtils.CloseAndRedirect(Page, redirectUrl);
            }
        }
Exemplo n.º 2
0
        public void Page_Load(object sender, EventArgs e)
        {
            if (IsForbidden)
            {
                return;
            }

            _departmentId = AuthRequest.GetQueryInt("departmentID");
            _areaId       = AuthRequest.GetQueryInt("areaID");
            _userName     = AuthRequest.GetQueryString("userName");

            if (Page.IsPostBack)
            {
                return;
            }

            VerifySystemPermissions(ConfigManager.SettingsPermissions.Admin);

            LtlPageTitle.Text = string.IsNullOrEmpty(_userName) ? "添加管理员" : "编辑管理员";

            DdlDepartmentId.Items.Add(new ListItem("<无所属部门>", "0"));
            var departmentIdList = DepartmentManager.GetDepartmentIdList();
            var count            = departmentIdList.Count;

            _isLastNodeArrayOfDepartment = new bool[count];
            foreach (var theDepartmentId in departmentIdList)
            {
                var departmentInfo = DepartmentManager.GetDepartmentInfo(theDepartmentId);
                var listitem       = new ListItem(GetDepartment(departmentInfo.DepartmentName, departmentInfo.ParentsCount, departmentInfo.IsLastNode), theDepartmentId.ToString());
                if (_departmentId == theDepartmentId)
                {
                    listitem.Selected = true;
                }
                DdlDepartmentId.Items.Add(listitem);
            }

            DdlAreaId.Items.Add(new ListItem("<无所在区域>", "0"));
            var areaIdList = AreaManager.GetAreaIdList();

            count = areaIdList.Count;
            _isLastNodeArrayOfArea = new bool[count];
            foreach (var theAreaId in areaIdList)
            {
                var areaInfo = AreaManager.GetAreaInfo(theAreaId);
                var listitem = new ListItem(GetArea(areaInfo.AreaName, areaInfo.ParentsCount, areaInfo.IsLastNode), theAreaId.ToString());
                if (_areaId == theAreaId)
                {
                    listitem.Selected = true;
                }
                DdlAreaId.Items.Add(listitem);
            }

            if (!string.IsNullOrEmpty(_userName))
            {
                var adminInfo = DataProvider.AdministratorDao.GetByUserName(_userName);
                if (adminInfo != null)
                {
                    ControlUtils.SelectSingleItem(DdlDepartmentId, adminInfo.DepartmentId.ToString());
                    TbUserName.Text    = adminInfo.UserName;
                    TbUserName.Enabled = false;
                    TbDisplayName.Text = adminInfo.DisplayName;
                    PhPassword.Visible = false;
                    ControlUtils.SelectSingleItem(DdlAreaId, adminInfo.AreaId.ToString());
                    TbEmail.Text  = adminInfo.Email;
                    TbMobile.Text = adminInfo.Mobile;
                }
            }

            BtnReturn.Attributes.Add("onclick", $"location.href='{PageAdministrator.GetRedirectUrl()}';return false;");
        }
Exemplo n.º 3
0
        public override void Submit_OnClick(object sender, EventArgs e)
        {
            if (!Page.IsPostBack || !Page.IsValid)
            {
                return;
            }

            if (string.IsNullOrEmpty(_userName))
            {
                var adminInfo = new AdministratorInfo
                {
                    UserName        = TbUserName.Text.Trim(),
                    Password        = TbPassword.Text,
                    CreatorUserName = AuthRequest.AdminName,
                    DisplayName     = TbDisplayName.Text,
                    Email           = TbEmail.Text,
                    Mobile          = TbMobile.Text,
                    DepartmentId    = TranslateUtils.ToInt(DdlDepartmentId.SelectedValue),
                    AreaId          = TranslateUtils.ToInt(DdlAreaId.SelectedValue)
                };

                if (!string.IsNullOrEmpty(DataProvider.AdministratorDao.GetUserNameByEmail(TbEmail.Text)))
                {
                    FailMessage("管理员添加失败,邮箱地址已存在");
                    return;
                }

                if (!string.IsNullOrEmpty(DataProvider.AdministratorDao.GetUserNameByMobile(TbMobile.Text)))
                {
                    FailMessage("管理员添加失败,手机号码已存在");
                    return;
                }

                string errorMessage;
                if (!AdminManager.CreateAdministrator(adminInfo, out errorMessage))
                {
                    FailMessage($"管理员添加失败:{errorMessage}");
                    return;
                }

                AuthRequest.AddAdminLog("添加管理员", $"管理员:{TbUserName.Text.Trim()}");
                SuccessMessage("管理员添加成功!");
                AddWaitAndRedirectScript(PageAdministrator.GetRedirectUrl());
            }
            else
            {
                var adminInfo = DataProvider.AdministratorDao.GetByUserName(_userName);

                if (adminInfo.Email != TbEmail.Text && !string.IsNullOrEmpty(DataProvider.AdministratorDao.GetUserNameByEmail(TbEmail.Text)))
                {
                    FailMessage("管理员设置失败,邮箱地址已存在");
                    return;
                }

                if (adminInfo.Mobile != TbMobile.Text && !string.IsNullOrEmpty(DataProvider.AdministratorDao.GetUserNameByMobile(adminInfo.Mobile)))
                {
                    FailMessage("管理员设置失败,手机号码已存在");
                    return;
                }

                adminInfo.DisplayName  = TbDisplayName.Text;
                adminInfo.Email        = TbEmail.Text;
                adminInfo.Mobile       = TbMobile.Text;
                adminInfo.DepartmentId = TranslateUtils.ToInt(DdlDepartmentId.SelectedValue);
                adminInfo.AreaId       = TranslateUtils.ToInt(DdlAreaId.SelectedValue);

                DataProvider.AdministratorDao.Update(adminInfo);

                AuthRequest.AddAdminLog("修改管理员属性", $"管理员:{TbUserName.Text.Trim()}");
                SuccessMessage("管理员设置成功!");
                AddWaitAndRedirectScript(PageAdministrator.GetRedirectUrl());
            }
        }