/// <summary> /// Gets a collection of all the users in the database. /// </summary> /// <returns>Returns a collection of all the users in the database.</returns> public static List <UserEntity> GetAllUsers() { List <UserEntity> users = new List <UserEntity>(); int totalRecords; foreach (MembershipUser user in MembershipGsp.GetAllUsers(0, 0x7fffffff, out totalRecords)) { users.Add(ToUserEntity(user)); } return(users); }
/// <summary> /// Adds a new user with the specified e-mail address to the data store. /// </summary> /// <param name="userName">The user name for the new user.</param> /// <param name="password">The password for the new user.</param> /// <param name="email">The email for the new user.</param> /// <returns>Returns a new user with the specified e-mail address to the data store.</returns> private static UserEntity CreateUser(string userName, string password, string email) { // This function is a re-implementation of the System.Web.Security.Membership.CreateUser method. We can't call it directly // because it uses the default provider, and we might be using a named provider. MembershipCreateStatus status; MembershipUser user = MembershipGsp.CreateUser(userName, password, email, null, null, true, null, out status); if (user == null) { throw new MembershipCreateUserException(status); } return(ToUserEntity(user)); }
private static MembershipUser ToMembershipUser(UserEntity u) { if (String.IsNullOrEmpty(u.UserName)) { throw new ArgumentException("UserEntity.UserName cannot be empty."); } MembershipUser user = MembershipGsp.GetUser(u.UserName, false); user.Comment = u.Comment; user.Email = u.Email; user.IsApproved = u.IsApproved; return(user); }
private static UserEntity ToUserEntity(MembershipUser u) { if (u == null) { return(null); } if (MembershipGsp.GetType().ToString() == "System.Web.Security.ActiveDirectoryMembershipProvider") { // The AD provider does not support a few properties so substitute default values for them. return(new UserEntity(u.Comment, u.CreationDate, u.Email, u.IsApproved, u.IsLockedOut, false, DateTime.MinValue, u.LastLockoutDate, DateTime.MinValue, u.LastPasswordChangedDate, u.PasswordQuestion, u.ProviderName, u.ProviderUserKey, u.UserName)); } else { return(new UserEntity(u.Comment, u.CreationDate, u.Email, u.IsApproved, u.IsLockedOut, u.IsOnline, u.LastActivityDate, u.LastLockoutDate, u.LastLoginDate, u.LastPasswordChangedDate, u.PasswordQuestion, u.ProviderName, u.ProviderUserKey, u.UserName)); } }
/// <summary> /// Removes a user from the membership data source. /// </summary> /// <param name="userName">The name of the user to delete.</param> /// <returns><c>true</c> if the user was successfully deleted; otherwise, <c>false</c>.</returns> public static bool DeleteUser(string userName) { return(MembershipGsp.DeleteUser(userName, true)); }
/// <summary> /// Updates information about a user in the data source. /// </summary> /// <param name="user">A <see cref="UserEntity"/> object that represents the user to update and the updated information for the user.</param> public static void UpdateUser(UserEntity user) { MembershipGsp.UpdateUser(ToMembershipUser(user)); }
/// <summary> /// Clears a lock so that the membership user can be validated. /// </summary> /// <param name="userName">The membership user whose lock status you want to clear.</param> /// <returns><c>true</c> if the membership user was successfully unlocked; otherwise, <c>false</c>.</returns> public static bool UnlockUser(string userName) { return(MembershipGsp.UnlockUser(userName)); }
/// <summary> /// Processes a request to update the password for a membership user. /// </summary> /// <param name="userName">The user to update the password for.</param> /// <param name="oldPassword">The current password for the specified user.</param> /// <param name="newPassword">The new password for the specified user.</param> /// <returns><c>true</c> if the password was updated successfully; otherwise, <c>false</c>.</returns> public static bool ChangePassword(string userName, string oldPassword, string newPassword) { return(MembershipGsp.ChangePassword(userName, oldPassword, newPassword)); }
/// <summary> /// Resets a user's password to a new, automatically generated password. /// </summary> /// <param name="userName">The user to reset the password for. </param> /// <returns>The new password for the specified user.</returns> public static String ResetPassword(string userName) { return(MembershipGsp.ResetPassword(userName, null)); }
/// <summary> /// Gets information from the data source for a user. Provides an option to update the last-activity date/time stamp for the user. /// </summary> /// <param name="userName">The name of the user to get information for.</param> /// <param name="userIsOnline"><c>true</c> to update the last-activity date/time stamp for the user; <c>false</c> to return user /// information without updating the last-activity date/time stamp for the user.</param> /// <returns>A <see cref="UserEntity"/> object populated with the specified user's information from the data source.</returns> public static UserEntity GetUser(string userName, bool userIsOnline) { return(ToUserEntity(MembershipGsp.GetUser(userName, userIsOnline))); }
/// <overloads> /// Gets information from the data source for a user. /// </overloads> /// <summary> /// Gets information from the data source for the current logged-on membership user. /// </summary> /// <returns>A <see cref="UserEntity"/> representing the current logged-on membership user.</returns> public static UserEntity GetUser() { return(ToUserEntity(MembershipGsp.GetUser(Util.UserName, false))); }