diff --git a/src/Yavsc.Org/Extensions/HostingExtensions.cs b/src/Yavsc.Org/Extensions/HostingExtensions.cs index 7c066df5..e986620f 100644 --- a/src/Yavsc.Org/Extensions/HostingExtensions.cs +++ b/src/Yavsc.Org/Extensions/HostingExtensions.cs @@ -18,6 +18,7 @@ using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.AspNetCore.Localization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Razor; +using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; @@ -1282,10 +1283,52 @@ ADD COLUMN IF NOT EXISTS ""Moderated"" boolean NOT NULL DEFAULT FALSE;"); app.UseFileServer(Config.AvatarsOptions); + app.Use(async (context, next) => + { + await next(); + + if (context.Response.StatusCode != StatusCodes.Status404NotFound + || context.Response.HasStarted + || !HttpMethods.IsGet(context.Request.Method) + || !context.Request.Path.StartsWithSegments(Constants.AvatarsPath, out var avatarFile)) + { + return; + } + + var webHostEnvironment = app.ApplicationServices.GetRequiredService(); + var fallbackAsset = ResolveAvatarFallbackAsset(avatarFile); + var fallbackFile = webHostEnvironment.WebRootFileProvider.GetFileInfo(fallbackAsset.TrimStart('/')); + if (!fallbackFile.Exists) + { + return; + } + + context.Response.StatusCode = StatusCodes.Status200OK; + context.Response.ContentType = "image/png"; + await context.Response.SendFileAsync(fallbackFile); + }); + app.UseFileServer(Config.GitOptions); app.UseStaticFiles(); return app; } + private static string ResolveAvatarFallbackAsset(PathString avatarFile) + { + var fileName = avatarFile.Value ?? string.Empty; + + if (fileName.EndsWith(".xs.png", StringComparison.OrdinalIgnoreCase)) + { + return "/images/Users/icon_user.xs.png"; + } + + if (fileName.EndsWith(".s.png", StringComparison.OrdinalIgnoreCase)) + { + return "/images/Users/icon_user.s.png"; + } + + return Constants.DefaultAvatar; + } + } diff --git a/src/Yavsc.Org/Views/Manage/Index.cshtml b/src/Yavsc.Org/Views/Manage/Index.cshtml index 2624c284..13b45339 100755 --- a/src/Yavsc.Org/Views/Manage/Index.cshtml +++ b/src/Yavsc.Org/Views/Manage/Index.cshtml @@ -2,6 +2,9 @@ @using System.Security.Claims @{ ViewBag.Title = "Manage your account"; + var avatarSrc = string.IsNullOrWhiteSpace(Model.UserName) + ? Yavsc.Constants.DefaultAvatar + : $"{Yavsc.Constants.AvatarsPath}/{Model.UserName}.s.png"; }

@ViewBag.Title

@@ -11,15 +14,15 @@
UserName:
- -
+ +
@Model.UserName [modifier]
E-mail
- -
+ +
@Model.EMail @if (Model.EmailConfirmed) { @@ -46,22 +49,22 @@
FullName:
-
- @Html.DisplayFor(m=>m.FullName) +
+ @Html.DisplayFor(m=>m.FullName) [modifier]
@if (Model.Roles.Count()>0) {
Roles:
-
+
@string.Join(", ",Model.Roles)
}
Password:
[@{if (Model.HasPassword) - {Change} else - {Create}}]
External Logins:
@@ -76,19 +79,19 @@ { Html.DisplayText("Set"); } - else + else { Html.DisplayText("Modify"); } } ] - +
Avatar:
- + [Modify] -
+
Vos cercles
(WIP) Ajouter suprimer des cercles @@ -115,8 +118,8 @@ Html.DisplayText("Modify");
Your posts:
@Model.PostsCounter
- -
TwoFactorAuthentication:
+ +
TwoFactorAuthentication:
@if (Model.TwoFactor) { @@ -139,19 +142,19 @@ Html.DisplayText("Modify"); } }
-
Calendar
-
+
Calendar
+
@Html.DisplayText(Model.HasDedicatedCalendar?"Yes":"No" ) @{ - if (Model.HasDedicatedCalendar) { + if (Model.HasDedicatedCalendar) { : @Model.DedicatedCalendarId } } [Select a Google calendar]
-
Credits:
-
+
Credits:
+
@(Model.Balance?.Credits ?? 0) € [Manage]
@@ -162,9 +165,9 @@ Html.DisplayText("Modify"); @if (Model.DiskQuota>0) { - @(((double)Model.DiskUsage/Model.DiskQuota).ToString("%#0")) : + @(((double)Model.DiskUsage/Model.DiskQuota).ToString("%#0")) : - } + } @(Model.DiskUsage.ToString("0,#")) / @(Model.DiskQuota.ToString("0,#")) diff --git a/src/Yavsc.Org/Views/Manage/SetAvatar.cshtml b/src/Yavsc.Org/Views/Manage/SetAvatar.cshtml index 71ad0f85..b9292434 100644 --- a/src/Yavsc.Org/Views/Manage/SetAvatar.cshtml +++ b/src/Yavsc.Org/Views/Manage/SetAvatar.cshtml @@ -1,9 +1,14 @@ -@model PerformerProfile -@{ ViewBag.Title = "Edit your avatar"; } +@model PerformerProfile +@{ ViewBag.Title = "Edit your avatar"; } +@{ + var previewAvatarSrc = string.IsNullOrWhiteSpace(User?.Identity?.Name) + ? Yavsc.Constants.DefaultAvatar + : $"{Yavsc.Constants.AvatarsPath}/{User.Identity.Name}.png"; +} @section header{ -} +} @section scripts{ } - +
diff --git a/src/Yavsc.Org/Views/Shared/DisplayTemplates/ApplicationUserLink.cshtml b/src/Yavsc.Org/Views/Shared/DisplayTemplates/ApplicationUserLink.cshtml index c3657f95..c85bd24d 100644 --- a/src/Yavsc.Org/Views/Shared/DisplayTemplates/ApplicationUserLink.cshtml +++ b/src/Yavsc.Org/Views/Shared/DisplayTemplates/ApplicationUserLink.cshtml @@ -1,5 +1,13 @@ +@using Yavsc.Abstract.Identity @model ApplicationUser -@if (Model!=null) { - +@if (Model != null) +{ + var avatarSrc = UserDisplayHelpers.AvatarSrc(Model); + if (avatarSrc.EndsWith(".s.png", StringComparison.Ordinal)) + { + avatarSrc = avatarSrc.Replace(".s.png", ".xs.png", StringComparison.Ordinal); + } + + } diff --git a/src/Yavsc.Org/Views/Shared/DisplayTemplates/IApplicationUser.cshtml b/src/Yavsc.Org/Views/Shared/DisplayTemplates/IApplicationUser.cshtml index 493eb5cd..f7a1515e 100644 --- a/src/Yavsc.Org/Views/Shared/DisplayTemplates/IApplicationUser.cshtml +++ b/src/Yavsc.Org/Views/Shared/DisplayTemplates/IApplicationUser.cshtml @@ -10,7 +10,7 @@ if (Model ==null || Model.UserName==null) } } else { - string avuri = "/Avatars/" + Model.UserName + ".s.png"; + string avuri = UserDisplayHelpers.AvatarSrc(Model);