예제 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string groupName = Request.QueryString["gn"];
            UserGroup profileOwner;

            try
            {

                profileOwner = new UserGroup(core, groupName);
            }
            catch
            {
                core.Functions.Generate404();
                return;
            }

            Response.ContentType = "text/css";
            Response.Clear();

            // don't allow to load up external stylesheets
            Response.Write(Regex.Replace(profileOwner.GroupInfo.Style, "\\@import(.+?)\\;", "", RegexOptions.IgnoreCase));

            if (db != null)
            {
                db.CloseConnection();
            }

            core.Prose.Close();
            //core.Dispose();
            //core = null;

            Response.End();
        }
예제 #2
0
        public GroupMember(Core core, UserGroup group, long userId)
            : base(core)
        {
            this.db = db;

            SelectQuery query = GetSelectQueryStub(core, UserLoadOptions.All);
            query.AddCondition("user_keys.user_id", userId);
            query.AddCondition("group_members.group_id", group.GroupId);

            System.Data.Common.DbDataReader memberReader = db.ReaderQuery(query);

            if (memberReader.HasRows)
            {
                memberReader.Read();

                loadItemInfo(memberReader);
                loadUserInfo(memberReader);
                loadUserIcon(memberReader);

                memberReader.Close();
                memberReader.Dispose();
            }
            else
            {
                memberReader.Close();
                memberReader.Dispose();

                throw new InvalidUserException();
            }
        }
        void AccountGroupsMembershipsManage_ResignOperator_Save(object sender, EventArgs e)
        {
            AuthoriseRequestSid();

            long groupId = core.Functions.RequestLong("id", 0);

            if (groupId == 0)
            {
                DisplayGenericError();
                return;
            }

            UserGroup thisGroup = new UserGroup(core, groupId);

            if (core.Display.GetConfirmBoxResult() == ConfirmBoxResult.Yes)
            {
                if (thisGroup.IsGroupOperator(LoggedInMember.ItemKey))
                {
                    if (thisGroup.Operators > 1)
                    {
                        db.BeginTransaction();
                        long deletedRows = db.UpdateQuery(string.Format("DELETE FROM group_operators WHERE group_id = {0} AND user_id = {1}",
                            thisGroup.GroupId, LoggedInMember.UserId));

                        db.UpdateQuery(string.Format("UPDATE group_info SET group_operators = group_operators - {1} WHERE group_id = {0}",
                            thisGroup.GroupId, deletedRows));

                        SetRedirectUri(thisGroup.Uri);
                        core.Display.ShowMessage("Success", "You successfully resigned as a group operator. You are still a member of the group. You will be redirected in a second.");
                    }
                    else
                    {
                        core.Display.ShowMessage("Cannot resign as operator", "Groups must have at least one operator, you cannot resign from this group at this moment.");
                        return;
                    }
                }
                else
                {
                    core.Display.ShowMessage("Error", "An error has occured. You are not an operator of this group, go back.");
                    return;
                }
            }
            else
            {
                SetRedirectUri(thisGroup.Uri);
                core.Display.ShowMessage("Cancelled", "You cancelled resignation from being a group operator.");
            }
        }
예제 #4
0
 public Forum(Core core, UserGroup owner, System.Data.Common.DbDataReader forumDataRow)
     : this(core, (ForumSettings)null, owner, forumDataRow)
 {
 }
예제 #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (session.IsLoggedIn)
            {
                // redirect to the homepage if we are already logged in
                Response.Redirect("/");
            }

            template.Parse("IS_CONTENT", "FALSE");
            template.Parse("S_POST", core.Hyperlink.AppendSid("/register/", true));

            string mode = Request.QueryString["mode"];

            if (mode == "optout")
            {
                string emailKey = Request.QueryString["key"];

                if (emailKey.Length == 32)
                {
                    long rowsChanged = db.UpdateQuery(string.Format("UPDATE invite_keys SET invite_allow = 0 WHERE email_key = '{0}'",
                        Mysql.Escape(emailKey)));

                    if (rowsChanged > 0)
                    {
                        core.Display.ShowMessage("Opt-out of " + core.Settings.SiteTitle + " Mailings", "You have successfully opted-out of further " + core.Settings.SiteTitle + " mailings. If you continue to receive mailings send an e-mail to contact@" + Hyperlink.Domain + " with the subject \"opt-out\".");
                        return;
                    }
                    else
                    {
                        core.Display.ShowMessage("Cannot Opt-out", "The opt-out key you have given is missing or incomplete. To manually opt-out send an e-mail to contact@" + Hyperlink.Domain + " with the subject \"opt-out\".");
                        return;
                    }
                }
                else
                {
                    core.Display.ShowMessage("Cannot Opt-out", "The opt-out key you have given is missing or incomplete. To manually opt-out send an e-mail to contact@" + Hyperlink.Domain + " with the subject \"opt-out\".");
                    return;
                }
            }
            else if (mode == "activate")
            {
                long userId = 0;
                string activateKey = (string)Request.QueryString["key"];

                try
                {
                    userId = long.Parse(Request.QueryString["id"]);
                }
                catch
                {
                    core.Display.ShowMessage("Error", "Error activating user.");
                    return;
                }

                DataTable userTable = db.Query(string.Format("SELECT user_id FROM user_info WHERE user_id = {0} AND user_activate_code = '{1}';",
                    userId, Mysql.Escape(activateKey)));

                if (userTable.Rows.Count == 1)
                {
                    db.UpdateQuery(string.Format("UPDATE user_info SET user_active = 1 WHERE user_id = {0} AND user_activate_code = '{1}';",
                        userId, Mysql.Escape(activateKey)));

                    core.Display.ShowMessage("Success", "You have successfully activated your account. You may now [iurl=\"/sign-in/\"]sign in[/iurl].", ShowMessageOptions.Bbcode);
                    return;
                }
                else
                {
                    core.Display.ShowMessage("Error", "Error activating user.");
                    return;
                }
            }
            else if (mode == "activate-password")
            {
                long userId = 0;
                string activateKey = (string)Request.QueryString["key"];

                try
                {
                    userId = long.Parse(Request.QueryString["id"]);
                }
                catch
                {
                    core.Display.ShowMessage("Error", "Error activating new password.");
                    return;
                }

                DataTable userTable = db.Query(string.Format("SELECT user_id, user_new_password FROM user_info WHERE user_id = {0} AND user_activate_code = '{1}';",
                    userId, Mysql.Escape(activateKey)));

                if (userTable.Rows.Count == 1)
                {
                    db.UpdateQuery(string.Format("UPDATE user_info SET user_password = '******', user_new_password = '' WHERE user_id = {0} AND user_activate_code = '{1}';",
                        userId, Mysql.Escape(activateKey), Mysql.Escape(BoxSocial.Internals.User.HashPassword((string)userTable.Rows[0]["user_new_password"]))));

                    core.Display.ShowMessage("Success", "You have successfully activated your new password. You may now [url=\"/sign-in/\"]sign in[/url].");
                    return;
                }
                else
                {
                    core.Display.ShowMessage("Error", "Error activating new password.");
                    return;
                }
            }
            else if (core.Http.Form["submit"] == null)
            {
                long groupId = core.Functions.FormLong("gid", core.Functions.RequestLong("gid", 0));
                string emailKey = core.Http.Query["key"];
                string referralKey = core.Http.Query["refer"];
                bool continueSignup = false;

                Dictionary<string, InviteKey> keys = InviteKey.GetInvites(core, emailKey);
                Dictionary<string, ReferralKey> referrals = ReferralKey.GetReferrals(core, referralKey);

                if (core.Settings.SignupMode == "invite")
                {
                    if (keys.Count == 0 && referrals.Count == 0)
                    {
                        continueSignup = false;
                    }
                    else
                    {
                        continueSignup = true;
                    }
                }
                else
                {
                    continueSignup = true;
                }

                if (continueSignup)
                {
                    template.Parse("GID", groupId.ToString());

                    prepareNewCaptcha();
                    if (!string.IsNullOrEmpty(emailKey))
                    {
                        template.Parse("EMAIL_KEY", emailKey);
                    }

                    if (!string.IsNullOrEmpty(referralKey))
                    {
                        template.Parse("REFERRAL_KEY", referralKey);
                    }

                    if (groupId > 0)
                    {
                        try
                        {
                            UserGroup thisGroup = new UserGroup(core, groupId);
                            if (loggedInMember != null)
                            {
                                if (loggedInMember.UserInfo.ShowCustomStyles)
                                {
                                    template.Parse("USER_STYLE_SHEET", string.Format("group/{0}.css", thisGroup.Key));
                                }
                            }
                            else
                            {
                                template.Parse("USER_STYLE_SHEET", string.Format("group/{0}.css", thisGroup.Key));
                            }
                        }
                        catch
                        {
                        }
                    }
                }
                else
                {
                    core.Display.ShowMessage("Invite Only", "Sorry, registration is current on an invite-only basis at the moment. Check back later.");
                }
            }
            else
            {
                long groupId = core.Functions.FormLong("gid", core.Functions.RequestLong("gid", 0));
                string emailKey = core.Http.Form["key"];
                string referralKey = core.Http.Form["refer"];
                bool continueSignup = false;
                List<long> invitedById = new List<long>();

                Dictionary<string, InviteKey> keys = InviteKey.GetInvites(core, emailKey);
                Dictionary<string, ReferralKey> referrals = ReferralKey.GetReferrals(core, referralKey);

                if (core.Settings.SignupMode == "invite")
                {
                    if (keys.Count == 0 && referrals.Count == 0)
                    {
                        continueSignup = false;
                    }
                    else
                    {
                        continueSignup = true;

                        foreach (string key in keys.Keys)
                        {
                            invitedById.Add(keys[key].InviteUserId);
                        }
                    }
                }
                else
                {
                    continueSignup = true;
                }

                if (continueSignup)
                {
                    // submit the form
                    template.Parse("USERNAME", (string)core.Http.Form["username"]);
                    template.Parse("EMAIL", (string)core.Http.Form["email"]);
                    template.Parse("CONFIRM_EMAIL", (string)core.Http.Form["confirm-email"]);
                    template.Parse("GID", groupId.ToString());

                    if (!string.IsNullOrEmpty(emailKey))
                    {
                        template.Parse("EMAIL_KEY", emailKey);
                    }

                    if (!string.IsNullOrEmpty(referralKey))
                    {
                        template.Parse("REFERRAL_KEY", referralKey);
                    }

                    DataTable confirmTable = db.Query(string.Format("SELECT confirm_code FROM confirm WHERE confirm_type = 1 AND session_id = '{0}' LIMIT 1",
                        Mysql.Escape(session.SessionId)));

                    if (confirmTable.Rows.Count != 1)
                    {
                        template.Parse("ERROR", "Captcha is invalid, please try again.");
                        prepareNewCaptcha();
                    }
                    else if (((string)confirmTable.Rows[0]["confirm_code"]).ToLower() != ((string)core.Http.Form["captcha"]).ToLower())
                    {
                        template.Parse("ERROR", "Captcha is invalid, please try again.");
                        prepareNewCaptcha();
                    }
                    else if (!BoxSocial.Internals.User.CheckUserNameValid(core.Http.Form["username"]))
                    {
                        template.Parse("ERROR", "Username is invalid, you may only use letters, numbers, period, underscores or a dash (a-z, 0-9, '_', '-', '.').");
                        prepareNewCaptcha();
                    }
                    else if (!BoxSocial.Internals.User.CheckUserNameUnique(db, core.Http.Form["username"]))
                    {
                        template.Parse("ERROR", "Username is already taken, please choose another one.");
                        prepareNewCaptcha();
                    }
                    else if (!BoxSocial.Internals.User.CheckEmailValid(core.Http.Form["email"]))
                    {
                        template.Parse("ERROR", "You have entered an invalid e-mail address, you must use a valid e-mail address to complete registration.");
                        prepareNewCaptcha();
                    }
                    else if (!BoxSocial.Internals.User.CheckEmailUnique(core, core.Http.Form["email"]))
                    {
                        template.Parse("ERROR", "The e-mail address you have entered has already been registered.");
                        prepareNewCaptcha();
                    }
                    else if (core.Http.Form["email"] != core.Http.Form["confirm-email"])
                    {
                        template.Parse("ERROR", "The e-mail addresses you entered do not match, may sure you have entered your e-mail address correctly.");
                        prepareNewCaptcha();
                    }
                    else if (core.Http.Form["password"] != core.Http.Form["confirm-password"])
                    {
                        template.Parse("ERROR", "The passwords you entered do not match, make sure you have entered your desired password correctly.");
                        prepareNewCaptcha();
                    }
                    else if (((string)core.Http.Form["password"]).Length < 6)
                    {
                        template.Parse("ERROR", "The password you entered is too short. Please choose a strong password of 6 characters or more.");
                        prepareNewCaptcha();
                    }
                    else if ((string)core.Http.Form["agree"] != "true")
                    {
                        template.Parse("ERROR", "You must accept the " + core.Settings.SiteTitle + " Terms of Service to register an account.");
                        prepareNewCaptcha();
                    }
                    else
                    {
                        User newUser = BoxSocial.Internals.User.Register(Core, core.Http.Form["username"], core.Http.Form["email"], core.Http.Form["password"], core.Http.Form["confirm-password"]);
                        if (newUser == null)
                        {
                            template.Parse("ERROR", "Bad registration details");
                            prepareNewCaptcha();
                        }
                        else
                        {
                            // captcha is a use once thing, destroy all for this session
                            db.UpdateQuery(string.Format("DELETE FROM confirm WHERE confirm_type = 1 AND session_id = '{0}'",
                                Mysql.Escape(session.SessionId)));

                            // Invite keys are single use
                            if (!string.IsNullOrEmpty(emailKey))
                            {
                                db.UpdateQuery(string.Format("DELETE FROM invite_keys WHERE email_key = '{0}'",
                                    Mysql.Escape(emailKey)));
                            }

                            foreach (long friendId in invitedById)
                            {
                                if (friendId > 0)
                                {
                                    long relationId = db.UpdateQuery(string.Format("INSERT INTO user_relations (relation_me, relation_you, relation_time_ut, relation_type) VALUES ({0}, {1}, UNIX_TIMESTAMP(), 'FRIEND');",
                                        newUser.UserId, friendId));

                                    long relationId2 = db.UpdateQuery(string.Format("INSERT INTO user_relations (relation_me, relation_you, relation_time_ut, relation_type) VALUES ({0}, {1}, UNIX_TIMESTAMP(), 'FRIEND');",
                                        friendId, newUser.UserId));

                                    db.UpdateQuery(string.Format("UPDATE user_info ui SET ui.user_friends = ui.user_friends + 1 WHERE ui.user_id = {0};",
                                        friendId));

                                    db.UpdateQuery(string.Format("UPDATE user_info ui SET ui.user_friends = ui.user_friends + 1 WHERE ui.user_id = {0};",
                                        newUser.UserId));
                                }
                            }

                            if (groupId > 0)
                            {
                                try
                                {
                                    UserGroup thisGroup = new UserGroup(core, groupId);

                                    if (loggedInMember != null)
                                    {
                                        if (loggedInMember.UserInfo.ShowCustomStyles)
                                        {
                                            template.Parse("USER_STYLE_SHEET", string.Format("group/{0}.css", thisGroup.Key));
                                        }
                                    }
                                    else
                                    {
                                        template.Parse("USER_STYLE_SHEET", string.Format("group/{0}.css", thisGroup.Key));
                                    }

                                    int activated = 0;

                                    switch (thisGroup.GroupType)
                                    {
                                        case "OPEN":
                                        case "PRIVATE": // assume as you've been invited that it is enough for activation
                                            activated = 1;
                                            break;
                                        case "REQUEST":
                                        case "CLOSED":
                                            activated = 0;
                                            break;
                                    }

                                    bool isInvited = thisGroup.IsGroupInvitee(newUser);

                                    // do not need an invite unless the group is private
                                    // private groups you must be invited to
                                    if (thisGroup.GroupType != "PRIVATE" || (thisGroup.GroupType == "PRIVATE" && isInvited))
                                    {
                                        db.BeginTransaction();
                                        db.UpdateQuery(string.Format("INSERT INTO group_members (group_id, user_id, group_member_approved, group_member_ip, group_member_date_ut) VALUES ({0}, {1}, {2}, '{3}', UNIX_TIMESTAMP());",
                                            thisGroup.GroupId, newUser.Id, activated, Mysql.Escape(session.IPAddress.ToString()), true));

                                        if (activated == 1)
                                        {
                                            db.UpdateQuery(string.Format("UPDATE group_info SET group_members = group_members + 1 WHERE group_id = {0}",
                                                thisGroup.GroupId));
                                        }

                                        // just do it anyway, can be invited to any type of group
                                        db.UpdateQuery(string.Format("DELETE FROM group_invites WHERE group_id = {0} AND user_id = {1}",
                                            thisGroup.GroupId, newUser.Id));
                                    }

                                    core.Template.Parse("REDIRECT_URI", thisGroup.Uri);
                                }
                                catch (InvalidGroupException)
                                {
                                }
                            }

                            //Response.Redirect("/", true);
                            core.Display.ShowMessage("Registered", "You have registered. Before you can use your account you must verify your e-mail address by clicking a verification link sent to it.");
                            return; /* stop processing the display of this page */
                        }
                    }
                }
                else
                {
                    core.Display.ShowMessage("Invite Only", "Sorry, registration is current on an invite-only basis at the moment. Check back later.");
                }
            }

            EndResponse();
        }
예제 #6
0
 public static string Uri(Core core, UserGroup thisGroup)
 {
     return core.Hyperlink.AppendSid(string.Format("{0}comments",
         thisGroup.UriStub));
 }
예제 #7
0
        public static UserGroup Create(Core core, string groupTitle, string groupSlug, string groupDescription, long groupCategory, string groupType)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            Mysql db = core.Db;
            SessionState session = core.Session;

            if (core.Session.LoggedInMember == null)
            {
                return null;
            }

            if (!CheckGroupNameUnique(core, groupSlug))
            {
                return null;
            }

            switch (groupType)
            {
                case "open":
                    groupType = "OPEN";
                    break;
                case "request":
                    groupType = "REQUEST";
                    break;
                case "closed":
                    groupType = "CLOSED";
                    break;
                case "private":
                    groupType = "PRIVATE";
                    break;
                default:
                    return null;
            }

            db.BeginTransaction();

            InsertQuery iQuery = new InsertQuery(UserGroup.GetTable(typeof(UserGroup)));
            iQuery.AddField("group_name", groupSlug);
            iQuery.AddField("group_domain", string.Empty);

            long groupId = db.Query(iQuery);

            iQuery = new InsertQuery(UserGroupInfo.GetTable(typeof(UserGroupInfo)));
            iQuery.AddField("group_id", groupId);
            iQuery.AddField("group_name", groupSlug);
            iQuery.AddField("group_name_display", groupTitle);
            iQuery.AddField("group_type", groupType);
            iQuery.AddField("group_abstract", groupDescription);
            iQuery.AddField("group_reg_date_ut", UnixTime.UnixTimeStamp());
            iQuery.AddField("group_operators", 1);
            iQuery.AddField("group_officers", 0);
            iQuery.AddField("group_members", 1);
            iQuery.AddField("group_category", groupCategory);
            iQuery.AddField("group_gallery_items", 0);
            iQuery.AddField("group_home_page", "/profile");
            iQuery.AddField("group_style", string.Empty);

            iQuery.AddField("group_reg_ip", session.IPAddress.ToString());
            iQuery.AddField("group_icon", 0);
            iQuery.AddField("group_bytes", 0);
            iQuery.AddField("group_views", 0);

            db.Query(iQuery);

            if (groupType != "PRIVATE")
            {
                db.UpdateQuery(string.Format("UPDATE global_categories SET category_groups = category_groups + 1 WHERE category_id = {0}",
                    groupCategory));
            }

            db.UpdateQuery(string.Format("INSERT INTO group_members (user_id, group_id, group_member_approved, group_member_ip, group_member_date_ut) VALUES ({0}, {1}, 1, '{2}', UNIX_TIMESTAMP())",
                session.LoggedInMember.UserId, groupId, Mysql.Escape(session.IPAddress.ToString())));

            db.UpdateQuery(string.Format("INSERT INTO group_operators (user_id, group_id) VALUES ({0}, {1})",
                session.LoggedInMember.UserId, groupId));

            UserGroup newGroup = new UserGroup(core, groupId);

            // Install a couple of applications
            try
            {
                ApplicationEntry profileAe = new ApplicationEntry(core, "Profile");
                profileAe.Install(core, newGroup);
            }
            catch
            {
            }

            try
            {
                ApplicationEntry groupsAe = new ApplicationEntry(core, "Groups");
                groupsAe.Install(core, newGroup);
            }
            catch
            {
            }

            try
            {
                ApplicationEntry galleryAe = new ApplicationEntry(core, "Gallery");
                galleryAe.Install(core, newGroup);
            }
            catch
            {
            }

            try
            {
                ApplicationEntry guestbookAe = new ApplicationEntry(core, "GuestBook");
                guestbookAe.Install(core, newGroup);
            }
            catch
            {
            }

            return newGroup;
        }
예제 #8
0
        void AccountGroupsInvite_Save(object sender, EventArgs e)
        {
            AuthoriseRequestSid();

            long groupId = core.Functions.FormLong("id", 0);

            try
            {
                UserGroup thisGroup = new UserGroup(core, groupId);

                try
                {
                    long userId = UserSelectBox.FormUser(core, "username", 0);

                    core.LoadUserProfile(userId);
                    User inviteMember = core.PrimitiveCache[userId];

                    if (!inviteMember.IsFriend(LoggedInMember.ItemKey))
                    {
                        core.Display.ShowMessage("Error", "You can only invite mutual friends to groups.");
                        return;
                    }

                    if (!thisGroup.IsGroupMember(LoggedInMember.ItemKey))
                    {
                        core.Display.ShowMessage("Error", "You must be a member of a group to invite someone to it.");
                        return;
                    }

                    if (!thisGroup.IsGroupMember(inviteMember.ItemKey))
                    {
                        // use their relation, otherwise you could just create a billion pending friends and still SPAM them with group invites
                        DataTable friendsTable = db.Query(string.Format("SELECT relation_time_ut FROM user_relations WHERE relation_me = {0} AND relation_you = {1} AND relation_type = 'FRIEND';",
                            inviteMember.UserId, LoggedInMember.Id));

                        if (friendsTable.Rows.Count > 0)
                        {
                            ApplicationEntry ae = Application.GetExecutingApplication(core, LoggedInMember);
                            ae.SendNotification(core, LoggedInMember, inviteMember, thisGroup.ItemKey, thisGroup.ItemKey, "_INVITED_YOU_TO_JOIN_A_GROUP", thisGroup.Uri, "invite");

                            SetRedirectUri(thisGroup.Uri);
                            core.Display.ShowMessage("Invited Friend", "You have invited a friend to the group.");
                        }
                        else
                        {
                            SetError("You can only invite people who are friends with you to join a group.");
                            return;
                        }
                    }
                    else
                    {
                        SetError("The person you are trying to invite is already a member of the group. An invitation has not been sent.");
                        return;
                    }
                }
                catch (InvalidUserException)
                {
                    SetError("The user you have entered does not exist.");
                    return;
                }
            }
            catch (InvalidGroupException)
            {
                DisplayGenericError();
                return;
            }
        }
        void AccountGroupsMembershipsManage_Join(object sender, ModuleModeEventArgs e)
        {
            long groupId = core.Functions.RequestLong("id", 0);
            UserGroup thisGroup;

            if (AuthorisedRequest())
            {
                AccountGroupsMembershipsManage_Join_Save(sender, new EventArgs());
            }
            else
            {

                try
                {
                    thisGroup = new UserGroup(core, groupId);
                }
                catch (InvalidGroupException)
                {
                    DisplayGenericError();
                    return;
                }

                Dictionary<string, string> hiddenFieldList = new Dictionary<string, string>();
                hiddenFieldList.Add("module", "groups");
                hiddenFieldList.Add("sub", "memberships");
                hiddenFieldList.Add("mode", "join");
                hiddenFieldList.Add("id", groupId.ToString());

                core.Display.ShowConfirmBox(HttpUtility.HtmlEncode(core.Hyperlink.AppendSid(Owner.AccountUriStub, true)),
                    "Confirm join group",
                    "Do you want to join the group `" + thisGroup.DisplayName + "`?",
                    hiddenFieldList);
            }
        }
        void AccountGroupsMembershipsManage_BanMember_Save(object sender, EventArgs e)
        {
            AuthoriseRequestSid();

            long groupId;
            long userId;

            try
            {
                string[] idString = core.Http.Form["id"].Split(new char[] { ',' });
                groupId = long.Parse(idString[0]);
                userId = long.Parse(idString[1]);
            }
            catch
            {
                core.Functions.ThrowError();
                return;
            }

            if (core.Display.GetConfirmBoxResult() == ConfirmBoxResult.Yes)
            {
                try
                {
                    UserGroup group = new UserGroup(core, groupId);

                    if (group.IsGroupOperator(LoggedInMember.ItemKey))
                    {
                        try
                        {
                            GroupMember member = new GroupMember(core, group, userId);

                            member.Ban();

                            core.Display.ShowMessage("Member Banned", "The member has been banned from the group.");
                            return;
                        }
                        catch (InvalidUserException)
                        {
                            DisplayGenericError();
                            return;
                        }
                    }
                    else
                    {
                        core.Display.ShowMessage("Cannot ban member", "Only group operators can ban members from groups.");
                        return;
                    }
                }
                catch (InvalidGroupException)
                {
                    DisplayGenericError();
                    return;
                }
            }
            else
            {
                core.Display.ShowMessage("Cancelled", "You cancelled the banning of this member.");
                return;
            }
        }
예제 #11
0
        public static SubUserGroup Create(Core core, UserGroup parent, string groupTitle, string groupSlug, string groupDescription, string groupType)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            Mysql db = core.Db;
            SessionState session = core.Session;

            if (core.Session.LoggedInMember == null)
            {
                return null;
            }

            if (!parent.CheckSubGroupNameUnique(groupSlug))
            {
                throw new GroupNameNotUniqueException();
            }

            switch (groupType.ToLower())
            {
                case "open":
                    groupType = "OPEN";
                    break;
                case "request":
                    groupType = "REQUEST";
                    break;
                case "closed":
                    groupType = "CLOSED";
                    break;
                case "private":
                    groupType = "PRIVATE";
                    break;
                default:
                    return null;
            }

            db.BeginTransaction();

            Item item = Item.Create(core, typeof(SubUserGroup), new FieldValuePair("sub_group_parent_id", parent.Id),
                new FieldValuePair("sub_group_name", groupSlug),
                new FieldValuePair("sub_group_name_first", groupSlug[0]),
                new FieldValuePair("sub_group_name_display", groupTitle),
                new FieldValuePair("sub_group_type", groupType),
                new FieldValuePair("sub_group_reg_ip", core.Session.IPAddress.ToString()),
                new FieldValuePair("sub_group_reg_date_ut", UnixTime.UnixTimeStamp()),
                new FieldValuePair("sub_group_colour", 0x000000),
                new FieldValuePair("sub_group_members", 0));

            /*db.UpdateQuery(string.Format("INSERT INTO sub_group_members (user_id, group_id, sub_group_id, sub_group_member_approved, sub_group_member_ip, sub_group_member_date_ut, sub_group_member_is_leader) VALUES ({0}, {1}, {2}, 1, '{3}', UNIX_TIMESTAMP(), 1)",
                session.LoggedInMember.UserId, parent.Id, ((SubUserGroup)item).Id, Mysql.Escape(session.IPAddress.ToString())));*/

            return (SubUserGroup)item;
        }
예제 #12
0
 /// <summary>
 /// Generates a URI pointing to the gallery photo upload form
 /// </summary>
 /// <param name="thisGroup">Group to upload photo to</param>
 /// <returns>URI pointing to the upload form</returns>
 public static string BuildGalleryUpload(Core core, UserGroup thisGroup)
 {
     return core.Hyperlink.AppendSid(string.Format("{0}gallery/?mode=upload",
         thisGroup.UriStub));
 }
예제 #13
0
        public Forum(Core core, ForumSettings settings, UserGroup owner, System.Data.Common.DbDataReader forumDataRow)
            : base(core)
        {
            this.owner = owner;
            this.settings = settings;
            ItemLoad += new ItemLoadHandler(Forum_ItemLoad);

            try
            {
                loadItemInfo(forumDataRow);
            }
            catch (InvalidItemException)
            {
                throw new InvalidForumException();
            }

            try
            {
                readStatus = new ForumReadStatus(core, forumDataRow);
                readStatusLoaded = true;
            }
            catch (InvalidForumReadStatusException)
            {
                readStatus = null;
                readStatusLoaded = true;
            }
        }
        void AccountGroupsMembershipsManage_ApproveMember(object sender, ModuleModeEventArgs e)
        {
            AuthoriseRequestSid();

            long groupId;
            long userId;

            try
            {
                string[] idString = core.Http.Query["id"].Split(new char[] { ',' });
                groupId = long.Parse(idString[0]);
                userId = long.Parse(idString[1]);
            }
            catch
            {
                DisplayGenericError();
                return;
            }

            try
            {
                UserGroup thisGroup = new UserGroup(core, groupId);

                if (thisGroup.IsGroupOperator(LoggedInMember.ItemKey))
                {
                    try
                    {
                        User member = new User(core, userId);

                        if (thisGroup.IsGroupMemberPending(member.ItemKey))
                        {
                            // we can approve the pending membership
                            db.BeginTransaction();
                            long rowsChanged = db.UpdateQuery(string.Format("UPDATE group_members SET group_member_approved = 1, group_member_date_ut = UNIX_TIMESTAMP() WHERE group_id = {0} AND user_id = {1} AND group_member_approved = 0;",
                                thisGroup.GroupId, member.UserId));

                            if (rowsChanged > 0) // committ the change
                            {
                                db.UpdateQuery(string.Format("UPDATE group_info SET group_members = group_members + 1 WHERE group_id = {0}",
                                    thisGroup.GroupId));

                                SetRedirectUri(thisGroup.MemberlistUri);
                                core.Display.ShowMessage("Membership Approved", "You have approved the membership for the user.");
                                return;
                            }
                            else
                            {
                                core.Display.ShowMessage("Not Pending", "This member is not pending membership. They may have cancelled their request, or been approved by another operator.");
                                return;
                            }
                        }
                        else
                        {
                            core.Display.ShowMessage("Not Pending", "This member is not pending membership. They may have cancelled their request, or been approved by another operator.");
                            return;
                        }
                    }
                    catch
                    {
                        core.Display.ShowMessage("Error", "An error has occured, group member does not exist, go back.");
                        return;
                    }
                }
                else
                {
                    core.Display.ShowMessage("Not Group Operator", "You must be an operator of the group to approve new memberships.");
                    return;
                }
            }
            catch
            {
                core.Display.ShowMessage("Error", "An error has occured, group does not exist, go back.");
                return;
            }
        }
        void AccountGroupsMembershipsManage_Join_Save(object sender, EventArgs e)
        {
            AuthoriseRequestSid();

            long groupId = core.Functions.FormLong("id", core.Functions.RequestLong("id", 0));

            if (groupId == 0)
            {
                core.Display.ShowMessage("Error", "Unable to complete action, missing data. Go back and try again.");
                return;
            }

            if (core.Display.GetConfirmBoxResult() == ConfirmBoxResult.Yes || core.Functions.RequestLong("id", 0) == groupId)
            {
                try
                {
                    UserGroup thisGroup = new UserGroup(core, groupId);
                    int activated = 0;

                    DataTable membershipTable = db.Query(string.Format("SELECT user_id FROM group_members WHERE group_id = {0} AND user_id = {1};",
                        thisGroup.GroupId, LoggedInMember.Id));

                    if (membershipTable.Rows.Count > 0)
                    {
                        SetRedirectUri(thisGroup.Uri);
                        core.Display.ShowMessage("Already a Member", "You are already a member of this group.");
                        return;
                    }

                    switch (thisGroup.GroupType)
                    {
                        case "OPEN":
                        case "PRIVATE": // assume as you've been invited that it is enough for activation
                            activated = 1;
                            break;
                        case "REQUEST":
                        case "CLOSED":
                            activated = 0;
                            break;
                    }

                    bool isInvited = thisGroup.IsGroupInvitee(LoggedInMember);

                    // do not need an invite unless the group is private
                    // private groups you must be invited to
                    if (thisGroup.GroupType != "PRIVATE" || (thisGroup.GroupType == "PRIVATE" && isInvited))
                    {
                        db.BeginTransaction();
                        db.UpdateQuery(string.Format("INSERT INTO group_members (group_id, user_id, group_member_approved, group_member_ip, group_member_date_ut) VALUES ({0}, {1}, {2}, '{3}', UNIX_TIMESTAMP());",
                            thisGroup.GroupId, LoggedInMember.Id, activated, Mysql.Escape(session.IPAddress.ToString()), true));

                        if (activated == 1)
                        {
                            db.UpdateQuery(string.Format("UPDATE group_info SET group_members = group_members + 1 WHERE group_id = {0}",
                                thisGroup.GroupId));
                        }

                        // just do it anyway, can be invited to any type of group
                        db.UpdateQuery(string.Format("DELETE FROM group_invites WHERE group_id = {0} AND user_id = {1}",
                            thisGroup.GroupId, LoggedInMember.Id));

                        SetRedirectUri(thisGroup.Uri);
                        if (thisGroup.GroupType == "OPEN" || thisGroup.GroupType == "PRIVATE")
                        {
                            core.Display.ShowMessage("Joined Group", "You have joined this group.");
                        }
                        else if (thisGroup.GroupType == "CLOSED")
                        {
                            core.Display.ShowMessage("Joined Group", "You applied to join this group. A group operator must approve your membership before you will be admitted into the group.");
                        }
                        return;
                    }
                    else
                    {
                        core.Display.ShowMessage("Cannot join group", "This group is private, you must be invited to be able to join it.");
                        return;
                    }
                }
                catch
                {
                    core.Display.ShowMessage("Group does not Exist", "The group you are trying to join does not exist.");
                    return;
                }
            }
            else
            {
                SetRedirectUri(BuildUri());
                core.Display.ShowMessage("Cancelled", "You cancelled joining the group.");
            }
        }
예제 #16
0
        void AccountGroupsInvite_Show(object sender, EventArgs e)
        {
            SetTemplate("account_group_invite");

            long groupId = core.Functions.RequestLong("id", 0);

            try
            {
                UserGroup thisGroup = new UserGroup(core, groupId);

                if (!thisGroup.IsGroupMember(LoggedInMember.ItemKey))
                {
                    core.Display.ShowMessage("Error", "You must be a member of a group to invite someone to it.");
                    return;
                }

                switch (thisGroup.GroupType)
                {
                    case "OPEN":
                    case "REQUEST":
                    case "CLOSED":
                    case "PRIVATE":
                        break;
                }

                UserSelectBox inviteUserSelectBox = new UserSelectBox(core, "username");
                inviteUserSelectBox.SelectMultiple = false;

                template.Parse("S_USERNAME", inviteUserSelectBox);
                template.Parse("S_ID", groupId.ToString());
            }
            catch (InvalidGroupException)
            {
                DisplayGenericError();
            }

            Save(new EventHandler(AccountGroupsInvite_Save));
        }
        void AccountGroupsMembershipsManage_Leave(object sender, ModuleModeEventArgs e)
        {
            AuthoriseRequestSid();

            long groupId = 0;

            try
            {
                groupId = long.Parse(core.Http.Query["id"]);
            }
            catch
            {
                core.Display.ShowMessage("Error", "Unable to complete action, missing data. Go back and try again.");
                return;
            }

            try
            {
                UserGroup thisGroup = new UserGroup(core, groupId);

                bool isGroupMemberPending = thisGroup.IsGroupMemberPending(LoggedInMember.ItemKey);
                bool isGroupMember = thisGroup.IsGroupMember(LoggedInMember.ItemKey);

                DataTable operatorsTable = db.Query(string.Format("SELECT user_id FROM group_operators WHERE group_id = {0} AND user_id = {1};",
                    thisGroup.GroupId, LoggedInMember.Id));

                if (operatorsTable.Rows.Count > 0)
                {
                    SetRedirectUri(thisGroup.Uri);
                    core.Display.ShowMessage("Cannot Leave Group", "You cannot leave this group while you are an operator of the group.");
                    return;
                }
                else
                {
                    if (isGroupMember)
                    {
                        db.BeginTransaction();
                        db.UpdateQuery(string.Format("DELETE FROM group_members WHERE group_id = {0} AND user_id = {1};",
                            thisGroup.GroupId, LoggedInMember.Id));

                        long officerRowsChanged = db.UpdateQuery(string.Format("DELETE FROM group_officers WHERE group_id = {0} AND user_id = {1};",
                            thisGroup.GroupId, LoggedInMember.Id));

                        db.UpdateQuery(string.Format("UPDATE group_info SET group_members = group_members - 1, group_officers = group_officers - {1} WHERE group_id = {0}",
                            thisGroup.GroupId, officerRowsChanged));

                        SetRedirectUri(thisGroup.Uri);
                        core.Display.ShowMessage("Left Group", "You have left the group.");
                        return;
                    }
                    else if (isGroupMemberPending)
                    {
                        db.UpdateQuery(string.Format("DELETE FROM group_members WHERE group_id = {0} AND user_id = {1};",
                            thisGroup.GroupId, LoggedInMember.UserId));

                        SetRedirectUri(thisGroup.Uri);
                        core.Display.ShowMessage("Left Group", "You are no longer pending membership of the group.");
                        return;
                    }
                    else
                    {
                        SetRedirectUri(thisGroup.Uri);
                        core.Display.ShowMessage("Not a Member", "You cannot leave a group you are not a member of.");
                        return;
                    }
                }
            }
            catch (InvalidGroupException)
            {
                core.Display.ShowMessage("Group does not Exist", "The group you are trying to leave does not exist.");
                return;
            }
        }
예제 #18
0
        public GroupInvite Create(Core core, UserGroup group, User invitee)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            core.Db.BeginTransaction();

            InsertQuery iQuery = new InsertQuery(Table);
            iQuery.AddField("group_id", group.Id);
            iQuery.AddField("user_id", invitee.Id);
            iQuery.AddField("inviter_id", core.LoggedInMemberId);
            iQuery.AddField("invite_date_ut", UnixTime.UnixTimeStamp());

            SelectQuery query = GetSelectQueryStub();
            query.AddCondition("group_id", group.Id);
            query.AddCondition("user_id", invitee.Id);

            DataTable table = Query(query);

            if (table.Rows.Count == 1)
            {
                return new GroupInvite(core, table.Rows[0]);
            }
            else
            {
                core.Db.RollBackTransaction();
                throw new Exception("Cannot create a new GroupInvite");
            }
        }
        void AccountGroupsMembershipsManage_MakeOfficer(object sender, ModuleModeEventArgs e)
        {
            SetTemplate("account_group_appoint_officer");

            long groupId;
            long userId;

            try
            {
                string[] idString = core.Http.Query["id"].Split(new char[] { ',' });
                groupId = long.Parse(idString[0]);
                userId = long.Parse(idString[1]);
            }
            catch
            {
                DisplayGenericError();
                return;
            }

            try
            {
                UserGroup thisGroup = new UserGroup(core, groupId);

                if (thisGroup.IsGroupOperator(LoggedInMember.ItemKey))
                {
                    try
                    {
                        User member = new User(core, userId);

                        if (thisGroup.IsGroupMember(member.ItemKey))
                        {
                            // all ok, don't really need to do much, so let's do it
                            template.Parse("S_ID", string.Format("{0},{1}", groupId, userId));
                            template.Parse("S_USERNAME", member.UserName);
                        }
                        else
                        {
                            core.Functions.ThrowError();
                            return;
                        }
                    }
                    catch
                    {
                        core.Functions.ThrowError();
                        return;
                    }
                }
                else
                {
                    core.Display.ShowMessage("Unauthorised", "You must be the group operator to appoint an operator.");
                    return;
                }
            }
            catch
            {
                core.Functions.ThrowError();
                return;
            }
        }
예제 #20
0
        protected void BeginGroupPage()
        {
            groupSlug = core.Http["gn"];

            try
            {
                primitive = new UserGroup(core, groupSlug);
            }
            catch (InvalidGroupException)
            {
                core.Functions.Generate404();
                return;
            }

            if (string.IsNullOrEmpty(Group.Domain) || Hyperlink.Domain == core.Http.Domain)
            {
                core.PagePath = core.PagePath.Substring(Group.Slug.Length + 1 + 6);
            }
            if (core.PagePath.Trim(new char[] { '/' }) == string.Empty)
            {
                core.PagePath = Group.GroupInfo.GroupHomepage;
            }
            if (core.PagePath.Trim(new char[] { '/' }) == string.Empty)
            {
                core.PagePath = "/profile";
            }

            if (core.Session.IsLoggedIn && Group.IsGroupMemberBanned(core.Session.LoggedInMember.ItemKey))
            {
                core.Functions.Generate403();
                return;
            }

            if (Group.GroupType == "PRIVATE" && (!core.Session.IsLoggedIn || !Group.IsGroupMember(core.Session.LoggedInMember.ItemKey)))
            {
                core.Functions.Generate403();
                return;
            }

            if (loggedInMember != null)
            {
                if (loggedInMember.UserInfo.ShowCustomStyles)
                {
                    template.Parse("USER_STYLE_SHEET", string.Format("group/{0}.css", Group.Key));
                }
            }
            else
            {
                template.Parse("USER_STYLE_SHEET", string.Format("group/{0}.css", Group.Key));
            }

            if (!string.IsNullOrEmpty(Group.Domain))
            {
                template.Parse("U_HOME", Group.Uri);
            }

            if (core.LoggedInMemberId > 0 && (!Group.IsGroupMember(core.Session.LoggedInMember.ItemKey)))
            {
                template.Parse("U_JOIN", Group.JoinUri);
            }

            template.Parse("U_REGISTER", core.Hyperlink.BuildRegisterUri(Group.Id));

            if (!core.PagePath.StartsWith("/account", StringComparison.Ordinal))
            {
                BoxSocial.Internals.Application.LoadApplications(core, AppPrimitives.Group, core.PagePath, BoxSocial.Internals.Application.GetApplications(core, Group));

                core.FootHooks += new Core.HookHandler(core_FootHooks);
                HookEventArgs e = new HookEventArgs(core, AppPrimitives.Group, Group);
                core.InvokeHeadHooks(e);
                core.InvokePrimitiveHeadHooks(e);
                core.InvokeFootHooks(e);
            }

            PageTitle = Group.DisplayName;

            core.Template.Parse("PRIMITIVE_THUMB", Owner.Thumbnail);
            core.Template.Parse("PRIMITIVE_ICON", Owner.Icon);
            core.Template.Parse("PRIMITIVE_TILE", Owner.Tile);
            core.Template.Parse("PRIMITIVE_SQUARE", Owner.Square);
            core.Template.Parse("PRIMITIVE_COVER_PHOTO", Owner.CoverPhoto);
            core.Template.Parse("PRIMITIVE_MOBILE_COVER_PHOTO", Owner.MobileCoverPhoto);
        }
        void AccountGroupsMembershipsManage_MakeOfficer_Save(object sender, EventArgs e)
        {
            long groupId = 0;
            long userId = 0;
            string title;

            try
            {
                string[] idString = core.Http.Form["id"].Split(new char[] { ',' });
                groupId = long.Parse(idString[0]);
                userId = long.Parse(idString[1]);
                title = core.Http.Form["title"];
            }
            catch
            {
                core.Functions.ThrowError();
                return;
            }

            if (string.IsNullOrEmpty(title))
            {
                core.Display.ShowMessage("Officer Title Empty", "The officer title must not be empty, go back and enter an officer title.");
                return;
            }
            else
            {
                if (title.Length < 4)
                {
                    core.Display.ShowMessage("Officer Title Too Short", "The officer title must be at least four characters, go back and enter an officer title.");
                    return;
                }
                else if (title.Length > 24)
                {
                    core.Display.ShowMessage("Officer Title Too Long", "The officer title must be at most twenty four characters, go back and enter an officer title.");
                    return;
                }
            }

            try
            {
                UserGroup thisGroup = new UserGroup(core, groupId);

                if (thisGroup.IsGroupOperator(LoggedInMember.ItemKey))
                {
                    try
                    {
                        User member = new User(core, userId);

                        if (thisGroup.IsGroupMember(member.ItemKey))
                        {
                            // allow to be an officer to many things
                            db.BeginTransaction();
                            long status = db.UpdateQuery(string.Format("INSERT INTO group_officers (group_id, user_id, officer_title) VALUES ({0}, {1}, '{2}');",
                                thisGroup.GroupId, member.UserId, Mysql.Escape(title)));

                            if (status >= 0)
                            {
                                db.UpdateQuery(string.Format("UPDATE group_info SET group_officers = group_officers + 1 WHERE group_id = {0}",
                                    thisGroup.GroupId));

                                SetRedirectUri(thisGroup.Uri);
                                core.Display.ShowMessage("Officer Appointed to Group", "You have successfully appointed an officer to the group.");
                            }
                            else
                            {
                                core.Display.ShowMessage("Already Officer", "This member is already appointed as this officer.");
                                return;
                            }
                        }
                        else
                        {
                            core.Functions.ThrowError();
                            return;
                        }
                    }
                    catch
                    {
                        core.Functions.ThrowError();
                        return;
                    }
                }
                else
                {
                    core.Display.ShowMessage("Unauthorised", "You must be the group operator to appoint an officer.");
                    return;
                }
            }
            catch
            {
                core.Functions.ThrowError();
                return;
            }
        }
예제 #22
0
        void AccountGroupsEdit_Save(object sender, EventArgs e)
        {
            AuthoriseRequestSid();

            long groupId;
            short category;
            string title;
            string description;
            string type;
            string homepage = "/profile";

            try
            {
                groupId = long.Parse(core.Http.Form["id"]);
                category = short.Parse(core.Http.Form["category"]);
                title = core.Http.Form["title"];
                description = core.Http.Form["description"];
                type = core.Http.Form["type"];
                homepage = core.Http.Form["homepage"];
            }
            catch
            {
                core.Display.ShowMessage("Error", "An error has occured, go back.");
                return;
            }

            switch (type)
            {
                case "open":
                    type = "OPEN";
                    break;
                case "request":
                    type = "REQUEST";
                    break;
                case "closed":
                    type = "CLOSED";
                    break;
                case "private":
                    type = "PRIVATE";
                    break;
                default:
                    core.Display.ShowMessage("Error", "An error has occured, go back.");
                    return;
            }

            UserGroup thisGroup = new UserGroup(core, groupId);

            if (!thisGroup.IsGroupOperator(LoggedInMember.ItemKey))
            {
                core.Display.ShowMessage("Cannot Edit Group", "You must be an operator of the group to edit it.");
                return;
            }
            else
            {

                // update the public viewcount is necessary
                if (type != "PRIVATE" && thisGroup.GroupType == "PRIVATE")
                {
                    db.BeginTransaction();
                    db.UpdateQuery(string.Format("UPDATE global_categories SET category_groups = category_groups + 1 WHERE category_id = {0}",
                        category));
                }
                else if (type == "PRIVATE" && thisGroup.GroupType != "PRIVATE")
                {
                    db.UpdateQuery(string.Format("UPDATE global_categories SET category_groups = category_groups - 1 WHERE category_id = {0}",
                        category));
                }

                if (homepage != "/profile" && homepage != "/blog")
                {
                    try
                    {
                        Page thisPage = new Page(core, thisGroup, homepage.TrimStart(new char[] { '/' }));
                    }
                    catch (PageNotFoundException)
                    {
                        homepage = "/profile";
                    }
                }

                // save the edits to the group
                db.UpdateQuery(string.Format("UPDATE group_info SET group_name_display = '{1}', group_category = {2}, group_abstract = '{3}', group_type = '{4}', group_home_page = '{5}' WHERE group_id = {0}",
                    thisGroup.GroupId, Mysql.Escape(title), category, Mysql.Escape(description), Mysql.Escape(type), Mysql.Escape(homepage)));

                SetRedirectUri(thisGroup.Uri);
                core.Display.ShowMessage("Group Saved", "You have successfully edited the group.");
                return;
            }
        }
        void AccountGroupsMembershipsManage_MakeOperator(object sender, ModuleModeEventArgs e)
        {
            AuthoriseRequestSid();

            long groupId;
            long userId;

            try
            {
                string[] idString = core.Http.Query["id"].Split(new char[] { ',' });
                groupId = long.Parse(idString[0]);
                userId = long.Parse(idString[1]);
            }
            catch
            {
                core.Display.ShowMessage("Error", "An error has occured, go back.");
                return;
            }

            try
            {
                UserGroup thisGroup = new UserGroup(core, groupId);

                if (thisGroup.IsGroupOperator(LoggedInMember.ItemKey))
                {
                    try
                    {
                        User member = new User(core, userId);
                        if (!thisGroup.IsGroupOperator(member.ItemKey))
                        {
                            db.BeginTransaction();
                            db.UpdateQuery(string.Format("INSERT INTO group_operators (group_id, user_id) VALUES ({0}, {1});",
                                thisGroup.GroupId, userId));

                            db.UpdateQuery(string.Format("UPDATE group_info SET group_operators = group_operators + 1 WHERE group_id = {0}",
                                thisGroup.GroupId));

                            SetRedirectUri(thisGroup.Uri);
                            core.Display.ShowMessage("Operator Appointed to Group", "You have successfully appointed an operator to the group.");
                        }
                        else
                        {
                            SetRedirectUri(thisGroup.Uri);
                            core.Display.ShowMessage("Already an Officer", "This member is already an officer.");
                            return;
                        }
                    }
                    catch
                    {
                        DisplayGenericError();
                        return;
                    }
                }
                else
                {
                    SetRedirectUri(thisGroup.Uri);
                    core.Display.ShowMessage("Unauthorised", "You must be the group operator to appoint an operator.");
                    return;
                }
            }
            catch
            {
                DisplayGenericError();
                return;
            }
        }
예제 #24
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string profileUserName = core.Http["un"];
            string groupUserName = core.Http["gn"];
            string applicationUserName = core.Http["an"];
            string mode = core.Http["mode"];
            bool retina = core.Http["retina"] == "true";
            User profileOwner = null;
            UserGroup thisGroup = null;
            ApplicationEntry anApplication = null;

            int width = 100;

            if (retina)
            {
                switch (mode)
                {
                    case "icon":
                        width = 100;
                        break;
                    case "tile":
                        width = 200;
                        break;
                    case "square":
                    case "high":
                        width = 400;
                        break;
                    case "tiny":
                        width = 160;
                        break;
                    case "thumb":
                        width = 320;
                        break;
                    case "mobile":
                        width = 640;
                        break;
                    case "display":
                        width = 1280;
                        break;
                    case "full":
                    case "ultra":
                        width = 2560;
                        break;
                }
            }
            else
            {
                switch (mode)
                {
                    case "icon":
                        width = 50;
                        break;
                    case "tile":
                        width = 100;
                        break;
                    case "square":
                        width = 200;
                        break;
                    case "high":
                        width = 400;
                        break;
                    case "tiny":
                        width = 80;
                        break;
                    case "thumb":
                        width = 160;
                        break;
                    case "mobile":
                        width = 320;
                        break;
                    case "display":
                        width = 640;
                        break;
                    case "full":
                        width = 1280;
                        break;
                    case "ultra":
                        width = 2560;
                        break;
                }
            }

            if (!string.IsNullOrEmpty(profileUserName))
            {
                try
                {

                    profileOwner = new User(core, profileUserName);
                }
                catch
                {
                    core.Functions.Generate404();
                    return;
                }

                if (profileOwner != null)
                {
                    if (profileOwner.UserInfo.DisplayPictureId > 0)
                    {
                        httpContext.Response.Redirect(string.Format("/memberpage.aspx?un={0}&path=/images/_{1}/_{0}.png", profileUserName, mode), true);
                        return;
                    }
                }
            }

            if (!string.IsNullOrEmpty(groupUserName))
            {
                try
                {

                    thisGroup = new UserGroup(core, groupUserName);
                }
                catch
                {
                    core.Functions.Generate404();
                    return;
                }

                if (thisGroup != null)
                {
                    if (thisGroup.GroupInfo.DisplayPictureId > 0)
                    {
                        httpContext.Response.Redirect(string.Format("/grouppage.aspx?gn={0}&path=/images/_{1}/_{0}.png", groupUserName, mode), true);
                        return;
                    }
                }
            }

            if (!string.IsNullOrEmpty(applicationUserName))
            {
                try
                {

                    anApplication = new ApplicationEntry(core, applicationUserName);
                }
                catch
                {
                    core.Functions.Generate404();
                    return;
                }

                if (anApplication != null)
                {
                    if (anApplication.GalleryIcon > 0)
                    {
                        httpContext.Response.Redirect(string.Format("/applicationpage.aspx?an={0}&path=/images/_{1}/_{0}.png", applicationUserName, mode), true);
                        return;
                    }
                }
            }

            Response.Cache.SetCacheability(HttpCacheability.Public);
            Response.Cache.SetMaxAge(new TimeSpan(10, 0, 0));
            Response.Cache.SetLastModified(DateTime.Now.Subtract(new TimeSpan(10, 0, 0)));
            Response.ContentType = "image/png";
            Response.Clear();

            Image image = null;

            string imagePath = string.Empty;

            if (!string.IsNullOrEmpty(profileUserName))
            {
                byte[] userBytes = System.Text.Encoding.UTF8.GetBytes(profileUserName);
                MD5 md5 = MD5.Create();
                int hash = BitConverter.ToInt32(md5.ComputeHash(userBytes), 0);

                image = Identicon.CreateIdenticon(hash, width, false);
                if (retina)
                {
                    imagePath = Path.Combine(Path.Combine(Path.Combine(Path.Combine(Server.MapPath("./"), "images"), "user"), "_" + mode), string.Format("{0}@2x.png",
                        profileUserName));
                }
                else
                {
                    imagePath = Path.Combine(Path.Combine(Path.Combine(Path.Combine(Server.MapPath("./"), "images"), "user"), "_" + mode), string.Format("{0}.png",
                        profileUserName));
                }
            }

            if (!string.IsNullOrEmpty(groupUserName))
            {
                byte[] userBytes = System.Text.Encoding.UTF8.GetBytes(groupUserName);
                MD5 md5 = MD5.Create();
                int hash = BitConverter.ToInt32(md5.ComputeHash(userBytes), 0);

                char letter = thisGroup.DisplayName.ToUpper()[0];
                image = CreateIcon(letter, width, false);
                if (retina)
                {
                    imagePath = Path.Combine(Path.Combine(Path.Combine(Path.Combine(Server.MapPath("./"), "images"), "group"), "_" + mode), string.Format("{0}@2x.png",
                        groupUserName));
                }
                else
                {
                    imagePath = Path.Combine(Path.Combine(Path.Combine(Path.Combine(Server.MapPath("./"), "images"), "group"), "_" + mode), string.Format("{0}.png",
                        groupUserName));
                }
            }

            if (!string.IsNullOrEmpty(applicationUserName))
            {
                byte[] userBytes = System.Text.Encoding.UTF8.GetBytes(applicationUserName);
                MD5 md5 = MD5.Create();
                int hash = BitConverter.ToInt32(md5.ComputeHash(userBytes), 0);

                char letter = anApplication.DisplayName.ToUpper()[0];
                image = CreateIcon(letter, width, false);
                if (retina)
                {
                    imagePath = Path.Combine(Path.Combine(Path.Combine(Path.Combine(Server.MapPath("./"), "images"), "application"), "_" + mode), string.Format("{0}@2x.png",
                        applicationUserName));
                }
                else
                {
                    imagePath = Path.Combine(Path.Combine(Path.Combine(Path.Combine(Server.MapPath("./"), "images"), "application"), "_" + mode), string.Format("{0}.png",
                        applicationUserName));
                }
            }

            try
            {
                FileStream newFileStream = new FileStream(imagePath, FileMode.Create);
                image.Save(newFileStream, ImageFormat.Png);
                newFileStream.Close();
            }
            catch { }

            MemoryStream newStream = new MemoryStream();
            image.Save(newStream, ImageFormat.Png);

            core.Http.WriteStream(newStream);

            if (db != null)
            {
                db.CloseConnection();
            }

            core.Prose.Close();
            //core.Dispose();
            //core = null;

            Response.End();
        }
        void AccountGroupsMembershipsManage_RemoveOfficer(object sender, ModuleModeEventArgs e)
        {
            AuthoriseRequestSid();

            long groupId;
            long userId;
            string title;

            try
            {
                string[] idString = core.Http.Query["id"].Split(new char[] { ',' });
                groupId = long.Parse(idString[0]);
                userId = long.Parse(idString[1]);
                title = UTF8Encoding.UTF8.GetString(Convert.FromBase64String(idString[2]));
            }
            catch
            {
                DisplayGenericError();
                return;
            }

            try
            {
                UserGroup thisGroup = new UserGroup(core, groupId);

                if (thisGroup.IsGroupOperator(LoggedInMember.ItemKey))
                {
                    db.BeginTransaction();
                    long deletedRows = db.UpdateQuery(string.Format("DELETE FROM group_officers WHERE group_id = {0} AND user_id = {1} AND officer_title = '{2}'",
                        groupId, userId, Mysql.Escape(title)));

                    if (deletedRows >= 0)
                    {
                        db.UpdateQuery(string.Format("UPDATE group_info SET group_officers = group_officers - {1} WHERE group_id = {0}",
                            thisGroup.GroupId, deletedRows));

                        SetRedirectUri(thisGroup.Uri);
                        core.Display.ShowMessage("Officer Removed from Group", "You have successfully removed an officer from the group.");
                    }
                    else
                    {
                        core.Display.ShowMessage("Error", "Could not delete officer, they may have already been delted.");
                        return;
                    }
                }
            }
            catch (InvalidGroupException)
            {
                DisplayGenericError();
                return;
            }
        }
예제 #26
0
        void AccountGroupsManage_Delete_Save(object sender, EventArgs e)
        {
            AuthoriseRequestSid();

            long groupId = core.Functions.RequestLong("id", -1);

            if (core.Display.GetConfirmBoxResult() == ConfirmBoxResult.Yes)
            {
                try
                {
                    UserGroup group = new UserGroup(core, groupId);

                    SetRedirectUri(BuildUri());
                    core.Display.ShowMessage("Cancelled", "This feature is currently not supported.");
                    return;
                }
                catch (InvalidGroupException)
                {
                    DisplayGenericError();
                    return;
                }
            }
            else
            {
                core.Display.ShowMessage("Cancelled", "You cancelled the deletion of the group.");
                return;
            }
        }
예제 #27
0
 public Forum(Core core, UserGroup owner, DataRow forumDataRow)
     : this(core, (ForumSettings)null, owner, forumDataRow)
 {
 }