Ejemplo n.º 1
0
        /// <summary>
        /// Deletes a user tag.
        /// </summary>
        /// <param name="core">Core token</param>
        /// <param name="tagId">Tag Id to delete</param>
        /// <returns>True on success</returns>
        public static bool DeleteTag(Core core, long tagId)
        {
            DeleteQuery query = new DeleteQuery("user_tags");
            query.AddCondition("tag_id", tagId);
            query.AddCondition("user_id", core.LoggedInMemberId);

            if (core.Db.Query(query) == 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
Ejemplo n.º 2
0
        public static bool UnsubscribeFromItem(Core core, ItemKey itemKey)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            core.Db.BeginTransaction();

            SelectQuery query = Subscription.GetSelectQueryStub(core, typeof(Subscription));
            query.AddCondition("subscription_item_id", itemKey.Id);
            query.AddCondition("subscription_item_type_id", itemKey.TypeId);
            query.AddCondition("user_id", core.LoggedInMemberId);

            DataTable subscriptionDataTable = core.Db.Query(query);

            if (subscriptionDataTable.Rows.Count == 1)
            {
                DeleteQuery dQuery = new DeleteQuery(typeof(Subscription));
                dQuery.AddCondition("subscription_item_id", itemKey.Id);
                dQuery.AddCondition("subscription_item_type_id", itemKey.TypeId);
                dQuery.AddCondition("user_id", core.LoggedInMemberId);

                core.Db.Query(dQuery);

                ItemInfo info = new ItemInfo(core, itemKey);
                info.DecrementSubscribers();

                UpdateQuery uQuery = new UpdateQuery(typeof(UserInfo));
                uQuery.AddField("user_subscriptions", new QueryOperation("user_subscriptions", QueryOperations.Subtraction, 1));
                uQuery.AddCondition("user_id", core.LoggedInMemberId);
                core.Db.Query(uQuery);

                return true;
            }

            return false;
        }
Ejemplo n.º 3
0
        public void SessionEnd(string sessionId, long userId, DnsRecord record)
        {
            string cookieName = "hailToTheChef";
            //XmlSerializer xs;
            //StringWriter stw;

            if (!string.IsNullOrEmpty(sessionId))
            {
                if (!IsValidSid(sessionId))
                {
                    return;
                }
            }
            else
            {
                return;
            }

            //
            // Delete existing session
            //
            if (record == null)
            {
                db.UpdateQuery(string.Format("DELETE FROM user_sessions WHERE (session_string = '{0}' OR session_root_string = '{0}') AND user_id = {1};",
                    sessionId, userId));
            }
            else
            {
                SelectQuery query = new SelectQuery(typeof(Session));
                query.AddCondition("session_string", sessionId);
                query.AddCondition("user_id", userId);
                query.AddCondition("session_domain", record.Domain);

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

                List<string> rootSessionIds = new List<string>();
                while (sessionReader.Read())
                {
                    rootSessionIds.Add((string)sessionReader["session_root_string"]);
                }

                sessionReader.Close();
                sessionReader.Dispose();

                if (rootSessionIds.Count > 0)
                {
                    DeleteQuery dQuery = new DeleteQuery(typeof(Session));
                    QueryCondition qc1 = dQuery.AddCondition("session_string", ConditionEquality.In, rootSessionIds);
                    qc1.AddCondition(ConditionRelations.Or, "session_root_string", ConditionEquality.In, rootSessionIds);
                    dQuery.AddCondition("user_id", userId);

                    db.Query(dQuery);
                }
            }

            //
            // Remove this auto-login entry (if applicable)
            //

            //
            // We expect that message_die will be called after this function,
            // but just in case it isn't, reset $userdata to the details for a guest
            //

            if (record == null)
            {
                Response.Cookies.Clear();

                SelectQuery query = User.GetSelectQueryStub(core, UserLoadOptions.Info);
                query.AddCondition("user_keys.user_id", 0);

                DataTable userTable = db.Query(query);

                Response.Cookies.Clear();

                if (userTable.Rows.Count == 1)
                {
                    loggedInMember = new User(core, userTable.Rows[0], UserLoadOptions.Info);
                }
                HttpCookie newSessionDataCookie = new HttpCookie(cookieName + "_data");
                newSessionDataCookie.Path = "/";
                newSessionDataCookie.Value = "";
                newSessionDataCookie.Expires = DateTime.Now.AddYears(-1);
                newSessionDataCookie.Secure = core.Settings.UseSecureCookies && core.Hyperlink.CurrentDomain == Hyperlink.Domain;
                newSessionDataCookie.HttpOnly = true;
                Response.Cookies.Add(newSessionDataCookie);

                HttpCookie newSessionSidCookie = new HttpCookie(cookieName + "_sid");
                newSessionSidCookie.Path = "/";
                newSessionSidCookie.Value = "";
                newSessionSidCookie.Expires = DateTime.Now.AddYears(-1);
                newSessionSidCookie.Secure = core.Settings.UseSecureCookies && core.Hyperlink.CurrentDomain == Hyperlink.Domain;
                newSessionSidCookie.HttpOnly = true;
                Response.Cookies.Add(newSessionSidCookie);

                if (Request.Cookies[cookieName + "_sid"] == null && signInState != SessionSignInState.Bot)
                {
                    core.Hyperlink.SidUrls = true;
                }
            }

            return;
        }
Ejemplo n.º 4
0
        public static void ClearStale(Core core, string session, byte type)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            DeleteQuery dQuery = new DeleteQuery(GetTable(typeof(Confirmation)));
            dQuery.AddCondition("confirm_type", type);
            dQuery.AddCondition("session_id", session);

            core.Db.Query(dQuery);
        }
Ejemplo n.º 5
0
        public void Delete(Core core)
        {
            if (core.LoggedInMemberId == userId)
            {
                DeleteQuery dQuery = new DeleteQuery("events");
                dQuery.AddCondition("user_id", core.LoggedInMemberId);
                dQuery.AddCondition("event_id", EventId);

                db.BeginTransaction();
                db.Query(dQuery);

                dQuery = new DeleteQuery("event_invites");
                dQuery.AddCondition("event_id", EventId);

                if (db.Query(dQuery) < 0)
                {
                    throw new Exception();
                }
                else
                {
                    return;
                }
            }
            else
            {
                throw new NotLoggedInException();
            }
        }
Ejemplo n.º 6
0
 public override long Query(DeleteQuery query)
 {
     return UpdateQuery(query);
 }
Ejemplo n.º 7
0
 public void RemoveRecipient(User user, RecipientType type)
 {
     if (core.Session.SignedIn && (SenderId == core.Session.LoggedInMember.Id || user.Id == core.Session.LoggedInMember.Id))
     {
         DeleteQuery dQuery = new DeleteQuery(typeof(MessageRecipient));
         dQuery.AddCondition("message_id", Id);
         dQuery.AddCondition("user_id", user.Id);
         if (type != RecipientType.Any)
         {
             dQuery.AddCondition("recipient_type", (byte)type);
         }
         db.Query(dQuery);
     }
 }
Ejemplo n.º 8
0
        void AccountStatus_Delete(object sender, EventArgs e)
        {
            AuthoriseRequestSid();

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

            if (messageId > 0)
            {
                StatusMessage message = new StatusMessage(core, messageId);

                if (message.Owner.Id == Owner.Id)
                {
                    ItemKey messageKey = message.ItemKey;
                    long count = message.Delete();

                    DeleteQuery dQuery = new DeleteQuery(typeof(BoxSocial.Internals.Action));
                    dQuery.AddCondition("action_primitive_id", Owner.Id);
                    dQuery.AddCondition("action_primitive_type_id", Owner.TypeId);
                    dQuery.AddCondition("action_item_id", messageKey.Id);
                    dQuery.AddCondition("action_item_type_id", messageKey.TypeId);

                    core.Db.Query(dQuery);

                    core.Response.SendStatus("messageDeleted");
                    return;
                }
            }

            // IsAjax true
            core.Response.ShowMessage("permissionDenied", "Permission Denied", "You cannot delete this item.");
        }
Ejemplo n.º 9
0
        public static void LoadTagsIntoItem(Core core, NumberedItem item, List<long> tagIds, bool isNewItem)
        {
            if (isNewItem)
            {
                if (tagIds.Count == 0)
                {
                    return;
                }
            }

            List<Tag> itemTags = GetTags(core, item);
            List<long> itemTagIds = new List<long>();

            List<long> tagsToAdd = new List<long>();
            List<long> tagsToRemove = new List<long>();

            foreach (Tag tag in itemTags)
            {
                itemTagIds.Add(tag.Id);
                if (!tagIds.Contains(tag.Id))
                {
                    tagsToRemove.Add(tag.Id);
                }
            }

            foreach (long tagId in tagIds)
            {
                if (!itemTagIds.Contains(tagId))
                {
                    tagsToAdd.Add(tagId);
                }
            }

            if (tagsToAdd.Count > 0)
            {
                for (int i = 0; i < tagsToAdd.Count; i++)
                {
                    ItemTag.Create(core, item, tagsToAdd[i]);
                }

                UpdateQuery uQuery = new UpdateQuery(typeof(Tag));
                uQuery.AddField("tag_items", new QueryOperation("tag_items", QueryOperations.Addition, 1));
                uQuery.AddCondition("tag_id", ConditionEquality.In, tagsToAdd.ToArray());

                core.Db.Query(uQuery);
            }

            if (tagsToRemove.Count > 0)
            {
                DeleteQuery dQuery = new DeleteQuery(typeof(ItemTag));
                dQuery.AddCondition("tag_id", ConditionEquality.In, tagsToRemove.ToArray());
                dQuery.AddCondition("item_id", item.Id);
                dQuery.AddCondition("item_type_id", item.ItemKey.TypeId);

                core.Db.Query(dQuery);

                UpdateQuery uQuery = new UpdateQuery(typeof(Tag));
                uQuery.AddField("tag_items", new QueryOperation("tag_items", QueryOperations.Subtraction, 1));
                uQuery.AddCondition("tag_id", ConditionEquality.In, tagsToRemove.ToArray());

                core.Db.Query(uQuery);
            }
        }
Ejemplo n.º 10
0
        public static void LoadTagsIntoItem(Core core, NumberedItem item, string tagList, bool isNewItem)
        {
            if (isNewItem)
            {
                if (string.IsNullOrEmpty(tagList))
                {
                    return;
                }

                if (tagList.Trim(new char[] { ' ', '\t', ';', ',', ':', '.', '-', '(', ')', '<', '>', '[', ']', '{', '}', '|', '\\', '/' }).Length < 2)
                {
                    return;
                }
            }

            List<Tag> itemTags = GetTags(core, item);
            List<string> tagsListNormalised = new List<string>();
            List<string> tagsNormalised = new List<string>();
            List<string> tagsToAdd = new List<string>();
            List<string> tagsToAddNormalised = new List<string>();
            List<string> tagsToRemoveNormalised = new List<string>();
            List<string> tagsToLoad = new List<string>();

            int totalTags = 0;

            foreach (Tag tag in itemTags)
            {
                tagsListNormalised.Add(tag.TagTextNormalised);
            }

            string[] tags = tagList.Split(new char[] {' '});

            for (int i = 0; i < tags.Length; i++)
            {
                string tag = tags[i].Trim(new char[] { ',', ';', ' ' });
                string tagNormalised = string.Empty;
                NormaliseTag(tag, ref tagNormalised);

                if (!tagsListNormalised.Contains(tagNormalised))
                {
                    tagsListNormalised.Add(tagNormalised);
                    tagsToAddNormalised.Add(tagNormalised);
                    tagsToAdd.Add(tag);
                }

                tagsNormalised.Add(tagNormalised);

                totalTags++;
                /* Limit to 10 tags per item */
                if (totalTags == 10)
                {
                    break;
                }
            }

            foreach (Tag tag in itemTags)
            {
                if (!tagsNormalised.Contains(tag.TagTextNormalised))
                {
                    tagsToRemoveNormalised.Add(tag.TagTextNormalised);
                }
            }

            foreach (string tag in tagsToAddNormalised)
            {
                tagsToLoad.Add(tag);
            }

            foreach (string tag in tagsToRemoveNormalised)
            {
                tagsToLoad.Add(tag);
            }

            List<Tag> tagIds = GetTags(core, tagsToLoad.ToArray());
            Dictionary<string, Tag> tagIdsNormalised = new Dictionary<string, Tag>();

            foreach (Tag tag in tagIds)
            {
                tagIdsNormalised.Add(tag.TagTextNormalised, tag);
            }

            if (tagsToAddNormalised.Count > 0)
            {
                for (int i = 0; i < tagsToAddNormalised.Count; i++)
                {
                    if (!tagIdsNormalised.ContainsKey(tagsToAddNormalised[i]))
                    {
                        Tag newTag = Tag.Create(core, tagsToAdd[i]);
                        ItemTag.Create(core, item, newTag);
                    }
                    else
                    {
                        ItemTag.Create(core, item, tagIdsNormalised[tagsToAddNormalised[i]]);
                    }
                }

                UpdateQuery uQuery = new UpdateQuery(typeof(Tag));
                uQuery.AddField("tag_items", new QueryOperation("tag_items", QueryOperations.Addition, 1));
                uQuery.AddCondition("tag_text_normalised", ConditionEquality.In, tagsToAddNormalised.ToArray());

                core.Db.Query(uQuery);
            }

            if (tagsToRemoveNormalised.Count > 0)
            {
                List<long> tagToRemoveIds = new List<long>();
                foreach (string tag in tagsToRemoveNormalised)
                {
                    tagToRemoveIds.Add(tagIdsNormalised[tag].Id);
                }

                DeleteQuery dQuery = new DeleteQuery(typeof(ItemTag));
                dQuery.AddCondition("tag_id", ConditionEquality.In, tagToRemoveIds.ToArray());
                dQuery.AddCondition("item_id", item.Id);
                dQuery.AddCondition("item_type_id", item.ItemKey.TypeId);

                core.Db.Query(dQuery);

                UpdateQuery uQuery = new UpdateQuery(typeof(Tag));
                uQuery.AddField("tag_items", new QueryOperation("tag_items", QueryOperations.Subtraction, 1));
                uQuery.AddCondition("tag_id", ConditionEquality.In, tagToRemoveIds.ToArray());

                core.Db.Query(uQuery);
            }
        }
Ejemplo n.º 11
0
        public void UnBan()
        {
            DeleteQuery query = new DeleteQuery("group_members");
            query.AddCondition("user_id", userId);
            query.AddCondition("group_id", groupId);

            db.Query(query);
        }
Ejemplo n.º 12
0
        void Forum_ItemDeleted(object sender, ItemDeletedEventArgs e)
        {
            long postAdjust = forumPosts;
            long topicAdjust = forumTopics;
            List<long> parentIds = new List<long>();
            List<long> childIds = new List<long>();
            childIds.Add(Id);

            List<Forum> children = GetForums();

            /* Delete Children First */
            foreach (Forum child in children)
            {
                childIds.Add(child.Id);
                child.Delete(true);
            }

            if (!e.ParentDeleted)
            {
                foreach (ParentTreeNode parent in Parents.Nodes)
                {
                    parentIds.Add(parent.ParentId);
                }

                /* Update parent forums */
                {
                    UpdateQuery uQuery = new UpdateQuery(typeof(Forum));
                    uQuery.AddField("forum_posts", new QueryOperation("forum_posts", QueryOperations.Subtraction, postAdjust));
                    uQuery.AddField("forum_topics", new QueryOperation("forum_topics", QueryOperations.Subtraction, topicAdjust));
                    uQuery.AddCondition("forum_id", ConditionEquality.In, parentIds);

                    db.Query(uQuery);
                }

                /* Update forum statistics */
                {
                    UpdateQuery uQuery = new UpdateQuery(typeof(ForumSettings));
                    uQuery.AddField("forum_posts", new QueryOperation("forum_posts", QueryOperations.Subtraction, postAdjust));
                    uQuery.AddField("forum_topics", new QueryOperation("forum_topics", QueryOperations.Subtraction, topicAdjust));
                    uQuery.AddCondition("forum_item_id", ownerKey.Id);
                    uQuery.AddCondition("forum_item_type_id", ownerKey.TypeId);

                    db.Query(uQuery);
                }

                /* Delete topics */
                {
                    DeleteQuery dQuery = new DeleteQuery(typeof(ForumTopic));
                    dQuery.AddCondition("forum_id", ConditionEquality.In, childIds);

                    db.Query(dQuery);
                }

                /* Delete posts and update post counts */
                {
                    DeleteQuery dQuery = new DeleteQuery(typeof(TopicPost));
                    dQuery.AddCondition("forum_id", ConditionEquality.In, childIds);

                    db.Query(dQuery);
                }

                /* */
                {
                    DeleteQuery dQuery = new DeleteQuery(typeof(TopicReadStatus));
                    dQuery.AddCondition("forum_id", ConditionEquality.In, childIds);

                    db.Query(dQuery);
                }

                /* */
                {
                    DeleteQuery dQuery = new DeleteQuery(typeof(ForumReadStatus));
                    dQuery.AddCondition("forum_id", ConditionEquality.In, childIds);

                    db.Query(dQuery);
                }
            }
        }
Ejemplo n.º 13
0
        internal new long Delete()
        {
            DeleteQuery dQuery = new DeleteQuery(Item.GetTable(this.GetType()));
            dQuery.AddCondition("grant_primitive_id", PrimitiveKey.Id);
            dQuery.AddCondition("grant_primitive_type_id", PrimitiveKey.TypeId);
            dQuery.AddCondition("grant_item_id", ItemKey.Id);
            dQuery.AddCondition("grant_item_type_id", ItemKey.TypeId);
            dQuery.AddCondition("grant_permission_id", permissionId);

            long result = db.Query(dQuery);

            return result;
        }
Ejemplo n.º 14
0
        public bool Uninstall(Core core, Primitive viewer, Primitive owner, bool force)
        {
            if (this.ApplicationType != Internals.ApplicationType.Native) return false;

            if (!force)
            {
                if (isPrimitive)
                {
                    // Groups and Networks are primitive applications
                    return false;
                }

                switch (assemblyName.ToLower())
                {
                    case "profile":
                    case "networks":
                    case "groups":
                    case "gallery":
                    case "mail":
                        return false;
                    case "calendar":
                        if (owner.ItemKey.Equals(viewer.ItemKey))
                        {
                            return false;
                        }
                        break;
                }
            }

            if (HasInstalled(core, owner))
            {
                Application newApplication = Application.GetApplication(core, owner.AppPrimitive, this);

                Dictionary<string, PageSlugAttribute> slugs = newApplication.GetPageSlugs(owner.AppPrimitive);

                foreach (string slug in slugs.Keys)
                {
                    Page page = new Page(core, owner, slug, string.Empty);
                    page.Delete();
                }

                DeleteQuery dQuery = new DeleteQuery(typeof(PrimitiveApplicationInfo));
                dQuery.AddCondition("application_id", Id);
                dQuery.AddCondition("item_id", owner.Id);
                dQuery.AddCondition("item_type_id", owner.TypeId);

                if (core.Db.Query(dQuery) > 0)
                {
                    return true;
                }
            }
            return false;
        }
Ejemplo n.º 15
0
        public bool Deauthorise(Core core, Primitive viewer, Primitive owner)
        {
            if (this.ApplicationType != Internals.ApplicationType.OAuth) return false;

            try
            {
                PrimitiveApplicationInfo pai = new PrimitiveApplicationInfo(core, owner, this.Id);

                OAuthToken token = new OAuthToken(core, pai.OAuthAccessToken);
                token.UseToken();
                token.Update();

                DeleteQuery dQuery = new DeleteQuery(typeof(PrimitiveApplicationInfo));
                dQuery.AddCondition("application_id", Id);
                dQuery.AddCondition("item_id", owner.Id);
                dQuery.AddCondition("item_type_id", owner.TypeId);

                if (core.Db.Query(dQuery) > 0)
                {
                    return true;
                }
            }
            catch (InvalidPrimitiveAppInfoException)
            {
            }
            catch (InvalidOAuthTokenException)
            {
            }

            return false;
        }