114 lines
		
	
	
		
			3.9 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			114 lines
		
	
	
		
			3.9 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
| @page "/login"
 | |
| @page "/login/{redirectUrl}"
 | |
| @page "/login/{redirectUrl}/{redirectUrlSub}"
 | |
| @attribute [AllowAnonymous]
 | |
| @inject MesaFabApprovalAuthStateProvider authStateProvider
 | |
| @inject NavigationManager navManager
 | |
| @inject ISnackbar snackbar
 | |
| 
 | |
| <MudPaper Class="p-2 m-2">
 | |
|     <MudText Typo="Typo.h3" Align="Align.Center">Login</MudText>
 | |
| </MudPaper>
 | |
| 
 | |
| <MudPaper Class="p-2 m-2">
 | |
|     <MudForm @bind-IsValid="@success" @bind-Errors="@errors">
 | |
|         <MudTextField T="string"
 | |
|                       Label="Windows Username"
 | |
|                       Required="true"
 | |
|                       RequiredError="Username is required!"
 | |
|                       Variant="Variant.Outlined"
 | |
|                       @bind-Value=username 
 | |
|                       Class="m-1"
 | |
|                       Immediate="true"
 | |
|                       AutoFocus
 | |
|                       OnKeyDown=SubmitIfEnter />
 | |
|         <MudTextField T="string"
 | |
|                       Label="Windows Password"
 | |
|                       Required="true"
 | |
|                       RequiredError="Password is required!"
 | |
|                       Variant="Variant.Outlined"
 | |
|                       @bind-Value=password
 | |
|                       InputType="InputType.Password"
 | |
|                       Class="m-1"
 | |
|                       Immediate="true" 
 | |
|                       OnKeyDown=SubmitIfEnter />
 | |
|         <MudButton 
 | |
|             Variant="Variant.Filled"
 | |
|             Color="Color.Tertiary"
 | |
|             Disabled="@(!success)"
 | |
|             Class="m-1"
 | |
|             OnClick=SubmitLogin >
 | |
|             @if (processing) {
 | |
|                 <MudProgressCircular Class="m-1" Size="Size.Small" Indeterminate="true" />
 | |
|                 <MudText>Processing</MudText>
 | |
|             } else {
 | |
|                 <MudText>Log In</MudText>
 | |
|             }
 | |
|         </MudButton>
 | |
|         <MudDivider />
 | |
|         @* <MudButton
 | |
|             Variant="Variant.Filled"
 | |
|             Color="Color.Tertiary"
 | |
|             Class="m-1"
 | |
|             OnClick="LoginLocal" >
 | |
|         @if (processingLocal) {
 | |
|             <MudProgressCircular Class="m-1" Size="Size.Small" Indeterminate="true" />
 | |
|             <MudText>Processing</MudText>
 | |
|         } else {
 | |
|             <MudText>Log In (SSO)</MudText>
 | |
|         }
 | |
|         </MudButton> *@
 | |
|     </MudForm>
 | |
| </MudPaper>
 | |
| 
 | |
| @code {
 | |
|     [Parameter]
 | |
|     public string? redirectUrl { get; set; }
 | |
|     [Parameter]
 | |
|     public string? redirectUrlSub { get; set; }
 | |
|     private bool success;
 | |
|     private bool processing = false;
 | |
|     private bool processingLocal = false;
 | |
|     private string[] errors = { };
 | |
|     private string? username;
 | |
|     private string? password;
 | |
| 
 | |
|     private async Task SubmitLogin() {
 | |
|         processing = true;
 | |
|         if (string.IsNullOrWhiteSpace(username)) snackbar.Add("Username is required!", Severity.Error);
 | |
|         else if (string.IsNullOrWhiteSpace(password)) snackbar.Add("Password is required!", Severity.Error);
 | |
|         else {
 | |
|             await authStateProvider.LoginAsync(username, password);
 | |
|             if (!string.IsNullOrWhiteSpace(redirectUrl) && !string.IsNullOrWhiteSpace(redirectUrlSub)) {
 | |
|                 navManager.NavigateTo($"{redirectUrl}/{redirectUrlSub}");
 | |
|             } else if (!string.IsNullOrWhiteSpace(redirectUrl)) {
 | |
|                 navManager.NavigateTo(redirectUrl);
 | |
|             } else {
 | |
|                 navManager.NavigateTo("dashboard");
 | |
|             }
 | |
|         }
 | |
|         processing = false;
 | |
|     }
 | |
| 
 | |
|     private async Task SubmitIfEnter(KeyboardEventArgs e) {
 | |
|         if (e.Key == "Enter" && success) {
 | |
|             SubmitLogin();
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     private async Task LoginLocal() {
 | |
|         processingLocal = true;
 | |
| 
 | |
|         await authStateProvider.LoginLocal();
 | |
|         if (!string.IsNullOrWhiteSpace(redirectUrl) && !string.IsNullOrWhiteSpace(redirectUrlSub)) {
 | |
|             navManager.NavigateTo($"{redirectUrl}/{redirectUrlSub}");
 | |
|         } else if (!string.IsNullOrWhiteSpace(redirectUrl)) {
 | |
|             navManager.NavigateTo(redirectUrl);
 | |
|         } else {
 | |
|             navManager.NavigateTo("dashboard");
 | |
|         }
 | |
| 
 | |
|         processingLocal = false;
 | |
|     }
 | |
| }
 |