Profile Page
This commit is contained in:
@@ -63,6 +63,11 @@ namespace FoodsharingSiegen.Contracts.Entity
|
||||
/// </summary>
|
||||
public string Mail { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value of the memo (ab)
|
||||
/// </summary>
|
||||
public string? Memo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value of the name (ab)
|
||||
/// </summary>
|
||||
|
||||
@@ -157,5 +157,25 @@ namespace FoodsharingSiegen.Server.Auth
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Method RefreshState
|
||||
|
||||
/// <summary>
|
||||
/// Refreshes the state (a. beging, 21.05.2022)
|
||||
/// </summary>
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,6 @@ namespace FoodsharingSiegen.Server.BaseClasses
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Override OnInitializedAsync
|
||||
|
||||
/// <summary>
|
||||
@@ -33,6 +32,14 @@ namespace FoodsharingSiegen.Server.BaseClasses
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Refreshes the state (a. beging, 21.05.2022)
|
||||
/// </summary>
|
||||
protected async Task RefreshState()
|
||||
{
|
||||
await AuthService?.RefreshState()!;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of the current user (ab)
|
||||
/// </summary>
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace FoodsharingSiegen.Server.Data
|
||||
/// <param name="options">The options (ab)</param>
|
||||
public FsContext(DbContextOptions<FsContext> options) : base(options)
|
||||
{
|
||||
Database.EnsureCreated();
|
||||
// Database.EnsureCreated();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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<string>("Memo")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
@@ -14,10 +14,10 @@ namespace FoodsharingSiegen.Server.Migrations
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
FsId = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
Name = table.Column<string>(type: "TEXT", nullable: false),
|
||||
Created = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||
Memo = table.Column<string>(type: "TEXT", nullable: true)
|
||||
FsId = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
Memo = table.Column<string>(type: "TEXT", nullable: true),
|
||||
Name = table.Column<string>(type: "TEXT", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
@@ -29,14 +29,15 @@ namespace FoodsharingSiegen.Server.Migrations
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
Mail = table.Column<string>(type: "TEXT", nullable: false),
|
||||
Type = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
Verified = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||
Name = table.Column<string>(type: "TEXT", nullable: false),
|
||||
Created = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||
EncryptedPassword = table.Column<string>(type: "TEXT", nullable: false),
|
||||
ForceLogout = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||
Groups = table.Column<string>(type: "TEXT", nullable: false),
|
||||
ForceLogout = table.Column<bool>(type: "INTEGER", nullable: false)
|
||||
Mail = table.Column<string>(type: "TEXT", nullable: false),
|
||||
Memo = table.Column<string>(type: "TEXT", nullable: true),
|
||||
Name = table.Column<string>(type: "TEXT", nullable: false),
|
||||
Type = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
Verified = table.Column<bool>(type: "INTEGER", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
@@ -48,14 +49,14 @@ namespace FoodsharingSiegen.Server.Migrations
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
UserID = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
Alert = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||
Created = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||
Date = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||
Info = table.Column<string>(type: "TEXT", nullable: true),
|
||||
Type = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
ProspectID = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
Alert = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||
NotNeeded = table.Column<bool>(type: "INTEGER", nullable: false),
|
||||
Created = table.Column<DateTime>(type: "TEXT", nullable: false)
|
||||
ProspectID = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
Type = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
UserID = table.Column<Guid>(type: "TEXT", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
@@ -104,6 +104,9 @@ namespace FoodsharingSiegen.Server.Migrations
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Memo")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
36
FoodsharingSiegen.Server/Pages/Profile.razor
Normal file
36
FoodsharingSiegen.Server/Pages/Profile.razor
Normal file
@@ -0,0 +1,36 @@
|
||||
@page "/profile"
|
||||
|
||||
@using FoodsharingSiegen.Server.BaseClasses
|
||||
|
||||
@inherits FsBase
|
||||
|
||||
<PageTitle>Profil</PageTitle>
|
||||
|
||||
<div style="width: 100%; max-width: 500px;">
|
||||
<h4>Mein Profil</h4>
|
||||
<Button Color="Color.Primary" Clicked="SaveProfile">Speichern</Button>
|
||||
<Fields Class="mt-1">
|
||||
<Validations @ref="ValidationsRef">
|
||||
<Validation Validator="ValidationRule.IsNotEmpty">
|
||||
<Field ColumnSize="ColumnSize.Is12">
|
||||
<FieldLabel>Name</FieldLabel>
|
||||
<FieldBody>
|
||||
<TextEdit @bind-Text="User.Name"></TextEdit>
|
||||
</FieldBody>
|
||||
</Field>
|
||||
</Validation>
|
||||
<Validation Validator="ValidationRule.None">
|
||||
<Field ColumnSize="ColumnSize.Is12">
|
||||
<FieldLabel>Info über dich</FieldLabel>
|
||||
<FieldBody>
|
||||
<MemoEdit Rows="3" Placeholder="z.B. Bieb bei Rewe Musterhausen" @bind-Text="User.Memo" />
|
||||
</FieldBody>
|
||||
</Field>
|
||||
</Validation>
|
||||
</Validations>
|
||||
</Fields>
|
||||
|
||||
<h3>Sicherheit</h3>
|
||||
<Button Color="Color.Primary" Class="mb-2">Passwort ändern</Button>
|
||||
<Button Color="Color.Danger" Class="mb-2">Konto löschen</Button>
|
||||
</div>
|
||||
77
FoodsharingSiegen.Server/Pages/Profile.razor.cs
Normal file
77
FoodsharingSiegen.Server/Pages/Profile.razor.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using Blazorise;
|
||||
using FoodsharingSiegen.Contracts.Entity;
|
||||
using FoodsharingSiegen.Server.Data.Service;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace FoodsharingSiegen.Server.Pages
|
||||
{
|
||||
/// <summary>
|
||||
/// The profile class (a. beging, 21.05.2022)
|
||||
/// </summary>
|
||||
public partial class Profile
|
||||
{
|
||||
#region Dependencies (Injected)
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value of the user service (ab)
|
||||
/// </summary>
|
||||
[Inject] public UserService? UserService { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value of the user (ab)
|
||||
/// </summary>
|
||||
private User User { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value of the validations ref (ab)
|
||||
/// </summary>
|
||||
private Validations? ValidationsRef { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Override OnAfterRenderAsync
|
||||
|
||||
/// <summary>
|
||||
/// Ons the after render using the specified first render (a. beging, 21.05.2022)
|
||||
/// </summary>
|
||||
/// <param name="firstRender">The first render</param>
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if(firstRender) await ValidationsRef?.ValidateAll()!;
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Override OnInitializedAsync
|
||||
|
||||
/// <summary>
|
||||
/// Ons the initialized (a. beging, 21.05.2022)
|
||||
/// </summary>
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await base.OnInitializedAsync();
|
||||
User = CurrentUser.Clone();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Method SaveProfile
|
||||
|
||||
/// <summary>
|
||||
/// Saves the profile (a. beging, 21.05.2022)
|
||||
/// </summary>
|
||||
private async Task SaveProfile()
|
||||
{
|
||||
var updateR = await UserService?.Update(User)!;
|
||||
if (updateR.Success) await RefreshState();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,11 @@
|
||||
|
||||
<div class="@NavMenuCssClass" @onclick="ToggleNavMenu">
|
||||
<nav class="flex-column">
|
||||
<div class="nav-item px-3">
|
||||
<NavLink class="nav-link" href="profile" Match="NavLinkMatch.All">
|
||||
<span class="fas fa-user mr-1" aria-hidden="true" style="font-size: 1.4em;"></span> Profil
|
||||
</NavLink>
|
||||
</div>
|
||||
<div class="nav-item px-3">
|
||||
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
|
||||
<span class="fas fa-tasks mr-1" aria-hidden="true" style="font-size: 1.4em;"></span> Übersicht
|
||||
@@ -26,6 +31,7 @@
|
||||
</div>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private bool collapseNavMenu = true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user