public async Task <IViewComponentResult> InvokeAsync( ReportOptions options, ChartOptions chart) { if (options == null) { options = new ReportOptions(); } if (chart == null) { chart = new ChartOptions(); } var results = await _aggregatedMetricsRepository.SelectGroupedByStringAsync( "[Url]", options.Start, options.End, 100); if (results != null) { var url = await _contextFacade.GetBaseUrlAsync(); foreach (var result in results.Data) { result.Aggregate = result.Aggregate?.ToLower().Replace(url.ToLower(), ""); } } return(View(results)); }
// Share dialog public async Task <IActionResult> Index(EntityOptions opts) { // We always need an entity Id if (opts.Id <= 0) { throw new ArgumentOutOfRangeException(nameof(opts.Id)); } // We always need an entity var entity = await _entityStore.GetByIdAsync(opts.Id); if (entity == null) { return(NotFound()); } // Build route values RouteValueDictionary routeValues = null; // Append offset if (opts.ReplyId > 0) { routeValues = new RouteValueDictionary() { ["area"] = "Plato.Discuss", ["controller"] = "Home", ["action"] = "Reply", ["opts.id"] = entity.Id, ["opts.alias"] = entity.Alias, ["opts.replyId"] = opts.ReplyId }; } else { routeValues = new RouteValueDictionary() { ["area"] = "Plato.Discuss", ["controller"] = "Home", ["action"] = "Display", ["opts.id"] = entity.Id, ["opts.alias"] = entity.Alias }; } // Build view model var baseUrl = await _contextFacade.GetBaseUrlAsync(); var viewModel = new ShareViewModel { Url = baseUrl + _contextFacade.GetRouteUrl(routeValues) }; // Return view return(View(viewModel)); }
public async Task <ICommandResult <EmailMessage> > SendPasswordResetTokenAsync(IUser user) { // Get reset password email var culture = await _contextFacade.GetCurrentCultureAsync(); var email = await _localeStore.GetFirstOrDefaultByKeyAsync <LocaleEmail>(culture, "ResetPassword"); if (email != null) { // Build reset password link var baseUrl = await _contextFacade.GetBaseUrlAsync(); var callbackUrl = baseUrl + _contextFacade.GetRouteUrl(new RouteValueDictionary() { ["area"] = "Plato.Users", ["controller"] = "Account", ["action"] = "ResetPassword", ["code"] = user.ResetToken }); var body = string.Format(email.Message, user.DisplayName, callbackUrl); var message = new MailMessage() { Subject = email.Subject, Body = WebUtility.HtmlDecode(body), IsBodyHtml = true }; message.To.Add(user.Email); // send email return(await _emailManager.SaveAsync(message)); } var result = new CommandResult <EmailMessage>(); return(result.Failed("An error occurred whilst attempting to send the password reset token email.")); }
async Task <string> ParseEntityUrls(string html) { _baseUrl = await _contextFacade.GetBaseUrlAsync(); // Build extracted results var urls = TryGetUris(html); if (urls != null) { // Serialize results to return return(await urls.SerializeAsync()); } // No results found, return empty return(string.Empty); }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { if (!string.IsNullOrEmpty(Href)) { var isHttp = Href.IndexOf(Http, StringComparison.OrdinalIgnoreCase) >= 0; var isHttps = Href.IndexOf(Https, StringComparison.OrdinalIgnoreCase) >= 0; output.TagName = "link"; output.Attributes.SetAttribute("rel", RelValue); output.Attributes.SetAttribute("href", isHttp || isHttps ? Href : await _contextFacade.GetBaseUrlAsync() + Href); } else { output.SuppressOutput(); } }
public override async Task <IViewProviderResult> BuildDisplayAsync(Article entity, IViewProviderContext context) { // Build view model var baseUrl = await _contextFacade.GetBaseUrlAsync(); var viewModel = new ShareViewModel { Url = baseUrl + _contextFacade.GetRouteUrl(new RouteValueDictionary() { ["area"] = "Plato.Articles", ["controller"] = "Home", ["action"] = "Display", ["opts.id"] = entity.Id, ["opts.alias"] = entity.Alias }) }; return(Views( View <ShareViewModel>("Article.Share.Display.Sidebar", model => viewModel) .Zone("sidebar") .Order(int.MaxValue - 100) )); }
public async Task <IActionResult> Get( int page = 1, int size = 10, string sort = "CreatedDate", OrderBy order = OrderBy.Desc) { // Ensure we are authenticated var user = await base.GetAuthenticatedUserAsync(); if (user == null) { return(base.UnauthorizedException()); } // Get notifications var userNotifications = await GetUserNotifications( page, size, user.Id, sort, order); IPagedResults <UserNotificationApiResult> results = null; if (userNotifications != null) { results = new PagedResults <UserNotificationApiResult> { Total = userNotifications.Total }; var baseUrl = await _contextFacade.GetBaseUrlAsync(); foreach (var userNotification in userNotifications.Data) { var toUrl = baseUrl + _contextFacade.GetRouteUrl(new RouteValueDictionary() { ["area"] = "Plato.Users", ["controller"] = "Home", ["action"] = "Display", ["opts.id"] = userNotification.To.Id, ["opts.alias"] = userNotification.To.Alias }); var fromUrl = baseUrl + _contextFacade.GetRouteUrl(new RouteValueDictionary() { ["area"] = "Plato.Users", ["controller"] = "Home", ["action"] = "Display", ["opts.id"] = userNotification.From.Id, ["opts.alias"] = userNotification.From.Alias }); var url = userNotification.Url; if (url != null) { var noHttp = url.IndexOf("http://", StringComparison.OrdinalIgnoreCase) == -1; var noHttps = url.IndexOf("https://", StringComparison.OrdinalIgnoreCase) == -1; var relativeUrl = (noHttp && noHttps); if (relativeUrl) { url = baseUrl + url; } } results.Data.Add(new UserNotificationApiResult() { Id = userNotification.Id, To = new UserApiResult() { Id = userNotification.To.Id, DisplayName = userNotification.To.DisplayName, UserName = userNotification.To.UserName, Avatar = userNotification.To.Avatar, Url = toUrl }, From = new UserApiResult() { Id = userNotification.From.Id, DisplayName = userNotification.From.DisplayName, UserName = userNotification.From.UserName, Avatar = userNotification.From.Avatar, Url = fromUrl }, Title = userNotification.Title, Message = userNotification.Message, Url = url, Date = new FriendlyDate() { Text = userNotification.CreatedDate.ToPrettyDate(), Value = userNotification.CreatedDate } }); } } IPagedApiResults <UserNotificationApiResult> output = null; if (results != null) { output = new PagedApiResults <UserNotificationApiResult>() { Page = page, Size = size, Total = results.Total, TotalPages = results.Total.ToSafeCeilingDivision(size), Data = results.Data }; } return(output != null ? base.Result(output) : base.NoResults()); }
public async Task <IActionResult> Get( int page = 1, int size = 10, string keywords = "", SortBy sort = SortBy.LastReply, OrderBy order = OrderBy.Desc) { // Get search settings var searchSettings = await _searchSettingsStore.GetAsync(); // Set default sort column if auto is specified if (sort == SortBy.LastReply) { // Get search settings if (searchSettings != null) { sort = searchSettings.SearchType == SearchTypes.Tsql ? SortBy.LastReply : SortBy.Rank; } else { sort = SortBy.LastReply; } } // Get results var entities = await _searchService .ConfigureDb(o => { if (searchSettings != null) { o.SearchType = searchSettings.SearchType; } }) .ConfigureQuery(async q => { // Hide hidden? if (!await _authorizationService.AuthorizeAsync(HttpContext.User, Permissions.SearchHidden)) { q.HidePrivate.True(); } // Hide spam? if (!await _authorizationService.AuthorizeAsync(HttpContext.User, Permissions.SearchSpam)) { q.HideSpam.True(); } // Hide deleted? if (!await _authorizationService.AuthorizeAsync(HttpContext.User, Permissions.SearchDeleted)) { q.HideDeleted.True(); } // Hide private? if (!await _authorizationService.AuthorizeAsync(HttpContext.User, Permissions.SearchPrivate)) { q.HidePrivate.True(); } }) .GetResultsAsync(new EntityIndexOptions() { Search = keywords, Sort = sort, Order = order }, new PagerOptions() { Page = page, Size = size }); IPagedResults <SearchApiResult> results = null; if (entities != null) { results = new PagedResults <SearchApiResult> { Total = entities.Total }; var baseUrl = await _contextFacade.GetBaseUrlAsync(); foreach (var entity in entities.Data) { var url = baseUrl + _contextFacade.GetRouteUrl(new RouteValueDictionary() { ["area"] = entity.ModuleId, ["controller"] = "Home", ["action"] = "Display", ["opts.id"] = entity.Id, ["opts.alias"] = entity.Alias }); results.Data.Add(new SearchApiResult() { Id = entity.Id, CreatedBy = new UserApiResult() { Id = entity.CreatedBy.Id, DisplayName = entity.CreatedBy.DisplayName, UserName = entity.CreatedBy.UserName, Avatar = entity.CreatedBy.Avatar, Url = baseUrl + _contextFacade.GetRouteUrl(new RouteValueDictionary() { ["area"] = "Plato.Users", ["controller"] = "Home", ["action"] = "Display", ["opts.id"] = entity.CreatedBy.Id, ["opts.alias"] = entity.CreatedBy.Alias }) }, ModifiedBy = new UserApiResult() { Id = entity.ModifiedBy.Id, DisplayName = entity.ModifiedBy.DisplayName, UserName = entity.ModifiedBy.UserName, Avatar = entity.ModifiedBy.Avatar, Url = baseUrl + _contextFacade.GetRouteUrl(new RouteValueDictionary() { ["area"] = "Plato.Users", ["controller"] = "Home", ["action"] = "Display", ["opts.id"] = entity.ModifiedBy.Id, ["opts.alias"] = entity.ModifiedBy.Alias }) }, LastReplyBy = new UserApiResult() { Id = entity.LastReplyBy.Id, DisplayName = entity.LastReplyBy.DisplayName, UserName = entity.LastReplyBy.UserName, Avatar = entity.LastReplyBy.Avatar, Url = baseUrl + _contextFacade.GetRouteUrl(new RouteValueDictionary() { ["area"] = "Plato.Users", ["controller"] = "Home", ["action"] = "Display", ["opts.id"] = entity.LastReplyBy.Id, ["opts.alias"] = entity.LastReplyBy.Alias }) }, Title = entity.Title, Excerpt = entity.Abstract, Url = url, CreatedDate = new FriendlyDate() { Text = entity.CreatedDate.ToPrettyDate(), Value = entity.CreatedDate }, ModifiedDate = new FriendlyDate() { Text = entity.ModifiedDate.ToPrettyDate(), Value = entity.ModifiedDate }, LastReplyDate = new FriendlyDate() { Text = entity.LastReplyDate.ToPrettyDate(), Value = entity.LastReplyDate }, Relevance = entity.Relevance }); } } IPagedApiResults <SearchApiResult> output = null; if (results != null) { output = new PagedApiResults <SearchApiResult>() { Page = page, Size = size, Total = results.Total, TotalPages = results.Total.ToSafeCeilingDivision(size), Data = results.Data }; } return(output != null ? base.Result(output) : base.NoResults()); }
async Task <string> GetUrl() { return(await _contextFacade.GetBaseUrlAsync()); }
public async Task <IActionResult> Get( int page = 1, int size = 10, string keywords = "", string sort = "LastReplyDate", OrderBy order = OrderBy.Desc) { var entities = await GetEntities( page, size, keywords, sort, order); IPagedResults <EntityApiResult> results = null; if (entities != null) { results = new PagedResults <EntityApiResult> { Total = entities.Total }; var baseUrl = await _contextFacade.GetBaseUrlAsync(); foreach (var entity in entities.Data) { var createdByUrl = baseUrl + _contextFacade.GetRouteUrl(new RouteValueDictionary() { ["area"] = "Plato.Users", ["controller"] = "Home", ["action"] = "Display", ["opts.id"] = entity.CreatedBy.Id, ["opts.alias"] = entity.CreatedBy.Alias }); var modifiedByUrl = baseUrl + _contextFacade.GetRouteUrl(new RouteValueDictionary() { ["area"] = "Plato.Users", ["controller"] = "Home", ["action"] = "Display", ["opts.id"] = entity.ModifiedBy.Id, ["opts.alias"] = entity.ModifiedBy.Alias }); var url = _contextFacade.GetRouteUrl(new RouteValueDictionary() { ["area"] = entity.ModuleId, ["controller"] = "Home", ["action"] = "Display", ["opts.id"] = entity.Id, ["opts.alias"] = entity.Alias }); results.Data.Add(new EntityApiResult() { Id = entity.Id, CreatedBy = new UserApiResult() { Id = entity.CreatedBy.Id, DisplayName = entity.CreatedBy.DisplayName, UserName = entity.CreatedBy.UserName, Url = createdByUrl }, ModifiedBy = new UserApiResult() { Id = entity.ModifiedBy.Id, DisplayName = entity.ModifiedBy.DisplayName, UserName = entity.ModifiedBy.UserName, Url = modifiedByUrl }, LastReplyBy = new UserApiResult() { Id = entity.ModifiedBy.Id, DisplayName = entity.ModifiedBy.DisplayName, UserName = entity.ModifiedBy.UserName, Url = modifiedByUrl }, Title = entity.Title, Message = entity.Message, Url = url, CreatedDate = new FriendlyDate() { Text = entity.CreatedDate.ToPrettyDate(), Value = entity.CreatedDate } }); } } IPagedApiResults <EntityApiResult> output = null; if (results != null) { output = new PagedApiResults <EntityApiResult>() { Page = page, Size = size, Total = results.Total, TotalPages = results.Total.ToSafeCeilingDivision(size), Data = results.Data }; } return(output != null ? base.Result(output) : base.NoResults()); }
public async Task <IActionResult> Get( int page = 1, int size = 10, string keywords = "", string sort = "LastLoginDate", OrderBy order = OrderBy.Desc) { var users = await GetUsers( page, size, keywords, sort, order); IPagedResults <UserApiResult> results = null; if (users != null) { results = new PagedResults <UserApiResult> { Total = users.Total }; var baseUrl = await _contextFacade.GetBaseUrlAsync(); foreach (var user in users.Data) { var profileUrl = baseUrl + _contextFacade.GetRouteUrl(new RouteValueDictionary() { ["area"] = "Plato.Users", ["controller"] = "Home", ["action"] = "Display", ["opts.id"] = user.Id, ["opts.alias"] = user.Alias }); results.Data.Add(new UserApiResult() { Id = user.Id, DisplayName = user.DisplayName, UserName = user.UserName, Url = profileUrl, Avatar = user.Avatar }); } } IPagedApiResults <UserApiResult> output = null; if (results != null) { output = new PagedApiResults <UserApiResult>() { Page = page, Size = size, Total = results.Total, TotalPages = results.Total.ToSafeCeilingDivision(size), Data = results.Data }; } return(output != null ? base.Result(output) : base.NoResults()); }
public async Task <IActionResult> Get( int page = 1, int size = 10, int entityId = 0, int entityReplyId = 0, string sort = "CreatedDate", OrderBy order = OrderBy.Desc) { // Get histories var histories = await GetEntityHistory( page, size, entityId, entityReplyId, sort, order); IPagedResults <EntityHistoryApiResult> results = null; if (histories != null) { results = new PagedResults <EntityHistoryApiResult> { Total = histories.Total }; var baseUrl = await _contextFacade.GetBaseUrlAsync(); foreach (var history in histories.Data) { var createdByUrl = baseUrl + _contextFacade.GetRouteUrl(new RouteValueDictionary() { ["area"] = "Plato.Users", ["controller"] = "Home", ["action"] = "Display", ["opts.id"] = history.CreatedBy.Id, ["opts.alias"] = history.CreatedBy.Alias }); var sb = new StringBuilder(); sb.Append(history.CreatedBy.DisplayName) .Append(" ") .Append(history.MajorVersion == 1 && history.MinorVersion == 0 ? T["created"].Value : T["edited"].Value) .Append(" ") .Append(history.CreatedDate.ToPrettyDate()); results.Data.Add(new EntityHistoryApiResult() { Id = history.Id, Text = sb.ToString(), Version = history.Version, CreatedBy = new UserApiResult() { Id = history.CreatedBy.Id, DisplayName = history.CreatedBy.DisplayName, UserName = history.CreatedBy.UserName, Avatar = history.CreatedBy.Avatar, Url = createdByUrl }, Date = new FriendlyDate() { Text = history.CreatedDate.ToPrettyDate(), Value = history.CreatedDate } }); } } IPagedApiResults <EntityHistoryApiResult> output = null; if (results != null) { output = new PagedApiResults <EntityHistoryApiResult>() { Page = page, Size = size, Total = results.Total, TotalPages = results.Total.ToSafeCeilingDivision(size), Data = results.Data }; } return(output != null ? base.Result(output) : base.NoResults()); }
public async Task <IActionResult> Index([FromBody] TagApiParams parameters) { // Get tags var tags = await GetTags(parameters); // Build results IPagedResults <TagApiResult> results = null; if (tags != null) { // Get feature for tags IShellFeature feature = null; if (parameters.FeatureId > 0) { feature = await _shellFeatureStore.GetByIdAsync(parameters.FeatureId); } results = new PagedResults <TagApiResult> { Total = tags.Total }; var baseUrl = await _contextFacade.GetBaseUrlAsync(); foreach (var tag in tags.Data) { var url = _contextFacade.GetRouteUrl(new RouteValueDictionary() { ["area"] = feature?.ModuleId ?? "Plato.Tags", ["controller"] = "Home", ["action"] = "Tag", ["opts.id"] = tag.Id, ["opts.alias"] = tag.Alias }); results.Data.Add(new TagApiResult() { Id = tag.Id, Name = tag.Name, Entities = tag.TotalEntities.ToPrettyInt(), Follows = tag.TotalFollows.ToPrettyInt(), Url = url }); } } IPagedApiResults <TagApiResult> output = null; if (results != null) { output = new PagedApiResults <TagApiResult>() { Page = parameters.Page, Size = parameters.Size, Total = results.Total, TotalPages = results.Total.ToSafeCeilingDivision(parameters.Size), Data = results.Data }; } return(output != null ? base.Result(output) : base.NoResults()); }
public async Task <IActionResult> Get(LabelIndexOptions opts, PagerOptions pager) { if (opts == null) { opts = new LabelIndexOptions();; } if (pager == null) { pager = new PagerOptions(); } if (opts.Sort == LabelSortBy.Auto) { opts.Sort = LabelSortBy.Entities; opts.Order = OrderBy.Desc; } var labels = await _labelService.GetResultsAsync(opts, pager); PagedResults <LabelApiResult> results = null; if (labels != null) { results = new PagedResults <LabelApiResult> { Total = labels.Total }; var baseUrl = await _contextFacade.GetBaseUrlAsync(); foreach (var label in labels.Data) { var url = baseUrl + _contextFacade.GetRouteUrl(new RouteValueDictionary() { ["opts.labelId"] = label.Id, ["opts.alias"] = label.Alias }); results.Data.Add(new LabelApiResult() { Id = label.Id, Name = label.Name, Description = label.Description, ForeColor = label.ForeColor, BackColor = label.BackColor, Alias = label.Alias, TotalEntities = new FriendlyNumber() { Text = label.TotalEntities.ToPrettyInt(), Value = label.TotalEntities }, Rank = 0 }); } } LabelApiResults output = null; if (results != null) { output = new LabelApiResults() { Page = pager.Page, Size = pager.Size, Total = results.Total, TotalPages = results.Total.ToSafeCeilingDivision(pager.Size), Data = results.Data }; } return(output != null ? base.Result(output) : base.NoResults()); }
public async Task <IActionResult> IndexPost(SignUpViewModel model) { // Ensure default shell, We cannot sign-up from tenants if (!_shellSettings.IsDefaultShell()) { return(Unauthorized()); } // We are intentionally not using cross site request forgery protection // for this POST request, we need to allow trusted 3rd party sites to post here // Instead ensure the request is referred from a trusted site // Only allow posts from trusted domains var allowedReferers = new List <string>() { "http://instantasp.co.uk", "https://instantasp.co.uk", "http://www.instantasp.co.uk", "https://www.instantasp.co.uk", "http://plato.instantasp.co.uk", "https://plato.instantasp.co.uk", }; // Allow posts from our current host allowedReferers.Add(await _contextFacade.GetBaseUrlAsync()); // Check referee, not perfect and to be improved var request = HttpContext.Request; var header = request.GetTypedHeaders(); var referer = header.Referer?.ToString() ?? string.Empty; var allowReferer = false; foreach (var allowedReferer in allowedReferers) { if (referer.StartsWith(allowedReferer, StringComparison.OrdinalIgnoreCase)) { allowReferer = true; break; } } // The referee is not allowed if (!allowReferer) { return(Unauthorized()); } // Validate if (model == null) { throw new ArgumentNullException(nameof(model)); } if (string.IsNullOrEmpty(model.Email)) { throw new ArgumentNullException(nameof(model.Email)); } if (!ModelState.IsValid) { return(View(model)); } // Create sign-up var result = await _signUpManager.CreateAsync(new Models.SignUp() { Email = model.Email, EmailUpdates = model.EmailUpdates }); // Ensure sign-up was created successfully if (result.Succeeded) { // Send security token email var emailResult = await _signUpEmails.SendSecurityTokenAsync(result.Response); // Ensure email was sent successfully if (emailResult.Succeeded) { // Redirect to sign-up confirmation return(RedirectToAction(nameof(IndexConfirmation), new RouteValueDictionary() { ["sessionId"] = result.Response.SessionId.ToString() })); } else { foreach (var error in emailResult.Errors) { ViewData.ModelState.AddModelError(string.Empty, error.Description); } } } else { foreach (var error in result.Errors) { ViewData.ModelState.AddModelError(string.Empty, error.Description); } } // If we reach this point errors occurred return(View(model)); }
public async Task <ICommandResult <Question> > SendAsync(INotificationContext <Question> context) { // Ensure correct notification provider if (!context.Notification.Type.Name.Equals(EmailNotifications.NewMention.Name, StringComparison.Ordinal)) { return(null); } // We always need a model if (context.Model == null) { return(null); } // The entity should be visible if (context.Model.IsHidden()) { return(null); } // Create result var result = new CommandResult <Question>(); // Get email template const string templateId = "NewQuestionsMention"; // Tasks run in a background thread and don't have access to HttpContext // Create a dummy principal to represent the user so we can still obtain // the current culture for the email var principal = await _claimsPrincipalFactory.CreateAsync((User)context.Notification.To); var culture = await _contextFacade.GetCurrentCultureAsync(principal.Identity); var email = await _localeStore.GetFirstOrDefaultByKeyAsync <LocaleEmail>(culture, templateId); if (email != null) { // Build topic url var baseUri = await _contextFacade.GetBaseUrlAsync(); var url = _contextFacade.GetRouteUrl(new RouteValueDictionary() { ["area"] = "Plato.Questions", ["controller"] = "Home", ["action"] = "Display", ["opts.id"] = context.Model.Id, ["opts.alias"] = context.Model.Alias }); // Build message from template var message = email.BuildMailMessage(); message.Body = string.Format( email.Message, context.Notification.To.DisplayName, context.Model.Title, baseUri + url); message.IsBodyHtml = true; message.To.Add(new MailAddress(context.Notification.To.Email)); // Send message var emailResult = await _emailManager.SaveAsync(message); if (emailResult.Succeeded) { return(result.Success(context.Model)); } return(result.Failed(emailResult.Errors?.ToArray())); } return(result.Failed($"No email template with the Id '{templateId}' exists within the 'locales/{culture}/emails.json' file!")); }
public async Task <IActionResult> Get( int page = 1, int size = 10, string keywords = "", string sort = "TotalEntities", OrderBy order = OrderBy.Desc) { var tags = await GetTags( page, size, keywords, sort, order); IPagedResults <TagApiResult> results = null; if (tags != null) { results = new PagedResults <TagApiResult> { Total = tags.Total }; var baseUrl = await _contextFacade.GetBaseUrlAsync(); foreach (var tag in tags.Data) { var url = _contextFacade.GetRouteUrl(new RouteValueDictionary() { ["area"] = "Plato.Tags", ["controller"] = "Home", ["action"] = "Tag", ["opts.id"] = tag.Id, ["opts.alias"] = tag.Alias }); results.Data.Add(new TagApiResult() { Id = tag.Id, Name = tag.Name, Url = url }); } } IPagedApiResults <TagApiResult> output = null; if (results != null) { output = new PagedApiResults <TagApiResult>() { Page = page, Size = size, Total = results.Total, TotalPages = results.Total.ToSafeCeilingDivision(size), Data = results.Data }; } return(output != null ? base.Result(output) : base.NoResults()); }