Example #1
0
        public async Task <ActionResult> ConfirmEmail(string userId, string code)
        {
            if (userId == null || code == null)
            {
                return(View("Error"));
            }
            var result = await UserManager.ConfirmEmailAsync(userId, code);

            if (result.Succeeded)
            {
                var viewModel = new AccountAfterConfirmationViewModel
                {
                    UserId = userId
                };
                return(View("ConfirmEmail", viewModel));
            }
            return(View("Error"));
        }
Example #2
0
        public async Task <ActionResult> CreateAccountAfterConfirmation(AccountAfterConfirmationViewModel viewModel)
        {
            var user = await UserManager.FindByIdAsync(viewModel.UserId);

            var passwordChangeResult = await UserManager.AddPasswordAsync(user.Id, viewModel.Password);

            if (passwordChangeResult.Succeeded)
            {
                user.UserName = viewModel.Username;
                var updateResult = await UserManager.UpdateAsync(user);

                if (updateResult.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(RedirectToAction("Index", "Home"));
        }