v1.0.6.0
Refresh Online Session with profile region and sports.
This commit is contained in:
@@ -14,7 +14,7 @@ using Newtonsoft.Json.Converters;
|
||||
namespace Saxonite.Net.Standard.Base.App
|
||||
{
|
||||
//=======================================================================
|
||||
public class SaxSessionData
|
||||
public abstract class SaxSessionData
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Protected construction.
|
||||
@@ -28,7 +28,7 @@ namespace Saxonite.Net.Standard.Base.App
|
||||
private SaxSessionData(SaxSessionContext sessionContext)
|
||||
{
|
||||
SessionContext = sessionContext;
|
||||
User = new UserData(SessionContext, null, null);
|
||||
userData = CreateUserData(SessionContext, null, null);
|
||||
}
|
||||
/// <summary>
|
||||
/// Primary constructor - on user login.
|
||||
@@ -38,7 +38,7 @@ namespace Saxonite.Net.Standard.Base.App
|
||||
protected SaxSessionData(SaxSessionContext sessionContext, SaxUserAccount userAccount, List<SaxUserRole> userRoles)
|
||||
{
|
||||
SessionContext = sessionContext;
|
||||
User = new UserData(SessionContext, userAccount, userRoles);
|
||||
userData = CreateUserData(SessionContext, userAccount, userRoles);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
@@ -60,17 +60,12 @@ namespace Saxonite.Net.Standard.Base.App
|
||||
public class UserData
|
||||
{
|
||||
protected UserData() { }
|
||||
public UserData(SaxSessionContext sessionContext, SaxUserAccount userAccount, List<SaxUserRole> userRoles)
|
||||
protected UserData(SaxSessionContext sessionContext, SaxUserAccount userAccount, List<SaxUserRole> userRoles)
|
||||
{
|
||||
if (userAccount != null)
|
||||
{
|
||||
UserAccountId = userAccount.Id;
|
||||
FirstName = userAccount.FirstName;
|
||||
LastName = userAccount.LastName;
|
||||
DisplayName = userAccount.GetDisplayName();
|
||||
EmailAddress = userAccount.EmailAddress;
|
||||
RegionIdCountry = userAccount.RegionIdCountry;
|
||||
RegionIdProvince = userAccount.RegionIdProvince;
|
||||
RefreshUserData(userAccount);
|
||||
if (sessionContext.Application == Sax.Application.Admin)
|
||||
KeepLoggedIn = userAccount.KeepLoggedIn_Admin;
|
||||
else if (sessionContext.Application == Sax.Application.Online)
|
||||
@@ -84,7 +79,22 @@ namespace Saxonite.Net.Standard.Base.App
|
||||
}
|
||||
}
|
||||
}
|
||||
protected UserData(UserData userData)
|
||||
{
|
||||
UserAccountId = userData.UserAccountId;
|
||||
Title = userData.Title;
|
||||
FirstName = userData.FirstName;
|
||||
LastName = userData.LastName;
|
||||
DisplayName = userData.DisplayName;
|
||||
EmailAddress = userData.EmailAddress;
|
||||
RegionIdCountry = userData.RegionIdCountry;
|
||||
RegionIdProvince = userData.RegionIdProvince;
|
||||
KeepLoggedIn = userData.KeepLoggedIn;
|
||||
roles.AddRange(userData.Roles);
|
||||
}
|
||||
// Properties.
|
||||
public SysId UserAccountId { get; protected set; }
|
||||
public String Title { get; protected set; }
|
||||
public String FirstName { get; protected set; }
|
||||
public String LastName { get; protected set; }
|
||||
public String DisplayName { get; protected set; }
|
||||
@@ -93,6 +103,21 @@ namespace Saxonite.Net.Standard.Base.App
|
||||
public SysId RegionIdProvince { get; protected set; }
|
||||
public bool KeepLoggedIn { get; protected set; }
|
||||
public bool UserAccountSupplied { get; protected set; }
|
||||
// Refresh properties.
|
||||
protected bool RefreshUserData(SaxUserAccount userAccount)
|
||||
{
|
||||
// Check that user matches the session.
|
||||
if (!SysId.IsValid(UserAccountId) || !SysId.IsValid(userAccount?.Id ?? null) || !UserAccountId.Equals(userAccount.Id)) return false;
|
||||
// Refresh properties.
|
||||
Title = userAccount.Title;
|
||||
FirstName = userAccount.FirstName;
|
||||
LastName = userAccount.LastName;
|
||||
DisplayName = userAccount.GetDisplayName();
|
||||
EmailAddress = userAccount.EmailAddress;
|
||||
RegionIdCountry = userAccount.RegionIdCountry;
|
||||
RegionIdProvince = userAccount.RegionIdProvince;
|
||||
return true;
|
||||
}
|
||||
// Roles.
|
||||
public class RoleData
|
||||
{
|
||||
@@ -107,19 +132,20 @@ namespace Saxonite.Net.Standard.Base.App
|
||||
public Sax.UserRole Role { get; protected set; }
|
||||
public SaStatus Status { get; protected set; }
|
||||
}
|
||||
[JsonIgnore]
|
||||
private readonly List<RoleData> roles = new List<RoleData>();
|
||||
public List<RoleData> Roles { get { return new List<RoleData>(roles); } protected set { roles.Clear(); roles.AddRange(value); } }
|
||||
[JsonIgnore]
|
||||
public bool IsJournalist { get { return roles?.Exists(item => item.Role == Sax.UserRole.Journalist) ?? false; } }
|
||||
}
|
||||
public UserData User { get; private set; }
|
||||
protected abstract UserData CreateUserData(SaxSessionContext sessionContext, SaxUserAccount userAccount, List<SaxUserRole> userRoles);
|
||||
private UserData userData;
|
||||
public UserData User { get { return userData; } }
|
||||
/// <summary>User - JSON deserialisation route.</summary>
|
||||
protected void SetUser(UserData user)
|
||||
{
|
||||
if (User != null && User.UserAccountSupplied)
|
||||
if (this.userData != null && User.UserAccountSupplied)
|
||||
throw new NotSupportedException("Session User cannot be replaced.");
|
||||
User = user;
|
||||
this.userData = user;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user