/// <summary> /// Deletes a user, and reassigns any content created by that user to another existing user /// </summary> public static bool DeleteUser(IGraffitiUser user, IGraffitiUser userToAssumeContent, out string errorMessage) { if (!controller.CanDeleteUsers) { errorMessage = "The membership system in use does not support deleting users."; return(false); } if (user == null) { throw new Exception("The supplied user object is null and cannot be deleted"); } // Check if the user has created any content PostCollection pc = new PostCollection(); Query q = Post.CreateQuery(); q.AndWhere(Post.Columns.UserName, user.Name); pc.LoadAndCloseReader(q.ExecuteReader()); if (pc != null && pc.Count > 0) { if (userToAssumeContent == null) { errorMessage = "The user you are trying to delete has created posts. Another existing user must be selected to assign these posts to."; return(false); } foreach (Post p in pc) { if (p.UserName == user.Name) { p.UserName = userToAssumeContent.Name; } if (p.ModifiedBy == user.Name) { p.ModifiedBy = userToAssumeContent.Name; } if (p.CreatedBy == user.Name) { p.CreatedBy = userToAssumeContent.Name; } } } // Remove from roles if (user.Roles != null && user.Roles.Length > 0) { foreach (string roleName in user.Roles) { controller.RemoveUserFromRole(user.Name, roleName); } ZCache.RemoveByPattern("usersByRole-"); } controller.DeleteUser(user); ZCache.RemoveCache("user-" + user.Name.ToLower()); errorMessage = string.Empty; return(true); }
protected override void AfterCommit() { base.AfterCommit(); Post.UpdateCommentCount(PostId); if (!DontSendEmail) { try { EmailTemplateToolboxContext etc = new EmailTemplateToolboxContext(); etc.Put("comment", this); EmailTemplate ef = new EmailTemplate(); ef.Context = etc; ef.Subject = "New Comment: " + Post.Title; ef.To = Post.User.Email; ef.TemplateName = "comment.view"; ef.ReplyTo = ((this.Email == "") ? Post.User.Email : this.Email); Emailer.Send(ef); Log.Info("Comment Sent", "Email sent to {0} ({1}) from the post \"{2}\" ({3}).", Post.User.ProperName, Post.User.Email, Post.Title, Post.Id); } catch (Exception ex) { Log.Error("Email Failure", ex.Message); } } ZCache.RemoveCache("Comments-" + PostId); ZCache.RemoveByPattern("Comments-Recent"); }
protected override void AfterRemove(bool isDestroy) { Core.Post.UpdateCommentCount(this.PostId); ZCache.RemoveCache("Comments-" + PostId); ZCache.RemoveByPattern("Comments-Recent"); }
protected override void AfterCommit() { base.AfterCommit(); //Update the number of posts per category CategoryController.UpdatePostCounts(); //PostController.UpdateVersionCount(Id); //Save tags per post Tag.Destroy(Tag.Columns.PostId, Id); if (TagList != null) { foreach (string t in Util.ConvertStringToList(TagList)) { Tag tag = new Tag(); tag.Name = t.Trim(); tag.PostId = Id; tag.Save(); } } WritePages(); ZCache.RemoveByPattern("Posts-"); ZCache.RemoveCache("Post-" + Id); }
public static void UpdatePostStatus(int id, PostStatus status) { //UpdateVersionCount(id); QueryCommand command = new QueryCommand("Update graffiti_Posts Set Status = " + DataService.Provider.SqlVariable("Status") + " Where Id = " + DataService.Provider.SqlVariable("Id")); List <Parameter> parameters = Post.GenerateParameters(); command.Parameters.Add(Post.FindParameter(parameters, "Status")).Value = (int)status; command.Parameters.Add(Post.FindParameter(parameters, "Id")).Value = id; DataService.ExecuteNonQuery(command); ZCache.RemoveByPattern("Posts-"); ZCache.RemoveCache("Post-" + id); }
/// <summary> /// Creates a new user. UserName and Email must be unique. /// </summary> public static IGraffitiUser CreateUser(string username, string password, string email, string role) { username = username.ToLower(); controller.CreateUser(username, password, email, role); if (role != null) { ZCache.RemoveCache("usersByRole-" + role); ZCache.RemoveByPattern("usersByRole-"); } IGraffitiUser user = GetUser(username); Events.Instance().ExecuteAfterNewUser(user); return(user); }
/// <summary> /// Renames a user account /// </summary> public static void RenameUser(string oldUserName, string newUserName) { if (!controller.CanDeleteUsers) { throw new Exception("The membership system in use does not support deleting users"); } IGraffitiUser user = GetUser(oldUserName); if (user == null) { throw new Exception("The supplied username does not exist!"); } oldUserName = oldUserName.ToLower(); newUserName = newUserName.ToLower(); controller.RenameUser(oldUserName, newUserName); // Check if the user has created/modified any content PostCollection pc = new PostCollection(); Query q = Post.CreateQuery(); q.OrWhere(Post.Columns.UserName, oldUserName); q.OrWhere(Post.Columns.CreatedBy, oldUserName); q.OrWhere(Post.Columns.ModifiedBy, oldUserName); pc.LoadAndCloseReader(q.ExecuteReader()); if (pc != null && pc.Count > 0) { foreach (Post p in pc) { if (p.UserName == oldUserName) { p.UserName = newUserName; } if (p.ModifiedBy == oldUserName) { p.ModifiedBy = newUserName; } if (p.CreatedBy == oldUserName) { p.CreatedBy = newUserName; } p.Save(); } } // Check if user has created any comments CommentCollection cc = new CommentCollection(); q = Comment.CreateQuery(); q.OrWhere(Comment.Columns.UserName, oldUserName); q.OrWhere(Comment.Columns.CreatedBy, oldUserName); q.OrWhere(Comment.Columns.ModifiedBy, oldUserName); cc.LoadAndCloseReader(q.ExecuteReader()); if (cc != null && cc.Count > 0) { foreach (Comment c in cc) { if (c.UserName == oldUserName) { c.UserName = newUserName; } if (c.ModifiedBy == oldUserName) { c.ModifiedBy = newUserName; } if (c.CreatedBy == oldUserName) { c.CreatedBy = newUserName; } c.Save(); } } //Check if the user has created any post versions VersionStoreCollection vsc = new VersionStoreCollection(); vsc = VersionStoreCollection.FetchAll(); if (vsc != null && vsc.Count > 0) { foreach (VersionStore v in vsc) { Post vp = ObjectManager.ConvertToObject <Graffiti.Core.Post>(v.Data); if (v.CreatedBy == oldUserName) { v.CreatedBy = newUserName; } if (v.Type == "post/xml") { if (vp.UserName == oldUserName) { vp.UserName = newUserName; } if (vp.ModifiedBy == oldUserName) { vp.ModifiedBy = newUserName; } if (vp.CreatedBy == oldUserName) { vp.CreatedBy = newUserName; } v.Data = vp.ToXML(); } v.Save(); } } ZCache.RemoveCache("user-" + oldUserName); // Clear roles cache if (user.Roles != null && user.Roles.Length > 0) { ZCache.RemoveByPattern("usersByRole-"); } }