Preliminary email confirmation functionality

In this section, we are going to build a tentative email confirmation functionality to demonstrate client-side development. This functionality will evolve along the course of this book and will be perfected in later chapters. But for now, let's create our email confirmation functionality as follows:  

  1. Start Visual Studio 2019 and open the Tic-Tac-Toe project. Add a new method called EmailConfirmation to UserRegistrationController:
        [HttpGet] 
        public IActionResult EmailConfirmation (string email) 
        { 
          ViewBag.Email = email; 
          return View(); 
        } 
  1. Right-click on the EmailConfirmation method, generate the corresponding view, and update it with some meaningful information:
        @{ 
            ViewData["Title"] = "EmailConfirmation"; 
            Layout = "~/Views/Shared/_Layout.cshtml"; 
        } 
        <h2>EmailConfirmation</h2> 
        An email has been sent to @ViewBag.Email, please 
confirm your email address by clicking on the
provided link.
  1. Go to UserRegistrationController and modify the Index method to redirect to the EmailConfirmation method from the previous step, instead of returning the text message:
        [HttpPost] 
        public async Task<IActionResult> Index(UserModel userModel) 
        { 
          if (ModelState.IsValid) 
          { 
            await _userService.RegisterUser(userModel); 
            return RedirectToAction(nameof(EmailConfirmation),
new { userModel.Email }); } else { return View(userModel); } }
  1. Start the application by pressing F5, register a new user, and verify that the new EmailConfirmation page is displayed correctly:

Here, you have implemented the first set of modifications in order to finalize the user registration process. In the next section, we need to check that the user has confirmed their email address.

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

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