Ejemplo n.º 1
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            if (ModelState.IsValid)
            {
                var user = new LeaderUser {
                    UserName = Input.Email, Email = Input.Email, FirstName = Input.FirstName, LastName = Input.LastName
                };
                //var result = await _userManager.CreateAsync(user, Input.Password);

                /* Temp for debugging */
                IdentityResult result;
                try
                {
                    result = await _userManager.CreateAsync(user, Input.Password);
                }
                catch (System.Exception ex)
                {
                    @ViewData["Message"] = "Error: " + ex.Message;
                    return(Page());
                }

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { userId = user.Id, code = code },
                        protocol: Request.Scheme);

                    /* Ensure the user sees the correct culture when clicking conform email */
                    var currentCulture = System.Threading.Thread.CurrentThread.CurrentUICulture;

                    await _emailSender.SendEmailAsync(new string[] { Input.Email }, _stringLocalizer["Confirm your email"],
                                                      string.Format("{0} {1}<p/> {2} <a href='{3}&culture={4}'>{5}</a>", _stringLocalizer["Hello"], Input.FirstName + " " + Input.LastName, _stringLocalizer["Please confirm your account by"], HtmlEncoder.Default.Encode(callbackUrl), currentCulture, _stringLocalizer["clicking here"])
                                                      );

                    @ViewData["Message"] = _stringLocalizer["Thank you for registering. You have been sent an email to confirm your account. Please click the link in the email to confirm your account and log in"];
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
Ejemplo n.º 2
0
        public async Task OnGet()
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            if (user == null)
            {
                user = new LeaderUser();
            }
            Input = new InputModel
            {
                Email     = user.Email,
                FirstName = user.FirstName,
                LastName  = user.LastName
            };
        }