상속: IDisposable
    public RedeemUserRegistrationChallenge(Guid userId, Guid correlationId, string token,
      string emailOrPhone, Guid? userIdByContact, string username, Guid? userIdByUsername,
      string password, string passwordConfirmation) {

      using (var validate = new CommandValidator()) {
        validate.NotEmpty(userId, nameof(userId));
        validate.NotEmpty(correlationId, nameof(correlationId));
        validate.NotEmpty(token, nameof(token));

        validate.IsAvailable(emailOrPhone, nameof(emailOrPhone), () => !userIdByContact.HasValue);
        validate.AddErrors(new ValidateUsername(username, userIdByUsername).Errors);

        validate.NotEmpty(password, nameof(password));
        validate.NotEmpty(passwordConfirmation, nameof(passwordConfirmation));
        if (!validate.HasError(nameof(password), CommandRejectionReason.Empty)
          && !validate.HasError(nameof(passwordConfirmation), CommandRejectionReason.Empty)) {
          validate.AreEqual(password, nameof(password), passwordConfirmation);
        }
      }

      UserId = userId;
      CorrelationId = correlationId;
      Token = token;
      Username = username;
      Password = password;
    }
예제 #2
0
    public VerifyUserLogin(Guid userId, string login, string password) {
      PreValidate(login, password);
      using (var validate = new CommandValidator()) {
        validate.NotEmpty(userId, nameof(userId));
      }

      UserId = userId;
      Login = login?.Trim();
      Password = password;
    }
    public VerifyUserContactChallengeResponse(Guid userId, Guid correlationId, string code) {
      code = code?.Trim();
      using (var validate = new CommandValidator()) {
        validate.NotEmpty(userId, nameof(userId));
        validate.NotEmpty(correlationId, nameof(correlationId));
        validate.NotEmpty(code, nameof(code));
      }

      UserId = userId;
      CorrelationId = correlationId;
      Code = code?.Trim();
    }
예제 #4
0
 public ValidateUsername(string username, Guid? userIdByLogin) {
   using (var validate = new CommandValidator(throwIfErrorsOnDispose: false)) {
     validate.NotEmpty(username, nameof(username));
     if (!validate.HasError(nameof(username), CommandRejectionReason.Empty)) {
       validate.IsAvailable(username, nameof(username), () => !userIdByLogin.HasValue);
       if (!validate.HasError(nameof(username), CommandRejectionReason.AlreadyExists)) {
         validate.OnlyCharacters(username, nameof(username), AllowedCharacters);
         if (!validate.HasError(nameof(username), CommandRejectionReason.InvalidFormat)) {
           validate.Length(username, nameof(username), MinLength, MaxLength);
         }
         validate.NotPhoneNumber(username, nameof(username));
       }
     }
     Errors = validate.Errors;
   }
 }
    public PrepareUserRegistrationChallenge(Guid correlationId, string emailOrPhone, Guid? userIdByEmailOrPhone, IPrincipal principal) {
      emailOrPhone = emailOrPhone?.Trim();
      using (var validate = new CommandValidator()) {
        validate.NotEmpty(correlationId, nameof(correlationId));
        validate.NotEmpty(emailOrPhone, nameof(emailOrPhone));
        validate.EmailOrPhone(emailOrPhone, nameof(emailOrPhone));
        if (!validate.HasError(nameof(emailOrPhone), CommandRejectionReason.InvalidFormat))
          validate.IsAvailable(emailOrPhone, nameof(emailOrPhone), () => !userIdByEmailOrPhone.HasValue);
        validate.LoggedOff(principal?.Identity, nameof(principal));
      }

      CorrelationId = correlationId;
      EmailOrPhone = emailOrPhone;
      bool isPhone = ContactIdParser.AsPhoneNumber(emailOrPhone) != null;
      bool isEmail = !isPhone && ContactIdParser.AsMailAddress(emailOrPhone) != null;
      if (isEmail) Purpose = ContactChallengePurpose.CreateUserFromEmail;
      else if (isPhone) Purpose = ContactChallengePurpose.CreateUserFromPhone;
      else throw new CommandRejectedException(nameof(emailOrPhone), emailOrPhone, CommandRejectionReason.InvalidFormat);
    }
예제 #6
0
 public static void PreValidate(string login, string password) {
   using (var validate = new CommandValidator()) {
     validate.NotEmpty(login, nameof(login));
     validate.NotEmpty(password, nameof(password));
   }
 }