FIXME SR is private

This commit is contained in:
Paul Schneider 2023-03-19 17:57:55 +00:00
commit 123283f277
576 changed files with 75350 additions and 13070 deletions

View file

@ -1,7 +1,7 @@
using System;
using System.Linq;
using System.Collections.Generic;
using Microsoft.AspNet.Http;
using Microsoft.AspNetCore.Http;
using Yavsc.ViewModels.Account;
namespace Yavsc.Helpers
@ -12,7 +12,7 @@ namespace Yavsc.Helpers
throw new ArgumentNullException(nameof(context));
}
return from description in context.Authentication.GetAuthenticationSchemes()
return from description in context.GetExternalProviders()
where !string.IsNullOrEmpty(description.DisplayName)
select
( new YaAuthenticationDescription
@ -35,4 +35,4 @@ namespace Yavsc.Helpers
}
}
}

View file

@ -1,5 +1,5 @@
using System.Collections.Generic;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNetCore.Mvc;
using Yavsc.Models.Messaging;
namespace Yavsc.Helpers
@ -52,7 +52,7 @@ namespace Yavsc.Helpers
if (accepted == "application/json")
{
if (controller.ModelState.ErrorCount>0)
result = controller.HttpBadRequest(controller.ModelState);
result = controller.BadRequest(controller.ModelState);
else
result = controller.Ok(model);
return true;
@ -69,4 +69,4 @@ namespace Yavsc.Helpers
else return controller.View(viewname, model);
}
}
}
}

View file

@ -1,11 +1,9 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Data.Entity;

using Newtonsoft.Json.Linq;
namespace Yavsc.Helpers.Auth
{
using Microsoft.EntityFrameworkCore;
using Yavsc.Models;
using Yavsc.Models.Auth;
public static class ExternalAuthStoreHelper {

View file

@ -1,14 +1,9 @@
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Security.Claims;
using System.Threading;
using System.Web;
using Microsoft.AspNet.FileProviders;
using Microsoft.AspNet.Http;
using Microsoft.AspNetCore.Html;
using Microsoft.Extensions.FileProviders;
using Yavsc.Exceptions;
using Yavsc.Models;
using Yavsc.Models.FileSystem;
@ -314,5 +309,10 @@ namespace Yavsc.Helpers
var basename = flow.DifferedFileName.Substring(0,namelen);
return $"{basename}-{flow.SequenceNumber}{ext}";
}
public static void SaveAs(this IFormFile file, string destFileName)
{
throw new NotImplementedException();
}
}
}

View file

@ -23,8 +23,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Data.Entity;
using Microsoft.AspNet.Identity.EntityFramework;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
@ -37,6 +35,9 @@ using Yavsc.Models;
using Yavsc.Models.Calendar;
using Yavsc.Services;
using Yavsc.Server.Helpers;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Yavsc.Server.Models.Calendar;
namespace Yavsc.Helpers
{

View file

@ -1,6 +1,7 @@
using System;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Rendering;
using Yavsc.Models.Drawing;
namespace Yavsc.Helpers

View file

@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.Rendering;
using Yavsc.Models;
using Yavsc.Models.Workflow;
@ -19,4 +19,4 @@ namespace Yavsc.Helpers {
return items;
}
}
}
}

View file

@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.Extensions.Localization;
namespace Yavsc.Server.Helpers

View file

@ -2,16 +2,16 @@ using System.Collections.Generic;
using Microsoft.Extensions.Logging;
using Yavsc.Models.Billing;
using Microsoft.AspNet.Http;
using Microsoft.AspNetCore.Http;
using System.Threading.Tasks;
using Newtonsoft.Json;
using PayPal.PayPalAPIInterfaceService.Model;
using PayPal.PayPalAPIInterfaceService;
using Yavsc.ViewModels.PayPal;
using Yavsc.Models;
using Microsoft.Data.Entity;
using System.Linq;
using Yavsc.Models.Payment;
using Microsoft.EntityFrameworkCore;
namespace Yavsc.Helpers
{

View file

@ -1,12 +1,11 @@
using System.Collections.Generic;
using Microsoft.Extensions.Logging;
using Microsoft.AspNet.Http;
using Microsoft.AspNetCore.Http;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Yavsc.ViewModels;
using Yavsc.Models;
using Microsoft.Data.Entity;
using System.Linq;
namespace Yavsc.Helpers
@ -26,4 +25,4 @@ namespace Yavsc.Helpers
return host;
}
}
}
}

View file

@ -1,153 +0,0 @@
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using MarkdownDeep;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.Razor.TagHelpers;
namespace Yavsc.TagHelpers
{
[HtmlTargetElement("div", Attributes = MarkdownContentAttributeName)]
[HtmlTargetElement("h1", Attributes = MarkdownContentAttributeName)]
[HtmlTargetElement("h2", Attributes = MarkdownContentAttributeName)]
[HtmlTargetElement("h3", Attributes = MarkdownContentAttributeName)]
[HtmlTargetElement("p", Attributes = "ismarkdown")]
[HtmlTargetElement("div", Attributes = "ismarkdown")]
[HtmlTargetElement("h1", Attributes = "ismarkdown")]
[HtmlTargetElement("h2", Attributes = "ismarkdown")]
[HtmlTargetElement("h3", Attributes = "ismarkdown")]
[HtmlTargetElement("markdown")]
[OutputElementHint("p")]
public class MarkdownTagHelper : TagHelper
{
private const string MarkdownContentAttributeName = "markdown";
private const string MarkdownMarkAttributeName = "ismarkdown";
private const string SummaryMarkAttributeName = "summary";
[HtmlAttributeName("site")]
public SiteSettings Site { get; set; }
[HtmlAttributeName("base")]
public string Base { get; set; }
[HtmlAttributeName(MarkdownContentAttributeName)]
public string MarkdownContent { get; set; }
[HtmlAttributeName(SummaryMarkAttributeName)]
public int Summary { get; set; }
static Regex rxExtractLanguage = new Regex("^({{(.+)}}[\r\n])", RegexOptions.Compiled);
private static string FormatCodePrettyPrint(MarkdownDeep.Markdown m, string code)
{
// Try to extract the language from the first line
var match = rxExtractLanguage.Match(code);
string language = null;
if (match.Success)
{
// Save the language
var g = (Group)match.Groups[2];
language = g.ToString();
// Remove the first line
code = code.Substring(match.Groups[1].Length);
}
// If not specified, look for a link definition called "default_syntax" and
// grab the language from its title
if (language == null)
{
var d = m.GetLinkDefinition("default_syntax");
if (d != null)
language = d.title;
}
// Common replacements
if (language == "C#")
language = "csharp";
if (language == "C++")
language = "cpp";
// Wrap code in pre/code tags and add PrettyPrint attributes if necessary
if (string.IsNullOrEmpty(language))
return string.Format("<pre><code>{0}</code></pre>\n", code);
else
return string.Format("<pre class=\"prettyprint lang-{0}\"><code>{1}</code></pre>\n",
language.ToLowerInvariant(), code);
}
/// <summary>
/// Transforms a string of Markdown into HTML.
/// </summary>
/// <param name="text">The Markdown that should be transformed.</param>
/// <param name="urlBaseLocation">The url Base Location.</param>
/// <returns>The HTML representation of the supplied Markdown.</returns>
public string Markdown(string text, string urlBaseLocation = "")
{
// Transform the supplied text (Markdown) into HTML.
var markdownTransformer = GetMarkdownTransformer();
markdownTransformer.UrlBaseLocation = urlBaseLocation;
// Si seul un sommaire est demandé,
// s'assurer que la longueur du contenu ne dépasse pas de trop la longueur indiquée
if (Summary > 0)
{
if (text.Length > Summary + 28)
{
text = text.Substring(0, Summary + 28);
}
}
string html = markdownTransformer.Transform(text);
// Wrap the html in an MvcHtmlString otherwise it'll be HtmlEncoded and displayed to the user as HTML :(
return html;
}
internal Markdown GetMarkdownTransformer()
{
var markdownTransformer = new Markdown();
markdownTransformer.ExtraMode = true;
markdownTransformer.NoFollowLinks = true;
markdownTransformer.SafeMode = false;
markdownTransformer.FormatCodeBlock = FormatCodePrettyPrint;
markdownTransformer.ExtractHeadBlocks = true;
markdownTransformer.UserBreaks = true;
markdownTransformer.SummaryLength = Summary;
// TODO markdownTransformer.DoOnlyHtmlChunk = true;
return markdownTransformer;
}
public ModelExpression Content { get; set; }
public async override Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
if (output.TagName == "markdown")
{
output.TagName = null;
}
output.Attributes.RemoveAll("markdown");
var content = await GetContent(output);
var markdown = content;
var htbase = Base;
var html = Markdown(markdown, htbase);
output.Content.SetHtmlContent(html ?? "");
}
private async Task<string> GetContent(TagHelperOutput output)
{
if (MarkdownContent != null)
return MarkdownContent;
if (Content != null)
return Content.Model?.ToString();
return (await output.GetChildContentAsync(false)).GetContent();
}
}
}

View file

@ -2,13 +2,14 @@ using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.Mvc.ViewEngines;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewEngines;
namespace Yavsc.Helpers
{
using Microsoft.AspNetCore.Mvc.Infrastructure;
using ViewModels.Gen;
public class TeXString : HtmlString
{
@ -172,8 +173,8 @@ namespace Yavsc.Helpers
public static string RenderViewToString(
this Controller controller, IViewEngine engine,
IHttpContextAccessor httpContextAccessor,
string viewName, object model)
IActionContextAccessor contextAccessor,
string viewName, object model, bool isMainPage = true)
{
using (var sw = new StringWriter())
{
@ -182,19 +183,17 @@ namespace Yavsc.Helpers
// try to find the specified view
controller.TryValidateModel(model);
ViewEngineResult viewResult = engine.FindPartialView(controller.ActionContext, viewName);
ViewEngineResult viewResult = engine.FindView(contextAccessor.ActionContext, viewName, isMainPage);
// create the associated context
ViewContext viewContext = new ViewContext();
viewContext.ActionDescriptor = controller.ActionContext.ActionDescriptor;
viewContext.HttpContext = controller.ActionContext.HttpContext;
viewContext.ActionDescriptor = contextAccessor.ActionContext.ActionDescriptor;
viewContext.HttpContext = contextAccessor.ActionContext.HttpContext;
viewContext.TempData = controller.TempData;
viewContext.View = viewResult.View;
viewContext.Writer = sw;
// write the render view with the given context to the stringwriter
viewResult.View.RenderAsync(viewContext);
viewResult.EnsureSuccessful();
viewResult.View.RenderAsync(viewContext).Wait();
return sw.GetStringBuilder().ToString();
}
}

View file

@ -1,6 +1,7 @@
using System.Security.Claims;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Data.Entity;
using Microsoft.EntityFrameworkCore;
using Yavsc.Models;
using Yavsc.Models.Blog;
@ -9,6 +10,21 @@ namespace Yavsc.Helpers
public static class UserHelpers
{
public static string GetUserId(this ClaimsPrincipal user)
{
return user.FindFirstValue(ClaimTypes.NameIdentifier);
}
public static string GetUserName(this ClaimsPrincipal user)
{
return user.FindFirstValue(ClaimTypes.Name);
}
public static bool IsSignedIn(this ClaimsPrincipal user)
{
return user.Identity.IsAuthenticated;
}
public static IEnumerable<BlogPost> UserPosts(this ApplicationDbContext dbContext, string posterId, string readerId)
{
long[] readerCirclesMemberships = dbContext.Circle.Include(c=>c.Members).Where(c=>c.Members.Any(m=>m.MemberId == readerId))

View file

@ -4,7 +4,7 @@ namespace Yavsc.Helpers
{
using System.Collections.Generic;
using System.Linq;
using Microsoft.Data.Entity;
using Microsoft.EntityFrameworkCore;
using Yavsc.Models;
using Yavsc.Services;
using Yavsc.ViewModels.FrontOffice;