public async Task <ActionResult> Login(LoginVM model) { tc.TrackEvent("Login attempt"); try { if (ModelState.IsValid) { var user = await _userAccountManager.GetUser(model.Email); if (user != null) { var passwordHash = _userAccountManager.GetHash(model.Password, user.Salt); if (user.Password == passwordHash) { await _userAccountManager.UpdateLastLoginTime(user.Id); if (user.DefaultTeamId == null) { tc.TrackEvent("User with no default team!" + user.Id); // This sould not happen! But if in case var teams = await _userAccountManager.GetTeams(user.Id); if (teams.Any()) { user.DefaultTeamId = teams.First().Id; await this._userAccountManager.SetDefaultTeam(user.Id, user.DefaultTeamId.Value); } } this._userSessionHelper.SetUserIDToSession(user.Id, user.DefaultTeamId.Value, model.Email); return(RedirectToAction(nameof(DashboardController.Index), "dashboard")); } } } ModelState.AddModelError("", "Username/Password is incorrect!"); } catch (Exception ex) { ModelState.AddModelError("", "Oops! Something went wrong :("); tc.TrackException(ex); } return(View(model)); }