예제 #1
0
        public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;

            var allowedEmail = await _ruleFacade.Validate(model.Email);

            if (ModelState.IsValid && allowedEmail)
            {
                var result = await _accountFacade.CreateUserAsync(model.Email, model.Password);

                if (result.Suceeded)
                {
                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(result.User);

                    var callbackUrl = Url.Action <AccountController>(
                        c => c.ConfirmEmail(With.No <string>(), With.No <string>()),
                        new { userId = result.User.Id, code = code },
                        protocol: HttpContext.Request.Scheme);

                    await _emailSender.SendEmailAsync(result.User.Email, "Confirm your account",
                                                      $"Please confirm your account by clicking this link: <a href='{callbackUrl}'>link</a>");

                    return(Redirect(callbackUrl));
                }
                else
                {
                    AddErrors(result.Identity);
                }
            }
            else if (!allowedEmail)
            {
                ModelState.AddModelError(nameof(model.Email), "Email Address is not in allowed email address list.");
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }