Creating the Tic-Tac-Toe user registration page

You will now integrate the second component, the user registration page with its form, which will allow new users to register to play the Tic-Tac-Toe game:

  1. Add a new folder called Models to the project.
  2. Add a new model by right-clicking on the Models folder in your project and selecting Add | Class, and name it UserModel:
        public class UserModel 
        { 
          public Guid Id { get; set; } 
          public string FirstName { get; set; } 
          public string LastName { get; set; } 
          public string Email { get; set; } 
          public string Password { get; set; } 
          public bool IsEmailConfirmed { get; set; } 
          public System.DateTime? EmailConfirmationDate { get;
set; } public int Score { get; set; } }
  1. Add a new controller and call it UserRegistrationController (if you do not know how to do this, then refer to the Creating the Tic-Tac-Toe home page section).
  2. Right-click on the method called Index and choose Add View. This time, select the Create template, choose UserModel as the Model classas mentioned in the previous point, and enable the usage of the layout page:

Note that you can leave the layout page empty if you want to use the _ViewStart.cshtml file in the Shared folder to define a unified common layout for all your views.

The _ViewStart.cshtml file is used to share settings between views, while the _ViewImports file is used to share using namespaces and inject DI instances. Visual Studio 2019 includes two templates for these files.

  1. Remove the autogenerated Id, IsEmailConfirmed, EmailConfirmationDate, and Score elements from the view; we do not need them for the user registration form.
  2. The view is now ready; display it by pressing F5 and clicking on the registration link on the home page:

You will be presented with a form that can be used to fill user details such as first name, last name, email, and password. Note that the input fields are shorter; to be precise, they are 280 pixels long because of the CSS styling we did in a previous section; otherwise, they would span the entire length of the screen.

We have done the user registration page, but you will quickly notice that a user is a central part of the application. A user will have to sign in and sign out, be validated in different ways, and will have other functionalities apart from just being registered. It is not surprising that we will need to have a user service that will co-ordinate everything that is happening for a user with the rest of the application. We are going to create a user service in the next section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.162.76