private MembershipUser UserToMembershipUser(User user) { var nullDate = new DateTime(1900, 1, 1, 0, 0, 0); return new MembershipUser( Membership.Provider.Name, user.Username, user.Id, user.Email, user.PasswordQuestion, user.Comment, user.IsApproved, user.IsLockedOut, user.CreationDate, user.LastLoginDate.HasValue ? user.LastLoginDate.Value : nullDate, user.LastActivityDate, user.LastPasswordChangedDate.HasValue ? user.LastPasswordChangedDate.Value : nullDate, user.LastLockedOutDate.HasValue ? user.LastLockedOutDate.Value : nullDate ); }
public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status) { var args = new ValidatePasswordEventArgs(username, password, true); OnValidatingPassword(args); if (args.Cancel) { throw new MembershipCreateUserException(MembershipCreateStatus.InvalidPassword); } if (RequiresUniqueEmail && GetUserNameByEmail(email) != string.Empty) { throw new MembershipCreateUserException(MembershipCreateStatus.DuplicateEmail); } var existingUser = GetUser(username, false); if (existingUser != null) { throw new MembershipCreateUserException(MembershipCreateStatus.DuplicateUserName); } var salt = GenerateSalt(); var newUser = new User { ApplicationName = this.ApplicationName, Username = username, PasswordSalt = salt, PasswordHash = EncodePassword(password, salt), Email = email, PasswordQuestion = passwordQuestion, PasswordAnswer = passwordAnswer == null ? string.Empty : EncodePassword(passwordAnswer, salt), IsApproved = isApproved, Comment = string.Empty, CreationDate = DateTime.UtcNow, LastActivityDate = DateTime.UtcNow }; using (var session = _documentStore.OpenSession()) { session.Advanced.UseOptimisticConcurrency = true; try { session.Store(newUser); session.SaveChanges(); } catch (Exception ex) { // TODO: handle store user exceptions throw new MembershipCreateUserException(MembershipCreateStatus.ProviderError); } } status = MembershipCreateStatus.Success; return GetUser(username, false); }