From 5961c06004452ac41369f2565b02add5bc0f49c6 Mon Sep 17 00:00:00 2001 From: Andre Beging Date: Sat, 21 May 2022 18:22:18 +0200 Subject: [PATCH] Profile Page --- FoodsharingSiegen.Contracts/Entity/User.cs | 5 ++ FoodsharingSiegen.Server/Auth/AuthService.cs | 20 +++++ .../BaseClasses/FsBase.cs | 11 ++- FoodsharingSiegen.Server/Data/FsContext.cs | 2 +- .../Data/Service/UserService.cs | 3 +- .../Dialogs/AddInteractionModal.razor.cs | 2 +- ...ner.cs => 20220521155432_init.Designer.cs} | 5 +- ...1114808_init.cs => 20220521155432_init.cs} | 27 +++---- .../Migrations/FsContextModelSnapshot.cs | 3 + FoodsharingSiegen.Server/Pages/Profile.razor | 36 +++++++++ .../Pages/Profile.razor.cs | 77 +++++++++++++++++++ FoodsharingSiegen.Server/Shared/NavMenu.razor | 6 ++ 12 files changed, 178 insertions(+), 19 deletions(-) rename FoodsharingSiegen.Server/Migrations/{20220521114808_init.Designer.cs => 20220521155432_init.Designer.cs} (97%) rename FoodsharingSiegen.Server/Migrations/{20220521114808_init.cs => 20220521155432_init.cs} (96%) create mode 100644 FoodsharingSiegen.Server/Pages/Profile.razor create mode 100644 FoodsharingSiegen.Server/Pages/Profile.razor.cs diff --git a/FoodsharingSiegen.Contracts/Entity/User.cs b/FoodsharingSiegen.Contracts/Entity/User.cs index 5e2688f..36bab23 100644 --- a/FoodsharingSiegen.Contracts/Entity/User.cs +++ b/FoodsharingSiegen.Contracts/Entity/User.cs @@ -63,6 +63,11 @@ namespace FoodsharingSiegen.Contracts.Entity /// public string Mail { get; set; } + /// + /// Gets or sets the value of the memo (ab) + /// + public string? Memo { get; set; } + /// /// Gets or sets the value of the name (ab) /// diff --git a/FoodsharingSiegen.Server/Auth/AuthService.cs b/FoodsharingSiegen.Server/Auth/AuthService.cs index 3bbcccd..6ff7bca 100644 --- a/FoodsharingSiegen.Server/Auth/AuthService.cs +++ b/FoodsharingSiegen.Server/Auth/AuthService.cs @@ -157,5 +157,25 @@ namespace FoodsharingSiegen.Server.Auth } #endregion + + #region Public Method RefreshState + + /// + /// Refreshes the state (a. beging, 21.05.2022) + /// + public async Task RefreshState() + { + if (_user == null) return; + + _user = await Context.Users?.FirstOrDefaultAsync(x => x.Id == _user.Id)!; + + if (_user != null) + { + var serializedToken = AuthHelper.CreateToken(_user); + await _localStorageService.SetItem(StorageKeys.TokenKey, serializedToken); + } + } + + #endregion } } \ No newline at end of file diff --git a/FoodsharingSiegen.Server/BaseClasses/FsBase.cs b/FoodsharingSiegen.Server/BaseClasses/FsBase.cs index 771331b..b3c8d2f 100644 --- a/FoodsharingSiegen.Server/BaseClasses/FsBase.cs +++ b/FoodsharingSiegen.Server/BaseClasses/FsBase.cs @@ -16,10 +16,9 @@ namespace FoodsharingSiegen.Server.BaseClasses /// Gets or sets the value of the auth service (ab) /// [Inject] private AuthService? AuthService { get; set; } - + #endregion - #region Override OnInitializedAsync /// @@ -33,6 +32,14 @@ namespace FoodsharingSiegen.Server.BaseClasses #endregion + /// + /// Refreshes the state (a. beging, 21.05.2022) + /// + protected async Task RefreshState() + { + await AuthService?.RefreshState()!; + } + /// /// Gets the value of the current user (ab) /// diff --git a/FoodsharingSiegen.Server/Data/FsContext.cs b/FoodsharingSiegen.Server/Data/FsContext.cs index 1835ae1..c885ab8 100644 --- a/FoodsharingSiegen.Server/Data/FsContext.cs +++ b/FoodsharingSiegen.Server/Data/FsContext.cs @@ -37,7 +37,7 @@ namespace FoodsharingSiegen.Server.Data /// The options (ab) public FsContext(DbContextOptions options) : base(options) { - Database.EnsureCreated(); + // Database.EnsureCreated(); } #endregion diff --git a/FoodsharingSiegen.Server/Data/Service/UserService.cs b/FoodsharingSiegen.Server/Data/Service/UserService.cs index 1c958af..c335891 100644 --- a/FoodsharingSiegen.Server/Data/Service/UserService.cs +++ b/FoodsharingSiegen.Server/Data/Service/UserService.cs @@ -144,7 +144,7 @@ namespace FoodsharingSiegen.Server.Data.Service { try { - var entityUser = await Context.Users.FirstOrDefaultAsync(x => x.Id == user.Id); + var entityUser = await Context?.Users?.FirstOrDefaultAsync(x => x.Id == user.Id)!; if (entityUser == null) return new OperationResult(new Exception("User not found")); if (entityUser.Mail != user.Mail || @@ -155,6 +155,7 @@ namespace FoodsharingSiegen.Server.Data.Service entityUser.ForceLogout = true; } + entityUser.Memo = user.Memo; entityUser.Mail = user.Mail; entityUser.Name = user.Name; entityUser.Type = user.Type; diff --git a/FoodsharingSiegen.Server/Dialogs/AddInteractionModal.razor.cs b/FoodsharingSiegen.Server/Dialogs/AddInteractionModal.razor.cs index f3003b6..1f73bfb 100644 --- a/FoodsharingSiegen.Server/Dialogs/AddInteractionModal.razor.cs +++ b/FoodsharingSiegen.Server/Dialogs/AddInteractionModal.razor.cs @@ -26,7 +26,7 @@ namespace FoodsharingSiegen.Server.Dialogs protected override async Task OnParametersSetAsync() { - if (Users?.Any() == true)SelectedUser = Users.First().Id; + if (Users?.Any() == true) SelectedUser = Users.First().Id; await base.OnParametersSetAsync(); } diff --git a/FoodsharingSiegen.Server/Migrations/20220521114808_init.Designer.cs b/FoodsharingSiegen.Server/Migrations/20220521155432_init.Designer.cs similarity index 97% rename from FoodsharingSiegen.Server/Migrations/20220521114808_init.Designer.cs rename to FoodsharingSiegen.Server/Migrations/20220521155432_init.Designer.cs index 9e4bd9f..b47d6c7 100644 --- a/FoodsharingSiegen.Server/Migrations/20220521114808_init.Designer.cs +++ b/FoodsharingSiegen.Server/Migrations/20220521155432_init.Designer.cs @@ -11,7 +11,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace FoodsharingSiegen.Server.Migrations { [DbContext(typeof(FsContext))] - [Migration("20220521114808_init")] + [Migration("20220521155432_init")] partial class init { protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -106,6 +106,9 @@ namespace FoodsharingSiegen.Server.Migrations .IsRequired() .HasColumnType("TEXT"); + b.Property("Memo") + .HasColumnType("TEXT"); + b.Property("Name") .IsRequired() .HasColumnType("TEXT"); diff --git a/FoodsharingSiegen.Server/Migrations/20220521114808_init.cs b/FoodsharingSiegen.Server/Migrations/20220521155432_init.cs similarity index 96% rename from FoodsharingSiegen.Server/Migrations/20220521114808_init.cs rename to FoodsharingSiegen.Server/Migrations/20220521155432_init.cs index 148892e..218decc 100644 --- a/FoodsharingSiegen.Server/Migrations/20220521114808_init.cs +++ b/FoodsharingSiegen.Server/Migrations/20220521155432_init.cs @@ -14,10 +14,10 @@ namespace FoodsharingSiegen.Server.Migrations columns: table => new { Id = table.Column(type: "TEXT", nullable: false), - FsId = table.Column(type: "INTEGER", nullable: false), - Name = table.Column(type: "TEXT", nullable: false), Created = table.Column(type: "TEXT", nullable: false), - Memo = table.Column(type: "TEXT", nullable: true) + FsId = table.Column(type: "INTEGER", nullable: false), + Memo = table.Column(type: "TEXT", nullable: true), + Name = table.Column(type: "TEXT", nullable: false) }, constraints: table => { @@ -29,14 +29,15 @@ namespace FoodsharingSiegen.Server.Migrations columns: table => new { Id = table.Column(type: "TEXT", nullable: false), - Mail = table.Column(type: "TEXT", nullable: false), - Type = table.Column(type: "INTEGER", nullable: false), - Verified = table.Column(type: "INTEGER", nullable: false), - Name = table.Column(type: "TEXT", nullable: false), Created = table.Column(type: "TEXT", nullable: false), EncryptedPassword = table.Column(type: "TEXT", nullable: false), + ForceLogout = table.Column(type: "INTEGER", nullable: false), Groups = table.Column(type: "TEXT", nullable: false), - ForceLogout = table.Column(type: "INTEGER", nullable: false) + Mail = table.Column(type: "TEXT", nullable: false), + Memo = table.Column(type: "TEXT", nullable: true), + Name = table.Column(type: "TEXT", nullable: false), + Type = table.Column(type: "INTEGER", nullable: false), + Verified = table.Column(type: "INTEGER", nullable: false) }, constraints: table => { @@ -48,14 +49,14 @@ namespace FoodsharingSiegen.Server.Migrations columns: table => new { Id = table.Column(type: "TEXT", nullable: false), - UserID = table.Column(type: "TEXT", nullable: false), + Alert = table.Column(type: "INTEGER", nullable: false), + Created = table.Column(type: "TEXT", nullable: false), Date = table.Column(type: "TEXT", nullable: false), Info = table.Column(type: "TEXT", nullable: true), - Type = table.Column(type: "INTEGER", nullable: false), - ProspectID = table.Column(type: "TEXT", nullable: false), - Alert = table.Column(type: "INTEGER", nullable: false), NotNeeded = table.Column(type: "INTEGER", nullable: false), - Created = table.Column(type: "TEXT", nullable: false) + ProspectID = table.Column(type: "TEXT", nullable: false), + Type = table.Column(type: "INTEGER", nullable: false), + UserID = table.Column(type: "TEXT", nullable: false) }, constraints: table => { diff --git a/FoodsharingSiegen.Server/Migrations/FsContextModelSnapshot.cs b/FoodsharingSiegen.Server/Migrations/FsContextModelSnapshot.cs index 5e4f5be..4e46091 100644 --- a/FoodsharingSiegen.Server/Migrations/FsContextModelSnapshot.cs +++ b/FoodsharingSiegen.Server/Migrations/FsContextModelSnapshot.cs @@ -104,6 +104,9 @@ namespace FoodsharingSiegen.Server.Migrations .IsRequired() .HasColumnType("TEXT"); + b.Property("Memo") + .HasColumnType("TEXT"); + b.Property("Name") .IsRequired() .HasColumnType("TEXT"); diff --git a/FoodsharingSiegen.Server/Pages/Profile.razor b/FoodsharingSiegen.Server/Pages/Profile.razor new file mode 100644 index 0000000..94a328d --- /dev/null +++ b/FoodsharingSiegen.Server/Pages/Profile.razor @@ -0,0 +1,36 @@ +@page "/profile" + +@using FoodsharingSiegen.Server.BaseClasses + +@inherits FsBase + +Profil + +
+

Mein Profil

+ + + + + + Name + + + + + + + + Info über dich + + + + + + + + +

Sicherheit

+ + +
\ No newline at end of file diff --git a/FoodsharingSiegen.Server/Pages/Profile.razor.cs b/FoodsharingSiegen.Server/Pages/Profile.razor.cs new file mode 100644 index 0000000..4ca499b --- /dev/null +++ b/FoodsharingSiegen.Server/Pages/Profile.razor.cs @@ -0,0 +1,77 @@ +using Blazorise; +using FoodsharingSiegen.Contracts.Entity; +using FoodsharingSiegen.Server.Data.Service; +using Microsoft.AspNetCore.Components; + +namespace FoodsharingSiegen.Server.Pages +{ + /// + /// The profile class (a. beging, 21.05.2022) + /// + public partial class Profile + { + #region Dependencies (Injected) + + /// + /// Gets or sets the value of the user service (ab) + /// + [Inject] public UserService? UserService { get; set; } + + #endregion + + #region Private Properties + + /// + /// Gets or sets the value of the user (ab) + /// + private User User { get; set; } = new(); + + /// + /// Gets or sets the value of the validations ref (ab) + /// + private Validations? ValidationsRef { get; set; } + + #endregion + + #region Override OnAfterRenderAsync + + /// + /// Ons the after render using the specified first render (a. beging, 21.05.2022) + /// + /// The first render + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if(firstRender) await ValidationsRef?.ValidateAll()!; + await base.OnAfterRenderAsync(firstRender); + } + + #endregion + + #region Override OnInitializedAsync + + /// + /// Ons the initialized (a. beging, 21.05.2022) + /// + protected override async Task OnInitializedAsync() + { + await base.OnInitializedAsync(); + User = CurrentUser.Clone(); + + } + + #endregion + + #region Private Method SaveProfile + + /// + /// Saves the profile (a. beging, 21.05.2022) + /// + private async Task SaveProfile() + { + var updateR = await UserService?.Update(User)!; + if (updateR.Success) await RefreshState(); + } + + #endregion + } +} \ No newline at end of file diff --git a/FoodsharingSiegen.Server/Shared/NavMenu.razor b/FoodsharingSiegen.Server/Shared/NavMenu.razor index f83e9cf..17864db 100644 --- a/FoodsharingSiegen.Server/Shared/NavMenu.razor +++ b/FoodsharingSiegen.Server/Shared/NavMenu.razor @@ -9,6 +9,11 @@
+ @code { private bool collapseNavMenu = true;