diff --git a/Shifty.App/App.razor b/Shifty.App/App.razor index 9287ef6..c0173c6 100644 --- a/Shifty.App/App.razor +++ b/Shifty.App/App.razor @@ -1,7 +1,17 @@ - +@using Shifty.App.Components +@using Shifty.App.Pages + - + + + + @if (routeData.PageType != typeof(Login)) + { + + } + + diff --git a/Shifty.App/Components/RedirectToLogin.razor b/Shifty.App/Components/RedirectToLogin.razor new file mode 100644 index 0000000..fd85df9 --- /dev/null +++ b/Shifty.App/Components/RedirectToLogin.razor @@ -0,0 +1,8 @@ +@inject NavigationManager Navigation + +@code { + protected override void OnInitialized() + { + Navigation.NavigateTo("/login", false); + } +} \ No newline at end of file diff --git a/Shifty.App/Pages/Login.razor b/Shifty.App/Pages/Login.razor index 5703d2f..c2256e7 100644 --- a/Shifty.App/Pages/Login.razor +++ b/Shifty.App/Pages/Login.razor @@ -1,48 +1,54 @@ @page "/Login" -@using Microsoft.AspNetCore.Components @using System.ComponentModel.DataAnnotations @using Shifty.App.Services @inject IAuthenticationService _authenticationService +@inject NavigationManager Navigation - - - - - @if (_loggingIn) - { - - } - else - { - if (!_successfulLogin) - { - Invalid credentials - } - - - - } - - - - Login - - - - +@attribute [AllowAnonymous] + + + Please login + + + + + @if (_loggingIn) + { + + } + else + { + if (!_successfulLogin) + { + Invalid credentials + } + + + + } + + + + Login + + + + + + @code { bool _loggingIn = false; @@ -65,5 +71,9 @@ _loggingIn = true; _successfulLogin = await _authenticationService.LoginUser(_loginForm.Email, _loginForm.Password); _loggingIn = false; + if (_successfulLogin) + { + Navigation.NavigateTo("/"); + } } } \ No newline at end of file diff --git a/Shifty.App/Shared/MainLayout.razor b/Shifty.App/Shared/MainLayout.razor index c9ab966..189eba2 100644 --- a/Shifty.App/Shared/MainLayout.razor +++ b/Shifty.App/Shared/MainLayout.razor @@ -1,4 +1,3 @@ -@using Shifty.App.Pages @using MudBlazor.Utilities @inherits LayoutComponentBase @@ -9,34 +8,27 @@ + + + + + + + Analog Shifty + - - - Analog Shifty - Shifty - - @Body - - - - - - - Please login - - - - - + + @Body + @code { @@ -59,10 +51,6 @@ } }; - protected override void OnInitialized() - { - } - void DrawerToggle() { _drawerOpen = !_drawerOpen; diff --git a/Shifty.App/_Imports.razor b/Shifty.App/_Imports.razor index 6859381..56cebf9 100644 --- a/Shifty.App/_Imports.razor +++ b/Shifty.App/_Imports.razor @@ -1,5 +1,6 @@ @using System.Net.Http @using System.Net.Http.Json +@using Microsoft.AspNetCore.Authorization @using Microsoft.AspNetCore.Components.Authorization @using Microsoft.AspNetCore.Components.Forms @using Microsoft.AspNetCore.Components.Routing @@ -11,3 +12,6 @@ @using Shifty.App.Shared @using MudBlazor + + +@attribute [Authorize] \ No newline at end of file