diff --git a/RobotApp/Components/Account/IdentityComponentsEndpointRouteBuilderExtensions.cs b/RobotApp/Components/Account/IdentityComponentsEndpointRouteBuilderExtensions.cs index 7b9de05..75fa522 100644 --- a/RobotApp/Components/Account/IdentityComponentsEndpointRouteBuilderExtensions.cs +++ b/RobotApp/Components/Account/IdentityComponentsEndpointRouteBuilderExtensions.cs @@ -1,14 +1,7 @@ -using System.Security.Claims; -using System.Text.Json; -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Components.Authorization; -using Microsoft.AspNetCore.Http.Extensions; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Primitives; -using RobotApp.Components.Account.Pages; -using RobotApp.Components.Account.Shared; using RobotApp.Data; +using System.Security.Claims; namespace Microsoft.AspNetCore.Routing { diff --git a/RobotApp/Components/Account/Pages/Register.razor b/RobotApp/Components/Account/Pages/Register.razor deleted file mode 100644 index 201bf98..0000000 --- a/RobotApp/Components/Account/Pages/Register.razor +++ /dev/null @@ -1,118 +0,0 @@ -@page "/Account/Register" - -@using System.ComponentModel.DataAnnotations -@using System.Text -@using System.Text.Encodings.Web -@using Microsoft.AspNetCore.Identity -@using Microsoft.AspNetCore.WebUtilities -@using RobotApp.Data - -@inject UserManager UserManager -@inject IUserStore UserStore -@inject SignInManager SignInManager -@inject IEmailSender EmailSender -@inject ILogger Logger -@inject NavigationManager NavigationManager -@inject IdentityRedirectManager RedirectManager - -Register - -
-

Create a new account.

- @if (!string.IsNullOrEmpty(errorMessage)) - { - var statusMessageClass = errorMessage.StartsWith("Error") ? "danger" : "success"; - - } - - -
- -
- - - -
-
- - - -
-
- - - -
- -
-
- - -@code { - private string errorMessage = string.Empty; - - private IEnumerable? identityErrors; - - [SupplyParameterFromForm] - private InputModel Input { get; set; } = new(); - - [SupplyParameterFromQuery] - private string? ReturnUrl { get; set; } - - private string? Message => identityErrors is null ? null : $"Error: {string.Join(", ", identityErrors.Select(error => error.Description))}"; - - public async Task RegisterUser(EditContext editContext) - { - var user = CreateUser(); - - await UserStore.SetUserNameAsync(user, Input.UserName, CancellationToken.None); - user.NormalizedUserName = Input.UserName.ToUpperInvariant(); - user.EmailConfirmed = true; - var result = await UserManager.CreateAsync(user, Input.Password); - - if (!result.Succeeded) - { - identityErrors = result.Errors; - return; - } - - Logger.LogInformation("User created a new account with password."); - - await SignInManager.SignInAsync(user, isPersistent: false); - RedirectManager.RedirectTo(ReturnUrl); - } - - private ApplicationUser CreateUser() - { - try - { - return Activator.CreateInstance(); - } - catch - { - throw new InvalidOperationException($"Can't create an instance of '{nameof(ApplicationUser)}'. " + - $"Ensure that '{nameof(ApplicationUser)}' is not an abstract class and has a parameterless constructor."); - } - } - - - private sealed class InputModel - { - [Required] - [Display(Name = "UserName")] - public string UserName { 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; } = ""; - } -} \ No newline at end of file diff --git a/RobotApp/robot.db b/RobotApp/robot.db index 9d7869e..fa4a3f5 100644 Binary files a/RobotApp/robot.db and b/RobotApp/robot.db differ