public async Task <IViewComponentResult> InvokeAsync(int id) { var vm = new UserMenuHeaderVM(); if (userSessionHelper.UserId > 0) { var u = await userAccountManager.GetUser(userSessionHelper.UserId); vm.UserDisplayName = u.Name; var teams = await userAccountManager.GetTeams(userSessionHelper.UserId); vm.Teams = teams.Select(x => new TeamDto { Id = x.Id, Name = x.Name }).ToList(); if (u.DefaultTeamId != null) { if (teams.Any(g => g.Id == u.DefaultTeamId)) { vm.CurrentTeamName = teams.FirstOrDefault(g => g.Id == u.DefaultTeamId.Value).Name; } else { vm.CurrentTeamName = teams.FirstOrDefault().Name; } } else { vm.CurrentTeamName = teams.FirstOrDefault().Name; } } return(View(vm)); }
public async Task <ActionResult> Login(LoginVM model) { try { if (ModelState.IsValid) { var user = accountManager.GetUser(model.Email); if (user != null) { if (user.Password == model.Password) { await accountManager.SaveLastLoginAsync(user.Id); int userDefaultTeamId = user.DefaultTeamId ?? 0; SetUserIDToSession(user.Id, userDefaultTeamId, user.Name); return(RedirectToAction("index", "dashboard")); } } } ModelState.AddModelError("", "Username/Password is incorrect!"); } catch (Exception ex) { ModelState.AddModelError("", "Oops! Something went wrong :("); log.Error(ex); } return(View(model)); }
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)); }
public async Task <ActionResult> Login(LoginVM model) { try { if (ModelState.IsValid) { var user = await userAccountManager.GetUser(model.Email); if (user != null) { var appUser = new AppUser { UserName = user.EmailAddress, Id = user.Id.ToString() }; if (user.Password == model.Password) { await userAccountManager.UpdateLastLoginTime(user.Id); if (user.DefaultTeamId == null) { // 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); return(RedirectToAction("index", "dashboard")); } } } ModelState.AddModelError("", "Username/Password is incorrect!"); } catch (Exception ex) { ModelState.AddModelError("", "Oops! Something went wrong :("); } return(View(model)); }
public async Task <ActionResult> Login(LoginVM model) { try { if (ModelState.IsValid) { var user = accountManager.GetUser(model.Email); if (user != null) { var appUser = new AppUser { UserName = user.EmailAddress, Id = user.Id.ToString() }; //var user1 = await um.FindAsync(model.Email, model.Password); //if (user1!= null) //{ await SignInAsync(appUser, model.RememberMe); // // return RedirectToLocal(returnUrl); //} if (user.Password == model.Password) { await accountManager.SaveLastLoginAsync(user.Id); int userDefaultTeamId = user.DefaultTeamId ?? 0; var claims = new[] { new Claim(ClaimTypes.Name, user.Name), new Claim(ClaimTypes.Email, user.EmailAddress) }; //var identity = new ClaimsIdentity(claims,DefaultAuthenticationTypes.ApplicationCookie); //ClaimsPrincipal principal = new ClaimsPrincipal(identity); //Thread.CurrentPrincipal = principal; //var context = Request.GetOwinContext(); //var authManager = context.Authentication; //authManager.SignIn(new AuthenticationProperties { IsPersistent = true }, identity); //AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie); //var identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie); //AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity); SetUserIDToSession(user.Id, userDefaultTeamId, user.Name); return(RedirectToAction("index", "dashboard")); } } } ModelState.AddModelError("", "Username/Password is incorrect!"); } catch (Exception ex) { ModelState.AddModelError("", "Oops! Something went wrong :("); log.Error(ex); } return(View(model)); }