add create signup code
This commit is contained in:
parent
161dcf7cab
commit
fbc6f562e3
9 changed files with 105 additions and 2 deletions
41
Femto.Modules.Auth/Models/SignupCode.cs
Normal file
41
Femto.Modules.Auth/Models/SignupCode.cs
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue