Пример #1
0
        protected void Page_Init(object sender, System.EventArgs e)
        {
            // locate group to delete
            _GroupId = AlwaysConvert.ToInt(Request.QueryString["GroupId"]);
            Group group = GroupDataSource.Load(_GroupId);

            if (group == null)
            {
                Response.Redirect("Default.aspx");
            }

            // groups managed by the application cannot be deleted
            if (group.IsReadOnly)
            {
                Response.Redirect("Default.aspx");
            }

            // ensure user has permission to edit this group
            IList <Group> managableGroups = SecurityUtility.GetManagableGroups();

            if (managableGroups.IndexOf(group) < 0)
            {
                Response.Redirect("Default.aspx");
            }

            Caption.Text         = string.Format(Caption.Text, group.Name);
            InstructionText.Text = string.Format(InstructionText.Text, group.Name);
            BindGroups(group);
        }
        /// <summary>
        /// Initializes the change groups dialog with current user group settings
        /// </summary>
        private void InitializeChangeGroupsDialog()
        {
            AvailableGroups.Items.Clear();
            SelectedGroups.Items.Clear();
            IList <Group>  managableGroups    = SecurityUtility.GetManagableGroups();
            IList <string> subscriptionGroups = new List <string>();

            foreach (Group group in managableGroups)
            {
                if (group.SubscriptionPlans != null && group.SubscriptionPlans.Count > 0)
                {
                    if (_User.IsInGroup(group.Id))
                    {
                        subscriptionGroups.Add(group.Name);
                        PHSubscriptionGroups.Controls.Add(new LiteralControl(string.Format("<option disabled='disabled'>{0}</option>", group.Name)));
                    }
                }
                else
                {
                    ListItem newItem       = new ListItem(group.Name, group.Id.ToString());
                    bool     groupSelected = _User.IsInGroup(group.Id);
                    if (groupSelected)
                    {
                        SelectedGroups.Items.Add(newItem);
                    }
                    else
                    {
                        AvailableGroups.Items.Add(newItem);
                    }
                }
            }
            phMyGroupsWarning.Visible   = (_UserId == AbleContext.Current.UserId);
            SubscriptionGroupLI.Visible = subscriptionGroups.Count > 0;
        }
Пример #3
0
 private void EditGroupDialog1_ItemUpdated(object sender, PersistentItemEventArgs e)
 {
     _ManagableGroups    = SecurityUtility.GetManagableGroups();
     GroupGrid.EditIndex = -1;
     GroupGrid.DataBind();
     AddPanel.Visible  = true;
     EditPanel.Visible = false;
     AddEditAjax.Update();
     GroupAjax.Update();
 }
Пример #4
0
 protected void Page_Init(object sender, EventArgs e)
 {
     AlphabetRepeater.DataSource = GetAlphabetDS();
     AlphabetRepeater.DataBind();
     AbleCommerce.Code.PageHelper.SetDefaultButton(SearchEmail, SearchButton.ClientID);
     SearchGroup.DataSource     = AbleContext.Current.Store.Groups;
     SearchGroup.DataTextField  = "Name";
     SearchGroup.DataValueField = "GroupId";
     SearchGroup.DataBind();
     AddGroup.DataSource = SecurityUtility.GetManagableGroups()
                           .Where(group => group.Name != Group.DefaultUserGroupName);
     AddGroup.DataBind();
     trAddGroup.Visible = AddGroup.Items.Count > 1;
     if (!Page.IsPostBack)
     {
         LoadLastSearch();
     }
 }
Пример #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            _GroupId = AlwaysConvert.ToInt(Request.QueryString["GroupId"]);
            Group group = GroupDataSource.Load(_GroupId);

            if (group == null)
            {
                Response.Redirect("Default.aspx");
            }

            // ensure user has permission to manage this group
            IList <Group> managableGroups = SecurityUtility.GetManagableGroups();

            if (managableGroups.IndexOf(group) < 0)
            {
                Response.Redirect("Default.aspx");
            }

            _IsReadonlyGroup = group.IsReadOnly;
            _Subscriptions   = group.SubscriptionPlans.Count;

            AlphabetRepeater.DataSource = GetAlphabetDS();
            AlphabetRepeater.DataBind();

            if (!Page.IsPostBack)
            {
                SearchGroup.DataSource     = AbleContext.Current.Store.Groups;
                SearchGroup.DataTextField  = "Name";
                SearchGroup.DataValueField = "GroupId";
                SearchGroup.DataBind();

                Caption.Text = string.Format(Caption.Text, group.Name);
                ListItem item = SearchGroup.Items.FindByValue(_GroupId.ToString());
                if (item != null)
                {
                    Session.Remove("ManageUserSearchCriteria");
                    SearchGroup.ClearSelection();
                    item.Selected = true;
                }
                LoadLastSearch();
            }
        }
        protected void ChangeGroupListOKButton_Click(object sender, System.EventArgs e)
        {
            // REMOVE ANY MANAGEABLE GROUPS ASSOCIATED WITH USER, EXCEPT THE SUBSCRIPTION GROUPS
            IList <Group> managableGroups = SecurityUtility.GetManagableGroups();

            for (int i = _User.UserGroups.Count - 1; i >= 0; i--)
            {
                if (managableGroups.IndexOf(_User.UserGroups[i].GroupId) > -1 &&
                    _User.UserGroups[i].Subscription == null)
                {
                    _User.UserGroups.DeleteAt(i);
                }
            }

            // LOOP SUBMITTED GROUPS AND ADD (VALID) SELECTED GROUPS
            int[] selectedGroups = AlwaysConvert.ToIntArray(Request.Form[HiddenSelectedGroups.UniqueID]);
            if (selectedGroups != null && selectedGroups.Length > 0)
            {
                foreach (int groupId in selectedGroups)
                {
                    int index = managableGroups.IndexOf(groupId);
                    if (index > -1)
                    {
                        _User.UserGroups.Add(new UserGroup(_User, managableGroups[index]));
                    }
                }
            }
            else
            {
                // ASSIGN TO DEFAULT USER GROUP (NO MATTER USER HAVE SOME SUBSCRIPTION GROUPS ALREADY ASSIGNED)
                _User.UserGroups.Add(new UserGroup(_User, GroupDataSource.LoadForName(Group.DefaultUserGroupName)));
            }

            // SAVE ANY CHANGES TO USER GROUPS
            _User.Save();
        }
Пример #7
0
 private void AddGroupDialog1_ItemAdded(object sender, PersistentItemEventArgs e)
 {
     _ManagableGroups = SecurityUtility.GetManagableGroups();
     GroupGrid.DataBind();
     GroupAjax.Update();
 }
Пример #8
0
 protected void Page_Init(object sender, EventArgs e)
 {
     AddGroupDialog1.ItemAdded    += new PersistentItemEventHandler(AddGroupDialog1_ItemAdded);
     EditGroupDialog1.ItemUpdated += new PersistentItemEventHandler(EditGroupDialog1_ItemUpdated);
     _ManagableGroups              = SecurityUtility.GetManagableGroups();
 }
Пример #9
0
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            // CHECK IF PAGE IS VALID
            if (Page.IsValid)
            {
                // MAKE SURE PASSWORD VALIDATES AGAINST POLICY
                if (ValidatePassword())
                {
                    // ATTEMPT TO CREATE THE USER
                    MembershipCreateStatus status;
                    User newUser = UserDataSource.CreateUser(AddEmail.Text, AddEmail.Text, AddPassword.Text, string.Empty, string.Empty, true, 0, out status);
                    if (status == MembershipCreateStatus.Success)
                    {
                        // FORCE PASSWORD EXPIRATION
                        newUser.Passwords[0].ForceExpiration = ForceExpiration.Checked;
                        newUser.Passwords[0].Save();

                        // ASSIGN GROUPS TO NEW USER
                        IList <Group> availableGroups = SecurityUtility.GetManagableGroups();
                        int           groupId         = AlwaysConvert.ToInt(AddGroup.SelectedValue);
                        if (groupId > 0)
                        {
                            int index = availableGroups.IndexOf(groupId);
                            if (groupId > -1)
                            {
                                // ADD THE GROUP ASSOCIATION FOR THE NEW USER
                                newUser.UserGroups.Add(new UserGroup(newUser, availableGroups[index]));
                                newUser.Save();
                            }
                        }

                        // REDIRECT TO EDIT FORM IF INDICATED
                        if (((Button)sender).ID == "AddEditButton")
                        {
                            Response.Redirect("EditUser.aspx?UserId=" + newUser.Id.ToString());
                        }

                        // NO REDIRECT, DISPLAY A CONFIRMATION FOR CREATED USER
                        UserAddedMessage.Text    = string.Format(UserAddedMessage.Text, newUser.UserName);
                        UserAddedMessage.Visible = true;

                        // RESET THE ADD FORM FIELDS
                        AddEmail.Text           = String.Empty;
                        AddPassword.Text        = String.Empty;
                        AddConfirmPassword.Text = String.Empty;
                        AddGroup.SelectedIndex  = -1;

                        //REBIND THE SEARCH
                        UserGrid.DataBind();
                    }
                    else
                    {
                        // CREATE USER FAILED WITHIN THE API
                        switch (status)
                        {
                        case MembershipCreateStatus.DuplicateEmail:
                        case MembershipCreateStatus.DuplicateUserName:
                            AddCustomValidationError(phEmailValidation, AddEmail, "The email address is already registered.");
                            break;

                        case MembershipCreateStatus.InvalidEmail:
                        case MembershipCreateStatus.InvalidUserName:
                            AddCustomValidationError(phEmailValidation, AddEmail, "The email address is invalid.");
                            break;

                        case MembershipCreateStatus.InvalidPassword:
                            AddCustomValidationError(phPasswordValidation, AddPassword, "The password is invalid.");
                            break;

                        default:
                            AddCustomValidationError(phEmailValidation, AddEmail, "Unexpected error: " + status.ToString());
                            break;
                        }
                        AddPopup.Show();
                    }
                }
                else
                {
                    AddPopup.Show();
                }
            }
            else
            {
                AddPopup.Show();
            }
        }