-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
6 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
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,25 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace ServerApp.Data | ||
{ | ||
public class Models | ||
{ | ||
} | ||
public class LoginModel | ||
{ | ||
[Required] | ||
public string Email { get; set; } | ||
|
||
[Required] | ||
public string Password { get; set; } | ||
|
||
public bool RememberMe { get; set; } | ||
} | ||
|
||
public class LoginResult | ||
{ | ||
public bool Successful { get; set; } | ||
public string Error { get; set; } | ||
public string Token { get; set; } | ||
} | ||
} |
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,79 @@ | ||
@page "/login" | ||
|
||
<h1>Login</h1> | ||
|
||
@if (ShowErrors) | ||
{ | ||
<div class="alert alert-danger" role="alert"> | ||
<p>@Error</p> | ||
</div> | ||
} | ||
|
||
<div class="card"> | ||
<div class="card-body"> | ||
<h5 class="card-title">Please enter your details</h5> | ||
<div class="form-group"> | ||
<label for="email">Email address</label> | ||
<text>@loginModel.Email</text> | ||
</div> | ||
<div class="form-group"> | ||
<label for="password">Password</label> | ||
<text>@loginModel.Password</text> | ||
</div> | ||
<button type="submit" class="btn btn-primary" @onclick="HandleLogin" >Submit</button> | ||
</div> | ||
</div> | ||
|
||
@code { | ||
public string ReturnUrl { get; set; } | ||
|
||
private LoginModel loginModel; | ||
private bool ShowErrors; | ||
private string Error = ""; | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
loginModel = new LoginModel(); | ||
} | ||
|
||
private async Task HandleLogin() | ||
{ | ||
ShowErrors = false; | ||
//string returnUrl = Url.Content("~/"); | ||
//try | ||
//{ | ||
// // Clear the existing external cookie | ||
// await HttpContext | ||
// .SignOutAsync( | ||
// CookieAuthenticationDefaults.AuthenticationScheme); | ||
//} | ||
//catch { } | ||
//// *** !!! This is where you would validate the user !!! *** | ||
//// In this example we just log the user in | ||
//// (Always log the user in for this demo) | ||
//var claims = new List<Claim> | ||
//{ | ||
// new Claim(ClaimTypes.Name, loginModel.Email), | ||
// new Claim(ClaimTypes.Role, "Administrator"), | ||
//}; | ||
//var claimsIdentity = new ClaimsIdentity( | ||
// claims, CookieAuthenticationDefaults.AuthenticationScheme); | ||
//var authProperties = new AuthenticationProperties | ||
//{ | ||
// IsPersistent = true, | ||
// RedirectUri = this.Request.Host.Value | ||
//}; | ||
//try | ||
//{ | ||
// await HttpContext.SignInAsync( | ||
// CookieAuthenticationDefaults.AuthenticationScheme, | ||
// new ClaimsPrincipal(claimsIdentity), | ||
// authProperties); | ||
//} | ||
//catch (Exception ex) | ||
//{ | ||
// string error = ex.Message; | ||
//} | ||
//return LocalRedirect(returnUrl); | ||
} | ||
} |
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