public async Task <IActionResult> PassphraseReset(LoginPassphraseViewModel model) { if (this.ModelState.IsValid) { var user = await this.users.FindByNameAsync(model.Email); if (user != null) { var previousPassphrase = user.PassPhrase; user.PassPhrase = model.PassPhrase; user.PassphraseChanges.Add(new PassphraseChange { PassphraseBefore = previousPassphrase, PassphraseAfter = model.PassPhrase, PassphraseChangedDateTime = DateTime.Now, UserId = user.Id }); var result = await this.users.UpdateAsync(user); if (result.Succeeded) { return(this.RedirectToAction("Login", new { passwordReset = true })); } } else { return(this.RedirectToAction("PassphraseReset", new { userNotFound = true })); } } return(this.RedirectToAction("LoginFail")); }
public async Task <IActionResult> LoginPassphrase(LoginPassphraseViewModel model) { if (this.ModelState.IsValid) { var email = string.Empty; if (this.User.Identity.IsAuthenticated) { email = this.User.Identity.Name; } else { email = model.Email; } var user = await this.users.FindByNameAsync(email); if (user != null) { var authenticationProperties = new AuthenticationProperties { RedirectUri = "~/Home/LoginPassphrase", IsPersistent = true, ExpiresUtc = DateTimeOffset.UtcNow.Add(TimeSpan.FromMinutes(30)) }; await this.signInManager.SignInAsync(user, authenticationProperties); var passPhraseMatch = user.PassPhrase.Equals(model.PassPhrase, StringComparison.Ordinal); if (passPhraseMatch) { user.LoginEntries.Add(new LoginEntry { LoginDateTime = DateTime.Now, LoginTypeId = (int)LoginTypeEnum.Passphrase, IsSuccessful = true, UserId = user.Id }); await this.users.UpdateAsync(user); return(this.RedirectToAction("LoginSuccess", new { loginTypeId = (int)LoginTypeEnum.Passphrase })); } else { user.LoginEntries.Add(new LoginEntry { LoginDateTime = DateTime.Now, LoginTypeId = (int)LoginTypeEnum.Passphrase, IsSuccessful = false, UserId = user.Id }); await this.users.UpdateAsync(user); return(this.RedirectToAction("LoginFailPassphrase", new { emailAddress = model.Email })); } } else { return(this.RedirectToAction("Login")); } } return(this.RedirectToAction("LoginFail")); }