public SettingsModel(ShoutBoxModuleSettings settings) { AllowAnonymous = settings.AllowAnonymous; FloodVoting = settings.FloodVoting; FloodReply = settings.FloodReply; FloodNewPost = settings.FloodNewPost; ProfileImageSource = settings.ProfileImageSource; RecordLimit = settings.NumberOfPostsToReturn; }
public HttpResponseMessage GetShouts() { int moduleId = Request.FindModuleId(); int tabId = Request.FindTabId(); bool allowEdit = false; bool allowInput = true; ShoutBoxModuleSettings.ProfileImage profileImg = 0; Log.DebugFormat("moduleId:{0}, tabId:{1}", moduleId, tabId); var moduleSettings = new ShoutBoxModuleSettings(moduleId, tabId); allowInput = moduleSettings.AllowAnonymous; profileImg = moduleSettings.ProfileImageSource; var posts = _repository .GetDisplayPosts(moduleId, moduleSettings.NumberOfPostsToReturn); if (this.UserInfo != null) { //work out if the userinfo //object has edit permission on this module var moduleInfo = ModuleController.Instance.GetModule(moduleId, this.Request.FindTabId(), false); allowEdit = ModulePermissionController .HasModuleAccess(SecurityAccessLevel.Edit, null, moduleInfo); //if we don't allow anonymous check to see if we are auth'd if (!allowInput) { allowInput = this.UserInfo != null && this.UserInfo.UserID > 0; } } Log.DebugFormat("Sending {0} posts to the client", posts.Count()); var response = new { success = true, data = new { posts = posts.ToArray(), allowEdit = allowEdit, allowInput = allowInput, profileImage = profileImg } }; return(this.Request.CreateResponse(response)); }
public HttpResponseMessage SaveSettings(SettingsModel settings) { var moduleSettings = new ShoutBoxModuleSettings(Request.FindModuleId(), Request.FindTabId()); moduleSettings.AllowAnonymous = settings.AllowAnonymous; moduleSettings.FloodNewPost = settings.FloodNewPost; moduleSettings.FloodReply = settings.FloodReply; moduleSettings.FloodVoting = settings.FloodVoting; moduleSettings.ProfileImageSource = settings.ProfileImageSource; moduleSettings.NumberOfPostsToReturn = settings.RecordLimit; var response = new { success = true }; return(Request.CreateResponse(response)); }
public HttpResponseMessage NewPost(string post) { var success = false; var message = string.Empty; var userId = -1; var moduleId = this.Request.FindModuleId(); var tabId = this.Request.FindTabId(); var moduleSettings = new ShoutBoxModuleSettings(moduleId, tabId); if (this.UserInfo != null && this.UserInfo.UserID > 0) { userId = this.UserInfo.UserID; } //validate the post for profanity if (ValidatePostForProfanity(post)) { var floodControl = new FloodControl(this.Request.FindModuleId(), this.Request.FindTabId(), this.Request.GetIPAddress(), this.UserInfo); if (floodControl.AllowNewPost()) { success = true; _repository.AddPost(new ShoutPost() { ModuleId = moduleId, CreatedDate = DateTime.Now, VoteDown = 0, VoteUp = 0, UserId = userId > 0 ? (int?)userId : null, Message = post }); Log.Debug("New post has been saved"); } else { Log.WarnFormat("Flood control block the new post. The IP:{0} has already posted a new item in the time limit window", this.Request.GetIPAddress()); message = message = Localization.GetString("FloodControlNewPost.Text", SharedResource); } } else { Log.WarnFormat("The new post was not saved due to profanity. The IP:{0}", this.Request.GetIPAddress()); message = Localization.GetString("ProfanityBanned.Text", SharedResource); } var posts = _repository .GetDisplayPosts(moduleId, moduleSettings.NumberOfPostsToReturn); return(Request.CreateResponse(new { success = success, message = message, data = new { posts = posts.ToArray() } })); }