Exemplo n.º 1
0
        protected void btnTransfer_Click(object sender, EventArgs e)
        {
            if (CurrentUsername == null) return;
            if (CurrentUsername != "admin")
            {
                if (CurrentGroupMember == null)
                {
                    Global.Logger.LogError("Unauthorized attempt to transfer a group by member " +
                                           CurrentUsername + " with IP " + Request.UserHostAddress + " (not a member)");
                    return;
                }
                if (!CurrentGroupMember.Active || CurrentGroupMember.Type != GroupMember.eType.Admin)
                {
                    Global.Logger.LogError("Unauthorized attempt to transfer a group by member " +
                                           CurrentUsername + " with IP " + Request.UserHostAddress +
                                           " (not active or admin)");
                    return;
                }
            }

            if (ddGroupMembers.SelectedValue == "admin" && !GroupMember.IsMember("admin", CurrentGroup.ID))
            {
                var groupMember = new GroupMember(CurrentGroup.ID, "admin")
                                      {
                                          Active = true,
                                          Type = GroupMember.eType.Admin
                                      };
                groupMember.Save();
                CurrentGroup.ActiveMembers++;
            }

            CurrentGroup.Owner = ddGroupMembers.SelectedValue;
            CurrentGroup.Save();

            MiscTemplates.TransferGroupOwnerMessage transferGroupOwnershipTemplate = null;
            User recipient = null;
            try
            {
                recipient = User.Load(ddGroupMembers.SelectedValue);
                transferGroupOwnershipTemplate = new MiscTemplates.TransferGroupOwnerMessage(recipient.LanguageId);
            }
            catch (NotFoundException)
            {
                transferGroupOwnershipTemplate = new MiscTemplates.TransferGroupOwnerMessage(PageBase.GetLanguageId());
            }
            var msg = new Message(((PageBase) Page).CurrentUserSession.Username, 
                ddGroupMembers.SelectedValue);
            string message = transferGroupOwnershipTemplate.Message;
            message = message.Replace("%%GROUP%%", Parsers.ProcessGroupName(CurrentGroup.Name));
            msg.Body = message;
            msg.Send();

            lblError.Text = Lang.Trans("The ownership has been transferred successfully.");

            mvEditGroup.SetActiveView(viewMain);
        }
Exemplo n.º 2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (!((AdminPageBase)Page).HasWriteAccess) return;

            #region Set fields

            string name = Config.Misc.EnableBadWordsFilterGroups ? Parsers.ProcessBadWords(txtName.Text.Trim()) : txtName.Text.Trim();
            string description = Config.Misc.EnableBadWordsFilterGroups ? Parsers.ProcessBadWords(txtDescription.Text.Trim()) : txtDescription.Text.Trim();
            Group.eAccessLevel accessLevel = (Group.eAccessLevel)Convert.ToInt32(ddAccessLevel.SelectedValue);
            string owner = ddOwner.SelectedValue;
            bool approved = ddApproved.SelectedIndex == 0 ? true : false;

            #endregion

            #region Validate fields

            #region Validate Group name

            if (Group.Name != txtName.Text)
            {
                if (Group.IsNameUsed(name))
                {
                    MessageBox.Show(Lang.TransA("Group name already exists."), Misc.MessageType.Error);
                    return;
                }
            }

            #endregion

            #region Validate Categories

            List<int> lCategoriesIDs = new List<int>();

            foreach (ListItem item in lbCategories.Items)
            {
                if (item.Selected)
                {
                    lCategoriesIDs.Add(Convert.ToInt32(item.Value));
                }
            }

            if (lCategoriesIDs.Count == 0)
            {
                MessageBox.Show(Lang.TransA("Please select category."), Misc.MessageType.Error);
                return;
            }

            #endregion

            #region Validate Description

            if (description.Length == 0)
            {
                MessageBox.Show(Lang.TransA("Please enter group description."), Misc.MessageType.Error);
                return;
            }
            #endregion

            #region Validate Group Icon

            if (fuGroupImage.HasFile)
            {
                System.Drawing.Image image = null;
                try
                {
                    image = System.Drawing.Image.FromStream
                        (fuGroupImage.PostedFile.InputStream);
                }
                catch
                {
                    MessageBox.Show(Lang.TransA("Invalid image!"), Misc.MessageType.Error);
                    return;
                }

                Group.SaveIcon(Group.ID, image);
            }

            #endregion

            #endregion

            Group.Name = name;
            Group.Description = description;
            Group.AccessLevel = accessLevel;

            if (Group.Owner != owner) // if the admin changes group owner
            {
                try
                {
                    User user = User.Load(owner);
                    MiscTemplates.TransferGroupOwnerMessage transferGroupOwnershipTemplate =
                        new MiscTemplates.TransferGroupOwnerMessage(user.LanguageId);
                    Message msg = new Message(Config.Users.SystemUsername, owner);
                    string message = transferGroupOwnershipTemplate.Message;
                    message = message.Replace("%%GROUP%%", Parsers.ProcessGroupName(Group.Name));
                    msg.Body = message;
                    msg.Send();
                }
                catch (NotFoundException)
                {
                }
            }
            
            Group.Owner = owner;
            Group.Approved = approved;
            if (ddAgeRestriction.SelectedValue != "-1") Group.MinAge = Convert.ToInt32(ddAgeRestriction.SelectedValue);
            else Group.MinAge = null;

            Group.Save();
            Group.SetCategories(lCategoriesIDs.ToArray());

            MessageBox.Show(Lang.TransA("The group has been successfully updated!"), Misc.MessageType.Success);
        }