mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
User RCL .NET Identity.
This commit is contained in:
@@ -31,6 +31,7 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Cicm.Database.Models;
|
using Cicm.Database.Models;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Cicm.Database.Models;
|
using Cicm.Database.Models;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
@@ -39,6 +40,7 @@ using Microsoft.EntityFrameworkCore.Query;
|
|||||||
namespace cicm_web.Areas.Admin.Controllers
|
namespace cicm_web.Areas.Admin.Controllers
|
||||||
{
|
{
|
||||||
[Area("Admin")]
|
[Area("Admin")]
|
||||||
|
[Authorize]
|
||||||
public class CompaniesController : Controller
|
public class CompaniesController : Controller
|
||||||
{
|
{
|
||||||
readonly cicmContext _context;
|
readonly cicmContext _context;
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ using Cicm.Database.Models;
|
|||||||
using cicm_web.Areas.Identity;
|
using cicm_web.Areas.Identity;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
[assembly: HostingStartup(typeof(IdentityHostingStartup))]
|
[assembly: HostingStartup(typeof(IdentityHostingStartup))]
|
||||||
@@ -45,11 +44,7 @@ namespace cicm_web.Areas.Identity
|
|||||||
{
|
{
|
||||||
builder.ConfigureServices((context, services) =>
|
builder.ConfigureServices((context, services) =>
|
||||||
{
|
{
|
||||||
services.AddDbContext<cicmContext>(options => options
|
services.AddDefaultIdentity<IdentityUser>()
|
||||||
.UseLazyLoadingProxies()
|
|
||||||
.UseMySql("server=localhost;port=3306;user=cicm;password=cicmpass;database=cicm"));
|
|
||||||
|
|
||||||
services.AddDefaultIdentity<IdentityUser>().AddRoles<IdentityRole>()
|
|
||||||
.AddEntityFrameworkStores<cicmContext>();
|
.AddEntityFrameworkStores<cicmContext>();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : AccessDenied.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
}
|
|
||||||
@page
|
|
||||||
@model AccessDeniedModel
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Access denied";
|
|
||||||
}
|
|
||||||
|
|
||||||
<header>
|
|
||||||
<h1 class="text-danger">@ViewData["Title"]</h1>
|
|
||||||
<p class="text-danger">You do not have access to this resource.</p>
|
|
||||||
</header>
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : AccessDenied.cshtml.cs
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
||||||
|
|
||||||
namespace cicm_web.Areas.Identity.Pages.Account
|
|
||||||
{
|
|
||||||
public class AccessDeniedModel : PageModel
|
|
||||||
{
|
|
||||||
public void OnGet() { }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : ConfirmEmail.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
}
|
|
||||||
@page
|
|
||||||
@model ConfirmEmailModel
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Confirm email";
|
|
||||||
}
|
|
||||||
|
|
||||||
<h1>@ViewData["Title"]</h1>
|
|
||||||
<div>
|
|
||||||
<p>
|
|
||||||
Thank you for confirming your email.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : ConfirmEmail.cshtml.cs
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Identity;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
||||||
|
|
||||||
namespace cicm_web.Areas.Identity.Pages.Account
|
|
||||||
{
|
|
||||||
[AllowAnonymous]
|
|
||||||
public class ConfirmEmailModel : PageModel
|
|
||||||
{
|
|
||||||
readonly UserManager<IdentityUser> _userManager;
|
|
||||||
|
|
||||||
public ConfirmEmailModel(UserManager<IdentityUser> userManager)
|
|
||||||
{
|
|
||||||
_userManager = userManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnGetAsync(string userId, string code)
|
|
||||||
{
|
|
||||||
if(userId == null || code == null) return RedirectToPage("/Index");
|
|
||||||
|
|
||||||
IdentityUser user = await _userManager.FindByIdAsync(userId);
|
|
||||||
if(user == null) return NotFound($"Unable to load user with ID '{userId}'.");
|
|
||||||
|
|
||||||
IdentityResult result = await _userManager.ConfirmEmailAsync(user, code);
|
|
||||||
if(!result.Succeeded)
|
|
||||||
throw new InvalidOperationException($"Error confirming email for user with ID '{userId}':");
|
|
||||||
|
|
||||||
return Page();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : ExternalLogin.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
}
|
|
||||||
@page
|
|
||||||
@model ExternalLoginModel
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Register";
|
|
||||||
}
|
|
||||||
|
|
||||||
<h1>@ViewData["Title"]</h1>
|
|
||||||
<h4>Associate your @Model.LoginProvider account.</h4>
|
|
||||||
<hr />
|
|
||||||
|
|
||||||
<p class="text-info">
|
|
||||||
You've successfully authenticated with <strong>@Model.LoginProvider</strong>.
|
|
||||||
Please enter an email address for this site below and click the Register button to finish
|
|
||||||
logging in.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-4">
|
|
||||||
<form asp-page-handler="Confirmation"
|
|
||||||
asp-route-returnUrl="@Model.ReturnUrl"
|
|
||||||
method="post">
|
|
||||||
<div asp-validation-summary="All"
|
|
||||||
class="text-danger">
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Input.Email"></label>
|
|
||||||
<input asp-for="Input.Email"
|
|
||||||
class="form-control" />
|
|
||||||
<span asp-validation-for="Input.Email"
|
|
||||||
class="text-danger">
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<button class="btn btn-primary"
|
|
||||||
type="submit">
|
|
||||||
Register
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@section Scripts {
|
|
||||||
<partial name="_ValidationScriptsPartial" />
|
|
||||||
}
|
|
||||||
@@ -1,157 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : ExternalLogin.cshtml.cs
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.Security.Claims;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Authentication;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Identity;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using SignInResult = Microsoft.AspNetCore.Identity.SignInResult;
|
|
||||||
|
|
||||||
namespace cicm_web.Areas.Identity.Pages.Account
|
|
||||||
{
|
|
||||||
[AllowAnonymous]
|
|
||||||
public class ExternalLoginModel : PageModel
|
|
||||||
{
|
|
||||||
readonly ILogger<ExternalLoginModel> _logger;
|
|
||||||
readonly SignInManager<IdentityUser> _signInManager;
|
|
||||||
readonly UserManager<IdentityUser> _userManager;
|
|
||||||
|
|
||||||
public ExternalLoginModel(SignInManager<IdentityUser> signInManager, UserManager<IdentityUser> userManager,
|
|
||||||
ILogger<ExternalLoginModel> logger)
|
|
||||||
{
|
|
||||||
_signInManager = signInManager;
|
|
||||||
_userManager = userManager;
|
|
||||||
_logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
[BindProperty]
|
|
||||||
public InputModel Input { get; set; }
|
|
||||||
|
|
||||||
public string LoginProvider { get; set; }
|
|
||||||
|
|
||||||
public string ReturnUrl { get; set; }
|
|
||||||
|
|
||||||
[TempData]
|
|
||||||
public string ErrorMessage { get; set; }
|
|
||||||
|
|
||||||
public IActionResult OnGetAsync() => RedirectToPage("./Login");
|
|
||||||
|
|
||||||
public IActionResult OnPost(string provider, string returnUrl = null)
|
|
||||||
{
|
|
||||||
// Request a redirect to the external login provider.
|
|
||||||
string redirectUrl = Url.Page("./ExternalLogin", "Callback", new {returnUrl});
|
|
||||||
AuthenticationProperties properties =
|
|
||||||
_signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);
|
|
||||||
return new ChallengeResult(provider, properties);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnGetCallbackAsync(string returnUrl = null, string remoteError = null)
|
|
||||||
{
|
|
||||||
returnUrl = returnUrl ?? Url.Content("~/");
|
|
||||||
if(remoteError != null)
|
|
||||||
{
|
|
||||||
ErrorMessage = $"Error from external provider: {remoteError}";
|
|
||||||
return RedirectToPage("./Login", new {ReturnUrl = returnUrl});
|
|
||||||
}
|
|
||||||
|
|
||||||
ExternalLoginInfo info = await _signInManager.GetExternalLoginInfoAsync();
|
|
||||||
if(info == null)
|
|
||||||
{
|
|
||||||
ErrorMessage = "Error loading external login information.";
|
|
||||||
return RedirectToPage("./Login", new {ReturnUrl = returnUrl});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sign in the user with this external login provider if the user already has a login.
|
|
||||||
SignInResult result =
|
|
||||||
await _signInManager.ExternalLoginSignInAsync(info.LoginProvider, info.ProviderKey, false, true);
|
|
||||||
if(result.Succeeded)
|
|
||||||
{
|
|
||||||
_logger.LogInformation("{Name} logged in with {LoginProvider} provider.", info.Principal.Identity.Name,
|
|
||||||
info.LoginProvider);
|
|
||||||
return LocalRedirect(returnUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(result.IsLockedOut) return RedirectToPage("./Lockout");
|
|
||||||
|
|
||||||
// If the user does not have an account, then ask the user to create an account.
|
|
||||||
ReturnUrl = returnUrl;
|
|
||||||
LoginProvider = info.LoginProvider;
|
|
||||||
if(info.Principal.HasClaim(c => c.Type == ClaimTypes.Email))
|
|
||||||
Input = new InputModel {Email = info.Principal.FindFirstValue(ClaimTypes.Email)};
|
|
||||||
return Page();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostConfirmationAsync(string returnUrl = null)
|
|
||||||
{
|
|
||||||
returnUrl = returnUrl ?? Url.Content("~/");
|
|
||||||
// Get the information about the user from the external login provider
|
|
||||||
ExternalLoginInfo info = await _signInManager.GetExternalLoginInfoAsync();
|
|
||||||
if(info == null)
|
|
||||||
{
|
|
||||||
ErrorMessage = "Error loading external login information during confirmation.";
|
|
||||||
return RedirectToPage("./Login", new {ReturnUrl = returnUrl});
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ModelState.IsValid)
|
|
||||||
{
|
|
||||||
IdentityUser user = new IdentityUser {UserName = Input.Email, Email = Input.Email};
|
|
||||||
IdentityResult result = await _userManager.CreateAsync(user);
|
|
||||||
if(result.Succeeded)
|
|
||||||
{
|
|
||||||
result = await _userManager.AddLoginAsync(user, info);
|
|
||||||
if(result.Succeeded)
|
|
||||||
{
|
|
||||||
await _signInManager.SignInAsync(user, false);
|
|
||||||
_logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider);
|
|
||||||
return LocalRedirect(returnUrl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach(IdentityError error in result.Errors) ModelState.AddModelError(string.Empty, error.Description);
|
|
||||||
}
|
|
||||||
|
|
||||||
LoginProvider = info.LoginProvider;
|
|
||||||
ReturnUrl = returnUrl;
|
|
||||||
return Page();
|
|
||||||
}
|
|
||||||
|
|
||||||
public class InputModel
|
|
||||||
{
|
|
||||||
[Required]
|
|
||||||
[EmailAddress]
|
|
||||||
public string Email { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : ForgotPassword.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
}
|
|
||||||
@page
|
|
||||||
@model ForgotPasswordModel
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Forgot your password?";
|
|
||||||
}
|
|
||||||
|
|
||||||
<h1>@ViewData["Title"]</h1>
|
|
||||||
<h4>Enter your email.</h4>
|
|
||||||
<hr />
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-4">
|
|
||||||
<form method="post">
|
|
||||||
<div asp-validation-summary="All"
|
|
||||||
class="text-danger">
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Input.Email"></label>
|
|
||||||
<input asp-for="Input.Email"
|
|
||||||
class="form-control" />
|
|
||||||
<span asp-validation-for="Input.Email"
|
|
||||||
class="text-danger">
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<button class="btn btn-primary"
|
|
||||||
type="submit">
|
|
||||||
Submit
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@section Scripts {
|
|
||||||
<partial name="_ValidationScriptsPartial" />
|
|
||||||
}
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : ForgotPassword.cshtml.cs
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.Text.Encodings.Web;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Identity;
|
|
||||||
using Microsoft.AspNetCore.Identity.UI.Services;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
||||||
|
|
||||||
namespace cicm_web.Areas.Identity.Pages.Account
|
|
||||||
{
|
|
||||||
[AllowAnonymous]
|
|
||||||
public class ForgotPasswordModel : PageModel
|
|
||||||
{
|
|
||||||
readonly IEmailSender _emailSender;
|
|
||||||
readonly UserManager<IdentityUser> _userManager;
|
|
||||||
|
|
||||||
public ForgotPasswordModel(UserManager<IdentityUser> userManager, IEmailSender emailSender)
|
|
||||||
{
|
|
||||||
_userManager = userManager;
|
|
||||||
_emailSender = emailSender;
|
|
||||||
}
|
|
||||||
|
|
||||||
[BindProperty]
|
|
||||||
public InputModel Input { get; set; }
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostAsync()
|
|
||||||
{
|
|
||||||
if(!ModelState.IsValid) return Page();
|
|
||||||
|
|
||||||
IdentityUser user = await _userManager.FindByEmailAsync(Input.Email);
|
|
||||||
if(user == null || !await _userManager.IsEmailConfirmedAsync(user))
|
|
||||||
// Don't reveal that the user does not exist or is not confirmed
|
|
||||||
return RedirectToPage("./ForgotPasswordConfirmation");
|
|
||||||
|
|
||||||
// For more information on how to enable account confirmation and password reset please
|
|
||||||
// visit https://go.microsoft.com/fwlink/?LinkID=532713
|
|
||||||
string code = await _userManager.GeneratePasswordResetTokenAsync(user);
|
|
||||||
string callbackUrl = Url.Page("/Account/ResetPassword", null, new {code}, Request.Scheme);
|
|
||||||
|
|
||||||
await _emailSender.SendEmailAsync(Input.Email, "Reset Password",
|
|
||||||
$"Please reset your password by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");
|
|
||||||
|
|
||||||
return RedirectToPage("./ForgotPasswordConfirmation");
|
|
||||||
}
|
|
||||||
|
|
||||||
public class InputModel
|
|
||||||
{
|
|
||||||
[Required]
|
|
||||||
[EmailAddress]
|
|
||||||
public string Email { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : ForgotPasswordConfirmation.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
}
|
|
||||||
@page
|
|
||||||
@model ForgotPasswordConfirmation
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Forgot password confirmation";
|
|
||||||
}
|
|
||||||
|
|
||||||
<h1>@ViewData["Title"]</h1>
|
|
||||||
<p>
|
|
||||||
Please check your email to reset your password.
|
|
||||||
</p>
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : ForgotPasswordConfirmation.cshtml.cs
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
||||||
|
|
||||||
namespace cicm_web.Areas.Identity.Pages.Account
|
|
||||||
{
|
|
||||||
[AllowAnonymous]
|
|
||||||
public class ForgotPasswordConfirmation : PageModel
|
|
||||||
{
|
|
||||||
public void OnGet() { }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : Lockout.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
}
|
|
||||||
@page
|
|
||||||
@model LockoutModel
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Locked out";
|
|
||||||
}
|
|
||||||
|
|
||||||
<header>
|
|
||||||
<h1 class="text-danger">@ViewData["Title"]</h1>
|
|
||||||
<p class="text-danger">This account has been locked out, please try again later.</p>
|
|
||||||
</header>
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : Lockout.cshtml.cs
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
||||||
|
|
||||||
namespace cicm_web.Areas.Identity.Pages.Account
|
|
||||||
{
|
|
||||||
[AllowAnonymous]
|
|
||||||
public class LockoutModel : PageModel
|
|
||||||
{
|
|
||||||
public void OnGet() { }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,141 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : Login.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
}
|
|
||||||
@page
|
|
||||||
@using Microsoft.AspNetCore.Authentication
|
|
||||||
@model LoginModel
|
|
||||||
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Log in";
|
|
||||||
}
|
|
||||||
|
|
||||||
<h1>@ViewData["Title"]</h1>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-4">
|
|
||||||
<section>
|
|
||||||
<form id="account"
|
|
||||||
method="post">
|
|
||||||
<h4>Use a local account to log in.</h4>
|
|
||||||
<hr />
|
|
||||||
<div asp-validation-summary="All"
|
|
||||||
class="text-danger">
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Input.Email"></label>
|
|
||||||
<input asp-for="Input.Email"
|
|
||||||
class="form-control" />
|
|
||||||
<span asp-validation-for="Input.Email"
|
|
||||||
class="text-danger">
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Input.Password"></label>
|
|
||||||
<input asp-for="Input.Password"
|
|
||||||
class="form-control" />
|
|
||||||
<span asp-validation-for="Input.Password"
|
|
||||||
class="text-danger">
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<div class="checkbox">
|
|
||||||
<label asp-for="Input.RememberMe">
|
|
||||||
<input asp-for="Input.RememberMe" />
|
|
||||||
@Html.DisplayNameFor(m => m.Input.RememberMe)
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<button class="btn btn-primary"
|
|
||||||
type="submit">
|
|
||||||
Log in
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<p>
|
|
||||||
<a asp-page="./ForgotPassword"
|
|
||||||
id="forgot-password">
|
|
||||||
Forgot your password?
|
|
||||||
</a>
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
<a asp-page="./Register"
|
|
||||||
asp-route-returnUrl="@Model.ReturnUrl">
|
|
||||||
Register as a new user
|
|
||||||
</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</section>
|
|
||||||
</div>
|
|
||||||
<div class="col-md-6 col-md-offset-2">
|
|
||||||
<section>
|
|
||||||
<h4>Use another service to log in.</h4>
|
|
||||||
<hr />
|
|
||||||
@{
|
|
||||||
if((Model.ExternalLogins?.Count ?? 0) == 0)
|
|
||||||
{
|
|
||||||
<div>
|
|
||||||
<p>
|
|
||||||
There are no external authentication services configured. See <a href="https://go.microsoft.com/fwlink/?LinkID=532715">this article</a>
|
|
||||||
for details on setting up this ASP.NET application to support logging in via external services.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
<form id="external-account"
|
|
||||||
asp-page="./ExternalLogin"
|
|
||||||
asp-route-returnUrl="@Model.ReturnUrl"
|
|
||||||
method="post"
|
|
||||||
class="form-horizontal">
|
|
||||||
<div>
|
|
||||||
<p>
|
|
||||||
@foreach(AuthenticationScheme 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" />
|
|
||||||
}
|
|
||||||
@@ -1,128 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : Login.cshtml.cs
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Authentication;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Identity;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using SignInResult = Microsoft.AspNetCore.Identity.SignInResult;
|
|
||||||
|
|
||||||
namespace cicm_web.Areas.Identity.Pages.Account
|
|
||||||
{
|
|
||||||
[AllowAnonymous]
|
|
||||||
public class LoginModel : PageModel
|
|
||||||
{
|
|
||||||
readonly ILogger<LoginModel> _logger;
|
|
||||||
readonly SignInManager<IdentityUser> _signInManager;
|
|
||||||
|
|
||||||
public LoginModel(SignInManager<IdentityUser> signInManager, ILogger<LoginModel> logger)
|
|
||||||
{
|
|
||||||
_signInManager = signInManager;
|
|
||||||
_logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
[BindProperty]
|
|
||||||
public InputModel Input { get; set; }
|
|
||||||
|
|
||||||
public IList<AuthenticationScheme> ExternalLogins { get; set; }
|
|
||||||
|
|
||||||
public string ReturnUrl { get; set; }
|
|
||||||
|
|
||||||
[TempData]
|
|
||||||
public string ErrorMessage { get; set; }
|
|
||||||
|
|
||||||
public async Task OnGetAsync(string returnUrl = null)
|
|
||||||
{
|
|
||||||
if(!string.IsNullOrEmpty(ErrorMessage)) ModelState.AddModelError(string.Empty, ErrorMessage);
|
|
||||||
|
|
||||||
returnUrl = returnUrl ?? Url.Content("~/");
|
|
||||||
|
|
||||||
// Clear the existing external cookie to ensure a clean login process
|
|
||||||
await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);
|
|
||||||
|
|
||||||
ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
|
|
||||||
|
|
||||||
ReturnUrl = returnUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostAsync(string returnUrl = null)
|
|
||||||
{
|
|
||||||
returnUrl = returnUrl ?? Url.Content("~/");
|
|
||||||
|
|
||||||
if(ModelState.IsValid)
|
|
||||||
{
|
|
||||||
// This doesn't count login failures towards account lockout
|
|
||||||
// To enable password failures to trigger account lockout, set lockoutOnFailure: true
|
|
||||||
SignInResult result =
|
|
||||||
await _signInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, true);
|
|
||||||
if(result.Succeeded)
|
|
||||||
{
|
|
||||||
_logger.LogInformation("User logged in.");
|
|
||||||
return LocalRedirect(returnUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(result.RequiresTwoFactor)
|
|
||||||
return RedirectToPage("./LoginWith2fa", new {ReturnUrl = returnUrl, Input.RememberMe});
|
|
||||||
|
|
||||||
if(result.IsLockedOut)
|
|
||||||
{
|
|
||||||
_logger.LogWarning("User account locked out.");
|
|
||||||
return RedirectToPage("./Lockout");
|
|
||||||
}
|
|
||||||
|
|
||||||
ModelState.AddModelError(string.Empty, "Invalid login attempt.");
|
|
||||||
return Page();
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we got this far, something failed, redisplay form
|
|
||||||
return Page();
|
|
||||||
}
|
|
||||||
|
|
||||||
public class InputModel
|
|
||||||
{
|
|
||||||
[Required]
|
|
||||||
[EmailAddress]
|
|
||||||
public string Email { get; set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
[DataType(DataType.Password)]
|
|
||||||
public string Password { get; set; }
|
|
||||||
|
|
||||||
[Display(Name = "Remember me?")]
|
|
||||||
public bool RememberMe { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : LoginWith2fa.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
}
|
|
||||||
@page
|
|
||||||
@model LoginWith2faModel
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Two-factor authentication";
|
|
||||||
}
|
|
||||||
|
|
||||||
<h1>@ViewData["Title"]</h1>
|
|
||||||
<hr />
|
|
||||||
<p>Your login is protected with an authenticator app. Enter your authenticator code below.</p>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-4">
|
|
||||||
<form method="post"
|
|
||||||
asp-route-returnUrl="@Model.ReturnUrl">
|
|
||||||
<input asp-for="RememberMe"
|
|
||||||
type="hidden" />
|
|
||||||
<div asp-validation-summary="All"
|
|
||||||
class="text-danger">
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Input.TwoFactorCode"></label>
|
|
||||||
<input asp-for="Input.TwoFactorCode"
|
|
||||||
class="form-control"
|
|
||||||
autocomplete="off" />
|
|
||||||
<span asp-validation-for="Input.TwoFactorCode"
|
|
||||||
class="text-danger">
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<div class="checkbox">
|
|
||||||
<label asp-for="Input.RememberMachine">
|
|
||||||
<input asp-for="Input.RememberMachine" />
|
|
||||||
@Html.DisplayNameFor(m => m.Input.RememberMachine)
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<button class="btn btn-primary"
|
|
||||||
type="submit">
|
|
||||||
Log in
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<p>
|
|
||||||
Don't have access to your authenticator device? You can
|
|
||||||
<a id="recovery-code-login"
|
|
||||||
asp-page="./LoginWithRecoveryCode"
|
|
||||||
asp-route-returnUrl="@Model.ReturnUrl">
|
|
||||||
log in with a recovery code
|
|
||||||
</a>.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
@section Scripts {
|
|
||||||
<partial name="_ValidationScriptsPartial" />
|
|
||||||
}
|
|
||||||
@@ -1,120 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : LoginWith2fa.cshtml.cs
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Identity;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using SignInResult = Microsoft.AspNetCore.Identity.SignInResult;
|
|
||||||
|
|
||||||
namespace cicm_web.Areas.Identity.Pages.Account
|
|
||||||
{
|
|
||||||
[AllowAnonymous]
|
|
||||||
public class LoginWith2faModel : PageModel
|
|
||||||
{
|
|
||||||
readonly ILogger<LoginWith2faModel> _logger;
|
|
||||||
readonly SignInManager<IdentityUser> _signInManager;
|
|
||||||
|
|
||||||
public LoginWith2faModel(SignInManager<IdentityUser> signInManager, ILogger<LoginWith2faModel> logger)
|
|
||||||
{
|
|
||||||
_signInManager = signInManager;
|
|
||||||
_logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
[BindProperty]
|
|
||||||
public InputModel Input { get; set; }
|
|
||||||
|
|
||||||
public bool RememberMe { get; set; }
|
|
||||||
|
|
||||||
public string ReturnUrl { get; set; }
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnGetAsync(bool rememberMe, string returnUrl = null)
|
|
||||||
{
|
|
||||||
// Ensure the user has gone through the username & password screen first
|
|
||||||
IdentityUser user = await _signInManager.GetTwoFactorAuthenticationUserAsync();
|
|
||||||
|
|
||||||
if(user == null) throw new InvalidOperationException("Unable to load two-factor authentication user.");
|
|
||||||
|
|
||||||
ReturnUrl = returnUrl;
|
|
||||||
RememberMe = rememberMe;
|
|
||||||
|
|
||||||
return Page();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostAsync(bool rememberMe, string returnUrl = null)
|
|
||||||
{
|
|
||||||
if(!ModelState.IsValid) return Page();
|
|
||||||
|
|
||||||
returnUrl = returnUrl ?? Url.Content("~/");
|
|
||||||
|
|
||||||
IdentityUser user = await _signInManager.GetTwoFactorAuthenticationUserAsync();
|
|
||||||
if(user == null) throw new InvalidOperationException("Unable to load two-factor authentication user.");
|
|
||||||
|
|
||||||
string authenticatorCode = Input.TwoFactorCode.Replace(" ", string.Empty).Replace("-", string.Empty);
|
|
||||||
|
|
||||||
SignInResult result =
|
|
||||||
await _signInManager.TwoFactorAuthenticatorSignInAsync(authenticatorCode, rememberMe,
|
|
||||||
Input.RememberMachine);
|
|
||||||
|
|
||||||
if(result.Succeeded)
|
|
||||||
{
|
|
||||||
_logger.LogInformation("User with ID '{UserId}' logged in with 2fa.", user.Id);
|
|
||||||
return LocalRedirect(returnUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(result.IsLockedOut)
|
|
||||||
{
|
|
||||||
_logger.LogWarning("User with ID '{UserId}' account locked out.", user.Id);
|
|
||||||
return RedirectToPage("./Lockout");
|
|
||||||
}
|
|
||||||
|
|
||||||
_logger.LogWarning("Invalid authenticator code entered for user with ID '{UserId}'.", user.Id);
|
|
||||||
ModelState.AddModelError(string.Empty, "Invalid authenticator code.");
|
|
||||||
return Page();
|
|
||||||
}
|
|
||||||
|
|
||||||
public class InputModel
|
|
||||||
{
|
|
||||||
[Required]
|
|
||||||
[StringLength(7, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.",
|
|
||||||
MinimumLength = 6)]
|
|
||||||
[DataType(DataType.Text)]
|
|
||||||
[Display(Name = "Authenticator code")]
|
|
||||||
public string TwoFactorCode { get; set; }
|
|
||||||
|
|
||||||
[Display(Name = "Remember this machine")]
|
|
||||||
public bool RememberMachine { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : LoginWithRecoveryCode.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
}
|
|
||||||
@page
|
|
||||||
@model LoginWithRecoveryCodeModel
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Recovery code verification";
|
|
||||||
}
|
|
||||||
|
|
||||||
<h1>@ViewData["Title"]</h1>
|
|
||||||
<hr />
|
|
||||||
<p>
|
|
||||||
You have requested to log in with a recovery code. This login will not be remembered until you provide
|
|
||||||
an authenticator app code at log in or disable 2FA and log in again.
|
|
||||||
</p>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-4">
|
|
||||||
<form method="post">
|
|
||||||
<div asp-validation-summary="All"
|
|
||||||
class="text-danger">
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Input.RecoveryCode"></label>
|
|
||||||
<input asp-for="Input.RecoveryCode"
|
|
||||||
class="form-control"
|
|
||||||
autocomplete="off" />
|
|
||||||
<span asp-validation-for="Input.RecoveryCode"
|
|
||||||
class="text-danger">
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<button class="btn btn-primary"
|
|
||||||
type="submit">
|
|
||||||
Log in
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@section Scripts {
|
|
||||||
<partial name="_ValidationScriptsPartial" />
|
|
||||||
}
|
|
||||||
@@ -1,109 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : LoginWithRecoveryCode.cshtml.cs
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Identity;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using SignInResult = Microsoft.AspNetCore.Identity.SignInResult;
|
|
||||||
|
|
||||||
namespace cicm_web.Areas.Identity.Pages.Account
|
|
||||||
{
|
|
||||||
[AllowAnonymous]
|
|
||||||
public class LoginWithRecoveryCodeModel : PageModel
|
|
||||||
{
|
|
||||||
readonly ILogger<LoginWithRecoveryCodeModel> _logger;
|
|
||||||
readonly SignInManager<IdentityUser> _signInManager;
|
|
||||||
|
|
||||||
public LoginWithRecoveryCodeModel(SignInManager<IdentityUser> signInManager,
|
|
||||||
ILogger<LoginWithRecoveryCodeModel> logger)
|
|
||||||
{
|
|
||||||
_signInManager = signInManager;
|
|
||||||
_logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
[BindProperty]
|
|
||||||
public InputModel Input { get; set; }
|
|
||||||
|
|
||||||
public string ReturnUrl { get; set; }
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnGetAsync(string returnUrl = null)
|
|
||||||
{
|
|
||||||
// Ensure the user has gone through the username & password screen first
|
|
||||||
IdentityUser user = await _signInManager.GetTwoFactorAuthenticationUserAsync();
|
|
||||||
if(user == null) throw new InvalidOperationException("Unable to load two-factor authentication user.");
|
|
||||||
|
|
||||||
ReturnUrl = returnUrl;
|
|
||||||
|
|
||||||
return Page();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostAsync(string returnUrl = null)
|
|
||||||
{
|
|
||||||
if(!ModelState.IsValid) return Page();
|
|
||||||
|
|
||||||
IdentityUser user = await _signInManager.GetTwoFactorAuthenticationUserAsync();
|
|
||||||
if(user == null) throw new InvalidOperationException("Unable to load two-factor authentication user.");
|
|
||||||
|
|
||||||
string recoveryCode = Input.RecoveryCode.Replace(" ", string.Empty);
|
|
||||||
|
|
||||||
SignInResult result = await _signInManager.TwoFactorRecoveryCodeSignInAsync(recoveryCode);
|
|
||||||
|
|
||||||
if(result.Succeeded)
|
|
||||||
{
|
|
||||||
_logger.LogInformation("User with ID '{UserId}' logged in with a recovery code.", user.Id);
|
|
||||||
return LocalRedirect(returnUrl ?? Url.Content("~/"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(result.IsLockedOut)
|
|
||||||
{
|
|
||||||
_logger.LogWarning("User with ID '{UserId}' account locked out.", user.Id);
|
|
||||||
return RedirectToPage("./Lockout");
|
|
||||||
}
|
|
||||||
|
|
||||||
_logger.LogWarning("Invalid recovery code entered for user with ID '{UserId}' ", user.Id);
|
|
||||||
ModelState.AddModelError(string.Empty, "Invalid recovery code entered.");
|
|
||||||
return Page();
|
|
||||||
}
|
|
||||||
|
|
||||||
public class InputModel
|
|
||||||
{
|
|
||||||
[BindProperty]
|
|
||||||
[Required]
|
|
||||||
[DataType(DataType.Text)]
|
|
||||||
[Display(Name = "Recovery Code")]
|
|
||||||
public string RecoveryCode { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : Logout.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
}
|
|
||||||
@page
|
|
||||||
@model LogoutModel
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Log out";
|
|
||||||
}
|
|
||||||
|
|
||||||
<header>
|
|
||||||
<h1>@ViewData["Title"]</h1>
|
|
||||||
<p>You have successfully logged out of the application.</p>
|
|
||||||
</header>
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : Logout.cshtml.cs
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Identity;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace cicm_web.Areas.Identity.Pages.Account
|
|
||||||
{
|
|
||||||
[AllowAnonymous]
|
|
||||||
public class LogoutModel : PageModel
|
|
||||||
{
|
|
||||||
readonly ILogger<LogoutModel> _logger;
|
|
||||||
readonly SignInManager<IdentityUser> _signInManager;
|
|
||||||
|
|
||||||
public LogoutModel(SignInManager<IdentityUser> signInManager, ILogger<LogoutModel> logger)
|
|
||||||
{
|
|
||||||
_signInManager = signInManager;
|
|
||||||
_logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnGet() { }
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnPost(string returnUrl = null)
|
|
||||||
{
|
|
||||||
await _signInManager.SignOutAsync();
|
|
||||||
_logger.LogInformation("User logged out.");
|
|
||||||
if(returnUrl != null) return LocalRedirect(returnUrl);
|
|
||||||
|
|
||||||
return Page();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : ChangePassword.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
}
|
|
||||||
@page
|
|
||||||
@model ChangePasswordModel
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Change password";
|
|
||||||
ViewData["ActivePage"] = ManageNavPages.ChangePassword;
|
|
||||||
}
|
|
||||||
|
|
||||||
<h4>@ViewData["Title"]</h4>
|
|
||||||
<partial for="StatusMessage"
|
|
||||||
name="_StatusMessage" />
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-6">
|
|
||||||
<form id="change-password-form"
|
|
||||||
method="post">
|
|
||||||
<div asp-validation-summary="All"
|
|
||||||
class="text-danger">
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Input.OldPassword"></label>
|
|
||||||
<input asp-for="Input.OldPassword"
|
|
||||||
class="form-control" />
|
|
||||||
<span asp-validation-for="Input.OldPassword"
|
|
||||||
class="text-danger">
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Input.NewPassword"></label>
|
|
||||||
<input asp-for="Input.NewPassword"
|
|
||||||
class="form-control" />
|
|
||||||
<span asp-validation-for="Input.NewPassword"
|
|
||||||
class="text-danger">
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Input.ConfirmPassword"></label>
|
|
||||||
<input asp-for="Input.ConfirmPassword"
|
|
||||||
class="form-control" />
|
|
||||||
<span asp-validation-for="Input.ConfirmPassword"
|
|
||||||
class="text-danger">
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<button class="btn btn-primary"
|
|
||||||
type="submit">
|
|
||||||
Update password
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@section Scripts {
|
|
||||||
<partial name="_ValidationScriptsPartial" />
|
|
||||||
}
|
|
||||||
@@ -1,114 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : ChangePassword.cshtml.cs
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Identity;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace cicm_web.Areas.Identity.Pages.Account.Manage
|
|
||||||
{
|
|
||||||
public class ChangePasswordModel : PageModel
|
|
||||||
{
|
|
||||||
readonly ILogger<ChangePasswordModel> _logger;
|
|
||||||
readonly SignInManager<IdentityUser> _signInManager;
|
|
||||||
readonly UserManager<IdentityUser> _userManager;
|
|
||||||
|
|
||||||
public ChangePasswordModel(UserManager<IdentityUser> userManager, SignInManager<IdentityUser> signInManager,
|
|
||||||
ILogger<ChangePasswordModel> logger)
|
|
||||||
{
|
|
||||||
_userManager = userManager;
|
|
||||||
_signInManager = signInManager;
|
|
||||||
_logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
[BindProperty]
|
|
||||||
public InputModel Input { get; set; }
|
|
||||||
|
|
||||||
[TempData]
|
|
||||||
public string StatusMessage { get; set; }
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnGetAsync()
|
|
||||||
{
|
|
||||||
IdentityUser user = await _userManager.GetUserAsync(User);
|
|
||||||
if(user == null) return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
|
||||||
|
|
||||||
bool hasPassword = await _userManager.HasPasswordAsync(user);
|
|
||||||
if(!hasPassword) return RedirectToPage("./SetPassword");
|
|
||||||
|
|
||||||
return Page();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostAsync()
|
|
||||||
{
|
|
||||||
if(!ModelState.IsValid) return Page();
|
|
||||||
|
|
||||||
IdentityUser user = await _userManager.GetUserAsync(User);
|
|
||||||
if(user == null) return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
|
||||||
|
|
||||||
IdentityResult changePasswordResult =
|
|
||||||
await _userManager.ChangePasswordAsync(user, Input.OldPassword, Input.NewPassword);
|
|
||||||
if(!changePasswordResult.Succeeded)
|
|
||||||
{
|
|
||||||
foreach(IdentityError error in changePasswordResult.Errors)
|
|
||||||
ModelState.AddModelError(string.Empty, error.Description);
|
|
||||||
return Page();
|
|
||||||
}
|
|
||||||
|
|
||||||
await _signInManager.RefreshSignInAsync(user);
|
|
||||||
_logger.LogInformation("User changed their password successfully.");
|
|
||||||
StatusMessage = "Your password has been changed.";
|
|
||||||
|
|
||||||
return RedirectToPage();
|
|
||||||
}
|
|
||||||
|
|
||||||
public class InputModel
|
|
||||||
{
|
|
||||||
[Required]
|
|
||||||
[DataType(DataType.Password)]
|
|
||||||
[Display(Name = "Current password")]
|
|
||||||
public string OldPassword { get; set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
[StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.",
|
|
||||||
MinimumLength = 6)]
|
|
||||||
[DataType(DataType.Password)]
|
|
||||||
[Display(Name = "New password")]
|
|
||||||
public string NewPassword { get; set; }
|
|
||||||
|
|
||||||
[DataType(DataType.Password)]
|
|
||||||
[Display(Name = "Confirm new password")]
|
|
||||||
[Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]
|
|
||||||
public string ConfirmPassword { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : DeletePersonalData.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
}
|
|
||||||
@page
|
|
||||||
@model DeletePersonalDataModel
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Delete Personal Data";
|
|
||||||
ViewData["ActivePage"] = ManageNavPages.PersonalData;
|
|
||||||
}
|
|
||||||
|
|
||||||
<h4>@ViewData["Title"]</h4>
|
|
||||||
|
|
||||||
<div class="alert alert-warning"
|
|
||||||
role="alert">
|
|
||||||
<p>
|
|
||||||
<span class="glyphicon glyphicon-warning-sign"></span>
|
|
||||||
<strong>Deleting this data will permanently remove your account, and this cannot be recovered.</strong>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<form class="form-group"
|
|
||||||
id="delete-user"
|
|
||||||
method="post">
|
|
||||||
<div asp-validation-summary="All"
|
|
||||||
class="text-danger">
|
|
||||||
</div>
|
|
||||||
@if(Model.RequirePassword)
|
|
||||||
{
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Input.Password"></label>
|
|
||||||
<input asp-for="Input.Password"
|
|
||||||
class="form-control" />
|
|
||||||
<span asp-validation-for="Input.Password"
|
|
||||||
class="text-danger">
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
<button class="btn btn-danger"
|
|
||||||
type="submit">
|
|
||||||
Delete data and close my account
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@section Scripts {
|
|
||||||
<partial name="_ValidationScriptsPartial" />
|
|
||||||
}
|
|
||||||
@@ -1,102 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : DeletePersonalData.cshtml.cs
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Identity;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace cicm_web.Areas.Identity.Pages.Account.Manage
|
|
||||||
{
|
|
||||||
public class DeletePersonalDataModel : PageModel
|
|
||||||
{
|
|
||||||
readonly ILogger<DeletePersonalDataModel> _logger;
|
|
||||||
readonly SignInManager<IdentityUser> _signInManager;
|
|
||||||
readonly UserManager<IdentityUser> _userManager;
|
|
||||||
|
|
||||||
public DeletePersonalDataModel(UserManager<IdentityUser> userManager,
|
|
||||||
SignInManager<IdentityUser> signInManager,
|
|
||||||
ILogger<DeletePersonalDataModel> logger)
|
|
||||||
{
|
|
||||||
_userManager = userManager;
|
|
||||||
_signInManager = signInManager;
|
|
||||||
_logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
[BindProperty]
|
|
||||||
public InputModel Input { get; set; }
|
|
||||||
|
|
||||||
public bool RequirePassword { get; set; }
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnGet()
|
|
||||||
{
|
|
||||||
IdentityUser user = await _userManager.GetUserAsync(User);
|
|
||||||
if(user == null) return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
|
||||||
|
|
||||||
RequirePassword = await _userManager.HasPasswordAsync(user);
|
|
||||||
return Page();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostAsync()
|
|
||||||
{
|
|
||||||
IdentityUser user = await _userManager.GetUserAsync(User);
|
|
||||||
if(user == null) return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
|
||||||
|
|
||||||
RequirePassword = await _userManager.HasPasswordAsync(user);
|
|
||||||
if(RequirePassword)
|
|
||||||
if(!await _userManager.CheckPasswordAsync(user, Input.Password))
|
|
||||||
{
|
|
||||||
ModelState.AddModelError(string.Empty, "Password not correct.");
|
|
||||||
return Page();
|
|
||||||
}
|
|
||||||
|
|
||||||
IdentityResult result = await _userManager.DeleteAsync(user);
|
|
||||||
string userId = await _userManager.GetUserIdAsync(user);
|
|
||||||
if(!result.Succeeded)
|
|
||||||
throw new InvalidOperationException($"Unexpected error occurred deleteing user with ID '{userId}'.");
|
|
||||||
|
|
||||||
await _signInManager.SignOutAsync();
|
|
||||||
|
|
||||||
_logger.LogInformation("User with ID '{UserId}' deleted themselves.", userId);
|
|
||||||
|
|
||||||
return Redirect("~/");
|
|
||||||
}
|
|
||||||
|
|
||||||
public class InputModel
|
|
||||||
{
|
|
||||||
[Required]
|
|
||||||
[DataType(DataType.Password)]
|
|
||||||
public string Password { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : Disable2fa.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
}
|
|
||||||
@page
|
|
||||||
@model Disable2faModel
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Disable two-factor authentication (2FA)";
|
|
||||||
ViewData["ActivePage"] = ManageNavPages.TwoFactorAuthentication;
|
|
||||||
}
|
|
||||||
|
|
||||||
<partial for="StatusMessage"
|
|
||||||
name="_StatusMessage" />
|
|
||||||
<h1>@ViewData["Title"]</h1>
|
|
||||||
|
|
||||||
<div class="alert alert-warning"
|
|
||||||
role="alert">
|
|
||||||
<p>
|
|
||||||
<span class="glyphicon glyphicon-warning-sign"></span>
|
|
||||||
<strong>This action only disables 2FA.</strong>
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
Disabling 2FA does not change the keys used in authenticator apps. If you wish to change the key
|
|
||||||
used in an authenticator app you should <a asp-page="./ResetAuthenticator">reset your authenticator keys.</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<form class="form-group"
|
|
||||||
method="post">
|
|
||||||
<button class="btn btn-danger"
|
|
||||||
type="submit">
|
|
||||||
Disable 2FA
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : Disable2fa.cshtml.cs
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Identity;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace cicm_web.Areas.Identity.Pages.Account.Manage
|
|
||||||
{
|
|
||||||
public class Disable2faModel : PageModel
|
|
||||||
{
|
|
||||||
readonly ILogger<Disable2faModel> _logger;
|
|
||||||
readonly UserManager<IdentityUser> _userManager;
|
|
||||||
|
|
||||||
public Disable2faModel(UserManager<IdentityUser> userManager, ILogger<Disable2faModel> logger)
|
|
||||||
{
|
|
||||||
_userManager = userManager;
|
|
||||||
_logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
[TempData]
|
|
||||||
public string StatusMessage { get; set; }
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnGet()
|
|
||||||
{
|
|
||||||
IdentityUser user = await _userManager.GetUserAsync(User);
|
|
||||||
if(user == null) return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
|
||||||
|
|
||||||
if(!await _userManager.GetTwoFactorEnabledAsync(user))
|
|
||||||
throw new
|
|
||||||
InvalidOperationException($"Cannot disable 2FA for user with ID '{_userManager.GetUserId(User)}' as it's not currently enabled.");
|
|
||||||
|
|
||||||
return Page();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostAsync()
|
|
||||||
{
|
|
||||||
IdentityUser user = await _userManager.GetUserAsync(User);
|
|
||||||
if(user == null) return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
|
||||||
|
|
||||||
IdentityResult disable2faResult = await _userManager.SetTwoFactorEnabledAsync(user, false);
|
|
||||||
if(!disable2faResult.Succeeded)
|
|
||||||
throw new
|
|
||||||
InvalidOperationException($"Unexpected error occurred disabling 2FA for user with ID '{_userManager.GetUserId(User)}'.");
|
|
||||||
|
|
||||||
_logger.LogInformation("User with ID '{UserId}' has disabled 2fa.", _userManager.GetUserId(User));
|
|
||||||
StatusMessage = "2fa has been disabled. You can reenable 2fa when you setup an authenticator app";
|
|
||||||
return RedirectToPage("./TwoFactorAuthentication");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : DownloadPersonalData.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
}
|
|
||||||
@page
|
|
||||||
@model DownloadPersonalDataModel
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Download Your Data";
|
|
||||||
ViewData["ActivePage"] = ManageNavPages.PersonalData;
|
|
||||||
}
|
|
||||||
|
|
||||||
<h4>@ViewData["Title"]</h4>
|
|
||||||
|
|
||||||
@section Scripts {
|
|
||||||
<partial name="_ValidationScriptsPartial" />
|
|
||||||
}
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : DownloadPersonalData.cshtml.cs
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Identity;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace cicm_web.Areas.Identity.Pages.Account.Manage
|
|
||||||
{
|
|
||||||
public class DownloadPersonalDataModel : PageModel
|
|
||||||
{
|
|
||||||
readonly ILogger<DownloadPersonalDataModel> _logger;
|
|
||||||
readonly UserManager<IdentityUser> _userManager;
|
|
||||||
|
|
||||||
public DownloadPersonalDataModel(UserManager<IdentityUser> userManager,
|
|
||||||
ILogger<DownloadPersonalDataModel> logger)
|
|
||||||
{
|
|
||||||
_userManager = userManager;
|
|
||||||
_logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostAsync()
|
|
||||||
{
|
|
||||||
IdentityUser user = await _userManager.GetUserAsync(User);
|
|
||||||
if(user == null) return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
|
||||||
|
|
||||||
_logger.LogInformation("User with ID '{UserId}' asked for their personal data.",
|
|
||||||
_userManager.GetUserId(User));
|
|
||||||
|
|
||||||
// Only include personal data for download
|
|
||||||
Dictionary<string, string> personalData = new Dictionary<string, string>();
|
|
||||||
IEnumerable<PropertyInfo> personalDataProps = typeof(IdentityUser)
|
|
||||||
.GetProperties()
|
|
||||||
.Where(prop =>
|
|
||||||
Attribute.IsDefined(prop,
|
|
||||||
typeof(PersonalDataAttribute)));
|
|
||||||
foreach(PropertyInfo p in personalDataProps)
|
|
||||||
personalData.Add(p.Name, p.GetValue(user)?.ToString() ?? "null");
|
|
||||||
|
|
||||||
Response.Headers.Add("Content-Disposition", "attachment; filename=PersonalData.json");
|
|
||||||
return new FileContentResult(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(personalData)),
|
|
||||||
"text/json");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,101 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : EnableAuthenticator.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
}
|
|
||||||
@page
|
|
||||||
@model EnableAuthenticatorModel
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Configure authenticator app";
|
|
||||||
ViewData["ActivePage"] = ManageNavPages.TwoFactorAuthentication;
|
|
||||||
}
|
|
||||||
|
|
||||||
<partial for="StatusMessage"
|
|
||||||
name="_StatusMessage" />
|
|
||||||
<h4>@ViewData["Title"]</h4>
|
|
||||||
<div>
|
|
||||||
<p>To use an authenticator app go through the following steps:</p>
|
|
||||||
<ol class="list">
|
|
||||||
<li>
|
|
||||||
<p>
|
|
||||||
Download a two-factor authenticator app like Microsoft Authenticator for
|
|
||||||
<a href="https://go.microsoft.com/fwlink/?Linkid=825071">Windows Phone</a>,
|
|
||||||
<a href="https://go.microsoft.com/fwlink/?Linkid=825072">Android</a> and
|
|
||||||
<a href="https://go.microsoft.com/fwlink/?Linkid=825073">iOS</a> or
|
|
||||||
Google Authenticator for
|
|
||||||
<a href="https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2&hl=en">Android</a> and
|
|
||||||
<a href="https://itunes.apple.com/us/app/google-authenticator/id388497605?mt=8">iOS</a>.
|
|
||||||
</p>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<p>Scan the QR Code or enter this key <kbd>@Model.SharedKey</kbd> into your two factor authenticator app. Spaces and casing do not matter.</p>
|
|
||||||
<div class="alert alert-info">To enable QR code generation please read our <a href="https://go.microsoft.com/fwlink/?Linkid=852423">documentation</a>.</div>
|
|
||||||
<div id="qrCode"></div>
|
|
||||||
<div id="qrCodeData"
|
|
||||||
data-url="@Html.Raw(Model.AuthenticatorUri)">
|
|
||||||
</div>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<p>
|
|
||||||
Once you have scanned the QR code or input the key above, your two factor authentication app will provide you
|
|
||||||
with a unique code. Enter the code in the confirmation box below.
|
|
||||||
</p>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-6">
|
|
||||||
<form id="send-code"
|
|
||||||
method="post">
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Input.Code"
|
|
||||||
class="control-label">
|
|
||||||
Verification Code
|
|
||||||
</label>
|
|
||||||
<input asp-for="Input.Code"
|
|
||||||
class="form-control"
|
|
||||||
autocomplete="off" />
|
|
||||||
<span asp-validation-for="Input.Code"
|
|
||||||
class="text-danger">
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<button class="btn btn-primary"
|
|
||||||
type="submit">
|
|
||||||
Verify
|
|
||||||
</button>
|
|
||||||
<div asp-validation-summary="ModelOnly"
|
|
||||||
class="text-danger">
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</li>
|
|
||||||
</ol>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@section Scripts {
|
|
||||||
<partial name="_ValidationScriptsPartial" />
|
|
||||||
}
|
|
||||||
@@ -1,170 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : EnableAuthenticator.cshtml.cs
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Text.Encodings.Web;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Identity;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace cicm_web.Areas.Identity.Pages.Account.Manage
|
|
||||||
{
|
|
||||||
public class EnableAuthenticatorModel : PageModel
|
|
||||||
{
|
|
||||||
const string AuthenticatorUriFormat =
|
|
||||||
"otpauth://totp/{0}:{1}?secret={2}&issuer={0}&digits=6";
|
|
||||||
readonly ILogger<EnableAuthenticatorModel> _logger;
|
|
||||||
readonly UrlEncoder _urlEncoder;
|
|
||||||
readonly UserManager<IdentityUser> _userManager;
|
|
||||||
|
|
||||||
public EnableAuthenticatorModel(UserManager<IdentityUser> userManager, ILogger<EnableAuthenticatorModel> logger,
|
|
||||||
UrlEncoder urlEncoder)
|
|
||||||
{
|
|
||||||
_userManager = userManager;
|
|
||||||
_logger = logger;
|
|
||||||
_urlEncoder = urlEncoder;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string SharedKey { get; set; }
|
|
||||||
|
|
||||||
public string AuthenticatorUri { get; set; }
|
|
||||||
|
|
||||||
[TempData]
|
|
||||||
public string[] RecoveryCodes { get; set; }
|
|
||||||
|
|
||||||
[TempData]
|
|
||||||
public string StatusMessage { get; set; }
|
|
||||||
|
|
||||||
[BindProperty]
|
|
||||||
public InputModel Input { get; set; }
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnGetAsync()
|
|
||||||
{
|
|
||||||
IdentityUser user = await _userManager.GetUserAsync(User);
|
|
||||||
if(user == null) return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
|
||||||
|
|
||||||
await LoadSharedKeyAndQrCodeUriAsync(user);
|
|
||||||
|
|
||||||
return Page();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostAsync()
|
|
||||||
{
|
|
||||||
IdentityUser user = await _userManager.GetUserAsync(User);
|
|
||||||
if(user == null) return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
|
||||||
|
|
||||||
if(!ModelState.IsValid)
|
|
||||||
{
|
|
||||||
await LoadSharedKeyAndQrCodeUriAsync(user);
|
|
||||||
return Page();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Strip spaces and hypens
|
|
||||||
string verificationCode = Input.Code.Replace(" ", string.Empty).Replace("-", string.Empty);
|
|
||||||
|
|
||||||
bool is2faTokenValid =
|
|
||||||
await _userManager.VerifyTwoFactorTokenAsync(user,
|
|
||||||
_userManager.Options.Tokens.AuthenticatorTokenProvider,
|
|
||||||
verificationCode);
|
|
||||||
|
|
||||||
if(!is2faTokenValid)
|
|
||||||
{
|
|
||||||
ModelState.AddModelError("Input.Code", "Verification code is invalid.");
|
|
||||||
await LoadSharedKeyAndQrCodeUriAsync(user);
|
|
||||||
return Page();
|
|
||||||
}
|
|
||||||
|
|
||||||
await _userManager.SetTwoFactorEnabledAsync(user, true);
|
|
||||||
string userId = await _userManager.GetUserIdAsync(user);
|
|
||||||
_logger.LogInformation("User with ID '{UserId}' has enabled 2FA with an authenticator app.", userId);
|
|
||||||
|
|
||||||
StatusMessage = "Your authenticator app has been verified.";
|
|
||||||
|
|
||||||
if(await _userManager.CountRecoveryCodesAsync(user) == 0)
|
|
||||||
{
|
|
||||||
IEnumerable<string> recoveryCodes = await _userManager.GenerateNewTwoFactorRecoveryCodesAsync(user, 10);
|
|
||||||
RecoveryCodes = recoveryCodes.ToArray();
|
|
||||||
return RedirectToPage("./ShowRecoveryCodes");
|
|
||||||
}
|
|
||||||
|
|
||||||
return RedirectToPage("./TwoFactorAuthentication");
|
|
||||||
}
|
|
||||||
|
|
||||||
async Task LoadSharedKeyAndQrCodeUriAsync(IdentityUser user)
|
|
||||||
{
|
|
||||||
// Load the authenticator key & QR code URI to display on the form
|
|
||||||
string unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user);
|
|
||||||
if(string.IsNullOrEmpty(unformattedKey))
|
|
||||||
{
|
|
||||||
await _userManager.ResetAuthenticatorKeyAsync(user);
|
|
||||||
unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
SharedKey = FormatKey(unformattedKey);
|
|
||||||
|
|
||||||
string email = await _userManager.GetEmailAsync(user);
|
|
||||||
AuthenticatorUri = GenerateQrCodeUri(email, unformattedKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
string FormatKey(string unformattedKey)
|
|
||||||
{
|
|
||||||
StringBuilder result = new StringBuilder();
|
|
||||||
int currentPosition = 0;
|
|
||||||
while(currentPosition + 4 < unformattedKey.Length)
|
|
||||||
{
|
|
||||||
result.Append(unformattedKey.Substring(currentPosition, 4)).Append(" ");
|
|
||||||
currentPosition += 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(currentPosition < unformattedKey.Length) result.Append(unformattedKey.Substring(currentPosition));
|
|
||||||
|
|
||||||
return result.ToString().ToLowerInvariant();
|
|
||||||
}
|
|
||||||
|
|
||||||
string GenerateQrCodeUri(string email, string unformattedKey) =>
|
|
||||||
string.Format(AuthenticatorUriFormat, _urlEncoder.Encode("cicm_web"), _urlEncoder.Encode(email),
|
|
||||||
unformattedKey);
|
|
||||||
|
|
||||||
public class InputModel
|
|
||||||
{
|
|
||||||
[Required]
|
|
||||||
[StringLength(7, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.",
|
|
||||||
MinimumLength = 6)]
|
|
||||||
[DataType(DataType.Text)]
|
|
||||||
[Display(Name = "Verification Code")]
|
|
||||||
public string Code { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,105 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : ExternalLogins.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
}
|
|
||||||
@page
|
|
||||||
@using Microsoft.AspNetCore.Authentication
|
|
||||||
@model ExternalLoginsModel
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Manage your external logins";
|
|
||||||
ViewData["ActivePage"] = ManageNavPages.ExternalLogins;
|
|
||||||
}
|
|
||||||
|
|
||||||
<partial for="StatusMessage"
|
|
||||||
name="_StatusMessage" />
|
|
||||||
@if(Model.CurrentLogins?.Count > 0)
|
|
||||||
{
|
|
||||||
<h4>Registered Logins</h4>
|
|
||||||
<table class="table">
|
|
||||||
<tbody>
|
|
||||||
@foreach(UserLoginInfo login in Model.CurrentLogins)
|
|
||||||
{
|
|
||||||
<tr>
|
|
||||||
<td>@login.ProviderDisplayName</td>
|
|
||||||
<td>
|
|
||||||
@if(Model.ShowRemoveButton)
|
|
||||||
{
|
|
||||||
<form asp-page-handler="RemoveLogin"
|
|
||||||
id="remove-login"
|
|
||||||
method="post">
|
|
||||||
<div>
|
|
||||||
<input asp-for="@login.LoginProvider"
|
|
||||||
name="LoginProvider"
|
|
||||||
type="hidden" />
|
|
||||||
<input asp-for="@login.ProviderKey"
|
|
||||||
name="ProviderKey"
|
|
||||||
type="hidden" />
|
|
||||||
<button type="submit"
|
|
||||||
class="btn btn-primary"
|
|
||||||
title="Remove this @login.ProviderDisplayName login from your account">
|
|
||||||
Remove
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
@:
|
|
||||||
}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
}
|
|
||||||
@if(Model.OtherLogins?.Count > 0)
|
|
||||||
{
|
|
||||||
<h4>Add another service to log in.</h4>
|
|
||||||
<hr />
|
|
||||||
<form asp-page-handler="LinkLogin"
|
|
||||||
class="form-horizontal"
|
|
||||||
id="link-login-form"
|
|
||||||
method="post">
|
|
||||||
<div id="socialLoginList">
|
|
||||||
<p>
|
|
||||||
@foreach(AuthenticationScheme provider in Model.OtherLogins)
|
|
||||||
{
|
|
||||||
<button id="link-login-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>
|
|
||||||
}
|
|
||||||
@@ -1,128 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : ExternalLogins.cshtml.cs
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Authentication;
|
|
||||||
using Microsoft.AspNetCore.Identity;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
||||||
|
|
||||||
namespace cicm_web.Areas.Identity.Pages.Account.Manage
|
|
||||||
{
|
|
||||||
public class ExternalLoginsModel : PageModel
|
|
||||||
{
|
|
||||||
readonly SignInManager<IdentityUser> _signInManager;
|
|
||||||
readonly UserManager<IdentityUser> _userManager;
|
|
||||||
|
|
||||||
public ExternalLoginsModel(UserManager<IdentityUser> userManager, SignInManager<IdentityUser> signInManager)
|
|
||||||
{
|
|
||||||
_userManager = userManager;
|
|
||||||
_signInManager = signInManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IList<UserLoginInfo> CurrentLogins { get; set; }
|
|
||||||
|
|
||||||
public IList<AuthenticationScheme> OtherLogins { get; set; }
|
|
||||||
|
|
||||||
public bool ShowRemoveButton { get; set; }
|
|
||||||
|
|
||||||
[TempData]
|
|
||||||
public string StatusMessage { get; set; }
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnGetAsync()
|
|
||||||
{
|
|
||||||
IdentityUser user = await _userManager.GetUserAsync(User);
|
|
||||||
if(user == null) return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
|
||||||
|
|
||||||
CurrentLogins = await _userManager.GetLoginsAsync(user);
|
|
||||||
OtherLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync())
|
|
||||||
.Where(auth => CurrentLogins.All(ul => auth.Name != ul.LoginProvider)).ToList();
|
|
||||||
ShowRemoveButton = user.PasswordHash != null || CurrentLogins.Count > 1;
|
|
||||||
return Page();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostRemoveLoginAsync(string loginProvider, string providerKey)
|
|
||||||
{
|
|
||||||
IdentityUser user = await _userManager.GetUserAsync(User);
|
|
||||||
if(user == null) return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
|
||||||
|
|
||||||
IdentityResult result = await _userManager.RemoveLoginAsync(user, loginProvider, providerKey);
|
|
||||||
if(!result.Succeeded)
|
|
||||||
{
|
|
||||||
string userId = await _userManager.GetUserIdAsync(user);
|
|
||||||
throw new
|
|
||||||
InvalidOperationException($"Unexpected error occurred removing external login for user with ID '{userId}'.");
|
|
||||||
}
|
|
||||||
|
|
||||||
await _signInManager.RefreshSignInAsync(user);
|
|
||||||
StatusMessage = "The external login was removed.";
|
|
||||||
return RedirectToPage();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostLinkLoginAsync(string provider)
|
|
||||||
{
|
|
||||||
// Clear the existing external cookie to ensure a clean login process
|
|
||||||
await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);
|
|
||||||
|
|
||||||
// Request a redirect to the external login provider to link a login for the current user
|
|
||||||
string redirectUrl = Url.Page("./ExternalLogins", "LinkLoginCallback");
|
|
||||||
AuthenticationProperties properties =
|
|
||||||
_signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl,
|
|
||||||
_userManager.GetUserId(User));
|
|
||||||
return new ChallengeResult(provider, properties);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnGetLinkLoginCallbackAsync()
|
|
||||||
{
|
|
||||||
IdentityUser user = await _userManager.GetUserAsync(User);
|
|
||||||
if(user == null) return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
|
||||||
|
|
||||||
ExternalLoginInfo info =
|
|
||||||
await _signInManager.GetExternalLoginInfoAsync(await _userManager.GetUserIdAsync(user));
|
|
||||||
if(info == null)
|
|
||||||
throw new
|
|
||||||
InvalidOperationException($"Unexpected error occurred loading external login info for user with ID '{user.Id}'.");
|
|
||||||
|
|
||||||
IdentityResult result = await _userManager.AddLoginAsync(user, info);
|
|
||||||
if(!result.Succeeded)
|
|
||||||
throw new
|
|
||||||
InvalidOperationException($"Unexpected error occurred adding external login for user with ID '{user.Id}'.");
|
|
||||||
|
|
||||||
// Clear the existing external cookie to ensure a clean login process
|
|
||||||
await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);
|
|
||||||
|
|
||||||
StatusMessage = "The external login was added.";
|
|
||||||
return RedirectToPage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : GenerateRecoveryCodes.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
}
|
|
||||||
@page
|
|
||||||
@model GenerateRecoveryCodesModel
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Generate two-factor authentication (2FA) recovery codes";
|
|
||||||
ViewData["ActivePage"] = ManageNavPages.TwoFactorAuthentication;
|
|
||||||
}
|
|
||||||
|
|
||||||
<partial for="StatusMessage"
|
|
||||||
name="_StatusMessage" />
|
|
||||||
<h4>@ViewData["Title"]</h4>
|
|
||||||
<div class="alert alert-warning"
|
|
||||||
role="alert">
|
|
||||||
<p>
|
|
||||||
<span class="glyphicon glyphicon-warning-sign"></span>
|
|
||||||
<strong>Put these codes in a safe place.</strong>
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
If you lose your device and don't have the recovery codes you will lose access to your account.
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
Generating new recovery codes does not change the keys used in authenticator apps. If you wish to change the key
|
|
||||||
used in an authenticator app you should <a asp-page="./ResetAuthenticator">reset your authenticator keys.</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<form class="form-group"
|
|
||||||
method="post">
|
|
||||||
<button class="btn btn-danger"
|
|
||||||
type="submit">
|
|
||||||
Generate Recovery Codes
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : GenerateRecoveryCodes.cshtml.cs
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Identity;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace cicm_web.Areas.Identity.Pages.Account.Manage
|
|
||||||
{
|
|
||||||
public class GenerateRecoveryCodesModel : PageModel
|
|
||||||
{
|
|
||||||
readonly ILogger<GenerateRecoveryCodesModel> _logger;
|
|
||||||
readonly UserManager<IdentityUser> _userManager;
|
|
||||||
|
|
||||||
public GenerateRecoveryCodesModel(UserManager<IdentityUser> userManager,
|
|
||||||
ILogger<GenerateRecoveryCodesModel> logger)
|
|
||||||
{
|
|
||||||
_userManager = userManager;
|
|
||||||
_logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
[TempData]
|
|
||||||
public string[] RecoveryCodes { get; set; }
|
|
||||||
|
|
||||||
[TempData]
|
|
||||||
public string StatusMessage { get; set; }
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnGetAsync()
|
|
||||||
{
|
|
||||||
IdentityUser user = await _userManager.GetUserAsync(User);
|
|
||||||
if(user == null) return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
|
||||||
|
|
||||||
bool isTwoFactorEnabled = await _userManager.GetTwoFactorEnabledAsync(user);
|
|
||||||
if(isTwoFactorEnabled) return Page();
|
|
||||||
|
|
||||||
string userId = await _userManager.GetUserIdAsync(user);
|
|
||||||
throw new
|
|
||||||
InvalidOperationException($"Cannot generate recovery codes for user with ID '{userId}' because they do not have 2FA enabled.");
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostAsync()
|
|
||||||
{
|
|
||||||
IdentityUser user = await _userManager.GetUserAsync(User);
|
|
||||||
if(user == null) return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
|
||||||
|
|
||||||
bool isTwoFactorEnabled = await _userManager.GetTwoFactorEnabledAsync(user);
|
|
||||||
string userId = await _userManager.GetUserIdAsync(user);
|
|
||||||
if(!isTwoFactorEnabled)
|
|
||||||
throw new
|
|
||||||
InvalidOperationException($"Cannot generate recovery codes for user with ID '{userId}' as they do not have 2FA enabled.");
|
|
||||||
|
|
||||||
IEnumerable<string> recoveryCodes = await _userManager.GenerateNewTwoFactorRecoveryCodesAsync(user, 10);
|
|
||||||
RecoveryCodes = recoveryCodes.ToArray();
|
|
||||||
|
|
||||||
_logger.LogInformation("User with ID '{UserId}' has generated new 2FA recovery codes.", userId);
|
|
||||||
StatusMessage = "You have generated new recovery codes.";
|
|
||||||
return RedirectToPage("./ShowRecoveryCodes");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,102 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : Index.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
}
|
|
||||||
@page
|
|
||||||
@model IndexModel
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Profile";
|
|
||||||
ViewData["ActivePage"] = ManageNavPages.Index;
|
|
||||||
}
|
|
||||||
|
|
||||||
<h4>@ViewData["Title"]</h4>
|
|
||||||
<partial for="StatusMessage"
|
|
||||||
name="_StatusMessage" />
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-6">
|
|
||||||
<form id="profile-form"
|
|
||||||
method="post">
|
|
||||||
<div asp-validation-summary="All"
|
|
||||||
class="text-danger">
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Username"></label>
|
|
||||||
<input asp-for="Username"
|
|
||||||
class="form-control"
|
|
||||||
disabled />
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Input.Email"></label>
|
|
||||||
@if(Model.IsEmailConfirmed)
|
|
||||||
{
|
|
||||||
<div class="input-group">
|
|
||||||
<input asp-for="Input.Email"
|
|
||||||
class="form-control" />
|
|
||||||
<span aria-hidden="true"
|
|
||||||
class="input-group-addon">
|
|
||||||
<span class="glyphicon glyphicon-ok text-success"></span>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
<input asp-for="Input.Email"
|
|
||||||
class="form-control" />
|
|
||||||
<button asp-page-handler="SendVerificationEmail"
|
|
||||||
class="btn btn-link"
|
|
||||||
id="email-verification"
|
|
||||||
type="submit">
|
|
||||||
Send verification email
|
|
||||||
</button>
|
|
||||||
}
|
|
||||||
<span asp-validation-for="Input.Email"
|
|
||||||
class="text-danger">
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Input.PhoneNumber"></label>
|
|
||||||
<input asp-for="Input.PhoneNumber"
|
|
||||||
class="form-control" />
|
|
||||||
<span asp-validation-for="Input.PhoneNumber"
|
|
||||||
class="text-danger">
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<button class="btn btn-primary"
|
|
||||||
id="update-profile-button"
|
|
||||||
type="submit">
|
|
||||||
Save
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@section Scripts {
|
|
||||||
<partial name="_ValidationScriptsPartial" />
|
|
||||||
}
|
|
||||||
@@ -1,149 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : Index.cshtml.cs
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.Text.Encodings.Web;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Identity;
|
|
||||||
using Microsoft.AspNetCore.Identity.UI.Services;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
||||||
|
|
||||||
namespace cicm_web.Areas.Identity.Pages.Account.Manage
|
|
||||||
{
|
|
||||||
public class IndexModel : PageModel
|
|
||||||
{
|
|
||||||
readonly IEmailSender _emailSender;
|
|
||||||
readonly SignInManager<IdentityUser> _signInManager;
|
|
||||||
readonly UserManager<IdentityUser> _userManager;
|
|
||||||
|
|
||||||
public IndexModel(UserManager<IdentityUser> userManager, SignInManager<IdentityUser> signInManager,
|
|
||||||
IEmailSender emailSender)
|
|
||||||
{
|
|
||||||
_userManager = userManager;
|
|
||||||
_signInManager = signInManager;
|
|
||||||
_emailSender = emailSender;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Username { get; set; }
|
|
||||||
|
|
||||||
public bool IsEmailConfirmed { get; set; }
|
|
||||||
|
|
||||||
[TempData]
|
|
||||||
public string StatusMessage { get; set; }
|
|
||||||
|
|
||||||
[BindProperty]
|
|
||||||
public InputModel Input { get; set; }
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnGetAsync()
|
|
||||||
{
|
|
||||||
IdentityUser user = await _userManager.GetUserAsync(User);
|
|
||||||
if(user == null) return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
|
||||||
|
|
||||||
string userName = await _userManager.GetUserNameAsync(user);
|
|
||||||
string email = await _userManager.GetEmailAsync(user);
|
|
||||||
string phoneNumber = await _userManager.GetPhoneNumberAsync(user);
|
|
||||||
|
|
||||||
Username = userName;
|
|
||||||
|
|
||||||
Input = new InputModel {Email = email, PhoneNumber = phoneNumber};
|
|
||||||
|
|
||||||
IsEmailConfirmed = await _userManager.IsEmailConfirmedAsync(user);
|
|
||||||
|
|
||||||
return Page();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostAsync()
|
|
||||||
{
|
|
||||||
if(!ModelState.IsValid) return Page();
|
|
||||||
|
|
||||||
IdentityUser user = await _userManager.GetUserAsync(User);
|
|
||||||
if(user == null) return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
|
||||||
|
|
||||||
string email = await _userManager.GetEmailAsync(user);
|
|
||||||
if(Input.Email != email)
|
|
||||||
{
|
|
||||||
IdentityResult setEmailResult = await _userManager.SetEmailAsync(user, Input.Email);
|
|
||||||
if(!setEmailResult.Succeeded)
|
|
||||||
{
|
|
||||||
string userId = await _userManager.GetUserIdAsync(user);
|
|
||||||
throw new
|
|
||||||
InvalidOperationException($"Unexpected error occurred setting email for user with ID '{userId}'.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
string phoneNumber = await _userManager.GetPhoneNumberAsync(user);
|
|
||||||
if(Input.PhoneNumber != phoneNumber)
|
|
||||||
{
|
|
||||||
IdentityResult setPhoneResult = await _userManager.SetPhoneNumberAsync(user, Input.PhoneNumber);
|
|
||||||
if(!setPhoneResult.Succeeded)
|
|
||||||
{
|
|
||||||
string userId = await _userManager.GetUserIdAsync(user);
|
|
||||||
throw new
|
|
||||||
InvalidOperationException($"Unexpected error occurred setting phone number for user with ID '{userId}'.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await _signInManager.RefreshSignInAsync(user);
|
|
||||||
StatusMessage = "Your profile has been updated";
|
|
||||||
return RedirectToPage();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostSendVerificationEmailAsync()
|
|
||||||
{
|
|
||||||
if(!ModelState.IsValid) return Page();
|
|
||||||
|
|
||||||
IdentityUser user = await _userManager.GetUserAsync(User);
|
|
||||||
if(user == null) return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
|
||||||
|
|
||||||
string userId = await _userManager.GetUserIdAsync(user);
|
|
||||||
string email = await _userManager.GetEmailAsync(user);
|
|
||||||
string code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
|
|
||||||
string callbackUrl = Url.Page("/Account/ConfirmEmail", null, new {userId, code}, Request.Scheme);
|
|
||||||
await _emailSender.SendEmailAsync(email, "Confirm your email",
|
|
||||||
$"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");
|
|
||||||
|
|
||||||
StatusMessage = "Verification email sent. Please check your email.";
|
|
||||||
return RedirectToPage();
|
|
||||||
}
|
|
||||||
|
|
||||||
public class InputModel
|
|
||||||
{
|
|
||||||
[Required]
|
|
||||||
[EmailAddress]
|
|
||||||
public string Email { get; set; }
|
|
||||||
|
|
||||||
[Phone]
|
|
||||||
[Display(Name = "Phone number")]
|
|
||||||
public string PhoneNumber { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : ManageNavPages.cs
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
|
||||||
|
|
||||||
namespace cicm_web.Areas.Identity.Pages.Account.Manage
|
|
||||||
{
|
|
||||||
public static class ManageNavPages
|
|
||||||
{
|
|
||||||
public static string Index => "Index";
|
|
||||||
|
|
||||||
public static string ChangePassword => "ChangePassword";
|
|
||||||
|
|
||||||
public static string ExternalLogins => "ExternalLogins";
|
|
||||||
|
|
||||||
public static string PersonalData => "PersonalData";
|
|
||||||
|
|
||||||
public static string TwoFactorAuthentication => "TwoFactorAuthentication";
|
|
||||||
|
|
||||||
public static string IndexNavClass(ViewContext viewContext) => PageNavClass(viewContext, Index);
|
|
||||||
|
|
||||||
public static string ChangePasswordNavClass(ViewContext viewContext) =>
|
|
||||||
PageNavClass(viewContext, ChangePassword);
|
|
||||||
|
|
||||||
public static string ExternalLoginsNavClass(ViewContext viewContext) =>
|
|
||||||
PageNavClass(viewContext, ExternalLogins);
|
|
||||||
|
|
||||||
public static string PersonalDataNavClass(ViewContext viewContext) => PageNavClass(viewContext, PersonalData);
|
|
||||||
|
|
||||||
public static string TwoFactorAuthenticationNavClass(ViewContext viewContext) =>
|
|
||||||
PageNavClass(viewContext, TwoFactorAuthentication);
|
|
||||||
|
|
||||||
static string PageNavClass(ViewContext viewContext, string page)
|
|
||||||
{
|
|
||||||
string activePage = viewContext.ViewData["ActivePage"] as string ??
|
|
||||||
Path.GetFileNameWithoutExtension(viewContext.ActionDescriptor.DisplayName);
|
|
||||||
return string.Equals(activePage, page, StringComparison.OrdinalIgnoreCase) ? "active" : null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : PersonalData.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
}
|
|
||||||
@page
|
|
||||||
@model PersonalDataModel
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Personal Data";
|
|
||||||
ViewData["ActivePage"] = ManageNavPages.PersonalData;
|
|
||||||
}
|
|
||||||
|
|
||||||
<h4>@ViewData["Title"]</h4>
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-6">
|
|
||||||
<p>Your account contains personal data that you have given us. This page allows you to download or delete that data.</p>
|
|
||||||
<p>
|
|
||||||
<strong>Deleting this data will permanently remove your account, and this cannot be recovered.</strong>
|
|
||||||
</p>
|
|
||||||
<form asp-page="DownloadPersonalData"
|
|
||||||
class="form-group"
|
|
||||||
id="download-data"
|
|
||||||
method="post">
|
|
||||||
<button class="btn btn-primary"
|
|
||||||
type="submit">
|
|
||||||
Download
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
<p>
|
|
||||||
<a asp-page="DeletePersonalData"
|
|
||||||
class="btn btn-primary"
|
|
||||||
id="delete">
|
|
||||||
Delete
|
|
||||||
</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@section Scripts {
|
|
||||||
<partial name="_ValidationScriptsPartial" />
|
|
||||||
}
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : PersonalData.cshtml.cs
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Identity;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace cicm_web.Areas.Identity.Pages.Account.Manage
|
|
||||||
{
|
|
||||||
public class PersonalDataModel : PageModel
|
|
||||||
{
|
|
||||||
readonly ILogger<PersonalDataModel> _logger;
|
|
||||||
readonly UserManager<IdentityUser> _userManager;
|
|
||||||
|
|
||||||
public PersonalDataModel(UserManager<IdentityUser> userManager, ILogger<PersonalDataModel> logger)
|
|
||||||
{
|
|
||||||
_userManager = userManager;
|
|
||||||
_logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnGet()
|
|
||||||
{
|
|
||||||
IdentityUser user = await _userManager.GetUserAsync(User);
|
|
||||||
if(user == null) return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
|
||||||
|
|
||||||
return Page();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : ResetAuthenticator.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
}
|
|
||||||
@page
|
|
||||||
@model ResetAuthenticatorModel
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Reset authenticator key";
|
|
||||||
ViewData["ActivePage"] = ManageNavPages.TwoFactorAuthentication;
|
|
||||||
}
|
|
||||||
|
|
||||||
<partial for="StatusMessage"
|
|
||||||
name="_StatusMessage" />
|
|
||||||
<h4>@ViewData["Title"]</h4>
|
|
||||||
<div class="alert alert-warning"
|
|
||||||
role="alert">
|
|
||||||
<p>
|
|
||||||
<span class="glyphicon glyphicon-warning-sign"></span>
|
|
||||||
<strong>If you reset your authenticator key your authenticator app will not work until you reconfigure it.</strong>
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
This process disables 2FA until you verify your authenticator app.
|
|
||||||
If you do not complete your authenticator app configuration you may lose access to your account.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<form class="form-group"
|
|
||||||
id="reset-authenticator-form"
|
|
||||||
method="post">
|
|
||||||
<button class="btn btn-danger"
|
|
||||||
id="reset-authenticator-button"
|
|
||||||
type="submit">
|
|
||||||
Reset authenticator key
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : ResetAuthenticator.cshtml.cs
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Identity;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace cicm_web.Areas.Identity.Pages.Account.Manage
|
|
||||||
{
|
|
||||||
public class ResetAuthenticatorModel : PageModel
|
|
||||||
{
|
|
||||||
readonly SignInManager<IdentityUser> _signInManager;
|
|
||||||
readonly ILogger<ResetAuthenticatorModel> _logger;
|
|
||||||
readonly UserManager<IdentityUser> _userManager;
|
|
||||||
|
|
||||||
public ResetAuthenticatorModel(UserManager<IdentityUser> userManager,
|
|
||||||
SignInManager<IdentityUser> signInManager,
|
|
||||||
ILogger<ResetAuthenticatorModel> logger)
|
|
||||||
{
|
|
||||||
_userManager = userManager;
|
|
||||||
_signInManager = signInManager;
|
|
||||||
_logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
[TempData]
|
|
||||||
public string StatusMessage { get; set; }
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnGet()
|
|
||||||
{
|
|
||||||
IdentityUser user = await _userManager.GetUserAsync(User);
|
|
||||||
if(user == null) return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
|
||||||
|
|
||||||
return Page();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostAsync()
|
|
||||||
{
|
|
||||||
IdentityUser user = await _userManager.GetUserAsync(User);
|
|
||||||
if(user == null) return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
|
||||||
|
|
||||||
await _userManager.SetTwoFactorEnabledAsync(user, false);
|
|
||||||
await _userManager.ResetAuthenticatorKeyAsync(user);
|
|
||||||
_logger.LogInformation("User with ID '{UserId}' has reset their authentication app key.", user.Id);
|
|
||||||
|
|
||||||
await _signInManager.RefreshSignInAsync(user);
|
|
||||||
StatusMessage =
|
|
||||||
"Your authenticator app key has been reset, you will need to configure your authenticator app using the new key.";
|
|
||||||
|
|
||||||
return RedirectToPage("./EnableAuthenticator");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : SetPassword.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
}
|
|
||||||
@page
|
|
||||||
@model SetPasswordModel
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Set password";
|
|
||||||
ViewData["ActivePage"] = ManageNavPages.ChangePassword;
|
|
||||||
}
|
|
||||||
|
|
||||||
<h4>Set your password</h4>
|
|
||||||
<partial for="StatusMessage"
|
|
||||||
name="_StatusMessage" />
|
|
||||||
<p class="text-info">
|
|
||||||
You do not have a local username/password for this site. Add a local
|
|
||||||
account so you can log in without an external login.
|
|
||||||
</p>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-6">
|
|
||||||
<form id="set-password-form"
|
|
||||||
method="post">
|
|
||||||
<div asp-validation-summary="All"
|
|
||||||
class="text-danger">
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Input.NewPassword"></label>
|
|
||||||
<input asp-for="Input.NewPassword"
|
|
||||||
class="form-control" />
|
|
||||||
<span asp-validation-for="Input.NewPassword"
|
|
||||||
class="text-danger">
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Input.ConfirmPassword"></label>
|
|
||||||
<input asp-for="Input.ConfirmPassword"
|
|
||||||
class="form-control" />
|
|
||||||
<span asp-validation-for="Input.ConfirmPassword"
|
|
||||||
class="text-danger">
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<button class="btn btn-primary"
|
|
||||||
type="submit">
|
|
||||||
Set password
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@section Scripts {
|
|
||||||
<partial name="_ValidationScriptsPartial" />
|
|
||||||
}
|
|
||||||
@@ -1,104 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : SetPassword.cshtml.cs
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Identity;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
||||||
|
|
||||||
namespace cicm_web.Areas.Identity.Pages.Account.Manage
|
|
||||||
{
|
|
||||||
public class SetPasswordModel : PageModel
|
|
||||||
{
|
|
||||||
readonly SignInManager<IdentityUser> _signInManager;
|
|
||||||
readonly UserManager<IdentityUser> _userManager;
|
|
||||||
|
|
||||||
public SetPasswordModel(UserManager<IdentityUser> userManager, SignInManager<IdentityUser> signInManager)
|
|
||||||
{
|
|
||||||
_userManager = userManager;
|
|
||||||
_signInManager = signInManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
[BindProperty]
|
|
||||||
public InputModel Input { get; set; }
|
|
||||||
|
|
||||||
[TempData]
|
|
||||||
public string StatusMessage { get; set; }
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnGetAsync()
|
|
||||||
{
|
|
||||||
IdentityUser user = await _userManager.GetUserAsync(User);
|
|
||||||
if(user == null) return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
|
||||||
|
|
||||||
bool hasPassword = await _userManager.HasPasswordAsync(user);
|
|
||||||
|
|
||||||
if(hasPassword) return RedirectToPage("./ChangePassword");
|
|
||||||
|
|
||||||
return Page();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostAsync()
|
|
||||||
{
|
|
||||||
if(!ModelState.IsValid) return Page();
|
|
||||||
|
|
||||||
IdentityUser user = await _userManager.GetUserAsync(User);
|
|
||||||
if(user == null) return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
|
||||||
|
|
||||||
IdentityResult addPasswordResult = await _userManager.AddPasswordAsync(user, Input.NewPassword);
|
|
||||||
if(!addPasswordResult.Succeeded)
|
|
||||||
{
|
|
||||||
foreach(IdentityError error in addPasswordResult.Errors)
|
|
||||||
ModelState.AddModelError(string.Empty, error.Description);
|
|
||||||
return Page();
|
|
||||||
}
|
|
||||||
|
|
||||||
await _signInManager.RefreshSignInAsync(user);
|
|
||||||
StatusMessage = "Your password has been set.";
|
|
||||||
|
|
||||||
return RedirectToPage();
|
|
||||||
}
|
|
||||||
|
|
||||||
public class InputModel
|
|
||||||
{
|
|
||||||
[Required]
|
|
||||||
[StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.",
|
|
||||||
MinimumLength = 6)]
|
|
||||||
[DataType(DataType.Password)]
|
|
||||||
[Display(Name = "New password")]
|
|
||||||
public string NewPassword { get; set; }
|
|
||||||
|
|
||||||
[DataType(DataType.Password)]
|
|
||||||
[Display(Name = "Confirm new password")]
|
|
||||||
[Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]
|
|
||||||
public string ConfirmPassword { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,111 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : TwoFactorAuthentication.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
}
|
|
||||||
@page
|
|
||||||
@model TwoFactorAuthenticationModel
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Two-factor authentication (2FA)";
|
|
||||||
ViewData["ActivePage"] = ManageNavPages.TwoFactorAuthentication;
|
|
||||||
}
|
|
||||||
|
|
||||||
<partial for="StatusMessage"
|
|
||||||
name="_StatusMessage" />
|
|
||||||
<h4>@ViewData["Title"]</h4>
|
|
||||||
@if(Model.Is2faEnabled)
|
|
||||||
{
|
|
||||||
if(Model.RecoveryCodesLeft == 0)
|
|
||||||
{
|
|
||||||
<div class="alert alert-danger">
|
|
||||||
<strong>You have no recovery codes left.</strong>
|
|
||||||
<p>You must <a asp-page="./GenerateRecoveryCodes">generate a new set of recovery codes</a> before you can log in with a recovery code.</p>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
else if(Model.RecoveryCodesLeft == 1)
|
|
||||||
{
|
|
||||||
<div class="alert alert-danger">
|
|
||||||
<strong>You have 1 recovery code left.</strong>
|
|
||||||
<p>You can <a asp-page="./GenerateRecoveryCodes">generate a new set of recovery codes</a>.</p>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
else if(Model.RecoveryCodesLeft <= 3)
|
|
||||||
{
|
|
||||||
<div class="alert alert-warning">
|
|
||||||
<strong>You have @Model.RecoveryCodesLeft recovery codes left.</strong>
|
|
||||||
<p>You should <a asp-page="./GenerateRecoveryCodes">generate a new set of recovery codes</a>.</p>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
|
|
||||||
if(Model.IsMachineRemembered)
|
|
||||||
{
|
|
||||||
<form method="post"
|
|
||||||
style="display: inline-block">
|
|
||||||
<button class="btn btn-primary"
|
|
||||||
type="submit">
|
|
||||||
Forget this browser
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
}
|
|
||||||
<a asp-page="./Disable2fa"
|
|
||||||
class="btn btn-primary">
|
|
||||||
Disable 2FA
|
|
||||||
</a>
|
|
||||||
<a asp-page="./GenerateRecoveryCodes"
|
|
||||||
class="btn btn-primary">
|
|
||||||
Reset recovery codes
|
|
||||||
</a>
|
|
||||||
}
|
|
||||||
|
|
||||||
<h5>Authenticator app</h5>
|
|
||||||
@if(!Model.HasAuthenticator)
|
|
||||||
{
|
|
||||||
<a asp-page="./EnableAuthenticator"
|
|
||||||
class="btn btn-primary"
|
|
||||||
id="enable-authenticator">
|
|
||||||
Add authenticator app
|
|
||||||
</a>
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
<a asp-page="./EnableAuthenticator"
|
|
||||||
class="btn btn-primary"
|
|
||||||
id="enable-authenticator">
|
|
||||||
Setup authenticator app
|
|
||||||
</a>
|
|
||||||
<a asp-page="./ResetAuthenticator"
|
|
||||||
class="btn btn-primary"
|
|
||||||
id="reset-authenticator">
|
|
||||||
Reset authenticator app
|
|
||||||
</a>
|
|
||||||
}
|
|
||||||
|
|
||||||
@section Scripts {
|
|
||||||
<partial name="_ValidationScriptsPartial" />
|
|
||||||
}
|
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : TwoFactorAuthentication.cshtml.cs
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Identity;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace cicm_web.Areas.Identity.Pages.Account.Manage
|
|
||||||
{
|
|
||||||
public class TwoFactorAuthenticationModel : PageModel
|
|
||||||
{
|
|
||||||
const string AuthenicatorUriFormat =
|
|
||||||
"otpauth://totp/{0}:{1}?secret={2}&issuer={0}";
|
|
||||||
readonly ILogger<TwoFactorAuthenticationModel> _logger;
|
|
||||||
readonly SignInManager<IdentityUser> _signInManager;
|
|
||||||
|
|
||||||
readonly UserManager<IdentityUser> _userManager;
|
|
||||||
|
|
||||||
public TwoFactorAuthenticationModel(UserManager<IdentityUser> userManager,
|
|
||||||
SignInManager<IdentityUser> signInManager,
|
|
||||||
ILogger<TwoFactorAuthenticationModel> logger)
|
|
||||||
{
|
|
||||||
_userManager = userManager;
|
|
||||||
_signInManager = signInManager;
|
|
||||||
_logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool HasAuthenticator { get; set; }
|
|
||||||
|
|
||||||
public int RecoveryCodesLeft { get; set; }
|
|
||||||
|
|
||||||
[BindProperty]
|
|
||||||
public bool Is2faEnabled { get; set; }
|
|
||||||
|
|
||||||
public bool IsMachineRemembered { get; set; }
|
|
||||||
|
|
||||||
[TempData]
|
|
||||||
public string StatusMessage { get; set; }
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnGet()
|
|
||||||
{
|
|
||||||
IdentityUser user = await _userManager.GetUserAsync(User);
|
|
||||||
if(user == null) return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
|
||||||
|
|
||||||
HasAuthenticator = await _userManager.GetAuthenticatorKeyAsync(user) != null;
|
|
||||||
Is2faEnabled = await _userManager.GetTwoFactorEnabledAsync(user);
|
|
||||||
IsMachineRemembered = await _signInManager.IsTwoFactorClientRememberedAsync(user);
|
|
||||||
RecoveryCodesLeft = await _userManager.CountRecoveryCodesAsync(user);
|
|
||||||
|
|
||||||
return Page();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnPost()
|
|
||||||
{
|
|
||||||
IdentityUser user = await _userManager.GetUserAsync(User);
|
|
||||||
if(user == null) return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
|
|
||||||
|
|
||||||
await _signInManager.ForgetTwoFactorClientAsync();
|
|
||||||
StatusMessage =
|
|
||||||
"The current browser has been forgotten. When you login again from this browser you will be prompted for your 2fa code.";
|
|
||||||
return RedirectToPage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : _Layout.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
}
|
|
||||||
@{
|
|
||||||
Layout = "/Views/Shared/_Layout.cshtml";
|
|
||||||
}
|
|
||||||
|
|
||||||
<h1>Manage your account</h1>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<h4>Change your account settings</h4>
|
|
||||||
<hr />
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-3">
|
|
||||||
<partial name="_ManageNav" />
|
|
||||||
</div>
|
|
||||||
<div class="col-md-9">
|
|
||||||
@RenderBody()
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@section Scripts {
|
|
||||||
@RenderSection("Scripts", false)
|
|
||||||
}
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : _ManageNav.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
}
|
|
||||||
@inject SignInManager<IdentityUser> SignInManager
|
|
||||||
@{
|
|
||||||
bool hasExternalLogins = (await SignInManager.GetExternalAuthenticationSchemesAsync()).Any();
|
|
||||||
}
|
|
||||||
<ul class="flex-column nav nav-pills">
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link @ManageNavPages.IndexNavClass(ViewContext)"
|
|
||||||
id="profile"
|
|
||||||
asp-page="./Index">
|
|
||||||
Profile
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link @ManageNavPages.ChangePasswordNavClass(ViewContext)"
|
|
||||||
id="change-password"
|
|
||||||
asp-page="./ChangePassword">
|
|
||||||
Password
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
@if(hasExternalLogins)
|
|
||||||
{
|
|
||||||
<li class="nav-item"
|
|
||||||
id="external-logins">
|
|
||||||
<a id="external-login"
|
|
||||||
class="nav-link @ManageNavPages.ExternalLoginsNavClass(ViewContext)"
|
|
||||||
asp-page="./ExternalLogins">
|
|
||||||
External logins
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
}
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link @ManageNavPages.TwoFactorAuthenticationNavClass(ViewContext)"
|
|
||||||
id="two-factor"
|
|
||||||
asp-page="./TwoFactorAuthentication">
|
|
||||||
Two-factor authentication
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link @ManageNavPages.PersonalDataNavClass(ViewContext)"
|
|
||||||
id="personal-data"
|
|
||||||
asp-page="./PersonalData">
|
|
||||||
Personal data
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : _StatusMessage.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
}
|
|
||||||
@model string
|
|
||||||
|
|
||||||
@if(!string.IsNullOrEmpty(Model))
|
|
||||||
{
|
|
||||||
string statusMessageClass = Model.StartsWith("Error") ? "danger" : "success";
|
|
||||||
<div class="alert alert-@statusMessageClass alert-dismissible"
|
|
||||||
role="alert">
|
|
||||||
<button aria-label="Close"
|
|
||||||
class="close"
|
|
||||||
data-dismiss="alert"
|
|
||||||
type="button">
|
|
||||||
<span aria-hidden="true">×</span>
|
|
||||||
</button>
|
|
||||||
@Model
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : _ViewImports.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
}
|
|
||||||
@using cicm_web.Areas.Identity.Pages.Account.Manage
|
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : Register.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
}
|
|
||||||
@page
|
|
||||||
@model RegisterModel
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Register";
|
|
||||||
}
|
|
||||||
|
|
||||||
<h1>@ViewData["Title"]</h1>
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-4">
|
|
||||||
<form asp-route-returnUrl="@Model.ReturnUrl"
|
|
||||||
method="post">
|
|
||||||
<h4>Create a new account.</h4>
|
|
||||||
<hr />
|
|
||||||
<div asp-validation-summary="All"
|
|
||||||
class="text-danger">
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Input.Email"></label>
|
|
||||||
<input asp-for="Input.Email"
|
|
||||||
class="form-control" />
|
|
||||||
<span asp-validation-for="Input.Email"
|
|
||||||
class="text-danger">
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Input.Password"></label>
|
|
||||||
<input asp-for="Input.Password"
|
|
||||||
class="form-control" />
|
|
||||||
<span asp-validation-for="Input.Password"
|
|
||||||
class="text-danger">
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Input.ConfirmPassword"></label>
|
|
||||||
<input asp-for="Input.ConfirmPassword"
|
|
||||||
class="form-control" />
|
|
||||||
<span asp-validation-for="Input.ConfirmPassword"
|
|
||||||
class="text-danger">
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<button class="btn btn-primary"
|
|
||||||
type="submit">
|
|
||||||
Register
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@section Scripts {
|
|
||||||
<partial name="_ValidationScriptsPartial" />
|
|
||||||
}
|
|
||||||
@@ -1,119 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : Register.cshtml.cs
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.Text.Encodings.Web;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Identity;
|
|
||||||
using Microsoft.AspNetCore.Identity.UI.Services;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace cicm_web.Areas.Identity.Pages.Account
|
|
||||||
{
|
|
||||||
[AllowAnonymous]
|
|
||||||
public class RegisterModel : PageModel
|
|
||||||
{
|
|
||||||
readonly IEmailSender _emailSender;
|
|
||||||
readonly ILogger<RegisterModel> _logger;
|
|
||||||
readonly SignInManager<IdentityUser> _signInManager;
|
|
||||||
readonly UserManager<IdentityUser> _userManager;
|
|
||||||
|
|
||||||
public RegisterModel(UserManager<IdentityUser> userManager, SignInManager<IdentityUser> signInManager,
|
|
||||||
ILogger<RegisterModel> logger, IEmailSender emailSender)
|
|
||||||
{
|
|
||||||
_userManager = userManager;
|
|
||||||
_signInManager = signInManager;
|
|
||||||
_logger = logger;
|
|
||||||
_emailSender = emailSender;
|
|
||||||
}
|
|
||||||
|
|
||||||
[BindProperty]
|
|
||||||
public InputModel Input { get; set; }
|
|
||||||
|
|
||||||
public string ReturnUrl { get; set; }
|
|
||||||
|
|
||||||
public void OnGet(string returnUrl = null)
|
|
||||||
{
|
|
||||||
ReturnUrl = returnUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostAsync(string returnUrl = null)
|
|
||||||
{
|
|
||||||
returnUrl = returnUrl ?? Url.Content("~/");
|
|
||||||
if(ModelState.IsValid)
|
|
||||||
{
|
|
||||||
IdentityUser user = new IdentityUser {UserName = Input.Email, Email = Input.Email};
|
|
||||||
IdentityResult result = await _userManager.CreateAsync(user, Input.Password);
|
|
||||||
if(result.Succeeded)
|
|
||||||
{
|
|
||||||
_logger.LogInformation("User created a new account with password.");
|
|
||||||
|
|
||||||
string code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
|
|
||||||
string callbackUrl = Url.Page("/Account/ConfirmEmail", null, new {userId = user.Id, code},
|
|
||||||
Request.Scheme);
|
|
||||||
|
|
||||||
await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
|
|
||||||
$"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");
|
|
||||||
|
|
||||||
await _signInManager.SignInAsync(user, false);
|
|
||||||
return LocalRedirect(returnUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach(IdentityError error in result.Errors) ModelState.AddModelError(string.Empty, error.Description);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we got this far, something failed, redisplay form
|
|
||||||
return Page();
|
|
||||||
}
|
|
||||||
|
|
||||||
public class InputModel
|
|
||||||
{
|
|
||||||
[Required]
|
|
||||||
[EmailAddress]
|
|
||||||
[Display(Name = "Email")]
|
|
||||||
public string Email { get; set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
[StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.",
|
|
||||||
MinimumLength = 6)]
|
|
||||||
[DataType(DataType.Password)]
|
|
||||||
[Display(Name = "Password")]
|
|
||||||
public string Password { get; set; }
|
|
||||||
|
|
||||||
[DataType(DataType.Password)]
|
|
||||||
[Display(Name = "Confirm password")]
|
|
||||||
[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
|
|
||||||
public string ConfirmPassword { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : ResetPassword.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
}
|
|
||||||
@page
|
|
||||||
@model ResetPasswordModel
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Reset password";
|
|
||||||
}
|
|
||||||
|
|
||||||
<h1>@ViewData["Title"]</h1>
|
|
||||||
<h4>Reset your password.</h4>
|
|
||||||
<hr />
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-4">
|
|
||||||
<form method="post">
|
|
||||||
<div asp-validation-summary="All"
|
|
||||||
class="text-danger">
|
|
||||||
</div>
|
|
||||||
<input asp-for="Input.Code"
|
|
||||||
type="hidden" />
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Input.Email"></label>
|
|
||||||
<input asp-for="Input.Email"
|
|
||||||
class="form-control" />
|
|
||||||
<span asp-validation-for="Input.Email"
|
|
||||||
class="text-danger">
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Input.Password"></label>
|
|
||||||
<input asp-for="Input.Password"
|
|
||||||
class="form-control" />
|
|
||||||
<span asp-validation-for="Input.Password"
|
|
||||||
class="text-danger">
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Input.ConfirmPassword"></label>
|
|
||||||
<input asp-for="Input.ConfirmPassword"
|
|
||||||
class="form-control" />
|
|
||||||
<span asp-validation-for="Input.ConfirmPassword"
|
|
||||||
class="text-danger">
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<button class="btn btn-primary"
|
|
||||||
type="submit">
|
|
||||||
Reset
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@section Scripts {
|
|
||||||
<partial name="_ValidationScriptsPartial" />
|
|
||||||
}
|
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : ResetPasswordConfirmation.cshtml.cs
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Identity;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
||||||
|
|
||||||
namespace cicm_web.Areas.Identity.Pages.Account
|
|
||||||
{
|
|
||||||
[AllowAnonymous]
|
|
||||||
public class ResetPasswordModel : PageModel
|
|
||||||
{
|
|
||||||
readonly UserManager<IdentityUser> _userManager;
|
|
||||||
|
|
||||||
public ResetPasswordModel(UserManager<IdentityUser> userManager)
|
|
||||||
{
|
|
||||||
_userManager = userManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
[BindProperty]
|
|
||||||
public InputModel Input { get; set; }
|
|
||||||
|
|
||||||
public IActionResult OnGet(string code = null)
|
|
||||||
{
|
|
||||||
if(code == null) return BadRequest("A code must be supplied for password reset.");
|
|
||||||
|
|
||||||
Input = new InputModel {Code = code};
|
|
||||||
return Page();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostAsync()
|
|
||||||
{
|
|
||||||
if(!ModelState.IsValid) return Page();
|
|
||||||
|
|
||||||
IdentityUser user = await _userManager.FindByEmailAsync(Input.Email);
|
|
||||||
if(user == null)
|
|
||||||
// Don't reveal that the user does not exist
|
|
||||||
return RedirectToPage("./ResetPasswordConfirmation");
|
|
||||||
|
|
||||||
IdentityResult result = await _userManager.ResetPasswordAsync(user, Input.Code, Input.Password);
|
|
||||||
if(result.Succeeded) return RedirectToPage("./ResetPasswordConfirmation");
|
|
||||||
|
|
||||||
foreach(IdentityError error in result.Errors) ModelState.AddModelError(string.Empty, error.Description);
|
|
||||||
return Page();
|
|
||||||
}
|
|
||||||
|
|
||||||
public class InputModel
|
|
||||||
{
|
|
||||||
[Required]
|
|
||||||
[EmailAddress]
|
|
||||||
public string Email { get; set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
[StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.",
|
|
||||||
MinimumLength = 6)]
|
|
||||||
[DataType(DataType.Password)]
|
|
||||||
public string Password { get; set; }
|
|
||||||
|
|
||||||
[DataType(DataType.Password)]
|
|
||||||
[Display(Name = "Confirm password")]
|
|
||||||
[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
|
|
||||||
public string ConfirmPassword { get; set; }
|
|
||||||
|
|
||||||
public string Code { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : ResetPasswordConfirmation.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
}
|
|
||||||
@page
|
|
||||||
@model ResetPasswordConfirmationModel
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Reset password confirmation";
|
|
||||||
}
|
|
||||||
|
|
||||||
<h1>@ViewData["Title"]</h1>
|
|
||||||
<p>
|
|
||||||
Your password has been reset. Please <a asp-page="./Login">click here to log in</a>.
|
|
||||||
</p>
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : ResetPasswordConfirmation.cshtml.cs
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
||||||
|
|
||||||
namespace cicm_web.Areas.Identity.Pages.Account
|
|
||||||
{
|
|
||||||
[AllowAnonymous]
|
|
||||||
public class ResetPasswordConfirmationModel : PageModel
|
|
||||||
{
|
|
||||||
public void OnGet() { }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
@using cicm_web.Areas.Identity.Pages.Account
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : Error.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
}
|
|
||||||
@page
|
|
||||||
@model ErrorModel
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Error";
|
|
||||||
}
|
|
||||||
|
|
||||||
<h1 class="text-danger">Error.</h1>
|
|
||||||
<h2 class="text-danger">An error occurred while processing your request.</h2>
|
|
||||||
|
|
||||||
@if(Model.ShowRequestId)
|
|
||||||
{
|
|
||||||
<p>
|
|
||||||
<strong>Request ID:</strong> <code>@Model.RequestId</code>
|
|
||||||
</p>
|
|
||||||
}
|
|
||||||
|
|
||||||
<h3>Development Mode</h3>
|
|
||||||
<p>
|
|
||||||
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
<strong>Development environment should not be enabled in deployed applications</strong>, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>, and restarting the application.
|
|
||||||
</p>
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : Error.cshtml.cs
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
using System.Diagnostics;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
||||||
|
|
||||||
namespace cicm_web.Areas.Identity.Pages
|
|
||||||
{
|
|
||||||
[AllowAnonymous]
|
|
||||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
||||||
public class ErrorModel : PageModel
|
|
||||||
{
|
|
||||||
public string RequestId { get; set; }
|
|
||||||
|
|
||||||
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
|
|
||||||
|
|
||||||
public void OnGet()
|
|
||||||
{
|
|
||||||
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// Canary Islands Computer Museum Website
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : _ViewImports.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ASP.NET Identify management
|
|
||||||
//
|
|
||||||
// --[ License ] --------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2018 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
}
|
|
||||||
@using Microsoft.AspNetCore.Identity
|
|
||||||
@using cicm_web.Areas.Identity
|
|
||||||
@using Microsoft.AspNetCore.Identity
|
|
||||||
@namespace cicm_web.Areas.Identity.Pages
|
|
||||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
|
||||||
@@ -32,7 +32,6 @@ using Cicm.Database.Models;
|
|||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Identity;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
@@ -55,13 +54,14 @@ namespace cicm_web
|
|||||||
services.Configure<CookiePolicyOptions>(options =>
|
services.Configure<CookiePolicyOptions>(options =>
|
||||||
{
|
{
|
||||||
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
|
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
|
||||||
options.CheckConsentNeeded = context => true;
|
options.CheckConsentNeeded = context => true;
|
||||||
options.MinimumSameSitePolicy = SameSiteMode.None;
|
options.MinimumSameSitePolicy = SameSiteMode.None;
|
||||||
});
|
});
|
||||||
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. See http://go.microsoft.com/fwlink/?LinkId=723263 for guidance on storing connection strings.
|
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. See http://go.microsoft.com/fwlink/?LinkId=723263 for guidance on storing connection strings.
|
||||||
services.AddDbContext<cicmContext>(options => options
|
services.AddDbContext<cicmContext>(options => options
|
||||||
.UseLazyLoadingProxies()
|
.UseLazyLoadingProxies()
|
||||||
.UseMySql("server=localhost;port=3306;user=cicm;password=cicmpass;database=cicm"));
|
.UseMySql("server=localhost;port=3306;user=cicm;password=cicmpass;database=cicm"));
|
||||||
|
|
||||||
services.AddMvc();
|
services.AddMvc();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,10 +75,11 @@ namespace cicm_web
|
|||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.UseCookiePolicy();
|
app.UseCookiePolicy();
|
||||||
|
|
||||||
app.UseMvc(routes => { routes.MapRoute(
|
app.UseMvc(routes =>
|
||||||
name: "areas",
|
{
|
||||||
template: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
|
routes.MapRoute("areas", "{area:exists}/{controller=Home}/{action=Index}/{id?}")
|
||||||
).MapRoute("default", "{controller=Home}/{action=Index}/{id?}"); });
|
.MapRoute("default", "{controller=Home}/{action=Index}/{id?}");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||||
<Version>3.0.99.371</Version>
|
<Version>3.0.99.386</Version>
|
||||||
<Company>Canary Islands Computer Museum</Company>
|
<Company>Canary Islands Computer Museum</Company>
|
||||||
<Copyright>Copyright © 2003-2018 Natalia Portillo</Copyright>
|
<Copyright>Copyright © 2003-2018 Natalia Portillo</Copyright>
|
||||||
<Product>Canary Islands Computer Museum Website</Product>
|
<Product>Canary Islands Computer Museum Website</Product>
|
||||||
@@ -32,4 +32,9 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Cicm.Database\Cicm.Database.csproj" />
|
<ProjectReference Include="..\Cicm.Database\Cicm.Database.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="Microsoft.AspNetCore.Authorization, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60">
|
||||||
|
<HintPath>..\..\..\.nuget\packages\microsoft.aspnetcore.authorization\2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Authorization.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
Reference in New Issue
Block a user