/// <summary> /// Returns an TUser given the user's id /// </summary> /// <param name="userId">The user's id</param> /// <returns></returns> public TUser GetUserById(string userId) { ConnectionService.ThreadVanityUrl = ConnectionName; TUser newUser = null; AspNetUsersQuery q = new AspNetUsersQuery(); q.Where(q.Id == userId); AspNetUsers user = new AspNetUsers(); SetConnection(user); if (user.Load(q)) { newUser = (TUser)Activator.CreateInstance(typeof(TUser)); newUser.Id = user.Id; newUser.UserName = user.UserName; newUser.PasswordHash = user.PasswordHash; newUser.SecurityStamp = user.SecurityStamp; newUser.Email = user.Email; newUser.EmailConfirmed = user.EmailConfirmed == null ? false : user.EmailConfirmed.Value; newUser.PhoneNumber = user.PhoneNumber; newUser.PhoneNumberConfirmed = user.PhoneNumberConfirmed == null ? false : user.PhoneNumberConfirmed.Value; newUser.LockoutEnabled = user.LockoutEnabled == null ? false : user.LockoutEnabled.Value; newUser.LockoutEndDateUtc = user.LockoutEndDateUtc == null ? DateTime.UtcNow : user.LockoutEndDateUtc.Value; newUser.AccessFailedCount = user.AccessFailedCount == null ? 0 : user.AccessFailedCount.Value; } return(newUser); }
/// <summary> /// Returns a User ID given a user name /// </summary> /// <param name="userName">The user's name</param> /// <returns></returns> public string GetUserId(string userName) { ConnectionService.ThreadVanityUrl = ConnectionName; string userId = null; AspNetUsersQuery q = new AspNetUsersQuery(); q.Select(q.Id); q.Where(q.UserName == userName); AspNetUsers user = new AspNetUsers(); SetConnection(user); if (user.Load(q)) { userId = user.Id; } return(userId); }
/// <summary> /// Return the user's password hash /// </summary> /// <param name="userId">The user's id</param> /// <returns></returns> public string GetPasswordHash(string userId) { ConnectionService.ThreadVanityUrl = ConnectionName; string passwordHash = null; AspNetUsersQuery q = new AspNetUsersQuery(); q.Select(q.PasswordHash); q.Where(q.Id == userId); AspNetUsers user = new AspNetUsers(); SetConnection(user); if (user.Load(q)) { passwordHash = user.PasswordHash; } return(passwordHash); }
/// <summary> /// Returns the user's security stamp /// </summary> /// <param name="userId"></param> /// <returns></returns> public string GetSecurityStamp(string userId) { ConnectionService.ThreadVanityUrl = ConnectionName; string stamp = null; AspNetUsersQuery q = new AspNetUsersQuery(); q.Select(q.SecurityStamp); q.Where(q.Id == userId); AspNetUsers user = new AspNetUsers(); SetConnection(user); if (user.Load(q)) { stamp = user.SecurityStamp; } return(stamp); }
/// <summary> /// Returns a list of TUser instances given a user name /// </summary> /// <param name="userName">User's name</param> /// <returns></returns> public List <TUser> GetUserByName(string userName) { ConnectionService.ThreadVanityUrl = ConnectionName; List <TUser> users = new List <TUser>(); AspNetUsersQuery q = new AspNetUsersQuery(); q.Where(q.UserName == userName); int id = Thread.CurrentThread.ManagedThreadId; AspNetUsersCollection coll = new AspNetUsersCollection(); SetConnection(coll); if (coll.Load(q)) { foreach (AspNetUsers user in coll) { TUser newUser = (TUser)Activator.CreateInstance(typeof(TUser)); newUser.Id = user.Id; newUser.UserName = user.UserName; newUser.PasswordHash = user.PasswordHash; newUser.SecurityStamp = user.SecurityStamp; newUser.Email = user.Email; newUser.EmailConfirmed = user.EmailConfirmed == null ? false : user.EmailConfirmed.Value; newUser.PhoneNumber = user.PhoneNumber; newUser.PhoneNumberConfirmed = user.PhoneNumberConfirmed == null ? false : user.PhoneNumberConfirmed.Value; newUser.LockoutEnabled = user.LockoutEnabled == null ? false : user.LockoutEnabled.Value; newUser.LockoutEndDateUtc = user.LockoutEndDateUtc == null ? DateTime.UtcNow : user.LockoutEndDateUtc.Value; newUser.AccessFailedCount = user.AccessFailedCount == null ? 0 : user.AccessFailedCount.Value; users.Add(newUser); } } return(users); }