-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6143866
commit a4c25a7
Showing
9 changed files
with
2,875 additions
and
84 deletions.
There are no files selected for viewing
1,013 changes: 1,013 additions & 0 deletions
1,013
maERP.Server/Migrations/20230725194616_initDatabase.Designer.cs
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
1,010 changes: 1,010 additions & 0 deletions
1,010
maERP.Server/Migrations/ApplicationDbContextModelSnapshot.cs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
using maERP.Shared.Models; | ||
using Microsoft.AspNetCore.Components; | ||
using MudBlazor; | ||
using maERP.Shared.Contracts; | ||
using Blazored.LocalStorage; | ||
using System.Text.Json; | ||
|
||
namespace maERP.Shared.Pages.Auth; | ||
|
||
public partial class Login | ||
{ | ||
[Inject] | ||
private NavigationManager? _navManager { get; set; } | ||
|
||
[Inject] | ||
private ILocalStorageService? _localStorage { get; set; } | ||
|
||
[Inject] | ||
private IAuthenticationService? _authenticationService { get; set; } | ||
|
||
private string _title = "Login"; | ||
private bool _showServerOverlay; | ||
private string newServer = string.Empty; | ||
|
||
MudForm? _form; | ||
bool _success; | ||
bool _loading; | ||
|
||
List<LoginServer> _serverList = new(); | ||
LoginFormModel _model = new(); | ||
|
||
private string _spinnerClass = string.Empty; | ||
private string _errorMessage = string.Empty; | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
await base.OnInitializedAsync(); | ||
|
||
if(await _localStorage.ContainKeyAsync("serverList")) | ||
{ | ||
try | ||
{ | ||
string serverJson = await _localStorage.GetItemAsStringAsync("serverList"); | ||
_serverList = JsonSerializer.Deserialize<List<LoginServer>>(serverJson); | ||
} | ||
catch | ||
{ | ||
await _localStorage.RemoveItemAsync("serverList"); | ||
} | ||
} | ||
|
||
SelectFirstServerFromList(); | ||
|
||
if(await _localStorage.ContainKeyAsync("username")) | ||
{ | ||
_model.UserName = await _localStorage.GetItemAsStringAsync("username"); | ||
} | ||
} | ||
|
||
public void OpenServerOverlay() | ||
{ | ||
if (_showServerOverlay) | ||
{ | ||
_showServerOverlay = false; | ||
SelectFirstServerFromList(); | ||
} | ||
else | ||
{ | ||
_showServerOverlay = true; | ||
} | ||
|
||
StateHasChanged(); | ||
} | ||
|
||
void RemoveFromServerList(string s) | ||
{ | ||
_serverList = _serverList.Where(u => u.Url != s.ToString()).ToList(); | ||
} | ||
|
||
void AddToServerList() | ||
{ | ||
var newServerItem = new LoginServer | ||
{ | ||
Url = newServer, | ||
LastUsed = DateTime.MinValue, | ||
Version = string.Empty | ||
}; | ||
|
||
_serverList.Add(newServerItem); | ||
newServer = string.Empty; | ||
} | ||
|
||
void SelectFirstServerFromList() | ||
{ | ||
if (_serverList.Count > 0) | ||
{ | ||
_model.Server = _serverList.FirstOrDefault().Url; | ||
} | ||
} | ||
|
||
private async void OnSubmit() | ||
{ | ||
_spinnerClass = "spinner-border spinner-border-sm"; | ||
|
||
await _localStorage.SetItemAsStringAsync("server", _model.Server); | ||
|
||
var loginResponse = await _authenticationService.AuthenticateAsync(_model.UserName, _model.Password); | ||
|
||
if (loginResponse == true) | ||
{ | ||
if(_model.RememberMe == true) | ||
{ | ||
await _localStorage.SetItemAsStringAsync("username", _model.UserName); | ||
} | ||
|
||
string serverJson = JsonSerializer.Serialize(_serverList); | ||
await _localStorage.SetItemAsStringAsync("serverList", serverJson); | ||
|
||
_navManager.NavigateTo("/"); | ||
return; | ||
} | ||
|
||
_errorMessage = "Login fehlgeschlagen"; | ||
_spinnerClass = ""; | ||
|
||
await _localStorage.RemoveItemAsync("server"); | ||
|
||
this.StateHasChanged(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters