Пример #1
0
    public void PrepareRegistrationChallenge(Guid correlationId, string emailOrPhone, ContactChallengePurpose purpose) {
      if (ContactChallenges.ContainsKey(correlationId))
        throw new CommandRejectedException(nameof(correlationId), correlationId, CommandRejectionReason.AlreadyApplied,
          $"Contact challenge for correlationId '{correlationId}' has already been prepared.");

      string stamp = Guid.NewGuid().ToString();
      string code = ContactChallengers.TotpCodeProvider.Generate(Id, emailOrPhone, purpose, stamp);
      string token = ContactChallengers.DataProtectionTokenProvider.Generate(Id, purpose, stamp);
      var assembly = Assembly.GetExecutingAssembly();
      string message = assembly.GetManifestResourceText(assembly.GetManifestResourceName($"{purpose}.Message.txt")).Replace("{Code}", code);
      ContactChallengePrepared eventToRaise;
      switch (purpose) {

        case ContactChallengePurpose.CreateUserFromEmail:
          string subject = assembly.GetManifestResourceText(assembly.GetManifestResourceName($"{purpose}.Subject.txt"));
          eventToRaise = new ContactEmailChallengePrepared(Id, DateTime.UtcNow, correlationId,
            emailOrPhone, purpose, stamp, token, subject, message);
          break;

        case ContactChallengePurpose.CreateUserFromPhone:
          var phoneNumber = ContactIdParser.AsPhoneNumber(emailOrPhone);
          eventToRaise = new ContactSmsChallengePrepared(Id, DateTime.UtcNow, correlationId,
            phoneNumber.NationalNumber, ContactIdParser.DefaultRegionCode, emailOrPhone, purpose, stamp, token, message);
          break;

        default:
          throw new CommandRejectedException(nameof(emailOrPhone), emailOrPhone, CommandRejectionReason.Unknown);
      }

      RaiseEvent(eventToRaise);
    }
 public UserDocumentContactSmsChallenge(ContactSmsChallengePrepared message)
   : base(message) {
   PhoneNumber = message.PhoneNumber;
   RegionCode = message.RegionCode;
   Message = message.Message;
 }
Пример #3
0
 private void Apply(ContactSmsChallengePrepared e) {
   var challenge = new ContactSmsChallenge(e);
   ContactChallenges[e.CorrelationId] = challenge;
 }
Пример #4
0
 internal ContactSmsChallenge(ContactSmsChallengePrepared e) : base(e) {
   PhoneNumber = ContactIdParser.AsPhoneNumber(e.PhoneNumber, e.RegionCode);
   UnformattedPhone = e.UnformattedPhone;
 }