public async Task <ProjectSecurityResult> ValidatePermissions( string projectId, string userName, string providedPassword, CancellationToken cancellationToken) { var displayName = string.Empty; var isAuthenticated = false; var canEditPosts = false; var canEditPages = false; var authUser = await userManager.FindByNameAsync(userName); if (authUser != null) { isAuthenticated = await userManager.CheckPasswordAsync(authUser, providedPassword); } if (isAuthenticated) { var claimsPrincipal = await signInManager.CreateUserPrincipalAsync(authUser); if (string.IsNullOrEmpty(projectId)) { projectId = claimsPrincipal.GetProjectId(); } if (string.IsNullOrEmpty(projectId)) { var project = await projectResolver.GetCurrentProjectSettings(cancellationToken); if (project != null) { projectId = project.Id; } } if (!string.IsNullOrEmpty(projectId)) { canEditPosts = await claimsPrincipal.CanEditBlog(projectId, authorizationService); canEditPages = await claimsPrincipal.CanEditPages(projectId, authorizationService); } //displayName = claimsPrincipal.GetDisplayName(); displayName = claimsPrincipal.Identity.Name; } var blogSecurity = new ProjectSecurityResult(displayName, projectId, isAuthenticated, canEditPosts, canEditPages); return(blogSecurity); }
private async Task <bool> EnsureSettings() { if (_currentSettings != null) { return(true); } _currentSettings = await _settingsResolver.GetCurrentProjectSettings(CancellationToken.None); if (_currentSettings != null) { return(true); } return(false); }
private async Task <bool> EnsureSettings() { if (currentSettings != null) { return(true); } currentSettings = await settingsResolver.GetCurrentProjectSettings(CancellationToken); if (currentSettings != null) { //if (context.User.Identity.IsAuthenticated) //{ // var userBlog = context.User.GetBlogId(); // if (!string.IsNullOrEmpty(userBlog)) // { // if (currentSettings.ProjectId == userBlog) { userIsBlogOwner = true; } // } //} return(true); } return(false); }
public async Task Handle(string projectId, string postId, CancellationToken cancellationToken = default(CancellationToken)) { var post = await _postQueries.GetPost(projectId, postId, cancellationToken); var project = await _projectSettingsResolver.GetCurrentProjectSettings(cancellationToken); var url = await _blogUrlResolver.ResolvePostUrl(post, project); var message = new PushMessageModel() { MessageType = "contentdelete", Body = "Content deleted", Data = url }; var queueItem = new PushQueueItem( message, BuiltInRecipientProviderNames.AllButCurrentUserPushNotificationRecipientProvider); queueItem.TenantId = post.BlogId; queueItem.RecipientProviderCustom1 = _userIdResolver.GetCurrentUserId(); _pushNotificationsQueue.Enqueue(queueItem); }
public async Task <string> GetUserTimeZoneId(CancellationToken cancellationToken = default(CancellationToken)) { var project = await _projectSettingsResolver.GetCurrentProjectSettings(cancellationToken); return(project.TimeZoneId); }
public async Task <IActionResult> Export() { var project = await _projectResolver.GetCurrentProjectSettings(CancellationToken.None); var articles = await _blogService.GetPosts(true); var baseUrl = string.Concat(HttpContext.Request.Scheme, "://", HttpContext.Request.Host.ToUriComponent()); var feedUrl = baseUrl + "api/rss"; var sb = new StringBuilder(); using (XmlWriter xmlWriter = XmlWriter.Create(sb, new XmlWriterSettings() { Async = true, Indent = true })) { var writer = new RssFeedWriter(xmlWriter); await writer.WriteTitle(project.Title); await writer.WriteDescription(".NET Foundation Blog"); if (!string.IsNullOrEmpty(project.LanguageCode)) { await writer.WriteLanguage(new CultureInfo(project.LanguageCode)); } foreach (var a in articles) { var postUrl = await _blogService.ResolvePostUrl(a); var item = new SyndicationItem() { Title = a.Title, Description = a.Content, Id = baseUrl + postUrl, Published = a.PubDate, LastUpdated = a.LastModified }; foreach (var c in a.Categories) { item.AddCategory(new SyndicationCategory(c)); } item.AddLink(new SyndicationLink(new Uri(baseUrl + postUrl))); //item.AddContributor(new SyndicationPerson("test", "*****@*****.**")); await writer.Write(item); } xmlWriter.Flush(); } var result = new ContentResult { ContentType = "application/xml", Content = sb.ToString(), StatusCode = 200 }; return(result); }