create role for new users
This commit is contained in:
parent
34aee3a168
commit
22e838849f
2 changed files with 15 additions and 5 deletions
|
@ -1,6 +1,7 @@
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Unicode;
|
using System.Text.Unicode;
|
||||||
using Femto.Common.Domain;
|
using Femto.Common.Domain;
|
||||||
|
using Femto.Modules.Auth.Contracts;
|
||||||
using Femto.Modules.Auth.Models.Events;
|
using Femto.Modules.Auth.Models.Events;
|
||||||
using Geralt;
|
using Geralt;
|
||||||
|
|
||||||
|
@ -15,7 +16,7 @@ internal class UserIdentity : Entity
|
||||||
public Password? Password { get; private set; }
|
public Password? Password { get; private set; }
|
||||||
|
|
||||||
public ICollection<UserSession> Sessions { get; private set; } = [];
|
public ICollection<UserSession> Sessions { get; private set; } = [];
|
||||||
|
|
||||||
public ICollection<UserRole> Roles { get; private set; } = [];
|
public ICollection<UserRole> Roles { get; private set; } = [];
|
||||||
|
|
||||||
private UserIdentity() { }
|
private UserIdentity() { }
|
||||||
|
@ -25,6 +26,8 @@ internal class UserIdentity : Entity
|
||||||
this.Id = Guid.CreateVersion7();
|
this.Id = Guid.CreateVersion7();
|
||||||
this.Username = username;
|
this.Username = username;
|
||||||
|
|
||||||
|
this.Roles = [new UserRole(Role.User)];
|
||||||
|
|
||||||
this.AddDomainEvent(new UserWasCreatedEvent(this));
|
this.AddDomainEvent(new UserWasCreatedEvent(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,24 +48,24 @@ internal class UserIdentity : Entity
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.Password.Check(requestPassword);
|
return this.Password.Check(requestPassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserSession PossiblyRefreshSession(string sessionId)
|
public UserSession PossiblyRefreshSession(string sessionId)
|
||||||
{
|
{
|
||||||
var session = this.Sessions.Single(s => s.Id == sessionId);
|
var session = this.Sessions.Single(s => s.Id == sessionId);
|
||||||
|
|
||||||
if (session.ExpiresSoon)
|
if (session.ExpiresSoon)
|
||||||
return this.StartNewSession();
|
return this.StartNewSession();
|
||||||
|
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserSession StartNewSession()
|
public UserSession StartNewSession()
|
||||||
{
|
{
|
||||||
var session = UserSession.Create();
|
var session = UserSession.Create();
|
||||||
|
|
||||||
this.Sessions.Add(session);
|
this.Sessions.Add(session);
|
||||||
|
|
||||||
return session;
|
return session;
|
||||||
|
|
|
@ -7,4 +7,11 @@ internal class UserRole
|
||||||
public Guid UserId { get; set; }
|
public Guid UserId { get; set; }
|
||||||
|
|
||||||
public Role Role { get; set; }
|
public Role Role { get; set; }
|
||||||
|
|
||||||
|
private UserRole() {}
|
||||||
|
|
||||||
|
public UserRole( Role role){
|
||||||
|
Role = role;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue