Add admin login

This commit is contained in:
MET18937 2023-06-26 09:41:13 +02:00
parent 3356a91d47
commit 31a82177d5
9 changed files with 202 additions and 89 deletions

View File

@ -221,8 +221,8 @@ public partial class WebApiContext : DbContext
entity.ToTable("bestellungsposition_has_menuitem");
entity.Property(e => e.Bestellungsposition_IDBestellung).HasColumnType("int(11)").HasColumnName("Bestellungsposition_IDBestellung");
entity.Property(e => e.MenuItem_IDMenuItem).HasColumnType("int(11)").HasColumnName("MenuItem_IDMenuItem");
entity.Property(e => e.Bestellungsposition_IDBestellung).HasColumnType("int(11)").HasColumnName("bestellungsposition_IDBestellung");
entity.Property(e => e.MenuItem_IDMenuItem).HasColumnType("int(11)").HasColumnName("menuItem_IDMenuItem");
});
modelBuilder.Entity<MenuitemHasAllergie>(entity =>

View File

@ -4,6 +4,7 @@
@inject HttpClient Http
@inject Blazored.LocalStorage.ISyncLocalStorageService localStorage
@inject NavigationManager _navigationManager
@inject IJSRuntime JSRuntime;
<PageTitle>Yummy4Friends</PageTitle>
@ -32,14 +33,22 @@
{
localStorage.SetItem("kunde", kunde);
_navigationManager.NavigateTo("/speisekarte");
break;
return;
}
}
JSRuntime.InvokeVoidAsync("alert", "Zugangscode ist falsch!");
}
protected override async Task OnInitializedAsync()
{
kunden = await Http.GetFromJsonAsync<List<Kunde>>("https://localhost:7076/api/kunden");
// if already logged in navigate to speisekarte
if (localStorage.ContainKey("kunde"))
{
_navigationManager.NavigateTo("/speisekarte");
}
}
public class Kunde

View File

@ -89,6 +89,13 @@
{
localStorage.SetItem("RabattEinloesen", false);
localStorage.SetItem("Summe", summe);
// if summe > 8€ add treuepunkte
if (summe >= 8)
{
kunde.Treuepunkte++;
// add treuepunkte to API
Http.PutAsJsonAsync("https://localhost:7076/api/kunden/" + kunde.Idkunde, kunde);
}
}
// add bestellung to API
@ -108,6 +115,7 @@
}
}
}
foreach (var item in menuitemIds)
{
bestellungspositionId++;
@ -138,10 +146,9 @@
Http.PostAsJsonAsync("https://localhost:7076/api/bestellungspositionhasmenuitems", bestellungspositionHasMenuItem);
}
// delete all localStorage
localStorage.SetItem("MenuItemIds", new Dictionary<int, int>());
//localStorage.SetItem("Hour", 0);
//localStorage.SetItem("Minute", 0);
localStorage.SetItem("Summe", 0);
localStorage.SetItem("RabattEinloesen", false);
@ -319,7 +326,7 @@
public class BestellungspositionHasMenuitem
{
public int? Bestellungsposition_IDBestellung { get; set; }
public int? MenuItem_IDMenuItem { get; set; }
public int Bestellungsposition_IDBestellung { get; set; }
public int MenuItem_IDMenuItem { get; set; }
}
}

View File

@ -96,7 +96,6 @@
menuitemueberkategories = await Http.GetFromJsonAsync<List<Menuitemueberkategorie>>("https://localhost:7076/api/Menuitemueberkategories");
rabatte = await Http.GetFromJsonAsync<List<Rabatt>>("https://localhost:7076/api/Rabatte");
// test use the first kunde
// get kunde from local storage
kunde = localStorage.GetItem<Kunde>("kunde");

View File

@ -4,14 +4,19 @@
@inject HttpClient Http
@inject Blazored.LocalStorage.ISyncLocalStorageService localStorage
@inject NavigationManager _navigationManager
@*// logout button*@
<div class="container col-lg-5 col-md-9 col-sm-12 d-flex flex-column " id="content">
<button type="button" class="btn" @onclick="@Logout">Logout</button>
</div>
<div class="container d-flex flex-column">
<div class="row">
<div class="col-lg-8">
<div class="col-12">
<br /><br />
<table class="table table-bordered">
<thead>
<tr>
<th colspan="2">Aktive Bestellungen @day.@month.@year</th>
<th>Aktive Bestellungen @day.@month.@year</th>
</tr>
</thead>
<tbody>
@ -59,7 +64,7 @@
</tbody>
</table>
</div>
@*<div class="col-lg-3">
<div class="col-lg-3">
<p id="text" readonly>Abholzeit</p>
<br />
<form id="button" action="Bestelluebersicht">
@ -72,7 +77,7 @@
<input type="submit" value="1 Std" class="btn">
</form>
</div>*@
</div>
</div>
</div>
@ -90,6 +95,11 @@
private Kunde kunde = new Kunde();
public void Logout()
{
localStorage.Clear();
_navigationManager.NavigateTo("/");
}
public void BDetail(int id)
{
localStorage.SetItem<int>("KundeId", id);

View File

@ -5,8 +5,15 @@
@inject Blazored.LocalStorage.ISyncLocalStorageService localStorage
@inject NavigationManager _navigationManager
@*// logout button*@
<div class="container col-lg-5 col-md-9 col-sm-12 d-flex flex-column " id="content">
<button type="button" class="btn" @onclick="@Logout">Logout</button>
</div>
<div class="container">
<div class="row">
<div class="col-sm-12 col-lg-6">
@*Tabelle Ihre Bestellung*@
<div class="tbl-container">
@ -69,7 +76,7 @@
<div class="d-flex flex-column align-items-center ">
<div class="tbl-container w-100">
<!-- <== overflow: hidden applied to parent -->
<table class="table table-bordered bdr " style=" border-radius: 50px; margin-left: 50px;">
<table class="table table-bordered bdr " style=" border-radius: 50px; ">
<thead class="bg_green">
<tr>
<td class="d-flex justify-content-center align-items-center" style="border-bottom:0px;">
@ -113,6 +120,7 @@
</div>
</div>
</div>*@
@code {
public int hour;
@ -137,6 +145,11 @@
private List<Rabatt> rabatte = new List<Rabatt>();
private List<BestellungspositionHasMenuitem> bestellungspositionHasMenuitems = new List<BestellungspositionHasMenuitem>();
public void Logout()
{
localStorage.Clear();
_navigationManager.NavigateTo("/");
}
protected override async Task OnInitializedAsync()
{
// get data from api

View File

@ -10,8 +10,9 @@
@*log out Button *@
<div class="container mt-auto">
<button class="btn" type="button" onclick="@Logout" id="button1">@button1</button>
<button class="btn" type="button" onclick="@Logout" id="button1">Abmelden</button>
</div>
<br />
<div class="container mt-auto">
<h4>AccountID: @kunde.Code</h4>

View File

@ -1,61 +1,93 @@
<nav class="navbar navbar-expand-md navbar-light mb-4 me-5 ms-5 ">
<div class="container-fluid">
@*<a class="navbar-brand" href="">Yummy4Friends</a>*@
<a class="navbar-brand" href="">
<img src="assets/Logo_new.png" alt="Yummy4Friends" width="60px" height="auto">
</a>
@inject HttpClient Http
@inject Blazored.LocalStorage.ISyncLocalStorageService localStorage
@inject NavigationManager _navigationManager
<button class="navbar-toggler @NavButtonCssClass" type="button" data-bs-toggle="collapse" data-bs-target="#navbarCollapse"
aria-controls="navbarCollapse" aria-label="Toggle navigation" @onclick="ToggleNavMenu">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-end @NavBarCssClass" id="navbarCollapse" @onclick="ToggleNavMenu">
<ul class="navbar-nav">
<li class="nav-item">
</li>
<li class="nav-item">
<NavLink class="nav-link" href="allergene">
Allergene
</NavLink>
</li>
<li class="nav-item">
<NavLink class="nav-link" href="speisekarte">
Speisekarte
</NavLink>
</li>
<li class="nav-item">
<NavLink class="nav-link" href="yummy-punkte">
Yummy-Punkte
</NavLink>
</li>
<li class="nav-item">
<NavLink class="nav-link" href="shopping_cart">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-cart3" viewBox="0 0 16 16">
<path d="M0 1.5A.5.5 0 0 1 .5 1H2a.5.5 0 0 1 .485.379L2.89 3H14.5a.5.5 0 0 1 .49.598l-1 5a.5.5 0 0 1-.465.401l-9.397.472L4.415 11H13a.5.5 0 0 1 0 1H4a.5.5 0 0 1-.491-.408L2.01 3.607 1.61 2H.5a.5.5 0 0 1-.5-.5zM3.102 4l.84 4.479 9.144-.459L13.89 4H3.102zM5 12a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm7 0a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm-7 1a1 1 0 1 1 0 2 1 1 0 0 1 0-2zm7 0a1 1 0 1 1 0 2 1 1 0 0 1 0-2z" />
</svg>
</NavLink>
</li>
<li class="nav-item">
<NavLink class="nav-link" href="Kontoverwaltung">
#12345
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-person-fill" viewBox="0 0 16 16">
<path d="M3 14s-1 0-1-1 1-4 6-4 6 3 6 4-1 1-1 1H3Zm5-6a3 3 0 1 0 0-6 3 3 0 0 0 0 6Z" />
</svg>
</NavLink>
</li>
</ul>
</div>
</div>
<nav class="navbar navbar-expand-md navbar-light mb-4 me-5 ms-5 ">
<div class="container-fluid">
@*<a class="navbar-brand" href="">Yummy4Friends</a>*@
<a class="navbar-brand" href="">
<img src="assets/Logo_new.png" alt="Yummy4Friends" width="60px" height="auto">
</a>
<button class="navbar-toggler @NavButtonCssClass" type="button" data-bs-toggle="collapse" data-bs-target="#navbarCollapse"
aria-controls="navbarCollapse" aria-label="Toggle navigation" @onclick="ToggleNavMenu">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-end @NavBarCssClass" id="navbarCollapse" @onclick="ToggleNavMenu">
<ul class="navbar-nav">
<li class="nav-item">
</li>
<li class="nav-item">
<NavLink class="nav-link" href="allergene">
Allergene
</NavLink>
</li>
<li class="nav-item">
<NavLink class="nav-link" href="speisekarte">
Speisekarte
</NavLink>
</li>
<li class="nav-item">
<NavLink class="nav-link" href="yummy-punkte">
Yummy-Punkte
</NavLink>
</li>
<li class="nav-item">
<NavLink class="nav-link" href="shopping_cart">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-cart3" viewBox="0 0 16 16">
<path d="M0 1.5A.5.5 0 0 1 .5 1H2a.5.5 0 0 1 .485.379L2.89 3H14.5a.5.5 0 0 1 .49.598l-1 5a.5.5 0 0 1-.465.401l-9.397.472L4.415 11H13a.5.5 0 0 1 0 1H4a.5.5 0 0 1-.491-.408L2.01 3.607 1.61 2H.5a.5.5 0 0 1-.5-.5zM3.102 4l.84 4.479 9.144-.459L13.89 4H3.102zM5 12a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm7 0a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm-7 1a1 1 0 1 1 0 2 1 1 0 0 1 0-2zm7 0a1 1 0 1 1 0 2 1 1 0 0 1 0-2z" />
</svg>
</NavLink>
</li>
<li class="nav-item">
<NavLink class="nav-link" href="Kontoverwaltung">
#@kunde.Code
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-person-fill" viewBox="0 0 16 16">
<path d="M3 14s-1 0-1-1 1-4 6-4 6 3 6 4-1 1-1 1H3Zm5-6a3 3 0 1 0 0-6 3 3 0 0 0 0 6Z" />
</svg>
</NavLink>
</li>
</ul>
</div>
</div>
</nav>
@code {
private bool collapseNavMenu = true;
private string? NavBarCssClass => collapseNavMenu ? null : "show";
private string? NavButtonCssClass => collapseNavMenu ? "collapsed" : null;
private bool collapseNavMenu = true;
private string? NavBarCssClass => collapseNavMenu ? null : "show";
private string? NavButtonCssClass => collapseNavMenu ? "collapsed" : null;
private void ToggleNavMenu()
{
collapseNavMenu = !collapseNavMenu;
}
private void ToggleNavMenu()
{
collapseNavMenu = !collapseNavMenu;
}
private List<Kunde> kunden = new List<Kunde>();
private Kunde kunde = new Kunde();
protected override async Task OnInitializedAsync()
{
// kunde login start
kunden = await Http.GetFromJsonAsync<List<Kunde>>("https://localhost:7076/api/kunden");
if (localStorage.ContainKey("kunde"))
kunde = localStorage.GetItem<Kunde>("kunde");
else
_navigationManager.NavigateTo("/");
if (kunde != null && !kunden.Any(k => k.Code == kunde.Code))
_navigationManager.NavigateTo("/");
// kunde login end
}
public class Kunde
{
int Idkunde { get; set; }
public string Code { get; set; }
public int Treuepunkte { get; set; }
}
}

View File

@ -1,36 +1,78 @@
@page "/RegistrierungA"
@using System.Text;
@using System.Security.Cryptography;
@layout Registrierung
@inject NavigationManager NavManager
@inject HttpClient Http
@inject Blazored.LocalStorage.ISyncLocalStorageService localStorage
@inject NavigationManager _navigationManager
@inject IJSRuntime JSRuntime;
<div class="container col-lg-5 col-md-9 col-sm-12 d-flex flex-column " id="content">
<p>Benutzername:</p>
<p>Benutzername:</p>
<input type="text" class="form-control" id="name" name="name" @bind="@inputName">
<input type="text" class="form-control" id="name" name="name" @bind="@inputName">
<p>Passwort:</p>
<input type="password" class="form-control" id="password" name="password" @bind="@inputPassword">
<button type="button" class="btn" @onclick="@Login">Login</button>
<p>Passwort:</p>
<input type="password" class="form-control" id="password" name="password" @bind="@inputPassword">
<button type="button" class="btn" @onclick="@Login">Login</button>
</div>
@code {
public string inputName { get; set; } = string.Empty;
public string inputPassword { get; set; } = string.Empty;
public string inputName { get; set; }
public string inputPassword { get; set; }
public string inputPasswordEnc { get; set; }
public static string userName { get; set; } = string.Empty;
private List<Admin> admins = new List<Admin>();
private Admin admin = new Admin();
public void Login() {
if (inputName == userDataName && inputPassword == userDataPassword) {
localStorage.SetItem("name", inputName);
userName = localStorage.GetItem<string>("name");
NavManager.NavigateTo("/Bestelluebersicht");
}
}
}
public void Login()
{
// if inputName and inputPassword is not null
if (string.IsNullOrEmpty(inputName) || string.IsNullOrEmpty(inputPassword))
{
JSRuntime.InvokeVoidAsync("alert", "Benutzernamen oder Passwort ist falsch!");
return;
}
else
{
//encode inputpassword
inputPasswordEnc = Convert.ToHexString(SHA512.Create().ComputeHash(Encoding.UTF8.GetBytes(inputPassword)));
@code {
public string userDataName { get; set; } = "";
public string userDataPassword { get; set; } = "";
// if inputName is in admins with the encrypt SHA512 password
if (admins.Any(a => a.Username == inputName && a.Password == inputPasswordEnc))
{
localStorage.SetItem("admin", admins.First(a => a.Username == inputName && a.Password == inputPasswordEnc));
_navigationManager.NavigateTo("/Bestelluebersicht");
}
}
}
protected override async Task OnInitializedAsync()
{
admins = await Http.GetFromJsonAsync<List<Admin>>("https://localhost:7076/api/admins");
// if already logged in navigate to Bestelluebersicht
// if localsorage admin object is valid from the api
if (localStorage.ContainKey("admin"))
{
admin = localStorage.GetItem<Admin>("admin");
if (admin != null && !admins.Any(a => a.Username == admin.Username && a.Password == admin.Password))
_navigationManager.NavigateTo("/RegistrierungA");
else
_navigationManager.NavigateTo("/Bestelluebersicht");
}
}
public partial class Admin
{
public int Id { get; set; }
public string Username { get; set; }
public string Password { get; set; }
}
}