diff --git a/src/PostIt/PostIt/ViewModels/Commands/BrushViewModel.cs b/src/PostIt/PostIt/ViewModels/Commands/BrushViewModel.cs index 03dab60e..986b046e 100644 --- a/src/PostIt/PostIt/ViewModels/Commands/BrushViewModel.cs +++ b/src/PostIt/PostIt/ViewModels/Commands/BrushViewModel.cs @@ -10,7 +10,6 @@ using Yavsc.Abstract.Workflow; using Yavsc.Api.Client; using Yavsc.Models.Haircut; namespace PostIt.ViewModels.Commands; - public partial class BrushViewModel : RdvViewModel { public override string SupportMessage => "Choisissez une prestation coiffure puis postez la commande."; diff --git a/src/Yavsc.Org/Extensions/HostingExtensions.cs b/src/Yavsc.Org/Extensions/HostingExtensions.cs index e986620f..7c066df5 100644 --- a/src/Yavsc.Org/Extensions/HostingExtensions.cs +++ b/src/Yavsc.Org/Extensions/HostingExtensions.cs @@ -18,7 +18,6 @@ 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; @@ -1283,52 +1282,10 @@ 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 13b45339..2624c284 100755 --- a/src/Yavsc.Org/Views/Manage/Index.cshtml +++ b/src/Yavsc.Org/Views/Manage/Index.cshtml @@ -2,9 +2,6 @@ @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

@@ -14,15 +11,15 @@
UserName:
- -
+ +
@Model.UserName [modifier]
E-mail
- -
+ +
@Model.EMail @if (Model.EmailConfirmed) { @@ -49,22 +46,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:
@@ -79,19 +76,19 @@ { Html.DisplayText("Set"); } - else + else { Html.DisplayText("Modify"); } } ] - +
Avatar:
- + [Modify] -
+
Vos cercles
(WIP) Ajouter suprimer des cercles @@ -118,8 +115,8 @@ Html.DisplayText("Modify");
Your posts:
@Model.PostsCounter
- -
TwoFactorAuthentication:
+ +
TwoFactorAuthentication:
@if (Model.TwoFactor) { @@ -142,19 +139,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]
@@ -165,9 +162,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 b9292434..71ad0f85 100644 --- a/src/Yavsc.Org/Views/Manage/SetAvatar.cshtml +++ b/src/Yavsc.Org/Views/Manage/SetAvatar.cshtml @@ -1,14 +1,9 @@ -@model PerformerProfile -@{ ViewBag.Title = "Edit your avatar"; } -@{ - var previewAvatarSrc = string.IsNullOrWhiteSpace(User?.Identity?.Name) - ? Yavsc.Constants.DefaultAvatar - : $"{Yavsc.Constants.AvatarsPath}/{User.Identity.Name}.png"; -} +@model PerformerProfile +@{ ViewBag.Title = "Edit your avatar"; } @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 c85bd24d..c3657f95 100644 --- a/src/Yavsc.Org/Views/Shared/DisplayTemplates/ApplicationUserLink.cshtml +++ b/src/Yavsc.Org/Views/Shared/DisplayTemplates/ApplicationUserLink.cshtml @@ -1,13 +1,5 @@ -@using Yavsc.Abstract.Identity @model ApplicationUser -@if (Model != null) -{ - var avatarSrc = UserDisplayHelpers.AvatarSrc(Model); - if (avatarSrc.EndsWith(".s.png", StringComparison.Ordinal)) - { - avatarSrc = avatarSrc.Replace(".s.png", ".xs.png", StringComparison.Ordinal); - } - - +@if (Model!=null) { + } diff --git a/src/Yavsc.Org/Views/Shared/DisplayTemplates/IApplicationUser.cshtml b/src/Yavsc.Org/Views/Shared/DisplayTemplates/IApplicationUser.cshtml index f7a1515e..493eb5cd 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 = UserDisplayHelpers.AvatarSrc(Model); + string avuri = "/Avatars/" + Model.UserName + ".s.png";
diff --git a/src/Yavsc.Server/Helpers/RequestHelper.cs b/src/Yavsc.Server/Helpers/RequestHelper.cs index 99fe1524..1bdde9fe 100644 --- a/src/Yavsc.Server/Helpers/RequestHelper.cs +++ b/src/Yavsc.Server/Helpers/RequestHelper.cs @@ -9,6 +9,84 @@ namespace Yavsc.Server.Helpers /// public class RequestHelper { + string WRPostMultipart(string url, Dictionary parameters, string authorizationHeader = null) + { + + string boundary = "---------------------------" + DateTime.UtcNow.Ticks.ToString("x"); + byte[] boundaryBytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n"); + + HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); + request.ContentType = "multipart/form-data; boundary=" + boundary; + request.Method = "POST"; + request.KeepAlive = true; + request.Credentials = System.Net.CredentialCache.DefaultCredentials; + if (authorizationHeader != null) + request.Headers["Authorization"] = authorizationHeader; + if (parameters != null && parameters.Count > 0) + { + + using (Stream requestStream = request.GetRequestStream()) + { + using (WebResponse response = request.GetResponse()) + { + + + foreach (KeyValuePair pair in parameters) + { + + requestStream.Write(boundaryBytes, 0, boundaryBytes.Length); + if (pair.Value is FormFile) + { + FormFile file = pair.Value as FormFile; + string header = "Content-Disposition: form-data; name=\"" + pair.Key + "\"; filename=\"" + file.Name + "\"\r\nContent-Type: " + file.ContentType + "\r\n\r\n"; + byte[] bytes = System.Text.Encoding.UTF8.GetBytes(header); + requestStream.Write(bytes, 0, bytes.Length); + byte[] buffer = new byte[32768]; + int bytesRead; + if (file.Stream == null) + { + // upload from file + using (FileStream fileStream = File.OpenRead(file.FilePath)) + { + while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0) + requestStream.Write(buffer, 0, bytesRead); + fileStream.Close(); + } + } + else + { + // upload from given stream + while ((bytesRead = file.Stream.Read(buffer, 0, buffer.Length)) != 0) + requestStream.Write(buffer, 0, bytesRead); + } + } + else + { + string data = "Content-Disposition: form-data; name=\"" + pair.Key + "\"\r\n\r\n" + pair.Value; + byte[] bytes = System.Text.Encoding.UTF8.GetBytes(data); + requestStream.Write(bytes, 0, bytes.Length); + } + + } + + byte[] trailer = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "--\r\n"); + requestStream.Write(trailer, 0, trailer.Length); + requestStream.Close(); + + using (Stream responseStream = response.GetResponseStream()) + using (StreamReader reader = new StreamReader(responseStream)) + { + return reader.ReadToEnd(); + } + } // end WebResponse response + + } // end using requestStream + + } + else throw new ArgumentOutOfRangeException("no parameter found "); + + } + public static async Task PostMultipart(string url, FormFile[] formFiles, string access_token = null) {