diff --git a/FoodsharingSiegen.Contracts/FoodsharingSiegen.Contracts.csproj b/FoodsharingSiegen.Contracts/FoodsharingSiegen.Contracts.csproj index eb2460e..78e054a 100644 --- a/FoodsharingSiegen.Contracts/FoodsharingSiegen.Contracts.csproj +++ b/FoodsharingSiegen.Contracts/FoodsharingSiegen.Contracts.csproj @@ -6,4 +6,8 @@ enable + + + + diff --git a/FoodsharingSiegen.Server/Auth/AuthService.cs b/FoodsharingSiegen.Server/Auth/AuthService.cs index 3c47524..eb4cc06 100644 --- a/FoodsharingSiegen.Server/Auth/AuthService.cs +++ b/FoodsharingSiegen.Server/Auth/AuthService.cs @@ -5,6 +5,7 @@ using FoodsharingSiegen.Contracts.Entity; using FoodsharingSiegen.Server.Data; using FoodsharingSiegen.Server.Data.Service; using FoodsharingSiegen.Server.Service; +using FoodsharingSiegen.Shared.Helper; using Microsoft.AspNetCore.Components.Authorization; using Microsoft.EntityFrameworkCore; using Microsoft.IdentityModel.Tokens; @@ -92,25 +93,7 @@ namespace FoodsharingSiegen.Server.Auth if (User != null) { - - - // Daten korrekt - var tokenHandler = new JwtSecurityTokenHandler(); - var tokenDescriptor = new SecurityTokenDescriptor - { - Subject = new ClaimsIdentity(new[] - { - new Claim(ClaimTypes.NameIdentifier, User.Id.ToString()), - }), - Expires = DateTime.UtcNow.AddDays(30), - Issuer = "FS-Siegen", - Audience = "FS-Siegen", - SigningCredentials = new SigningCredentials(AuthHelper.GetSigningKey(), SecurityAlgorithms.HmacSha256Signature) - }; - - var token = tokenHandler.CreateToken(tokenDescriptor); - var serializedToken = tokenHandler.WriteToken(token); - + var serializedToken = AuthHelper.CreateToken(User.Id); await _localStorageService.SetItem(StorageKeys.TokenKey, serializedToken); return new OperationResult(); diff --git a/FoodsharingSiegen.Server/Auth/TokenAuthStateProvider.cs b/FoodsharingSiegen.Server/Auth/TokenAuthStateProvider.cs index 5e62014..59eade6 100644 --- a/FoodsharingSiegen.Server/Auth/TokenAuthStateProvider.cs +++ b/FoodsharingSiegen.Server/Auth/TokenAuthStateProvider.cs @@ -1,6 +1,7 @@ using System.Security.Claims; using FoodsharingSiegen.Contracts; using FoodsharingSiegen.Server.Auth; +using FoodsharingSiegen.Shared.Helper; using Microsoft.AspNetCore.Components.Authorization; namespace FoodsharingSiegen.Server.Service diff --git a/FoodsharingSiegen.Server/Data/Service/ProspectService.cs b/FoodsharingSiegen.Server/Data/Service/ProspectService.cs index e810c09..79e1c45 100644 --- a/FoodsharingSiegen.Server/Data/Service/ProspectService.cs +++ b/FoodsharingSiegen.Server/Data/Service/ProspectService.cs @@ -35,7 +35,8 @@ namespace FoodsharingSiegen.Server.Data.Service if (targetProspect == null) return new OperationResult(new Exception("Invalid prospect id")); interaction.ProspectId = Guid.Empty; - + interaction.Created = DateTime.UtcNow; + targetProspect.Interactions.Add(interaction); await Context.SaveChangesAsync(); @@ -111,7 +112,7 @@ namespace FoodsharingSiegen.Server.Data.Service { try { - var prospects = await Context.Prospects.AsNoTracking().Include(x => x.Interactions).ThenInclude(x => x.User).OrderBy(x => x.Name).ToListAsync(); + var prospects = await Context.Prospects.AsNoTracking().Include(x => x.Interactions.OrderBy(i => i.Date)).ThenInclude(x => x.User).OrderBy(x => x.Name).ToListAsync(); return new OperationResult>(prospects); } catch (Exception e) diff --git a/FoodsharingSiegen.Server/Dialogs/AddInteractionModal.razor b/FoodsharingSiegen.Server/Dialogs/AddInteractionModal.razor index 5c792a2..a1a44ba 100644 --- a/FoodsharingSiegen.Server/Dialogs/AddInteractionModal.razor +++ b/FoodsharingSiegen.Server/Dialogs/AddInteractionModal.razor @@ -1,20 +1,28 @@ @using FoodsharingSiegen.Contracts.Entity - +
@_header
- - - +
+
+ + +
+
+ + +
+
+ @if (_showInfo) { diff --git a/FoodsharingSiegen.Shared/FoodsharingSiegen.Shared.csproj b/FoodsharingSiegen.Shared/FoodsharingSiegen.Shared.csproj new file mode 100644 index 0000000..2d1eb67 --- /dev/null +++ b/FoodsharingSiegen.Shared/FoodsharingSiegen.Shared.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/FoodsharingSiegen.Server/Auth/AuthHelper.cs b/FoodsharingSiegen.Shared/Helper/AuthHelper.cs similarity index 67% rename from FoodsharingSiegen.Server/Auth/AuthHelper.cs rename to FoodsharingSiegen.Shared/Helper/AuthHelper.cs index 7390a65..48d2c08 100644 --- a/FoodsharingSiegen.Server/Auth/AuthHelper.cs +++ b/FoodsharingSiegen.Shared/Helper/AuthHelper.cs @@ -1,15 +1,45 @@ using System.IdentityModel.Tokens.Jwt; +using System.Security.Claims; using System.Security.Cryptography; using System.Text; using Microsoft.IdentityModel.Tokens; -namespace FoodsharingSiegen.Server.Auth +namespace FoodsharingSiegen.Shared.Helper { /// /// The auth helper class (a. beging, 04.04.2022) /// public static class AuthHelper { + #region Public Method CreateToken + + /// + /// Creates the token using the specified user id (a. beging, 04.04.2022) + /// + /// The user id + /// The string + public static string CreateToken(Guid userId) + { + var tokenHandler = new JwtSecurityTokenHandler(); + var tokenDescriptor = new SecurityTokenDescriptor + { + Subject = new ClaimsIdentity(new[] + { + new Claim(ClaimTypes.NameIdentifier, userId.ToString()), + new Claim("CanDoShit","yes") + }), + Expires = DateTime.UtcNow.AddDays(30), + Issuer = Issuer, + Audience = Audience, + SigningCredentials = new SigningCredentials(GetSigningKey(), SecurityAlgorithms.HmacSha256Signature) + }; + + var token = tokenHandler.CreateToken(tokenDescriptor); + return tokenHandler.WriteToken(token); + } + + #endregion + #region Public Method Decrypt /// @@ -61,16 +91,6 @@ namespace FoodsharingSiegen.Server.Auth #endregion - #region Public Method GetSigningKey - - /// - /// Gets the signing key (a. beging, 04.04.2022) - /// - /// The security key - public static SecurityKey GetSigningKey() => new SymmetricSecurityKey(Encoding.ASCII.GetBytes(SigningKey)); - - #endregion - #region Public Method ValidateToken /// @@ -89,10 +109,10 @@ namespace FoodsharingSiegen.Server.Auth IssuerSigningKey = GetSigningKey(), ValidateAudience = true, - ValidAudience = "FS-Siegen", + ValidAudience = Audience, ValidateIssuer = true, - ValidIssuer = "FS-Siegen" + ValidIssuer = Issuer }); return result.IsValid; @@ -125,9 +145,29 @@ namespace FoodsharingSiegen.Server.Auth #endregion + #region Private Method GetSigningKey + + /// + /// Gets the signing key (a. beging, 04.04.2022) + /// + /// The security key + private static SecurityKey GetSigningKey() => new SymmetricSecurityKey(Encoding.ASCII.GetBytes(SigningKey)); + + #endregion + /// /// The signing key /// - public const string SigningKey = "2uasw2§$%1nd47n9s43&%Zs3529s23&/%AW"; + private const string SigningKey = "2uasw2§$%1nd47n9s43&%Zs3529s23&/%AW"; + + /// + /// The audience + /// + private const string Audience = "FS-Siegen"; + + /// + /// The issuer + /// + private const string Issuer = "FS-Siegen"; } } \ No newline at end of file diff --git a/FoodsharingSiegen.sln b/FoodsharingSiegen.sln index de13e0f..8e33901 100644 --- a/FoodsharingSiegen.sln +++ b/FoodsharingSiegen.sln @@ -4,6 +4,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FoodsharingSiegen.Server", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FoodsharingSiegen.Contracts", "FoodsharingSiegen.Contracts\FoodsharingSiegen.Contracts.csproj", "{F39AE3B4-E4CE-421E-AFB0-E9C9B3B670FE}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FoodsharingSiegen.Shared", "FoodsharingSiegen.Shared\FoodsharingSiegen.Shared.csproj", "{625167D9-A375-40AF-82DE-87484519F6D9}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -18,5 +20,9 @@ Global {F39AE3B4-E4CE-421E-AFB0-E9C9B3B670FE}.Debug|Any CPU.Build.0 = Debug|Any CPU {F39AE3B4-E4CE-421E-AFB0-E9C9B3B670FE}.Release|Any CPU.ActiveCfg = Release|Any CPU {F39AE3B4-E4CE-421E-AFB0-E9C9B3B670FE}.Release|Any CPU.Build.0 = Release|Any CPU + {625167D9-A375-40AF-82DE-87484519F6D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {625167D9-A375-40AF-82DE-87484519F6D9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {625167D9-A375-40AF-82DE-87484519F6D9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {625167D9-A375-40AF-82DE-87484519F6D9}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal