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); }
private void Apply(ContactEmailChallengePrepared e) { var challenge = new ContactEmailChallenge(e); ContactChallenges[e.CorrelationId] = challenge; }
internal ContactEmailChallenge(ContactEmailChallengePrepared e) : base(e) { MailAddress = new MailAddress(e.EmailAddress); }
public UserDocumentContactEmailChallenge(ContactEmailChallengePrepared message) : base(message) { EmailAddress = message.EmailAddress; MessageSubject = message.MessageSubject; MessageBody = message.MessageBody; }