This commit integrates ASP.NET Core Identity into the application to enable user registration, login, and management. This lays the groundwork for securing data per user.
**Key Changes:**
* **DbContext Configuration:**
* Modified `ApplicationDbContext.cs` to inherit from `IdentityDbContext<IdentityUser>`.
* Removed an unnecessary `using` statement from `ApplicationDbContext.cs`.
* **Program.cs Setup:**
* Configured `AddDefaultIdentity<IdentityUser>` with `AddEntityFrameworkStores<ApplicationDbContext>()` to register Identity services.
* Ensured correct ordering of `UseAuthentication()` and `UseAuthorization()` middleware.
* Added `app.MapRazorPages()` to enable the Identity UI pages.
* Verified core package versions in `turf_tasker.csproj` for consistency across EF Core and Identity components (`8.0.6`).
* **Identity UI:**
* Scaffolded ASP.NET Core Identity pages (Login, Register, Manage, etc.) to provide the user interface for authentication.
* Added a `_LoginPartial.cshtml` partial view to the `Views/Shared` folder.
* Rendered `_LoginPartial` in `Views/Shared/_Layout.cshtml` to display login/register/logout links in the navigation bar.
* **Migrations:**
* Created and applied a new migration (`AddIdentitySchema`) to create the necessary ASP.NET Core Identity database tables (e.g., `AspNetUsers`, `AspNetRoles`).
83 lines
3.7 KiB
Text
83 lines
3.7 KiB
Text
@page
|
|
@model LoginModel
|
|
|
|
@{
|
|
ViewData["Title"] = "Log in";
|
|
}
|
|
|
|
<h1>@ViewData["Title"]</h1>
|
|
<div class="row">
|
|
<div class="col-md-4">
|
|
<section>
|
|
<form id="account" method="post">
|
|
<h2>Use a local account to log in.</h2>
|
|
<hr />
|
|
<div asp-validation-summary="ModelOnly" class="text-danger" role="alert"></div>
|
|
<div class="form-floating mb-3">
|
|
<input asp-for="Input.Email" class="form-control" autocomplete="username" aria-required="true" placeholder="name@example.com" />
|
|
<label asp-for="Input.Email" class="form-label">Email</label>
|
|
<span asp-validation-for="Input.Email" class="text-danger"></span>
|
|
</div>
|
|
<div class="form-floating mb-3">
|
|
<input asp-for="Input.Password" class="form-control" autocomplete="current-password" aria-required="true" placeholder="password" />
|
|
<label asp-for="Input.Password" class="form-label">Password</label>
|
|
<span asp-validation-for="Input.Password" class="text-danger"></span>
|
|
</div>
|
|
<div class="checkbox mb-3">
|
|
<label asp-for="Input.RememberMe" class="form-label">
|
|
<input class="form-check-input" asp-for="Input.RememberMe" />
|
|
@Html.DisplayNameFor(m => m.Input.RememberMe)
|
|
</label>
|
|
</div>
|
|
<div>
|
|
<button id="login-submit" type="submit" class="w-100 btn btn-lg btn-primary">Log in</button>
|
|
</div>
|
|
<div>
|
|
<p>
|
|
<a id="forgot-password" asp-page="./ForgotPassword">Forgot your password?</a>
|
|
</p>
|
|
<p>
|
|
<a asp-page="./Register" asp-route-returnUrl="@Model.ReturnUrl">Register as a new user</a>
|
|
</p>
|
|
<p>
|
|
<a id="resend-confirmation" asp-page="./ResendEmailConfirmation">Resend email confirmation</a>
|
|
</p>
|
|
</div>
|
|
</form>
|
|
</section>
|
|
</div>
|
|
<div class="col-md-6 col-md-offset-2">
|
|
<section>
|
|
<h3>Use another service to log in.</h3>
|
|
<hr />
|
|
@{
|
|
if ((Model.ExternalLogins?.Count ?? 0) == 0)
|
|
{
|
|
<div>
|
|
<p>
|
|
There are no external authentication services configured. See this <a href="https://go.microsoft.com/fwlink/?LinkID=532715">article
|
|
about setting up this ASP.NET application to support logging in via external services</a>.
|
|
</p>
|
|
</div>
|
|
}
|
|
else
|
|
{
|
|
<form id="external-account" asp-page="./ExternalLogin" asp-route-returnUrl="@Model.ReturnUrl" method="post" class="form-horizontal">
|
|
<div>
|
|
<p>
|
|
@foreach (var provider in Model.ExternalLogins!)
|
|
{
|
|
<button type="submit" class="btn btn-primary" name="provider" value="@provider.Name" title="Log in using your @provider.DisplayName account">@provider.DisplayName</button>
|
|
}
|
|
</p>
|
|
</div>
|
|
</form>
|
|
}
|
|
}
|
|
</section>
|
|
</div>
|
|
</div>
|
|
|
|
@section Scripts {
|
|
<partial name="_ValidationScriptsPartial" />
|
|
}
|