This commit is contained in:
john 2025-05-16 16:10:01 +02:00
parent 14fd359ea8
commit a4ef2b4a20
26 changed files with 331 additions and 78 deletions

View file

@ -12,7 +12,7 @@ internal class UserIdentity : Entity
public string Username { get; private set; }
public UserPassword Password { get; private set; }
public Password? Password { get; private set; }
public ICollection<UserSession> Sessions { get; private set; } = [];
@ -34,7 +34,7 @@ internal class UserIdentity : Entity
public void SetPassword(string password)
{
this.Password = new UserPassword(password);
this.Password = new Password(password);
}
public bool HasPassword(string requestPassword)
@ -47,6 +47,16 @@ internal class UserIdentity : Entity
return this.Password.Check(requestPassword);
}
public UserSession PossiblyRefreshSession(string sessionId)
{
var session = this.Sessions.Single(s => s.Id == sessionId);
if (session.ExpiresSoon)
return this.StartNewSession();
return session;
}
public UserSession StartNewSession()
{
var session = UserSession.Create();