public async Task <ActionResult> ConfirmEmail(string userId, string code) { if (userId == null || code == null) { return(View("Error")); } var user = await _userManager.FindByIdAsync(userId); if (user != null && user.EmailConfirmed) { return(View("EmailAlreadyConfirmed")); } var result = await _userManager.ConfirmEmailAsync(userId, code); var autoLoginModel = new AutoLoginModel(); ViewBag.StatusMessage = user.AccountState == AccountState.RequiresConfirmation ? "Witamy wsród zamiłowanych użytkowników!" : user.AccountState == AccountState.EmailChanged ? "Zmiana adresu e-mail została właśnie potwierdzona." : string.Empty; if (user.AutoLoginEnabled && user.AccountState != AccountState.Confirmed) { autoLoginModel.AutoLoginEnabled = true; autoLoginModel.UserId = userId; } user.AccountState = AccountState.Confirmed; user.AutoLoginEnabled = false; await _userManager.UpdateAsync(user); return(result.Succeeded ? View("EmailConfirmation", autoLoginModel) : View("Error")); }
public async Task <ActionResult> AutoLogin(AutoLoginModel model) { if (!ModelState.IsValid || !model.AutoLoginEnabled) { return(View("Error")); } var user = await _userManager.FindByIdAsync(model.UserId); if (user != null && !user.EmailConfirmed) { return(View("Error")); } await _signInManager.SignInAsync(user, false, false); await UpdateLastLoginDate(user); return(RedirectToAction("Index", "Home")); }