/// <summary> /// Создание нового объекта User. /// </summary> /// <param name="id">Исходное значение свойства ID.</param> /// <param name="username">Исходное значение свойства Username.</param> /// <param name="email">Исходное значение свойства Email.</param> /// <param name="comment">Исходное значение свойства Comment.</param> /// <param name="password">Исходное значение свойства Password.</param> /// <param name="isApproved">Исходное значение свойства IsApproved.</param> /// <param name="lastActivityDate">Исходное значение свойства LastActivityDate.</param> /// <param name="lastLoginDate">Исходное значение свойства LastLoginDate.</param> /// <param name="lastPasswordChangedDate">Исходное значение свойства LastPasswordChangedDate.</param> /// <param name="creationDate">Исходное значение свойства CreationDate.</param> /// <param name="isLockedOut">Исходное значение свойства IsLockedOut.</param> /// <param name="lastLockedOutDate">Исходное значение свойства LastLockedOutDate.</param> /// <param name="failedPasswordAttemptCount">Исходное значение свойства FailedPasswordAttemptCount.</param> /// <param name="failedPasswordAttemptWindowStart">Исходное значение свойства FailedPasswordAttemptWindowStart.</param> /// <param name="failedPasswordAnswerAttemptCount">Исходное значение свойства FailedPasswordAnswerAttemptCount.</param> /// <param name="failedPasswordAnswerAttemptWindowStart">Исходное значение свойства FailedPasswordAnswerAttemptWindowStart.</param> /// <param name="isDeleted">Исходное значение свойства IsDeleted.</param> public static User CreateUser(global::System.Int32 id, global::System.String username, global::System.String email, global::System.String comment, global::System.String password, global::System.Boolean isApproved, global::System.DateTime lastActivityDate, global::System.DateTime lastLoginDate, global::System.DateTime lastPasswordChangedDate, global::System.DateTime creationDate, global::System.Boolean isLockedOut, global::System.DateTime lastLockedOutDate, global::System.Int32 failedPasswordAttemptCount, global::System.DateTime failedPasswordAttemptWindowStart, global::System.Int32 failedPasswordAnswerAttemptCount, global::System.DateTime failedPasswordAnswerAttemptWindowStart, global::System.Boolean isDeleted) { User user = new User(); user.ID = id; user.Username = username; user.Email = email; user.Comment = comment; user.Password = password; user.IsApproved = isApproved; user.LastActivityDate = lastActivityDate; user.LastLoginDate = lastLoginDate; user.LastPasswordChangedDate = lastPasswordChangedDate; user.CreationDate = creationDate; user.IsLockedOut = isLockedOut; user.LastLockedOutDate = lastLockedOutDate; user.FailedPasswordAttemptCount = failedPasswordAttemptCount; user.FailedPasswordAttemptWindowStart = failedPasswordAttemptWindowStart; user.FailedPasswordAnswerAttemptCount = failedPasswordAnswerAttemptCount; user.FailedPasswordAnswerAttemptWindowStart = failedPasswordAnswerAttemptWindowStart; user.IsDeleted = isDeleted; return user; }
/// <summary> /// Устаревший метод для добавления новых объектов в набор EntitySet Users. Взамен можно использовать метод .Add связанного свойства ObjectSet<T>. /// </summary> public void AddToUsers(User user) { base.AddObject("Users", user); }
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) { status = MembershipCreateStatus.InvalidPassword; return null; } if (RequiresUniqueEmail && !string.IsNullOrWhiteSpace(GetUserNameByEmail(email))) { status = MembershipCreateStatus.DuplicateEmail; return null; } var u = GetUser(username, false); if (u == null) { var createDate = DateTime.Now; if (providerUserKey != null) { if (!(providerUserKey is Guid)) { status = MembershipCreateStatus.InvalidProviderUserKey; return null; } } try { var user = new User { Username = username, Password = this.EncodePassword(password), Email = email, PasswordQuestion = passwordQuestion, PasswordAnswer = this.EncodePassword(passwordAnswer), IsApproved = isApproved }; _dataBase.Users.Add(user); var recAdded = _dataBase.SaveChanges(); status = recAdded > 0 ? MembershipCreateStatus.Success : MembershipCreateStatus.UserRejected; } catch (Exception e) { if (WriteExceptionsToEventLog) { WriteToEventLog(e, "CreateUser"); } status = MembershipCreateStatus.ProviderError; } return GetUser(username, false); } status = MembershipCreateStatus.DuplicateUserName; return null; }
private MembershipUser ConverDataBaseUserToMemberShipUser(User user) { var msUser = new MembershipUser( base.Name, user.Username, user.ID, user.Email, user.PasswordQuestion, null, true, false, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now); // TODO: тут идут требования к полям стандартного мембершип провайдера, захардкодим стандартные значения return msUser; }
private MembershipUser ConverDataBaseUserToMemberShipUser(User user) { var msUser = new MembershipUser( base.Name, user.Username, user.ID, user.Email, user.PasswordQuestion, user.Comment, user.IsApproved, user.IsLockedOut, user.CreationDate, user.LastLoginDate, user.LastActivityDate, user.LastPasswordChangedDate, user.LastLockedOutDate); return msUser; }