add create signup code

This commit is contained in:
john 2025-05-18 19:11:43 +02:00
parent 161dcf7cab
commit fbc6f562e3
9 changed files with 105 additions and 2 deletions

View file

@ -0,0 +1,41 @@
using Femto.Common.Domain;
namespace Femto.Modules.Auth.Models;
public class SignupCode
{
private static readonly TimeSpan ExpiryTime = TimeSpan.FromDays(14);
public string Code { get; private set; }
/// <summary>
/// The email of the intended recipient
/// </summary>
public string RecipientEmail { get; private set; }
/// <summary>
/// The name of the intended recipient
/// </summary>
public string RecipientName { get; private set; }
public DateTimeOffset CreatedAt { get; private set; }
public DateTimeOffset? ExpiresAt { get; private set; }
public Guid? RedeemingUserId { get; private set; }
private SignupCode() { }
public SignupCode(string recipientEmail, string recipientName, string code)
{
this.Code = code;
this.RecipientEmail = recipientEmail;
this.RecipientName = recipientName;
this.CreatedAt = DateTimeOffset.UtcNow;
this.ExpiresAt = this.CreatedAt + ExpiryTime;
}
public void Redeem(Guid userGuid)
{
if (this.RedeemingUserId is not null)
throw new DomainError("invalid signup code");
this.RedeemingUserId = userGuid;
}
}