ensure the avatar path
This commit is contained in:
parent
e788910826
commit
0d784e919c
5 changed files with 88 additions and 29 deletions
|
|
@ -18,6 +18,7 @@ using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
||||||
using Microsoft.AspNetCore.Localization;
|
using Microsoft.AspNetCore.Localization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.Razor;
|
using Microsoft.AspNetCore.Mvc.Razor;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
|
@ -1282,10 +1283,52 @@ ADD COLUMN IF NOT EXISTS ""Moderated"" boolean NOT NULL DEFAULT FALSE;");
|
||||||
|
|
||||||
app.UseFileServer(Config.AvatarsOptions);
|
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<IWebHostEnvironment>();
|
||||||
|
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.UseFileServer(Config.GitOptions);
|
||||||
app.UseStaticFiles();
|
app.UseStaticFiles();
|
||||||
return app;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,9 @@
|
||||||
@using System.Security.Claims
|
@using System.Security.Claims
|
||||||
@{
|
@{
|
||||||
ViewBag.Title = "Manage your account";
|
ViewBag.Title = "Manage your account";
|
||||||
|
var avatarSrc = string.IsNullOrWhiteSpace(Model.UserName)
|
||||||
|
? Yavsc.Constants.DefaultAvatar
|
||||||
|
: $"{Yavsc.Constants.AvatarsPath}/{Model.UserName}.s.png";
|
||||||
}
|
}
|
||||||
|
|
||||||
<h2>@ViewBag.Title</h2>
|
<h2>@ViewBag.Title</h2>
|
||||||
|
|
@ -11,15 +14,15 @@
|
||||||
<hr />
|
<hr />
|
||||||
<dl class="dl-horizontal">
|
<dl class="dl-horizontal">
|
||||||
<dt>UserName:</dt>
|
<dt>UserName:</dt>
|
||||||
|
|
||||||
<dd>
|
<dd>
|
||||||
@Model.UserName
|
@Model.UserName
|
||||||
<a asp-action="SetUserName">[modifier]</a>
|
<a asp-action="SetUserName">[modifier]</a>
|
||||||
</dd>
|
</dd>
|
||||||
|
|
||||||
<dt>E-mail</dt>
|
<dt>E-mail</dt>
|
||||||
|
|
||||||
<dd>
|
<dd>
|
||||||
@Model.EMail
|
@Model.EMail
|
||||||
|
|
||||||
@if (Model.EmailConfirmed) {
|
@if (Model.EmailConfirmed) {
|
||||||
|
|
@ -46,22 +49,22 @@
|
||||||
|
|
||||||
|
|
||||||
<dt>FullName:</dt>
|
<dt>FullName:</dt>
|
||||||
<dd>
|
<dd>
|
||||||
@Html.DisplayFor(m=>m.FullName)
|
@Html.DisplayFor(m=>m.FullName)
|
||||||
<a asp-action="SetFullName">[modifier]</a>
|
<a asp-action="SetFullName">[modifier]</a>
|
||||||
</dd>
|
</dd>
|
||||||
|
|
||||||
@if (Model.Roles.Count()>0) {
|
@if (Model.Roles.Count()>0) {
|
||||||
<dt>Roles:</dt>
|
<dt>Roles:</dt>
|
||||||
<dd>
|
<dd>
|
||||||
@string.Join(", ",Model.Roles)
|
@string.Join(", ",Model.Roles)
|
||||||
</dd>}
|
</dd>}
|
||||||
<dt>Password:</dt>
|
<dt>Password:</dt>
|
||||||
<dd>[@{if (Model.HasPassword)
|
<dd>[@{if (Model.HasPassword)
|
||||||
{<a asp-controller="Manage"
|
{<a asp-controller="Manage"
|
||||||
asp-action="ChangePassword">Change</a>}
|
asp-action="ChangePassword">Change</a>}
|
||||||
else
|
else
|
||||||
{<a asp-controller="Manage"
|
{<a asp-controller="Manage"
|
||||||
asp-action="SetPassword">Create</a>}}]</dd>
|
asp-action="SetPassword">Create</a>}}]</dd>
|
||||||
|
|
||||||
<dt>External Logins:</dt>
|
<dt>External Logins:</dt>
|
||||||
|
|
@ -76,19 +79,19 @@
|
||||||
{
|
{
|
||||||
Html.DisplayText("Set");
|
Html.DisplayText("Set");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Html.DisplayText("Modify");
|
Html.DisplayText("Modify");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</a>]
|
</a>]
|
||||||
</dd>
|
</dd>
|
||||||
|
|
||||||
<dt>Avatar:</dt>
|
<dt>Avatar:</dt>
|
||||||
<dd>
|
<dd>
|
||||||
<img src="/Avatars/@(User.GetUserName()+".s").png" asp-append-version="true" class="smalltofhol" />
|
<img src="@avatarSrc" asp-append-version="true" class="smalltofhol" />
|
||||||
[<a asp-controller="Manage" asp-action="SetAvatar">Modify</a>]
|
[<a asp-controller="Manage" asp-action="SetAvatar">Modify</a>]
|
||||||
</dd>
|
</dd>
|
||||||
|
|
||||||
<dt>Vos cercles</dt>
|
<dt>Vos cercles</dt>
|
||||||
<dd> (WIP) <a asp-action="Index" asp-controller="Circle">Ajouter suprimer des cercles</a>
|
<dd> (WIP) <a asp-action="Index" asp-controller="Circle">Ajouter suprimer des cercles</a>
|
||||||
|
|
@ -115,8 +118,8 @@ Html.DisplayText("Modify");
|
||||||
|
|
||||||
<dt><a href="/Blog/@Model.UserName">Your posts:</a></dt>
|
<dt><a href="/Blog/@Model.UserName">Your posts:</a></dt>
|
||||||
<dd>@Model.PostsCounter</dd>
|
<dd>@Model.PostsCounter</dd>
|
||||||
|
|
||||||
<dt>TwoFactorAuthentication:</dt>
|
<dt>TwoFactorAuthentication:</dt>
|
||||||
<dd>
|
<dd>
|
||||||
@if (Model.TwoFactor)
|
@if (Model.TwoFactor)
|
||||||
{
|
{
|
||||||
|
|
@ -139,19 +142,19 @@ Html.DisplayText("Modify");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</dd>
|
</dd>
|
||||||
<dt>Calendar</dt>
|
<dt>Calendar</dt>
|
||||||
<dd>
|
<dd>
|
||||||
@Html.DisplayText(Model.HasDedicatedCalendar?"Yes":"No" )
|
@Html.DisplayText(Model.HasDedicatedCalendar?"Yes":"No" )
|
||||||
@{
|
@{
|
||||||
if (Model.HasDedicatedCalendar) {
|
if (Model.HasDedicatedCalendar) {
|
||||||
<text> : @Model.DedicatedCalendarId </text>
|
<text> : @Model.DedicatedCalendarId </text>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[<a asp-action="SetGoogleCalendar">Select a Google calendar</a>]
|
[<a asp-action="SetGoogleCalendar">Select a Google calendar</a>]
|
||||||
</dd>
|
</dd>
|
||||||
<environment names="Development">
|
<environment names="Development">
|
||||||
<dt>Credits:</dt>
|
<dt>Credits:</dt>
|
||||||
<dd>
|
<dd>
|
||||||
@(Model.Balance?.Credits ?? 0) €
|
@(Model.Balance?.Credits ?? 0) €
|
||||||
[<a asp-action="Credits">Manage</a>]
|
[<a asp-action="Credits">Manage</a>]
|
||||||
</dd>
|
</dd>
|
||||||
|
|
@ -162,9 +165,9 @@ Html.DisplayText("Modify");
|
||||||
@if (Model.DiskQuota>0)
|
@if (Model.DiskQuota>0)
|
||||||
{
|
{
|
||||||
<text>
|
<text>
|
||||||
@(((double)Model.DiskUsage/Model.DiskQuota).ToString("%#0")) :
|
@(((double)Model.DiskUsage/Model.DiskQuota).ToString("%#0")) :
|
||||||
</text>
|
</text>
|
||||||
}
|
}
|
||||||
<code>
|
<code>
|
||||||
@(Model.DiskUsage.ToString("0,#")) / @(Model.DiskQuota.ToString("0,#"))
|
@(Model.DiskUsage.ToString("0,#")) / @(Model.DiskQuota.ToString("0,#"))
|
||||||
</code>
|
</code>
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,14 @@
|
||||||
@model PerformerProfile
|
@model PerformerProfile
|
||||||
@{ ViewBag.Title = "Edit your avatar"; }
|
@{ 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 header{
|
||||||
<script src="https://unpkg.com/dropzone@5/dist/min/dropzone.min.js"></script>
|
<script src="https://unpkg.com/dropzone@5/dist/min/dropzone.min.js"></script>
|
||||||
<link rel="stylesheet" href="https://unpkg.com/dropzone@5/dist/min/dropzone.min.css" type="text/css" />
|
<link rel="stylesheet" href="https://unpkg.com/dropzone@5/dist/min/dropzone.min.css" type="text/css" />
|
||||||
}
|
}
|
||||||
@section scripts{
|
@section scripts{
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
|
@ -21,7 +26,7 @@ $(document).ready(function() {
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
}
|
}
|
||||||
<img src="~/avatars/@(User.Identity.Name).png">
|
<img src="@previewAvatarSrc">
|
||||||
|
|
||||||
<form id="postavatar" action="/api/setavatar" class="dropzone" method="post" enctype="multipart/form-data">
|
<form id="postavatar" action="/api/setavatar" class="dropzone" method="post" enctype="multipart/form-data">
|
||||||
<div class="fallback">
|
<div class="fallback">
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,13 @@
|
||||||
|
@using Yavsc.Abstract.Identity
|
||||||
@model ApplicationUser
|
@model ApplicationUser
|
||||||
|
|
||||||
@if (Model!=null) {
|
@if (Model != null)
|
||||||
<img src="/Avatars/@(Model.UserName+".xs").png" asp-append-version="true" class="smalltofhol" />
|
{
|
||||||
|
var avatarSrc = UserDisplayHelpers.AvatarSrc(Model);
|
||||||
|
if (avatarSrc.EndsWith(".s.png", StringComparison.Ordinal))
|
||||||
|
{
|
||||||
|
avatarSrc = avatarSrc.Replace(".s.png", ".xs.png", StringComparison.Ordinal);
|
||||||
|
}
|
||||||
|
|
||||||
|
<img src="@avatarSrc" asp-append-version="true" class="smalltofhol" />
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ if (Model ==null || Model.UserName==null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
string avuri = "/Avatars/" + Model.UserName + ".s.png";
|
string avuri = UserDisplayHelpers.AvatarSrc(Model);
|
||||||
|
|
||||||
<div class="userinfo">
|
<div class="userinfo">
|
||||||
<a title="Posts" asp-controller="Blogspot" asp-action="Index" asp-route-id="@Model.UserName" class="btn btn-primary">
|
<a title="Posts" asp-controller="Blogspot" asp-action="Index" asp-route-id="@Model.UserName" class="btn btn-primary">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue