public async Task<ActionResult> Login(LoginViewModel model) { var timeout = this.GetTimeoutToken(); var validationContext = new ValidationContext(); model.Validate(validationContext); if (validationContext.HasErrors) { this.AddModelStateError(validationContext); return await this.View(model, timeout); } var account = new Account { IdentityType = IdentityType.EmailAddress, IdentityValue = model.EmailAddress.Trim().ToLowerInvariant(), }; account = await this.accountStore.Get(account.PartitionKey, account.RowKey, timeout); if (account == null || BCrypt.Net.BCrypt.Verify(model.Password, account.PasswordHash) == false) { validationContext.AddError("Cannot find a matching account and password. Please try again!"); this.AddModelStateError(validationContext); return await this.View(model, timeout); } await this.CreateNewSession(account, model.RememberMe, timeout); return this.RedirectToAction("Index", "Home"); }
public async Task<ActionResult> Login() { var timeout = this.GetTimeoutToken(); if (await this.GetSession(timeout) != null) { return this.RedirectToAction("Index", "Home"); } var model = new LoginViewModel(); return await this.View(model, this.GetTimeoutToken()); }