/// <summary> /// Sets Current User session /// </summary> /// <param name="email"></param> /// <param name="tenantName"></param> /// <returns></returns> public async Task <ApplicationUser> SetCurrentSession(string email, string tenantName) { var user = DbContext.Users.Find((await base.FindByEmailAsync(email)).Id); var tenant = FindTenantByName(tenantName); if (tenant != null) { CurrentUserSession currentUserSession = user.CurrentSession; if (currentUserSession == null) { currentUserSession = new CurrentUserSession(); } currentUserSession.Tenant = tenant; user.CurrentSession = currentUserSession; await base.UpdateAsync(user); await DbContext.Entry(user).Collection(p => p.UserRoles).LoadAsync(); await DbContext.Entry(user).Collection(p => p.Claims).LoadAsync(); this.UpdateAsync(user); return(user); } return(null); }
public async Task <UserModel> LogIn(LoginViewModel model) { if (ModelState.IsValid) { try { var user = await UserManager.FindAsync(model.UserName.ToLower(), model.Password); if (user != null && user.DeleteTime == null) { HibernateSession.SignInUser(user, model.RememberMe); return(user); } else { CurrentUserSession.removeSecurityStampCookie(); return(null); } }catch (Exception e) { return(null); } } return(null); }
public Boolean IsUserAuthorized() { if (CurrentUserSession.IsNull()) { return(false); } return(CurrentUserSession.IsLoggedIn); }
public static async void SignInUser(UserModel user, bool remeberMe) { //CurrentUserSession.userSession = user.Id; if (remeberMe) { if (user.SecurityStamp == null) { user.SecurityStamp = Guid.NewGuid().ToString(); NHibernateUserStore hs = new NHibernateUserStore(); await hs.UpdateAsync(user); } CurrentUserSession.userSecurityStampCookie = user.SecurityStamp; } else { CurrentUserSession.removeSecurityStampCookie(); } }