private void setupServer(Application application) { ResourceConfig rc = new ApplicationAdapter(application); IDictionary <string, object> properties = new Dictionary <string, object>(); properties[ResourceConfig.FEATURE_TRACE] = "true"; rc.PropertiesAndFeatures = properties; Properties serverProperties = readProperties(); int port = int.Parse(serverProperties.getProperty(PORT_PROPERTY)); URI serverUri = UriBuilder.fromPath(ROOT_RESOURCE_PATH).scheme("http").host("localhost").port(port).build(); try { server = GrizzlyServerFactory.createHttpServer(serverUri, rc); } catch (System.ArgumentException e) { throw new ServerBootstrapException(e); } catch (System.NullReferenceException e) { throw new ServerBootstrapException(e); } catch (IOException e) { throw new ServerBootstrapException(e); } }
public override void Invoke(CreateSessionRequest request) { try { ApplicationAdapter applicationAdapter = MessageEngine.Instance.AdapterProxy.GetAdapterById("app") as ApplicationAdapter; if (MessageEngine.Instance.AdapterProxy.ResolveUriToEndPoint(new Uri("app://" + request.SessionId)) == null) { lock (Session.SyncLock) { Session.ClientIP = ((Uri)SourceMessage.Metadata.Read("ReceiveUri")).Host; Session.TerminalId = request.TerminalId; Session.ClientPlatform = request.ClientPlatform; Session.ClientVersion = request.ClientVersion; ApplicationAdapterEndPoint endPoint = applicationAdapter.StartApplication(request.ApplicationName, Session.Id); Session.ApplicationEndPoint = endPoint; } } CreateSessionResponse response = new CreateSessionResponse(); TransmitResponseMessage(response); } catch { SessionManager.Instance.DestroySession(request.SessionId); throw; } }
public async Task <ActionResult> ToggleMarkAsDone(int threadId = 0, int pageNo = 1) { var(result, thread) = await PerformSecurityCheckAsync(threadId, allowAnonymous : false); if (result != null) { return(result); } var userID = this.HttpContext.Session.GetUserID(); if (!(this.HttpContext.Session.CanPerformForumActionRight(thread.ForumID, ActionRights.FlagThreadAsDone) || (thread.StartedByUserID == userID))) { return(RedirectToAction("Index", "Home")); } if (thread.MarkedAsDone) { await ThreadManager.UnMarkThreadAsDoneAsync(thread.ThreadID, userID); } else { await ThreadManager.MarkThreadAsDoneAsync(thread.ThreadID); } ApplicationAdapter.InvalidateCachedNumberOfThreadsInSupportQueues(); return(RedirectToAction("Index", "Thread", new { threadId = threadId, pageNo = pageNo })); }
public async Task <ActionResult> DeleteUser_Perform(ActionWithUserSearchData data, string submitAction) { if (!this.HttpContext.Session.HasSystemActionRights() || !this.HttpContext.Session.HasSystemActionRight(ActionRights.UserManagement)) { return(RedirectToAction("Index", "Home")); } if (submitAction != "Delete") { return(RedirectToAction("Index", "Home")); } if (data.FindUserData.SelectedUserIDs == null || data.FindUserData.SelectedUserIDs.Count <= 0) { return(await DeleteUser_Find(data)); } int userIdToDelete = data.FindUserData.SelectedUserIDs.FirstOrDefault(); var user = await UserGuiHelper.GetUserAsync(userIdToDelete); bool result = await UserManager.DeleteUserAsync(userIdToDelete); if (result) { ApplicationAdapter.AddUserToListToBeLoggedOutByForce(user.NickName); } await FillUserDataForStateAsync(data.FindUserData, AdminFindUserState.PostAction, string.Empty, string.Empty); var viewData = new ActionWithUserSearchData(data.FindUserData); viewData.FinalActionResult = result ? "The user has been deleted" : "Deleting the user failed, perhaps you selected a user that couldn't be deleted?"; return(View("~/Views/Admin/DeleteUser.cshtml", viewData)); }
private async Task PerformResetPasswordAsync(ResetPasswordData data) { bool result = await UserManager.EmailPasswordResetLink(data.NickName, ApplicationAdapter.GetEmailData(this.Request.Host.Host, EmailTemplate.ResetPasswordLink)).ConfigureAwait(false); data.EmailSent = result; }
public async Task <ActionResult> Register(NewProfileData data) { if (!ModelState.IsValid) { return(View(data)); } data.Sanitize(); data.StripProtocolsFromUrls(); var nickNameExists = await UserGuiHelper.CheckIfNickNameExistAsync(data.NickName); if (nickNameExists) { ModelState.AddModelError("NickName", "NickName already exists"); return(View(data)); } var result = await UserManager.RegisterNewUserAsync(data.NickName, data.DateOfBirth, data.EmailAddress, data.EmailAddressIsPublic, data.IconURL, HnDGeneralUtils.GetRemoteIPAddressAsIP4String(this.HttpContext.Connection.RemoteIpAddress), data.Location, data.Occupation, data.Signature, data.Website, ApplicationAdapter.GetEmailData(this.Request.Host.Host, EmailTemplate.RegistrationReply), data.AutoSubscribeToThread, data.DefaultNumberOfMessagesPerPage); if (result > 0) { this.HttpContext.Session.UpdateUserSettings(data); return(RedirectToAction("Login", "Account")); } return(View(data)); }
private void FillMemoInformation(ThreadData container) { if (container.UserMayEditMemo && (container.Thread.Memo.Length > 0)) { // convert memo contents to HTML so it's displayed above the thread. container.MemoAsHTML = HnDGeneralUtils.TransformMarkdownToHtml(container.Thread.Memo, ApplicationAdapter.GetEmojiFilenamesPerName(), ApplicationAdapter.GetSmileyMappings()); } }
public async Task <ActionResult> Add([Bind(nameof(NewThreadData.MessageText), nameof(NewThreadData.ThreadSubject), nameof(NewThreadData.IsSticky), nameof(NewThreadData.Subscribe))] NewThreadData newThreadData, string submitButton, int forumId = 0) { if (submitButton != "Post") { // apparently canceled if (forumId <= 0) { return(RedirectToAction("Index", "Home")); } return(RedirectToAction("Index", "Forum", new { forumId = forumId })); } if (!ModelState.IsValid) { return(RedirectToAction("Index", "Home")); } var(userMayAddThread, forum, userMayAddStickThread) = await PerformAddThreadSecurityChecksAsync(forumId); if (!userMayAddThread) { return(RedirectToAction("Index", "Home")); } int newThreadId = 0; if (submitButton == "Post") { // allowed, proceed // parse message text to html var messageAsHtml = HnDGeneralUtils.TransformMarkdownToHtml(newThreadData.MessageText, ApplicationAdapter.GetEmojiFilenamesPerName(), ApplicationAdapter.GetSmileyMappings()); var(newThreadIdFromCall, newMessageId) = await ForumManager.CreateNewThreadInForumAsync(forumId, this.HttpContext.Session.GetUserID(), newThreadData.ThreadSubject, newThreadData.MessageText, messageAsHtml, userMayAddStickThread&& newThreadData.IsSticky, this.Request.Host.Host, forum.DefaultSupportQueueID, newThreadData.Subscribe); newThreadId = newThreadIdFromCall; ApplicationAdapter.InvalidateCachedNumberOfThreadsInSupportQueues(); if (this.HttpContext.Session.CheckIfNeedsAuditing(AuditActions.AuditNewThread)) { await SecurityManager.AuditNewThreadAsync(this.HttpContext.Session.GetUserID(), newThreadId); } _cache.Remove(CacheManager.ProduceCacheKey(CacheKeys.SingleForum, forumId)); } return(Redirect(this.Url.Action("Index", "Thread", new { threadId = newThreadId, pageNo = 1 }))); }
public async Task Invoke(HttpContext context) { var ipAddress = context.Connection.RemoteIpAddress; if (_cache != null) { var ipBans = await _cache.GetAllIPBansAsync(); var matchingIPBan = SecurityGuiHelper.GetIPBanMatchingUserIPAddress(ipBans, HnDGeneralUtils.GetRemoteIPAddressAsIP4String(ipAddress)); if (matchingIPBan != null) { context.Response.StatusCode = (int)HttpStatusCode.Forbidden; context.Response.Redirect(ApplicationAdapter.GetVirtualRoot() + "banned.html"); } } await _next.Invoke(context); }
public async Task <ActionResult> BanUnbanUser_Perform(ActionWithUserSearchData data, string submitAction) { if (!this.HttpContext.Session.HasSystemActionRights() || !this.HttpContext.Session.HasSystemActionRight(ActionRights.UserManagement)) { return(RedirectToAction("Index", "Home")); } if (submitAction != "ToggleBanFlag") { return(RedirectToAction("Index", "Home")); } if (data.FindUserData.SelectedUserIDs == null || data.FindUserData.SelectedUserIDs.Count <= 0) { return(await BanUnbanUser_Find(data)); } int userIdToToggleBanFlagOf = data.FindUserData.SelectedUserIDs.FirstOrDefault(); var(toggleResult, newBanFlagValue) = await UserManager.ToggleBanFlagValueAsync(userIdToToggleBanFlagOf); if (newBanFlagValue) { var user = await UserGuiHelper.GetUserAsync(userIdToToggleBanFlagOf); ApplicationAdapter.AddUserToListToBeLoggedOutByForce(user.NickName); } await FillUserDataForStateAsync(data.FindUserData, AdminFindUserState.PostAction, string.Empty, string.Empty); var viewData = new ActionWithUserSearchData(data.FindUserData); if (toggleResult) { viewData.FinalActionResult = newBanFlagValue ? "The user is now banned" : "The user has been unbanned"; } else { viewData.FinalActionResult = "Toggling the ban flag failed."; } return(View("~/Views/Admin/BanUnbanUser.cshtml", viewData)); }
public async Task <ActionResult> AddForum(AddEditForumData data, string submitAction) { if (!this.HttpContext.Session.HasSystemActionRights() || !this.HttpContext.Session.HasSystemActionRight(ActionRights.SystemManagement)) { return(RedirectToAction("Index", "Home")); } if (submitAction == "cancel") { return(RedirectToRoute("ManageForums")); } if (!ModelState.IsValid) { await ForumAdminController.FillDataSetsInModelObjectAsync(data); return(View("~/Views/Admin/AddForum.cshtml", data)); } data.Sanitize(); var welcomeMessageAsHtml = HnDGeneralUtils.TransformMarkdownToHtml(data.ForumEdited.NewThreadWelcomeText, ApplicationAdapter.GetEmojiFilenamesPerName(), ApplicationAdapter.GetSmileyMappings()); try { await ForumManager.CreateNewForumAsync(data.ForumEdited.SectionID, data.ForumEdited.ForumName, data.ForumEdited.ForumDescription, data.ForumEdited.HasRSSFeed, data.ForumEdited.DefaultSupportQueueID, data.ForumEdited.OrderNo, data.ForumEdited.MaxAttachmentSize, data.ForumEdited.MaxNoOfAttachmentsPerMessage, data.ForumEdited.NewThreadWelcomeText, welcomeMessageAsHtml); } catch (ORMQueryExecutionException ex) { ModelState.AddModelError("ForumName", "Save failed, likely due to the forum name not being unique. Please specify a unique forum name." + ex.Message); await ForumAdminController.FillDataSetsInModelObjectAsync(data); return(View("~/Views/Admin/AddForum.cshtml", data)); } return(View("~/Views/Admin/Forums.cshtml", data)); }