session
This commit is contained in:
parent
baea64229b
commit
0dc41337da
36 changed files with 324 additions and 95 deletions
60
Femto.Modules.Auth/Models/UserIdentity.cs
Normal file
60
Femto.Modules.Auth/Models/UserIdentity.cs
Normal file
|
@ -0,0 +1,60 @@
|
|||
using System.Text;
|
||||
using System.Text.Unicode;
|
||||
using Femto.Common.Domain;
|
||||
using Femto.Modules.Auth.Models.Events;
|
||||
using Geralt;
|
||||
|
||||
namespace Femto.Modules.Auth.Models;
|
||||
|
||||
internal class UserIdentity : Entity
|
||||
{
|
||||
public Guid Id { get; private set; }
|
||||
|
||||
public string Username { get; private set; }
|
||||
|
||||
public UserPassword Password { get; private set; }
|
||||
|
||||
public ICollection<UserSession> Sessions { get; private set; }
|
||||
|
||||
private UserIdentity() { }
|
||||
|
||||
public UserIdentity(string username)
|
||||
{
|
||||
this.Id = Guid.CreateVersion7();
|
||||
this.Username = username;
|
||||
|
||||
this.AddDomainEvent(new UserWasCreatedEvent(this));
|
||||
}
|
||||
|
||||
public UserIdentity WithPassword(string password)
|
||||
{
|
||||
this.SetPassword(password);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void SetPassword(string password)
|
||||
{
|
||||
this.Password = new UserPassword(password);
|
||||
}
|
||||
|
||||
public bool HasPassword(string requestPassword)
|
||||
{
|
||||
if (this.Password is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.Password.Check(requestPassword);
|
||||
}
|
||||
|
||||
public UserSession StartNewSession()
|
||||
{
|
||||
var session = UserSession.Create();
|
||||
|
||||
this.Sessions.Add(session);
|
||||
|
||||
return session;
|
||||
}
|
||||
}
|
||||
|
||||
public class SetPasswordError(string message, Exception inner) : DomainException(message, inner);
|
Loading…
Add table
Add a link
Reference in a new issue