/// <summary> /// Updates information about a user in the data source. /// </summary> /// <param name="user">A <see cref="T:System.Web.Security.MembershipUser"></see> object that represents the user to update and the updated information for the user.</param> public abstract void UpdateUser(MembershipUser user);
/// <summary> /// Creates the membership from internal user. /// </summary> /// <param name="user">The user.</param> /// <returns></returns> MembershipUser CreateMembershipFromInternalUser(MembershipUser user) { return new MembershipUser (user.UserName, user.ProviderUserKey, user.Email, user.PasswordQuestion, user.Comment, user.IsApproved, user.IsLockedOut, user.CreationDate, user.LastLoginDate, user.LastActivityDate, user.LastPasswordChangedDate, user.LastLockoutDate); }
public static void UpdateUser(MembershipUser user) { Provider.UpdateUser(user); }
/// <summary> /// Updates information about a user in the data source. /// </summary> /// <param name="user">A <see cref="T:System.Web.Security.MembershipUser"></see> object that represents the /// user to update and the updated information for the user.</param> public override void UpdateUser(MembershipUser user) { try { using (var session = DocumentStore.OpenSession()) { var suser = session.Query<MembershipUser> () .Where (x => x.UserName == user.UserName).FirstOrDefault (); if (suser == null) { throw new MembershipException ("User does not exist!"); } bool isUserNameOk = true; bool isEmailOk = true; ValidateUserNameAndEmail (suser.UserName, suser.Email, ref isUserNameOk, ref isEmailOk, Guid.Empty); if (!isUserNameOk) throw new MembershipException ("Username are not unique."); if (!isEmailOk) throw new MembershipException ("Email are not unique."); suser.Email = user.Email; suser.LastActivityDate = user.LastActivityDate; suser.LastLoginDate = user.LastLoginDate; suser.Comment = user.Comment; suser.IsApproved = user.IsApproved; session.SaveChanges (); } } catch { throw; } }
/// <summary> /// Adds a new membership user to the data source. /// </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 e-mail address for the new user.</param> /// <param name="passwordQuestion">The password question for the new user.</param> /// <param name="passwordAnswer">The password answer for the new user</param> /// <param name="isApproved">Whether or not the new user is approved to be validated.</param> /// <param name="providerUserKey">The unique identifier from the membership data source for the user.</param> /// <param name="status">A <see cref="T:System.Web.Security.MembershipCreateStatus"></see> enumeration value indicating whether the user was created successfully.</param> /// <returns> /// A <see cref="T:System.Web.Security.MembershipUser"></see> object populated with the information for the newly created user. /// </returns> public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, Guid providerUserKey, out MembershipCreateStatus status) { try { using (var session = DocumentStore.OpenSession()) { bool isUserNameOk = true; bool isEmailOk = true; ValidateUserNameAndEmail (username, email, ref isUserNameOk, ref isEmailOk, Guid.Empty); // Validate the username if (!isUserNameOk) { status = MembershipCreateStatus.InvalidUserName; return null; } // Validate the email if (!isEmailOk) { status = MembershipCreateStatus.InvalidEmail; return null; } // Raise the event before validating the password OnValidatingPassword ( new ValidatePasswordEventArgs ( username, password, true) ); // Validate the password if (!ValidatePassword (password)) { status = MembershipCreateStatus.InvalidPassword; return null; } // Everything is valid, create the user var user = new MembershipUser (username, providerUserKey, email, passwordQuestion, "", isApproved, false, DateTime.Today, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue); var secInfo = new UserSecurityInfo (); var salt = ""; secInfo.Password = TransformPassword (password, ref salt); secInfo.PasswordSalt = salt; secInfo.PasswordAnswer = passwordAnswer; secInfo.PasswordVerificationToken = new Guid ().ToString (); secInfo.UserName = username; session.Store (user); session.Store (secInfo); status = MembershipCreateStatus.Success; return CreateMembershipFromInternalUser (user); } } catch { throw; } }
/// <summary> /// Creates the account. /// </summary> /// <returns> /// A token that can be sent to the user to confirm the user account. /// </returns> /// <param name='userName'> /// The user name. /// </param> /// <param name='password'> /// The password. /// </param> /// <param name='requireConfirmationToken'> /// (Optional) true to specify that the user account must be confirmed; otherwise, false. The default is false. /// </param> public override string CreateAccount(string userName, string password, bool requireConfirmationToken = false) { try { using (var session = DocumentStore.OpenSession()) { bool isUserNameOk = true; bool isEmailOk = true; ValidateUserNameAndEmail (userName, "", ref isUserNameOk, ref isEmailOk, Guid.Empty); // Validate the username if (!isUserNameOk) { throw new MembershipException (string.Format ("The username {0} already exists.", userName)); } // Validate the password if (!ValidatePassword (password)) { throw new MembershipException ("The password is not valid."); } // Everything is valid, create the user var user = new MembershipUser (userName, Guid.NewGuid (), "", "", "", true, false, DateTime.Today, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue); var secInfo = new UserSecurityInfo (); var salt = ""; secInfo.Password = TransformPassword (password, ref salt); secInfo.PasswordSalt = salt; secInfo.PasswordAnswer = ""; secInfo.PasswordVerificationToken = requireConfirmationToken == false ? "" : Guid.NewGuid ().ToString (); secInfo.UserName = userName; session.Store (user); session.Store (secInfo); return secInfo.PasswordVerificationToken; } } catch { throw; } }
/// <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> /// true if the password was updated successfully; otherwise, false. /// </returns> public override bool ChangePassword(string username, string oldPassword, string newPassword) { using (var session = DocumentStore.OpenSession()) { var secInfo = session.Query<UserSecurityInfo> ().Where (x => x.UserName == username).FirstOrDefault (); if (secInfo == null) throw new MembershipException ("User does not exist."); if (ValidateUserInternal (secInfo, oldPassword)) { var args = new ValidatePasswordEventArgs (username, newPassword, false); OnValidatingPassword (args); if (args.Cancel) { if (args.FailureInformation != null) throw args.FailureInformation; else throw new MembershipException ("Change password canceled due to new password validation failure."); } if (!ValidatePassword (newPassword)) throw new ArgumentException ("Password does not meet password strength requirements."); /// string salt = ""; secInfo.Password = TransformPassword (newPassword, ref salt); secInfo.PasswordSalt = salt; var user = session.Query<MembershipUser> ().Where (x => x.UserName == username).FirstOrDefault (); var md = new MembershipUser (user.UserName, user.ProviderUserKey, user.Email, user.PasswordQuestion, user.Comment, user.IsApproved, user.IsLockedOut, user.CreationDate, user.LastLoginDate, user.LastActivityDate, DateTime.Now, user.LastLockoutDate); session.Store (md, md.UserName); session.SaveChanges (); return true; } return false; } }
void UpdateSelf(MembershipUser fromUser) { try { Comment = fromUser.Comment; } catch (NotSupportedException) { } try { CreationDate = fromUser.CreationDate; } catch (NotSupportedException) { } try { Email = fromUser.Email; } catch (NotSupportedException) { } try { IsApproved = fromUser.IsApproved; } catch (NotSupportedException) { } try { IsLockedOut = fromUser.IsLockedOut; } catch (NotSupportedException) { } try { LastActivityDate = fromUser.LastActivityDate; } catch (NotSupportedException) { } try { LastLockoutDate = fromUser.LastLockoutDate; } catch (NotSupportedException) { } try { LastLoginDate = fromUser.LastLoginDate; } catch (NotSupportedException) { } try { LastPasswordChangedDate = fromUser.LastPasswordChangedDate; } catch (NotSupportedException) { } try { PasswordQuestion = fromUser.PasswordQuestion; } catch (NotSupportedException) { } try { ProviderUserKey = fromUser.ProviderUserKey; } catch (NotSupportedException) { } }