Implemented new permission and identity system

This commit is contained in:
Marcel Baumgartner
2023-07-17 00:48:27 +02:00
parent 74d4ee729d
commit 0a86aa8aa4
86 changed files with 2372 additions and 2107 deletions

View File

@@ -24,7 +24,7 @@ public class BillingController : Controller
[HttpGet("cancel")] [HttpGet("cancel")]
public async Task<ActionResult> Cancel() public async Task<ActionResult> Cancel()
{ {
var user = await IdentityService.Get(); var user = IdentityService.User;
if (user == null) if (user == null)
return Redirect("/login"); return Redirect("/login");
@@ -35,7 +35,7 @@ public class BillingController : Controller
[HttpGet("success")] [HttpGet("success")]
public async Task<ActionResult> Success() public async Task<ActionResult> Success()
{ {
var user = await IdentityService.Get(); var user = IdentityService.User;
if (user == null) if (user == null)
return Redirect("/login"); return Redirect("/login");

View File

@@ -25,7 +25,7 @@ public class RegisterController : Controller
[HttpGet] [HttpGet]
public async Task<ActionResult<TokenRegister>> Register() public async Task<ActionResult<TokenRegister>> Register()
{ {
var user = await IdentityService.Get(); var user = IdentityService.User;
if (user == null) if (user == null)
return NotFound(); return NotFound();

View File

@@ -54,7 +54,7 @@ public class OAuth2Controller : Controller
{ {
try try
{ {
var currentUser = await IdentityService.Get(); var currentUser = IdentityService.User;
if (currentUser != null) if (currentUser != null)
{ {

View File

@@ -5,106 +5,379 @@ public static class Permissions
public static Permission AdminDashboard = new() public static Permission AdminDashboard = new()
{ {
Index = 0, Index = 0,
Name = "Admin dashboard", Name = "Admin Dashboard",
Description = "See basic information about growth and status of the moonlight instance" Description = "Access the main admin dashboard page"
}; };
public static Permission SystemDashboard = new() public static Permission AdminStatistics = new()
{ {
Index = 1, Index = 1,
Name = "System information", Name = "Admin Statistics",
Description = "See information about the moonlight instance like the uptime and memory usage" Description = "View statistical information about the moonlight instance"
}; };
public static Permission SystemSentry = new() public static Permission AdminDomains = new()
{
Index = 2,
Name = "Settings for Sentry",
Description = "See information about the sentry status"
};
public static Permission SystemMalware = new()
{
Index = 3,
Name = "Server malware scanner",
Description = "Scan running servers for malware"
};
public static Permission SystemSecurity = new()
{ {
Index = 4, Index = 4,
Name = "System security settings", Name = "Admin Domains",
Description = "Ban ip addresses and view the security logs" Description = "Manage domains in the admin area"
}; };
public static Permission SystemResources = new() public static Permission AdminNewDomain = new()
{ {
Index = 5, Index = 5,
Name = "Resources", Name = "Admin New Domain",
Description = "Read and write moonlight resources like configuration files" Description = "Create a new domain in the admin area"
}; };
public static Permission DiscordBot = new() public static Permission AdminSharedDomains = new()
{ {
Index = 6, Index = 6,
Name = "Discord bot actions", Name = "Admin Shared Domains",
Description = "Setup and remote control the discord bot if enabled" Description = "Manage shared domains in the admin area"
}; };
public static Permission NewsMessages = new() public static Permission AdminNewSharedDomain = new()
{ {
Index = 7, Index = 7,
Name = "News messages", Name = "Admin New Shared Domain",
Description = "Edit, view and delete messages for the user dashboard" Description = "Create a new shared domain in the admin area"
}; };
public static Permission SystemConfiguration = new() public static Permission AdminNodeDdos = new()
{ {
Index = 8, Index = 8,
Name = "System configuration", Name = "Admin Node DDoS",
Description = "Modify the moonlight configuration though the visual editor" Description = "Manage DDoS protection for nodes in the admin area"
}; };
public static Permission SystemMail = new() public static Permission AdminNodeEdit = new()
{ {
Index = 9, Index = 9,
Name = "System mail settings", Name = "Admin Node Edit",
Description = "Modify the mail templates and send test mails" Description = "Edit node settings in the admin area"
}; };
public static Permission ServersOverview = new() public static Permission AdminNodes = new()
{ {
Index = 10, Index = 10,
Name = "Servers overview", Name = "Admin Node",
Description = "View all servers and their owners" Description = "Access the node management page in the admin area"
}; };
public static Permission ServerAdminEdit = new() public static Permission AdminNewNode = new()
{ {
Index = 11, Index = 11,
Name = "Edit servers", Name = "Admin New Node",
Description = "View all servers and their owners" Description = "Create a new node in the admin area"
}; };
public static Permission ServerManager = new() public static Permission AdminNodeSetup = new()
{ {
Index = 12, Index = 12,
Name = "Server manager", Name = "Admin Node Setup",
Description = "View all servers are currently running and stop/kill all running servers" Description = "Set up a node in the admin area"
}; };
public static Permission ServerCleanup = new() public static Permission AdminNodeView = new()
{ {
Index = 13, Index = 13,
Name = "Server cleanup", Name = "Admin Node View",
Description = "View the stats about the cleanup system" Description = "View node details in the admin area"
}; };
public static Permission Nodes = new() public static Permission AdminNotificationDebugging = new()
{ {
Index = 14, Index = 14,
Name = "Nodes", Name = "Admin Notification Debugging",
Description = "View stats about the nodes" Description = "Manage debugging notifications in the admin area"
};
public static Permission AdminServerCleanup = new()
{
Index = 15,
Name = "Admin Server Cleanup",
Description = "Perform server cleanup tasks in the admin area"
};
public static Permission AdminServerEdit = new()
{
Index = 16,
Name = "Admin Server Edit",
Description = "Edit server settings in the admin area"
};
public static Permission AdminServers = new()
{
Index = 17,
Name = "Admin Server",
Description = "Access the server management page in the admin area"
};
public static Permission AdminServerManager = new()
{
Index = 18,
Name = "Admin Server Manager",
Description = "Manage servers in the admin area"
};
public static Permission AdminNewServer = new()
{
Index = 19,
Name = "Admin New Server",
Description = "Create a new server in the admin area"
};
public static Permission AdminServerImageEdit = new()
{
Index = 20,
Name = "Admin Server Image Edit",
Description = "Edit server image settings in the admin area"
};
public static Permission AdminServerImageIndex = new()
{
Index = 21,
Name = "Admin Server Image",
Description = "Access the server image management page in the admin area"
};
public static Permission AdminServerImageNew = new()
{
Index = 22,
Name = "Admin Server Image New",
Description = "Create a new server image in the admin area"
};
public static Permission AdminServerViewAllocations = new()
{
Index = 23,
Name = "Admin Server View Allocations",
Description = "View server allocations in the admin area"
};
public static Permission AdminServerViewArchive = new()
{
Index = 24,
Name = "Admin Server View Archive",
Description = "View server archive in the admin area"
};
public static Permission AdminServerViewDebug = new()
{
Index = 25,
Name = "Admin Server View Debug",
Description = "View server debugging information in the admin area"
};
public static Permission AdminServerViewImage = new()
{
Index = 26,
Name = "Admin Server View Image",
Description = "View server image details in the admin area"
};
public static Permission AdminServerViewIndex = new()
{
Index = 27,
Name = "Admin Server View",
Description = "Access the server view page in the admin area"
};
public static Permission AdminServerViewOverview = new()
{
Index = 28,
Name = "Admin Server View Overview",
Description = "View server overview in the admin area"
};
public static Permission AdminServerViewResources = new()
{
Index = 29,
Name = "Admin Server View Resources",
Description = "View server resources in the admin area"
};
public static Permission AdminSubscriptionEdit = new()
{
Index = 30,
Name = "Admin Subscription Edit",
Description = "Edit subscription settings in the admin area"
};
public static Permission AdminSubscriptions = new()
{
Index = 31,
Name = "Admin Subscriptions",
Description = "Access the subscription management page in the admin area"
};
public static Permission AdminNewSubscription = new()
{
Index = 32,
Name = "Admin New Subscription",
Description = "Create a new subscription in the admin area"
};
public static Permission AdminSupport = new()
{
Index = 33,
Name = "Admin Support",
Description = "Access the support page in the admin area"
};
public static Permission AdminSupportView = new()
{
Index = 34,
Name = "Admin Support View",
Description = "View support details in the admin area"
};
public static Permission AdminSysConfiguration = new()
{
Index = 35,
Name = "Admin system Configuration",
Description = "Access system configuration settings in the admin area"
};
public static Permission AdminSysDiscordBot = new()
{
Index = 36,
Name = "Admin system Discord Bot",
Description = "Manage Discord bot settings in the admin area"
};
public static Permission AdminSystem = new()
{
Index = 37,
Name = "Admin system",
Description = "Access the system management page in the admin area"
};
public static Permission AdminSysMail = new()
{
Index = 38,
Name = "Admin system Mail",
Description = "Manage mail settings in the admin area"
};
public static Permission AdminSysMalware = new()
{
Index = 39,
Name = "Admin system Malware",
Description = "Manage malware settings in the admin area"
};
public static Permission AdminSysResources = new()
{
Index = 40,
Name = "Admin system Resources",
Description = "View system resources in the admin area"
};
public static Permission AdminSysSecurity = new()
{
Index = 41,
Name = "Admin system Security",
Description = "Manage security settings in the admin area"
};
public static Permission AdminSysSentry = new()
{
Index = 42,
Name = "Admin system Sentry",
Description = "Manage Sentry settings in the admin area"
};
public static Permission AdminSysNewsEdit = new()
{
Index = 43,
Name = "Admin system News Edit",
Description = "Edit system news in the admin area"
};
public static Permission AdminSysNews = new()
{
Index = 44,
Name = "Admin system News",
Description = "Access the system news management page in the admin area"
};
public static Permission AdminSysNewsNew = new()
{
Index = 45,
Name = "Admin system News New",
Description = "Create new system news in the admin area"
};
public static Permission AdminUserEdit = new()
{
Index = 46,
Name = "Admin User Edit",
Description = "Edit user settings in the admin area"
};
public static Permission AdminUsers = new()
{
Index = 47,
Name = "Admin Users",
Description = "Access the user management page in the admin area"
};
public static Permission AdminNewUser = new()
{
Index = 48,
Name = "Admin New User",
Description = "Create a new user in the admin area"
};
public static Permission AdminUserSessions = new()
{
Index = 49,
Name = "Admin User Sessions",
Description = "View user sessions in the admin area"
};
public static Permission AdminUserView = new()
{
Index = 50,
Name = "Admin User View",
Description = "View user details in the admin area"
};
public static Permission AdminWebspaces = new()
{
Index = 51,
Name = "Admin Webspaces",
Description = "Access the webspaces management page in the admin area"
};
public static Permission AdminNewWebspace = new()
{
Index = 52,
Name = "Admin New Webspace",
Description = "Create a new webspace in the admin area"
};
public static Permission AdminWebspacesServerEdit = new()
{
Index = 53,
Name = "Admin Webspaces Server Edit",
Description = "Edit webspace server settings in the admin area"
};
public static Permission AdminWebspacesServers = new()
{
Index = 54,
Name = "Admin Webspaces Servers",
Description = "Access the webspace server management page in the admin area"
};
public static Permission AdminWebspacesServerNew = new()
{
Index = 55,
Name = "Admin Webspaces Server New",
Description = "Create a new webspace server in the admin area"
}; };
public static Permission? FromString(string name) public static Permission? FromString(string name)

View File

@@ -39,7 +39,7 @@ public class RatingService
if (!Enabled) if (!Enabled)
return false; return false;
var user = await IdentityService.Get(); var user = IdentityService.User;
if (user == null) if (user == null)
return false; return false;
@@ -62,7 +62,7 @@ public class RatingService
public async Task<bool> Rate(int rate) public async Task<bool> Rate(int rate)
{ {
var user = await IdentityService.Get(); var user = IdentityService.User;
// Double check states: // Double check states:

View File

@@ -5,7 +5,6 @@ using JWT.Exceptions;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Moonlight.App.Database.Entities; using Moonlight.App.Database.Entities;
using Moonlight.App.Helpers; using Moonlight.App.Helpers;
using Moonlight.App.Models.Misc;
using Moonlight.App.Perms; using Moonlight.App.Perms;
using Moonlight.App.Repositories; using Moonlight.App.Repositories;
using UAParser; using UAParser;
@@ -19,8 +18,9 @@ public class IdentityService
private readonly IHttpContextAccessor HttpContextAccessor; private readonly IHttpContextAccessor HttpContextAccessor;
private readonly string Secret; private readonly string Secret;
private User? UserCache; public User User { get; private set; }
public string Ip { get; private set; } = "N/A";
public string Device { get; private set; } = "N/A";
public PermissionStorage Permissions { get; private set; } public PermissionStorage Permissions { get; private set; }
public PermissionStorage UserPermissions { get; private set; } public PermissionStorage UserPermissions { get; private set; }
public PermissionStorage GroupPermissions { get; private set; } public PermissionStorage GroupPermissions { get; private set; }
@@ -40,15 +40,17 @@ public class IdentityService
.Moonlight.Security.Token; .Moonlight.Security.Token;
} }
public async Task<User?> Get() public async Task Load()
{
await LoadIp();
await LoadDevice();
await LoadUser();
}
private async Task LoadUser()
{ {
try try
{ {
if (UserCache != null)
return UserCache;
ConstructPermissions();
var token = "none"; var token = "none";
// Load token via http context if available // Load token via http context if available
@@ -68,13 +70,13 @@ public class IdentityService
if (token == "none") if (token == "none")
{ {
return null; return;
} }
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
return null; return;
var json = ""; string json;
try try
{ {
@@ -85,18 +87,18 @@ public class IdentityService
} }
catch (TokenExpiredException) catch (TokenExpiredException)
{ {
return null; return;
} }
catch (SignatureVerificationException) catch (SignatureVerificationException)
{ {
Logger.Warn($"Detected a manipulated JWT: {token}", "security"); Logger.Warn($"Detected a manipulated JWT: {token}", "security");
return null; return;
} }
catch (Exception e) catch (Exception e)
{ {
Logger.Error("Error reading jwt"); Logger.Error("Error reading jwt");
Logger.Error(e); Logger.Error(e);
return null; return;
} }
// To make it easier to use the json data // To make it easier to use the json data
@@ -111,7 +113,7 @@ public class IdentityService
{ {
Logger.Warn( Logger.Warn(
$"Cannot find user with the id '{userid}' in the database. Maybe the user has been deleted or a token has been successfully faked by a hacker"); $"Cannot find user with the id '{userid}' in the database. Maybe the user has been deleted or a token has been successfully faked by a hacker");
return null; return;
} }
var iat = data.GetValue<long>("iat", -1); var iat = data.GetValue<long>("iat", -1);
@@ -119,48 +121,54 @@ public class IdentityService
if (iat == -1) if (iat == -1)
{ {
Logger.Debug("Legacy token found (without the time the token has been issued at)"); Logger.Debug("Legacy token found (without the time the token has been issued at)");
return null; return;
} }
var iatD = DateTimeOffset.FromUnixTimeSeconds(iat).ToUniversalTime().DateTime; var iatD = DateTimeOffset.FromUnixTimeSeconds(iat).ToUniversalTime().DateTime;
if (iatD < user.TokenValidTime) if (iatD < user.TokenValidTime)
return null; return;
UserCache = user; User = user;
ConstructPermissions(); ConstructPermissions();
user.LastIp = GetIp(); User.LastIp = Ip;
UserRepository.Update(user); UserRepository.Update(User);
return UserCache;
} }
catch (Exception e) catch (Exception e)
{ {
Logger.Error("Unexpected error while processing token"); Logger.Error("Unexpected error while processing token");
Logger.Error(e); Logger.Error(e);
return null; return;
} }
} }
public string GetIp() private Task LoadIp()
{ {
if (HttpContextAccessor.HttpContext == null) if (HttpContextAccessor.HttpContext == null)
return "N/A"; {
Ip = "N/A";
return Task.CompletedTask;
}
if (HttpContextAccessor.HttpContext.Request.Headers.ContainsKey("X-Real-IP")) if (HttpContextAccessor.HttpContext.Request.Headers.ContainsKey("X-Real-IP"))
{ {
return HttpContextAccessor.HttpContext.Request.Headers["X-Real-IP"]!; Ip = HttpContextAccessor.HttpContext.Request.Headers["X-Real-IP"]!;
return Task.CompletedTask;
} }
return HttpContextAccessor.HttpContext.Connection.RemoteIpAddress!.ToString(); Ip = HttpContextAccessor.HttpContext.Connection.RemoteIpAddress!.ToString();
return Task.CompletedTask;
} }
public string GetDevice() private Task LoadDevice()
{ {
if (HttpContextAccessor.HttpContext == null) if (HttpContextAccessor.HttpContext == null)
return "N/A"; {
Device = "N/A";
return Task.CompletedTask;
}
try try
{ {
@@ -170,26 +178,29 @@ public class IdentityService
{ {
var version = userAgent.Remove(0, "Moonlight.App/".Length).Split(' ').FirstOrDefault(); var version = userAgent.Remove(0, "Moonlight.App/".Length).Split(' ').FirstOrDefault();
return "Moonlight App " + version; Device = "Moonlight App " + version;
return Task.CompletedTask;
} }
var uaParser = Parser.GetDefault(); var uaParser = Parser.GetDefault();
var info = uaParser.Parse(userAgent); var info = uaParser.Parse(userAgent);
return $"{info.OS} - {info.Device}"; Device = $"{info.OS} - {info.Device}";
return Task.CompletedTask;
} }
catch (Exception e) catch (Exception e)
{ {
return "UserAgent not present"; Device = "UserAgent not present";
return Task.CompletedTask;
} }
} }
public Task SavePermissions() public Task SavePermissions()
{ {
if (UserCache != null) if (User != null)
{ {
UserCache.Permissions = UserPermissions.Data; User.Permissions = UserPermissions.Data;
UserRepository.Update(UserCache); UserRepository.Update(User);
ConstructPermissions(); ConstructPermissions();
} }
@@ -198,7 +209,7 @@ public class IdentityService
private void ConstructPermissions() private void ConstructPermissions()
{ {
if (UserCache == null) if (User == null)
{ {
UserPermissions = new(Array.Empty<byte>()); UserPermissions = new(Array.Empty<byte>());
GroupPermissions = new(Array.Empty<byte>(), true); GroupPermissions = new(Array.Empty<byte>(), true);
@@ -210,7 +221,7 @@ public class IdentityService
var user = UserRepository var user = UserRepository
.Get() .Get()
.Include(x => x.PermissionGroup) .Include(x => x.PermissionGroup)
.First(x => x.Id == UserCache.Id); .First(x => x.Id == User.Id);
UserPermissions = new PermissionStorage(user.Permissions); UserPermissions = new PermissionStorage(user.Permissions);
@@ -219,7 +230,18 @@ public class IdentityService
else else
GroupPermissions = new PermissionStorage(user.PermissionGroup.Permissions, true); GroupPermissions = new PermissionStorage(user.PermissionGroup.Permissions, true);
Logger.Debug($"{UserPermissions[Perms.Permissions.AdminDashboard]} {GroupPermissions[Perms.Permissions.AdminDashboard]}"); if (user.Admin)
{
Permissions = new PermissionStorage(Array.Empty<byte>());
foreach (var permission in Perms.Permissions.GetAllPermissions())
{
Permissions[permission] = true;
}
Permissions.IsReadyOnly = true;
return;
}
Permissions = new PermissionStorage(BitHelper.OverwriteByteArrays( Permissions = new PermissionStorage(BitHelper.OverwriteByteArrays(
UserPermissions.Data, UserPermissions.Data,

View File

@@ -19,7 +19,7 @@ public class IpBanService
public Task<bool> IsBanned() public Task<bool> IsBanned()
{ {
var ip = IdentityService.GetIp(); var ip = IdentityService.Ip;
return Task.FromResult( return Task.FromResult(
IpBanRepository IpBanRepository

View File

@@ -15,7 +15,7 @@ public class IpLocateService
public async Task<string> GetLocation() public async Task<string> GetLocation()
{ {
var ip = IdentityService.GetIp(); var ip = IdentityService.Ip;
var location = "N/A"; var location = "N/A";
if (ip != "N/A") if (ip != "N/A")

View File

@@ -40,9 +40,9 @@ public class SessionClientService
public async Task Start() public async Task Start()
{ {
User = await IdentityService.Get(); User = IdentityService.User;
Ip = IdentityService.GetIp(); Ip = IdentityService.Ip;
Device = IdentityService.GetDevice(); Device = IdentityService.Device;
if (User != null) // Track users last visit if (User != null) // Track users last visit
{ {

View File

@@ -34,7 +34,7 @@ public class SupportChatAdminService : IDisposable
public async Task Start(User recipient) public async Task Start(User recipient)
{ {
User = await IdentityService.Get(); User = IdentityService.User;
Recipient = recipient; Recipient = recipient;
if (User != null) if (User != null)

View File

@@ -33,7 +33,7 @@ public class SupportChatClientService : IDisposable
public async Task Start() public async Task Start()
{ {
User = await IdentityService.Get(); User = IdentityService.User;
if (User != null) if (User != null)
{ {

View File

@@ -25,32 +25,30 @@ public class TotpService
return Task.FromResult(codeserver == code); return Task.FromResult(codeserver == code);
} }
public async Task<bool> GetEnabled() public Task<bool> GetEnabled()
{ {
var user = await IdentityService.Get(); return Task.FromResult(IdentityService.User.TotpEnabled);
return user!.TotpEnabled;
} }
public async Task<string> GetSecret() public Task<string> GetSecret()
{ {
var user = await IdentityService.Get(); return Task.FromResult(IdentityService.User.TotpSecret);
return user!.TotpSecret;
} }
public async Task GenerateSecret() public Task GenerateSecret()
{ {
var user = (await IdentityService.Get())!; var user = IdentityService.User;
user.TotpSecret = Base32Encoding.ToString(KeyGeneration.GenerateRandomKey(20));; user.TotpSecret = Base32Encoding.ToString(KeyGeneration.GenerateRandomKey(20));;
UserRepository.Update(user); UserRepository.Update(user);
return Task.CompletedTask;
} }
public async Task Enable(string code) public async Task Enable(string code)
{ {
var user = (await IdentityService.Get())!; var user = IdentityService.User;
if (!await Verify(user.TotpSecret, code)) if (!await Verify(user.TotpSecret, code))
{ {
@@ -61,9 +59,9 @@ public class TotpService
UserRepository.Update(user); UserRepository.Update(user);
} }
public async Task Disable() public Task Disable()
{ {
var user = (await IdentityService.Get())!; var user = IdentityService.User;
user.TotpEnabled = false; user.TotpEnabled = false;
user.TotpSecret = ""; user.TotpSecret = "";
@@ -71,5 +69,7 @@ public class TotpService
UserRepository.Update(user); UserRepository.Update(user);
//TODO: AuditLog //TODO: AuditLog
return Task.CompletedTask;
} }
} }

View File

@@ -85,8 +85,8 @@ public class UserService
TotpSecret = "", TotpSecret = "",
UpdatedAt = DateTimeService.GetCurrent(), UpdatedAt = DateTimeService.GetCurrent(),
TokenValidTime = DateTimeService.GetCurrent().AddDays(-5), TokenValidTime = DateTimeService.GetCurrent().AddDays(-5),
LastIp = IdentityService.GetIp(), LastIp = IdentityService.Ip,
RegisterIp = IdentityService.GetIp() RegisterIp = IdentityService.Ip
}); });
await MailService.SendMail(user!, "register", values => {}); await MailService.SendMail(user!, "register", values => {});
@@ -174,8 +174,8 @@ public class UserService
await MailService.SendMail(user!, "passwordChange", values => await MailService.SendMail(user!, "passwordChange", values =>
{ {
values.Add("Ip", IdentityService.GetIp()); values.Add("Ip", IdentityService.Ip);
values.Add("Device", IdentityService.GetDevice()); values.Add("Device", IdentityService.Device);
values.Add("Location", location); values.Add("Location", location);
}); });
@@ -212,8 +212,8 @@ public class UserService
{ {
await MailService.SendMail(user!, "login", values => await MailService.SendMail(user!, "login", values =>
{ {
values.Add("Ip", IdentityService.GetIp()); values.Add("Ip", IdentityService.Ip);
values.Add("Device", IdentityService.GetDevice()); values.Add("Device", IdentityService.Device);
values.Add("Location", location); values.Add("Location", location);
}); });
} }
@@ -249,8 +249,8 @@ public class UserService
await MailService.SendMail(user, "passwordReset", values => await MailService.SendMail(user, "passwordReset", values =>
{ {
values.Add("Ip", IdentityService.GetIp()); values.Add("Ip", IdentityService.Ip);
values.Add("Device", IdentityService.GetDevice()); values.Add("Device", IdentityService.Device);
values.Add("Location", location); values.Add("Location", location);
values.Add("Password", newPassword); values.Add("Password", newPassword);
}); });

View File

@@ -78,6 +78,8 @@
<_ContentIncludedByDefault Remove="Shared\Components\News\NewsEditor.razor" /> <_ContentIncludedByDefault Remove="Shared\Components\News\NewsEditor.razor" />
<_ContentIncludedByDefault Remove="Shared\News\Edit.razor" /> <_ContentIncludedByDefault Remove="Shared\News\Edit.razor" />
<_ContentIncludedByDefault Remove="Shared\Views\Admin\AaPanels\Index.razor" /> <_ContentIncludedByDefault Remove="Shared\Views\Admin\AaPanels\Index.razor" />
<_ContentIncludedByDefault Remove="Shared\Views\Admin\Databases\Index.razor" />
<_ContentIncludedByDefault Remove="Shared\Components\StateLogic\OnlyAdmin.razor" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@@ -49,9 +49,10 @@
private PasswordModel Password = new(); private PasswordModel Password = new();
private User User; private User User;
private async Task Load(LazyLoader loader) private Task Load(LazyLoader loader)
{ {
User = await IdentityService.Get(); User = IdentityService.User;
return Task.CompletedTask;
} }
private async Task DoChange() private async Task DoChange()

View File

@@ -50,9 +50,10 @@
private User User; private User User;
private NameModel Name = new (); private NameModel Name = new ();
private async Task Load(LazyLoader loader) private Task Load(LazyLoader loader)
{ {
User = await IdentityService.Get(); User = IdentityService.User;
return Task.CompletedTask;
} }
private async Task SetName() private async Task SetName()

View File

@@ -57,7 +57,7 @@ else
{ {
receivedExceptions.Add(exception); receivedExceptions.Add(exception);
var user = await IdentityService.Get(); var user = IdentityService.User;
var id = user == null ? -1 : user.Id; var id = user == null ? -1 : user.Id;
Logger.Error($"[{id}] An unhanded exception occured:"); Logger.Error($"[{id}] An unhanded exception occured:");

View File

@@ -1,5 +1,8 @@
@using Moonlight.App.Database.Entities @using Moonlight.App.Database.Entities
@using Moonlight.App.Models.Misc @using Moonlight.App.Models.Misc
@using Moonlight.App.Services.Sessions
@inject IdentityService IdentityService
<div class="card mb-5 mb-xl-10"> <div class="card mb-5 mb-xl-10">
<div class="card-body pt-9 pb-0"> <div class="card-body pt-9 pb-0">
@@ -8,16 +11,16 @@
<div class="d-flex justify-content-between align-items-start flex-wrap mb-2"> <div class="d-flex justify-content-between align-items-start flex-wrap mb-2">
<div class="d-flex flex-column"> <div class="d-flex flex-column">
<div class="d-flex align-items-center mb-2"> <div class="d-flex align-items-center mb-2">
<a class="text-gray-900 fs-2 fw-bold me-1 @(User.StreamerMode ? "blur" : "")">@(User.FirstName) @(User.LastName)</a> <a class="text-gray-900 fs-2 fw-bold me-1 @(IdentityService.User.StreamerMode ? "blur" : "")">@(IdentityService.User.FirstName) @(IdentityService.User.LastName)</a>
@if (User.Status == UserStatus.Verified) @if (IdentityService.User.Status == UserStatus.Verified)
{ {
<i class="text-success bx bx-md bxs-badge-check"></i> <i class="text-success bx bx-md bxs-badge-check"></i>
} }
</div> </div>
<div class="d-flex flex-wrap fw-semibold fs-6 mb-4 pe-2"> <div class="d-flex flex-wrap fw-semibold fs-6 mb-4 pe-2">
<span class="d-flex align-items-center text-gray-400 mb-2 @(User.StreamerMode ? "blur" : "")"> <span class="d-flex align-items-center text-gray-400 mb-2 @(IdentityService.User.StreamerMode ? "blur" : "")">
@(User.Email) @(IdentityService.User.Email)
</span> </span>
</div> </div>
</div> </div>
@@ -51,9 +54,6 @@
@code @code
{ {
[CascadingParameter]
public User User { get; set; }
[Parameter] [Parameter]
public int Index { get; set; } = 0; public int Index { get; set; } = 0;
} }

View File

@@ -106,7 +106,7 @@
{ {
if (firstRender) if (firstRender)
{ {
User = await IdentityService.Get(); User = IdentityService.User;
await InvokeAsync(StateHasChanged); await InvokeAsync(StateHasChanged);
} }

View File

@@ -54,7 +54,7 @@ else
if (!Allowed) if (!Allowed)
{ {
Logger.Warn($"{IdentityService.GetIp()} has tried to access {NavigationManager.Uri} without permission", "security"); Logger.Warn($"{IdentityService.Ip} has tried to access {NavigationManager.Uri} without permission", "security");
} }
return Task.CompletedTask; return Task.CompletedTask;

View File

@@ -49,7 +49,7 @@
{ {
if (firstRender) if (firstRender)
{ {
User = await IdentityService.Get(); User = IdentityService.User;
sidebar = await JsRuntime.InvokeAsync<string>("document.body.getAttribute", "data-kt-app-layout"); sidebar = await JsRuntime.InvokeAsync<string>("document.body.getAttribute", "data-kt-app-layout");
StateHasChanged(); StateHasChanged();
} }

View File

@@ -228,7 +228,7 @@ else
{ {
if (firstRender) if (firstRender)
{ {
User = await IdentityService.Get(); User = IdentityService.User;
await InvokeAsync(StateHasChanged); await InvokeAsync(StateHasChanged);
} }

View File

@@ -1,28 +0,0 @@
@using Moonlight.App.Services.Sessions
@using Moonlight.App.Database.Entities
@if (User != null)
{
if (User.Admin)
{
@ChildContent
}
else if(!Silent)
{
<div class="alert alert-danger">
<TL>Missing admin permissions. This attempt has been logged ;)</TL>
</div>
}
}
@code
{
[Parameter]
public RenderFragment ChildContent { get; set; }
[CascadingParameter]
public User? User { get; set; }
[Parameter]
public bool Silent { get; set; } = false;
}

View File

@@ -42,7 +42,6 @@
} }
<GlobalErrorBoundary> <GlobalErrorBoundary>
<CascadingValue Value="User">
<PageTitle>@(string.IsNullOrEmpty(title) ? "Dashboard - " : title)Moonlight</PageTitle> <PageTitle>@(string.IsNullOrEmpty(title) ? "Dashboard - " : title)Moonlight</PageTitle>
<div class="d-flex flex-column flex-root app-root" id="kt_app_root"> <div class="d-flex flex-column flex-root app-root" id="kt_app_root">
@@ -70,25 +69,25 @@
uri.LocalPath != "/passwordreset" && uri.LocalPath != "/passwordreset" &&
uri.LocalPath != "/register") uri.LocalPath != "/register")
{ {
if (User == null) if (IdentityService.User == null)
{ {
<Login></Login> <Login></Login>
} }
else else
{ {
if (User.Status == UserStatus.Banned) if (IdentityService.User.Status == UserStatus.Banned)
{ {
<BannedAlert></BannedAlert> <BannedAlert></BannedAlert>
} }
else if (User.Status == UserStatus.Disabled) else if (IdentityService.User.Status == UserStatus.Disabled)
{ {
<DisabledAlert></DisabledAlert> <DisabledAlert></DisabledAlert>
} }
else if (User.Status == UserStatus.PasswordPending) else if (IdentityService.User.Status == UserStatus.PasswordPending)
{ {
<PasswordChangeView></PasswordChangeView> <PasswordChangeView></PasswordChangeView>
} }
else if (User.Status == UserStatus.DataPending) else if (IdentityService.User.Status == UserStatus.DataPending)
{ {
<UserDataSetView></UserDataSetView> <UserDataSetView></UserDataSetView>
} }
@@ -155,19 +154,17 @@
</div> </div>
</div> </div>
</div> </div>
</CascadingValue>
</GlobalErrorBoundary> </GlobalErrorBoundary>
@code @code
{ {
private User? User;
private bool UserProcessed = false; private bool UserProcessed = false;
private bool IsIpBanned = false; private bool IsIpBanned = false;
protected override void OnAfterRender(bool firstRender) protected override void OnAfterRender(bool firstRender)
{ {
if(firstRender) if (firstRender)
AddBodyAttribute("data-kt-app-page-loading", "on"); AddBodyAttribute("data-kt-app-page-loading", "on");
//Initialize classes and attributes for layout with dark sidebar //Initialize classes and attributes for layout with dark sidebar
@@ -204,7 +201,7 @@
NavigationManager.NavigateTo(NavigationManager.Uri, true); NavigationManager.NavigateTo(NavigationManager.Uri, true);
}); });
User = await IdentityService.Get(); await IdentityService.Load();
UserProcessed = true; UserProcessed = true;
await InvokeAsync(StateHasChanged); await InvokeAsync(StateHasChanged);
@@ -215,7 +212,10 @@
await JsRuntime.InvokeVoidAsync("KTMenu.createInstances"); await JsRuntime.InvokeVoidAsync("KTMenu.createInstances");
await JsRuntime.InvokeVoidAsync("KTDrawer.createInstances"); await JsRuntime.InvokeVoidAsync("KTDrawer.createInstances");
} }
catch (Exception){ /* ignore errors to make sure that the session call is executed */ } catch (Exception)
{
/* ignore errors to make sure that the session call is executed */
}
await SessionClientService.Start(); await SessionClientService.Start();
@@ -225,14 +225,14 @@
await DynamicBackgroundService.Reset(); await DynamicBackgroundService.Reset();
}; };
if (User != null) if (IdentityService.User != null)
{ {
await Event.On<SupportChatMessage>( await Event.On<SupportChatMessage>(
$"supportChat.{User.Id}.message", $"supportChat.{IdentityService.User.Id}.message",
this, this,
async message => async message =>
{ {
if (!NavigationManager.Uri.EndsWith("/support") && message.Sender != User) if (!NavigationManager.Uri.EndsWith("/support") && message.Sender != IdentityService.User)
{ {
await ToastService.Info($"Support: {message.Content}"); await ToastService.Info($"Support: {message.Content}");
} }
@@ -259,9 +259,9 @@
await KeyListenerService.DisposeAsync(); await KeyListenerService.DisposeAsync();
if (User != null) if (IdentityService.User != null)
{ {
await Event.Off($"supportChat.{User.Id}.message", this); await Event.Off($"supportChat.{IdentityService.User.Id}.message", this);
} }
} }

View File

@@ -60,8 +60,6 @@
@code @code
{ {
private User? User;
protected override void OnInitialized() protected override void OnInitialized()
{ {
AddBodyAttribute("data-kt-app-page-loading", "on"); AddBodyAttribute("data-kt-app-page-loading", "on");
@@ -95,7 +93,7 @@
{ {
try try
{ {
User = await IdentityService.Get(); await IdentityService.Load();
await InvokeAsync(StateHasChanged); await InvokeAsync(StateHasChanged);
await Task.Delay(300); await Task.Delay(300);

View File

@@ -1,5 +0,0 @@
@page "/admin/databases"
<OnlyAdmin>
</OnlyAdmin>

View File

@@ -9,8 +9,9 @@
@inject DomainService DomainService @inject DomainService DomainService
@inject SmartTranslateService SmartTranslateService @inject SmartTranslateService SmartTranslateService
<OnlyAdmin> @attribute [PermissionRequired(nameof(Permissions.AdminDomains))]
<LazyLoader @ref="LazyLoader" Load="Load">
<LazyLoader @ref="LazyLoader" Load="Load">
<div class="row"> <div class="row">
<div class="card"> <div class="card">
<div class="card-header border-0 pt-5"> <div class="card-header border-0 pt-5">
@@ -60,8 +61,7 @@
</div> </div>
</div> </div>
</div> </div>
</LazyLoader> </LazyLoader>
</OnlyAdmin>
@code @code
{ {

View File

@@ -11,8 +11,9 @@
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@inject DomainService DomainService @inject DomainService DomainService
<OnlyAdmin> @attribute [PermissionRequired(nameof(Permissions.AdminNewDomain))]
<div class="row mb-5">
<div class="row mb-5">
<div class="card card-body p-10"> <div class="card card-body p-10">
<LazyLoader Load="Load"> <LazyLoader Load="Load">
<SmartForm Model="Model" OnValidSubmit="Add"> <SmartForm Model="Model" OnValidSubmit="Add">
@@ -48,7 +49,6 @@
</LazyLoader> </LazyLoader>
</div> </div>
</div> </div>
</OnlyAdmin>
@code @code
{ {

View File

@@ -12,8 +12,9 @@
@inject AlertService AlertService @inject AlertService AlertService
@inject ToastService ToastService @inject ToastService ToastService
<OnlyAdmin> @attribute [PermissionRequired(nameof(Permissions.AdminSharedDomains))]
<LazyLoader @ref="LazyLoader" Load="Load">
<LazyLoader @ref="LazyLoader" Load="Load">
<div class="card"> <div class="card">
<div class="card-header border-0 pt-5"> <div class="card-header border-0 pt-5">
<h3 class="card-title align-items-start flex-column"> <h3 class="card-title align-items-start flex-column">
@@ -44,7 +45,6 @@
</div> </div>
</div> </div>
</LazyLoader> </LazyLoader>
</OnlyAdmin>
@code @code
{ {

View File

@@ -12,6 +12,8 @@
@inject ToastService ToastService @inject ToastService ToastService
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@attribute [PermissionRequired(nameof(Permissions.AdminNewSharedDomain))]
<LazyLoader Load="Load" @ref="LazyLoader"> <LazyLoader Load="Load" @ref="LazyLoader">
<div class="row mb-5"> <div class="row mb-5">
<div class="card card-body"> <div class="card card-body">

View File

@@ -5,7 +5,6 @@
@using Moonlight.App.Database.Entities @using Moonlight.App.Database.Entities
@using Moonlight.App.Helpers @using Moonlight.App.Helpers
@using Moonlight.App.Models.Misc @using Moonlight.App.Models.Misc
@using Moonlight.App.Perms
@using Moonlight.App.Services @using Moonlight.App.Services
@using Newtonsoft.Json @using Newtonsoft.Json

View File

@@ -15,10 +15,11 @@
@inject SmartTranslateService SmartTranslateService @inject SmartTranslateService SmartTranslateService
@inject EventSystem Event @inject EventSystem Event
<OnlyAdmin> @attribute [PermissionRequired(nameof(Permissions.AdminNodeDdos))]
<AdminNodesNavigation Index="1"/>
<LazyLoader @ref="LazyLoader" Load="Load"> <AdminNodesNavigation Index="1"/>
<LazyLoader @ref="LazyLoader" Load="Load">
<div class="card"> <div class="card">
<div class="card-body pt-0"> <div class="card-body pt-0">
<div class="table-responsive"> <div class="table-responsive">
@@ -68,8 +69,7 @@
</div> </div>
</div> </div>
</div> </div>
</LazyLoader> </LazyLoader>
</OnlyAdmin>
@code @code
{ {

View File

@@ -9,8 +9,9 @@
@inject SmartTranslateService SmartTranslateService @inject SmartTranslateService SmartTranslateService
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
<OnlyAdmin> @attribute [PermissionRequired(nameof(Permissions.AdminNodeEdit))]
<LazyLoader Load="Load" @ref="LazyLoader">
<LazyLoader Load="Load" @ref="LazyLoader">
@if (Node == null) @if (Node == null)
{ {
<div class="alert alert-warning"> <div class="alert alert-warning">
@@ -149,7 +150,6 @@
</div> </div>
} }
</LazyLoader> </LazyLoader>
</OnlyAdmin>
@code @code
{ {

View File

@@ -13,10 +13,11 @@
@inject NodeService NodeService @inject NodeService NodeService
@inject SmartTranslateService SmartTranslateService @inject SmartTranslateService SmartTranslateService
<OnlyAdmin> @attribute [PermissionRequired(nameof(Permissions.AdminNodes))]
<AdminNodesNavigation Index="0"/>
<LazyLoader @ref="LazyLoader" Load="Load"> <AdminNodesNavigation Index="0"/>
<LazyLoader @ref="LazyLoader" Load="Load">
<div class="card"> <div class="card">
<div class="card-header border-0 pt-5"> <div class="card-header border-0 pt-5">
<h3 class="card-title align-items-start flex-column"> <h3 class="card-title align-items-start flex-column">
@@ -94,8 +95,7 @@
} }
</div> </div>
</div> </div>
</LazyLoader> </LazyLoader>
</OnlyAdmin>
@code @code
{ {

View File

@@ -9,8 +9,9 @@
@inject NodeRepository NodeRepository @inject NodeRepository NodeRepository
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
<OnlyAdmin> @attribute [PermissionRequired(nameof(Permissions.AdminNewNode))]
<div class="d-flex flex-center">
<div class="d-flex flex-center">
<div class="card rounded-3 w-md-550px"> <div class="card rounded-3 w-md-550px">
<div class="card-body"> <div class="card-body">
<div class="d-flex flex-center flex-column-fluid"> <div class="d-flex flex-center flex-column-fluid">
@@ -73,7 +74,6 @@
</div> </div>
</div> </div>
</div> </div>
</OnlyAdmin>
@code @code
{ {

View File

@@ -6,12 +6,13 @@
@inject NodeRepository NodeRepository @inject NodeRepository NodeRepository
@inject ConfigService ConfigService @inject ConfigService ConfigService
@attribute [PermissionRequired(nameof(Permissions.AdminNodeSetup))]
@{ @{
var appUrl = ConfigService.Get().Moonlight.AppUrl; var appUrl = ConfigService.Get().Moonlight.AppUrl;
} }
<OnlyAdmin> <LazyLoader Load="Load">
<LazyLoader Load="Load">
@if (Node == null) @if (Node == null)
{ {
<div class="alert alert-warning"> <div class="alert alert-warning">
@@ -141,7 +142,6 @@
</div> </div>
} }
</LazyLoader> </LazyLoader>
</OnlyAdmin>
@code @code
{ {

View File

@@ -10,7 +10,8 @@
@inject NodeRepository NodeRepository @inject NodeRepository NodeRepository
@inject NodeService NodeService @inject NodeService NodeService
<OnlyAdmin> @attribute [PermissionRequired(nameof(Permissions.AdminNodeView))]
<LazyLoader Load="Load"> <LazyLoader Load="Load">
@if (Node == null) @if (Node == null)
{ {
@@ -252,7 +253,6 @@ else
</div> </div>
} }
</LazyLoader> </LazyLoader>
</OnlyAdmin>
@code @code
{ {

View File

@@ -12,8 +12,9 @@
@implements IDisposable @implements IDisposable
<OnlyAdmin> @attribute [PermissionRequired(nameof(Permissions.AdminNotificationDebugging))]
<LazyLoader Load="Load">
<LazyLoader Load="Load">
<div class="card card-body"> <div class="card card-body">
<Table TableItem="ActiveNotificationClient" Items="Clients" PageSize="25" TableClass="table table-row-bordered table-row-gray-100 align-middle gs-0 gy-3" TableHeadClass="fw-bold text-muted"> <Table TableItem="ActiveNotificationClient" Items="Clients" PageSize="25" TableClass="table table-row-bordered table-row-gray-100 align-middle gs-0 gy-3" TableHeadClass="fw-bold text-muted">
<Column TableItem="ActiveNotificationClient" Title="@(SmartTranslateService.Translate("Id"))" Field="@(x => x.Client.Id)" Sortable="false" Filterable="true"/> <Column TableItem="ActiveNotificationClient" Title="@(SmartTranslateService.Translate("Id"))" Field="@(x => x.Client.Id)" Sortable="false" Filterable="true"/>
@@ -31,8 +32,6 @@
</Table> </Table>
</div> </div>
</LazyLoader> </LazyLoader>
</OnlyAdmin>
@code @code
{ {

View File

@@ -7,8 +7,9 @@
@implements IDisposable @implements IDisposable
<OnlyAdmin> @attribute [PermissionRequired(nameof(Permissions.AdminServerCleanup))]
<div class="row g-5 g-xl-10 mb-5 mb-xl-10">
<div class="row g-5 g-xl-10 mb-5 mb-xl-10">
<div class="col-xl-3"> <div class="col-xl-3">
<div class="card card-flush bgi-no-repeat bgi-size-contain bgi-position-x-end h-xl-100" style="background-color: #170049;"> <div class="card card-flush bgi-no-repeat bgi-size-contain bgi-position-x-end h-xl-100" style="background-color: #170049;">
<div class="card-header pt-5 mb-3"> <div class="card-header pt-5 mb-3">
@@ -76,7 +77,6 @@
</div> </div>
</div> </div>
</div> </div>
</OnlyAdmin>
@code @code
{ {

View File

@@ -13,8 +13,9 @@
@inject ImageRepository ImageRepository @inject ImageRepository ImageRepository
@inject Repository<User> UserRepository @inject Repository<User> UserRepository
<OnlyAdmin> @attribute [PermissionRequired(nameof(Permissions.AdminServerEdit))]
<LazyLoader @ref="LazyLoader" Load="Load">
<LazyLoader @ref="LazyLoader" Load="Load">
@if (Server == null) @if (Server == null)
{ {
<div class="alert alert-danger"> <div class="alert alert-danger">
@@ -171,7 +172,6 @@
</SmartForm> </SmartForm>
} }
</LazyLoader> </LazyLoader>
</OnlyAdmin>
@code @code
{ {

View File

@@ -8,7 +8,7 @@
@inject ServerRepository ServerRepository @inject ServerRepository ServerRepository
@inject SmartTranslateService SmartTranslateService @inject SmartTranslateService SmartTranslateService
@attribute [PermissionRequired(nameof(Permissions.ServersOverview))] @attribute [PermissionRequired(nameof(Permissions.AdminServers))]
<div class="row"> <div class="row">
<LazyLoader Load="Load"> <LazyLoader Load="Load">

View File

@@ -18,8 +18,9 @@
@inject AlertService AlertService @inject AlertService AlertService
@inject ServerService ServerService @inject ServerService ServerService
<OnlyAdmin> @attribute [PermissionRequired(nameof(Permissions.AdminServerManager))]
<div class="card mb-5">
<div class="card mb-5">
<div class="card-body"> <div class="card-body">
<WButton Text="@(SmartTranslateService.Translate("Refresh"))" <WButton Text="@(SmartTranslateService.Translate("Refresh"))"
WorkingText="@(SmartTranslateService.Translate("Working"))" WorkingText="@(SmartTranslateService.Translate("Working"))"
@@ -37,8 +38,8 @@
OnClick="KillAll"> OnClick="KillAll">
</WButton> </WButton>
</div> </div>
</div> </div>
<div class="card mb-5 bg-secondary"> <div class="card mb-5 bg-secondary">
<div class="card-body d-flex align-items-center"> <div class="card-body d-flex align-items-center">
@if (IsRunning) @if (IsRunning)
{ {
@@ -49,8 +50,8 @@
<TL>Scan complete</TL> <TL>Scan complete</TL>
} }
</div> </div>
</div> </div>
<div class="card card-body"> <div class="card card-body">
<div class="table-responsive"> <div class="table-responsive">
<Table TableItem="RunningServer" Items="RunningServers" PageSize="25" TableClass="table table-row-bordered table-row-gray-100 align-middle gs-0 gy-3" TableHeadClass="fw-bold text-muted"> <Table TableItem="RunningServer" Items="RunningServers" PageSize="25" TableClass="table table-row-bordered table-row-gray-100 align-middle gs-0 gy-3" TableHeadClass="fw-bold text-muted">
<Column TableItem="RunningServer" Title="@(SmartTranslateService.Translate("Name"))" Field="@(x => x.Server.Name)" Sortable="true" Filterable="true"> <Column TableItem="RunningServer" Title="@(SmartTranslateService.Translate("Name"))" Field="@(x => x.Server.Name)" Sortable="true" Filterable="true">
@@ -96,8 +97,7 @@
<Pager ShowPageNumber="true" ShowTotalCount="true"/> <Pager ShowPageNumber="true" ShowTotalCount="true"/>
</Table> </Table>
</div> </div>
</div> </div>
</OnlyAdmin>
@code @code
{ {

View File

@@ -17,8 +17,9 @@
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@inject UserRepository UserRepository @inject UserRepository UserRepository
<OnlyAdmin> @attribute [PermissionRequired(nameof(Permissions.AdminNewServer))]
<LazyLoader Load="Load">
<LazyLoader Load="Load">
<SmartForm Model="Model" OnValidSubmit="Create"> <SmartForm Model="Model" OnValidSubmit="Create">
<div class="row mb-5"> <div class="row mb-5">
<div class="card card-body p-10"> <div class="card card-body p-10">
@@ -173,7 +174,6 @@
</div> </div>
</SmartForm> </SmartForm>
</LazyLoader> </LazyLoader>
</OnlyAdmin>
@code @code
{ {

View File

@@ -10,8 +10,9 @@
@inject StatisticsViewService StatisticsViewService @inject StatisticsViewService StatisticsViewService
@inject SmartTranslateService SmartTranslateService @inject SmartTranslateService SmartTranslateService
<OnlyAdmin> @attribute [PermissionRequired(nameof(Permissions.AdminStatistics))]
<div class="row mt-4 mb-2">
<div class="row mt-4 mb-2">
<div class="col-12 col-lg-6 col-xl"> <div class="col-12 col-lg-6 col-xl">
<div class="card card-body"> <div class="card card-body">
<select class="form-select" @bind="TimeSpanBind"> <select class="form-select" @bind="TimeSpanBind">
@@ -33,9 +34,9 @@
</select> </select>
</div> </div>
</div> </div>
</div> </div>
<LazyLoader @ref="Loader" Load="Load"> <LazyLoader @ref="Loader" Load="Load">
@foreach (var charts in Charts.Chunk(2)) @foreach (var charts in Charts.Chunk(2))
{ {
<div class="row"> <div class="row">
@@ -80,8 +81,7 @@
</div> </div>
</div> </div>
</div> </div>
</LazyLoader> </LazyLoader>
</OnlyAdmin>
@code @code
{ {

View File

@@ -10,8 +10,9 @@
@inject SubscriptionRepository SubscriptionRepository @inject SubscriptionRepository SubscriptionRepository
@inject SubscriptionService SubscriptionService @inject SubscriptionService SubscriptionService
<OnlyAdmin> @attribute [PermissionRequired(nameof(Permissions.AdminSubscriptionEdit))]
<div class="card card-body p-10">
<div class="card card-body p-10">
<LazyLoader Load="Load"> <LazyLoader Load="Load">
@if (Subscription == null) @if (Subscription == null)
{ {
@@ -157,8 +158,7 @@
</SmartForm> </SmartForm>
} }
</LazyLoader> </LazyLoader>
</div> </div>
</OnlyAdmin>
@code @code
{ {

View File

@@ -9,8 +9,9 @@
@inject SubscriptionRepository SubscriptionRepository @inject SubscriptionRepository SubscriptionRepository
@inject SubscriptionService SubscriptionService @inject SubscriptionService SubscriptionService
<OnlyAdmin> @attribute [PermissionRequired(nameof(Permissions.AdminSubscriptions))]
<div class="card">
<div class="card">
<LazyLoader @ref="LazyLoader" Load="Load"> <LazyLoader @ref="LazyLoader" Load="Load">
<div class="card-header border-0 pt-5"> <div class="card-header border-0 pt-5">
<h3 class="card-title align-items-start flex-column"> <h3 class="card-title align-items-start flex-column">
@@ -54,7 +55,6 @@
</div> </div>
</LazyLoader> </LazyLoader>
</div> </div>
</OnlyAdmin>
@code @code
{ {

View File

@@ -8,8 +8,9 @@
@inject SubscriptionRepository SubscriptionRepository @inject SubscriptionRepository SubscriptionRepository
@inject SubscriptionService SubscriptionService @inject SubscriptionService SubscriptionService
<OnlyAdmin> @attribute [PermissionRequired(nameof(Permissions.AdminNewSubscription))]
<div class="card card-body p-10">
<div class="card card-body p-10">
<SmartForm Model="Model" OnValidSubmit="OnSubmit"> <SmartForm Model="Model" OnValidSubmit="OnSubmit">
<label class="form-label"> <label class="form-label">
<TL>Name</TL> <TL>Name</TL>
@@ -145,7 +146,6 @@
</div> </div>
</SmartForm> </SmartForm>
</div> </div>
</OnlyAdmin>
@code @code
{ {

View File

@@ -8,8 +8,9 @@
@implements IDisposable @implements IDisposable
<OnlyAdmin> @attribute [PermissionRequired(nameof(Permissions.AdminSupport))]
<LazyLoader @ref="LazyLoader" Load="Load">
<LazyLoader @ref="LazyLoader" Load="Load">
<div class="card"> <div class="card">
<div class="card-body"> <div class="card-body">
<div class="d-flex flex-column flex-xl-row p-5 pb-0"> <div class="d-flex flex-column flex-xl-row p-5 pb-0">
@@ -70,7 +71,6 @@
</div> </div>
</div> </div>
</LazyLoader> </LazyLoader>
</OnlyAdmin>
@code @code
{ {

View File

@@ -14,8 +14,9 @@
@implements IDisposable @implements IDisposable
<OnlyAdmin> @attribute [PermissionRequired(nameof(Permissions.AdminSupportView))]
<LazyLoader Load="Load">
<LazyLoader Load="Load">
@if (User == null) @if (User == null)
{ {
<div class="alert alert-danger"> <div class="alert alert-danger">
@@ -220,7 +221,6 @@
</div> </div>
} }
</LazyLoader> </LazyLoader>
</OnlyAdmin>
@code @code
{ {

View File

@@ -9,7 +9,7 @@
@inject ToastService ToastService @inject ToastService ToastService
@inject SmartTranslateService SmartTranslateService @inject SmartTranslateService SmartTranslateService
@attribute [PermissionRequired(nameof(Permissions.SystemConfiguration))] @attribute [PermissionRequired(nameof(Permissions.AdminSysConfiguration))]
<AdminSystemNavigation Index="8"/> <AdminSystemNavigation Index="8"/>

View File

@@ -4,7 +4,7 @@
@inject DiscordBotService DiscordBotService @inject DiscordBotService DiscordBotService
@attribute [PermissionRequired(nameof(Permissions.DiscordBot))] @attribute [PermissionRequired(nameof(Permissions.AdminSysDiscordBot))]
<AdminSystemNavigation Index="6"/> <AdminSystemNavigation Index="6"/>

View File

@@ -7,7 +7,7 @@
@inject HostSystemHelper HostSystemHelper @inject HostSystemHelper HostSystemHelper
@inject MoonlightService MoonlightService @inject MoonlightService MoonlightService
@attribute [PermissionRequired(nameof(Permissions.SystemDashboard))] @attribute [PermissionRequired(nameof(Permissions.AdminSystem))]
<AdminSystemNavigation Index="0"/> <AdminSystemNavigation Index="0"/>

View File

@@ -5,18 +5,19 @@
@using Moonlight.App.Helpers.Files @using Moonlight.App.Helpers.Files
@using Moonlight.App.Helpers @using Moonlight.App.Helpers
@using BlazorTable @using BlazorTable
@using Moonlight.App.Database.Entities
@using Moonlight.App.Models.Misc @using Moonlight.App.Models.Misc
@using Moonlight.App.Services @using Moonlight.App.Services
@using Moonlight.App.Services.Interop @using Moonlight.App.Services.Interop
@using Moonlight.App.Services.Mail @using Moonlight.App.Services.Mail
@using Moonlight.App.Services.Sessions
@inject SmartTranslateService SmartTranslateService @inject SmartTranslateService SmartTranslateService
@inject ToastService ToastService @inject ToastService ToastService
@inject AlertService AlertService @inject AlertService AlertService
@inject MailService MailService @inject MailService MailService
@inject IdentityService IdentityService
@attribute [PermissionRequired(nameof(Permissions.SystemMail))] @attribute [PermissionRequired(nameof(Permissions.AdminSysMail))]
<AdminSystemNavigation Index="9"/> <AdminSystemNavigation Index="9"/>
@@ -92,8 +93,7 @@
@code @code
{ {
[CascadingParameter]
public User User { get; set; }
private MailTemplate[] MailTemplateFiles; private MailTemplate[] MailTemplateFiles;
private FileAccess FileAccess; private FileAccess FileAccess;
@@ -174,7 +174,7 @@
private async Task SendTestMail() private async Task SendTestMail()
{ {
await MailService.SendMailRaw(User, "<html><body>If you see this mail, your moonlight mail configuration is ready to use</body></html>"); await MailService.SendMailRaw(IdentityService.User, "<html><body>If you see this mail, your moonlight mail configuration is ready to use</body></html>");
await AlertService.Info(SmartTranslateService.Translate("A test mail has been sent to the email address of your account")); await AlertService.Info(SmartTranslateService.Translate("A test mail has been sent to the email address of your account"));
} }
} }

View File

@@ -14,7 +14,7 @@
@implements IDisposable @implements IDisposable
@attribute [PermissionRequired(nameof(Permissions.SystemMalware))] @attribute [PermissionRequired(nameof(Permissions.AdminSysMalware))]
<AdminSystemNavigation Index="2"/> <AdminSystemNavigation Index="2"/>

View File

@@ -10,7 +10,7 @@
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@inject NewsEntryRepository NewsEntryRepository @inject NewsEntryRepository NewsEntryRepository
@attribute [PermissionRequired(nameof(Permissions.NewsMessages))] @attribute [PermissionRequired(nameof(Permissions.AdminSysNewsEdit))]
<LazyLoader Load="Load"> <LazyLoader Load="Load">
@if (Entry == null) @if (Entry == null)

View File

@@ -12,7 +12,7 @@
@inject SmartTranslateService SmartTranslateService @inject SmartTranslateService SmartTranslateService
@inject AlertService AlertService @inject AlertService AlertService
@attribute [PermissionRequired(nameof(Permissions.NewsMessages))] @attribute [PermissionRequired(nameof(Permissions.AdminSysNews))]
<AdminSystemNavigation Index="7"/> <AdminSystemNavigation Index="7"/>

View File

@@ -9,7 +9,7 @@
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@inject NewsEntryRepository NewsEntryRepository @inject NewsEntryRepository NewsEntryRepository
@attribute [PermissionRequired(nameof(Permissions.NewsMessages))] @attribute [PermissionRequired(nameof(Permissions.AdminSysNewsNew))]
<div class="card mb-6"> <div class="card mb-6">
<div class="card-header"> <div class="card-header">

View File

@@ -11,7 +11,7 @@
@inject ConfigService ConfigService @inject ConfigService ConfigService
@inject AlertService AlertService @inject AlertService AlertService
@attribute [PermissionRequired(nameof(Permissions.SystemResources))] @attribute [PermissionRequired(nameof(Permissions.AdminSysResources))]
<AdminSystemNavigation Index="5"/> <AdminSystemNavigation Index="5"/>

View File

@@ -13,7 +13,7 @@
@inject EventSystem Event @inject EventSystem Event
@inject ToastService ToastService @inject ToastService ToastService
@attribute [PermissionRequired(nameof(Permissions.SystemSecurity))] @attribute [PermissionRequired(nameof(Permissions.AdminSysSecurity))]
<AdminSystemNavigation Index="3"/> <AdminSystemNavigation Index="3"/>

View File

@@ -3,7 +3,7 @@
@using Moonlight.Shared.Components.Navigations @using Moonlight.Shared.Components.Navigations
@using global::Sentry @using global::Sentry
@attribute [PermissionRequired(nameof(Permissions.SystemSentry))] @attribute [PermissionRequired(nameof(Permissions.AdminSysSentry))]
<AdminSystemNavigation Index="1"/> <AdminSystemNavigation Index="1"/>

View File

@@ -12,8 +12,9 @@
@inject ToastService ToastService @inject ToastService ToastService
@inject SmartTranslateService SmartTranslateService @inject SmartTranslateService SmartTranslateService
<OnlyAdmin> @attribute [PermissionRequired(nameof(Permissions.AdminUserEdit))]
<LazyLoader Load="Load">
<LazyLoader Load="Load">
@if (User == null) @if (User == null)
{ {
<div class="alert alert-danger"> <div class="alert alert-danger">
@@ -156,7 +157,6 @@
<PermissionEditor @ref="PermissionEditor" OnSave="SavePermissions" /> <PermissionEditor @ref="PermissionEditor" OnSave="SavePermissions" />
</LazyLoader> </LazyLoader>
</OnlyAdmin>
@code @code
{ {

View File

@@ -9,10 +9,11 @@
@inject UserRepository UserRepository @inject UserRepository UserRepository
@inject SmartTranslateService SmartTranslateService @inject SmartTranslateService SmartTranslateService
<OnlyAdmin> @attribute [PermissionRequired(nameof(Permissions.AdminUsers))]
<AdminSessionNavigation Index="0"/>
<div class="card"> <AdminSessionNavigation Index="0"/>
<div class="card">
<LazyLoader Load="Load"> <LazyLoader Load="Load">
<div class="card-header border-0 pt-5"> <div class="card-header border-0 pt-5">
<h3 class="card-title align-items-start flex-column"> <h3 class="card-title align-items-start flex-column">
@@ -51,8 +52,7 @@
</div> </div>
</div> </div>
</LazyLoader> </LazyLoader>
</div> </div>
</OnlyAdmin>
@code @code
{ {

View File

@@ -8,8 +8,9 @@
@inject ToastService ToastService @inject ToastService ToastService
@inject UserService UserService @inject UserService UserService
<OnlyAdmin> @attribute [PermissionRequired(nameof(Permissions.AdminNewUser))]
<div class="row mb-5">
<div class="row mb-5">
<div class="card card-body p-10"> <div class="card card-body p-10">
<label class="form-label"> <label class="form-label">
<TL>First name</TL> <TL>First name</TL>
@@ -36,8 +37,8 @@
<input @bind="User.Password" type="password" class="form-control"> <input @bind="User.Password" type="password" class="form-control">
</div> </div>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="card card-body"> <div class="card card-body">
<div class="d-flex justify-content-end"> <div class="d-flex justify-content-end">
<a href="/admin/users" class="btn btn-danger me-3"> <a href="/admin/users" class="btn btn-danger me-3">
@@ -50,8 +51,7 @@
</WButton> </WButton>
</div> </div>
</div> </div>
</div> </div>
</OnlyAdmin>
@code @code
{ {

View File

@@ -13,10 +13,11 @@
@inject AlertService AlertService @inject AlertService AlertService
@inject ToastService ToastService @inject ToastService ToastService
<OnlyAdmin> @attribute [PermissionRequired(nameof(Permissions.AdminUserSessions))]
<AdminSessionNavigation Index="1"/>
<div class="card"> <AdminSessionNavigation Index="1"/>
<div class="card">
<LazyLoader Load="Load"> <LazyLoader Load="Load">
<div class="card-header border-0 pt-5"> <div class="card-header border-0 pt-5">
<h3 class="card-title align-items-start flex-column"> <h3 class="card-title align-items-start flex-column">
@@ -96,8 +97,7 @@
} }
</div> </div>
</LazyLoader> </LazyLoader>
</div> </div>
</OnlyAdmin>
@code @code
{ {

View File

@@ -10,16 +10,17 @@
@inject ServerRepository ServerRepository @inject ServerRepository ServerRepository
@inject DomainRepository DomainRepository @inject DomainRepository DomainRepository
<OnlyAdmin> @attribute [PermissionRequired(nameof(Permissions.AdminUserView))]
<LazyLoader Load="Load"> <LazyLoader Load="Load">
@if (User == null) @if (User == null)
{ {
<div class="alert alert-danger"> <div class="alert alert-danger">
<TL>No user with this id found</TL> <TL>No user with this id found</TL>
</div> </div>
} }
else else
{ {
<div class="row"> <div class="row">
<div class="col-md-4"> <div class="col-md-4">
<div class="card card-body mb-5"> <div class="card card-body mb-5">
@@ -237,9 +238,8 @@ else
</div> </div>
</div> </div>
</div> </div>
} }
</LazyLoader> </LazyLoader>
</OnlyAdmin>
@code @code
{ {

View File

@@ -11,10 +11,11 @@
@inject Repository<WebSpace> WebSpaceRepository @inject Repository<WebSpace> WebSpaceRepository
@inject WebSpaceService WebSpaceService @inject WebSpaceService WebSpaceService
<OnlyAdmin> @attribute [PermissionRequired(nameof(Permissions.AdminWebspaces))]
<AdminWebspacesNavigation Index="0"/>
<div class="card"> <AdminWebspacesNavigation Index="0"/>
<div class="card">
<div class="card-header border-0 pt-5"> <div class="card-header border-0 pt-5">
<h3 class="card-title align-items-start flex-column"> <h3 class="card-title align-items-start flex-column">
<span class="card-label fw-bold fs-3 mb-1"> <span class="card-label fw-bold fs-3 mb-1">
@@ -65,8 +66,7 @@
</div> </div>
</LazyLoader> </LazyLoader>
</div> </div>
</div> </div>
</OnlyAdmin>
@code @code
{ {

View File

@@ -9,8 +9,9 @@
@inject UserRepository UserRepository @inject UserRepository UserRepository
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
<OnlyAdmin> @attribute [PermissionRequired(nameof(Permissions.AdminNewWebspace))]
<div class="card card-body p-10">
<div class="card card-body p-10">
<LazyLoader Load="Load"> <LazyLoader Load="Load">
<SmartForm Model="Model" OnValidSubmit="OnValidSubmit"> <SmartForm Model="Model" OnValidSubmit="OnValidSubmit">
<label class="form-label"> <label class="form-label">
@@ -36,8 +37,7 @@
</div> </div>
</SmartForm> </SmartForm>
</LazyLoader> </LazyLoader>
</div> </div>
</OnlyAdmin>
@code @code
{ {

View File

@@ -8,8 +8,9 @@
@inject Repository<CloudPanel> CloudPanelRepository @inject Repository<CloudPanel> CloudPanelRepository
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
<OnlyAdmin> @attribute [PermissionRequired(nameof(Permissions.AdminWebspacesServerEdit))]
<LazyLoader Load="Load">
<LazyLoader Load="Load">
@if (CloudPanel == null) @if (CloudPanel == null)
{ {
<div class="d-flex justify-content-center flex-center"> <div class="d-flex justify-content-center flex-center">
@@ -63,7 +64,6 @@
</div> </div>
} }
</LazyLoader> </LazyLoader>
</OnlyAdmin>
@code @code
{ {

View File

@@ -10,10 +10,11 @@
@inject Repository<CloudPanel> CloudPanelRepository @inject Repository<CloudPanel> CloudPanelRepository
@inject WebSpaceService WebSpaceService @inject WebSpaceService WebSpaceService
<OnlyAdmin> @attribute [PermissionRequired(nameof(Permissions.AdminWebspacesServers))]
<AdminWebspacesNavigation Index="1"/>
<div class="card"> <AdminWebspacesNavigation Index="1"/>
<div class="card">
<div class="card-header border-0 pt-5"> <div class="card-header border-0 pt-5">
<h3 class="card-title align-items-start flex-column"> <h3 class="card-title align-items-start flex-column">
<span class="card-label fw-bold fs-3 mb-1"> <span class="card-label fw-bold fs-3 mb-1">
@@ -78,8 +79,7 @@
</div> </div>
</LazyLoader> </LazyLoader>
</div> </div>
</div> </div>
</OnlyAdmin>
@code @code
{ {

View File

@@ -7,8 +7,9 @@
@inject Repository<CloudPanel> CloudPanelRepository @inject Repository<CloudPanel> CloudPanelRepository
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
<OnlyAdmin> @attribute [PermissionRequired(nameof(Permissions.AdminWebspacesServerNew))]
<div class="card card-body p-10">
<div class="card card-body p-10">
<SmartForm Model="Model" OnValidSubmit="OnValidSubmit"> <SmartForm Model="Model" OnValidSubmit="OnValidSubmit">
<label class="form-label"> <label class="form-label">
<TL>Name</TL> <TL>Name</TL>
@@ -41,7 +42,6 @@
</div> </div>
</SmartForm> </SmartForm>
</div> </div>
</OnlyAdmin>
@code @code
{ {

View File

@@ -4,6 +4,7 @@
@using Moonlight.App.Models.Forms @using Moonlight.App.Models.Forms
@using Moonlight.App.Repositories.Domains @using Moonlight.App.Repositories.Domains
@using Microsoft.EntityFrameworkCore @using Microsoft.EntityFrameworkCore
@using Moonlight.App.Services.Sessions
@inject SubscriptionService SubscriptionService @inject SubscriptionService SubscriptionService
@inject DomainService DomainService @inject DomainService DomainService
@@ -11,6 +12,7 @@
@inject SharedDomainRepository SharedDomainRepository @inject SharedDomainRepository SharedDomainRepository
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@inject SmartTranslateService SmartTranslateService @inject SmartTranslateService SmartTranslateService
@inject IdentityService IdentityService
<LazyLoader Load="Load"> <LazyLoader Load="Load">
@if (!SharedDomains.Any()) @if (!SharedDomains.Any())
@@ -114,8 +116,7 @@
@code @code
{ {
[CascadingParameter]
public User User { get; set; }
private SharedDomain[] SharedDomains; private SharedDomain[] SharedDomains;
@@ -130,12 +131,12 @@
Model = new(); Model = new();
await lazyLoader.SetText(SmartTranslateService.Translate("Loading your subscription")); await lazyLoader.SetText(SmartTranslateService.Translate("Loading your subscription"));
Subscription = await SubscriptionService.GetActiveSubscription(User); Subscription = await SubscriptionService.GetActiveSubscription(IdentityService.User);
AllowOrder = DomainRepository AllowOrder = DomainRepository
.Get() .Get()
.Include(x => x.Owner) .Include(x => x.Owner)
.Count(x => x.Owner.Id == User.Id) < (await SubscriptionService.GetLimit(User, "domains")).Amount; .Count(x => x.Owner.Id == IdentityService.User.Id) < (await SubscriptionService.GetLimit(IdentityService.User, "domains")).Amount;
await lazyLoader.SetText("Loading shared domains"); await lazyLoader.SetText("Loading shared domains");
SharedDomains = SharedDomainRepository.Get().ToArray(); SharedDomains = SharedDomainRepository.Get().ToArray();
@@ -146,9 +147,9 @@
if (DomainRepository if (DomainRepository
.Get() .Get()
.Include(x => x.Owner) .Include(x => x.Owner)
.Count(x => x.Owner.Id == User.Id) < (await SubscriptionService.GetLimit(User, "domains")).Amount) .Count(x => x.Owner.Id == IdentityService.User.Id) < (await SubscriptionService.GetLimit(IdentityService.User, "domains")).Amount)
{ {
var domain = await DomainService.Create(Model.Name, Model.SharedDomain, User); var domain = await DomainService.Create(Model.Name, Model.SharedDomain, IdentityService.User);
NavigationManager.NavigateTo($"/domain/{domain.Id}"); NavigationManager.NavigateTo($"/domain/{domain.Id}");
} }

View File

@@ -7,11 +7,13 @@
@using Moonlight.App.Repositories @using Moonlight.App.Repositories
@using Moonlight.App.Repositories.Domains @using Moonlight.App.Repositories.Domains
@using Markdig @using Markdig
@using Moonlight.App.Services.Sessions
@inject ServerRepository ServerRepository @inject ServerRepository ServerRepository
@inject Repository<WebSpace> WebSpaceRepository @inject Repository<WebSpace> WebSpaceRepository
@inject DomainRepository DomainRepository @inject DomainRepository DomainRepository
@inject NewsEntryRepository NewsEntryRepository @inject NewsEntryRepository NewsEntryRepository
@inject IdentityService IdentityService
<LazyLoader Load="Load"> <LazyLoader Load="Load">
@if (NewsEntries.Any()) @if (NewsEntries.Any())
@@ -243,9 +245,6 @@
@code @code
{ {
[CascadingParameter]
public User User { get; set; }
private int ServerCount = 0; private int ServerCount = 0;
private int DomainCount = 0; private int DomainCount = 0;
private int WebSpaceCount = 0; private int WebSpaceCount = 0;
@@ -258,17 +257,17 @@
ServerCount = ServerRepository ServerCount = ServerRepository
.Get() .Get()
.Include(x => x.Owner) .Include(x => x.Owner)
.Count(x => x.Owner.Id == User.Id); .Count(x => x.Owner.Id == IdentityService.User.Id);
DomainCount = DomainRepository DomainCount = DomainRepository
.Get() .Get()
.Include(x => x.Owner) .Include(x => x.Owner)
.Count(x => x.Owner.Id == User.Id); .Count(x => x.Owner.Id == IdentityService.User.Id);
WebSpaceCount = WebSpaceRepository WebSpaceCount = WebSpaceRepository
.Get() .Get()
.Include(x => x.Owner) .Include(x => x.Owner)
.Count(x => x.Owner.Id == User.Id); .Count(x => x.Owner.Id == IdentityService.User.Id);
NewsEntries = NewsEntryRepository.Get().ToList(); NewsEntries = NewsEntryRepository.Get().ToList();

View File

@@ -4,13 +4,15 @@
@using Moonlight.App.Database.Entities @using Moonlight.App.Database.Entities
@using Moonlight.App.Repositories @using Moonlight.App.Repositories
@using Moonlight.App.Services @using Moonlight.App.Services
@using Moonlight.App.Services.Sessions
@inject Repository<User> UserRepository @inject Repository<User> UserRepository
@inject SmartTranslateService SmartTranslateService @inject SmartTranslateService SmartTranslateService
@inject IdentityService IdentityService
<ProfileNavigation Index="1"/> <ProfileNavigation Index="1"/>
@if (User.DiscordId == 0) @if (IdentityService.User.DiscordId == 0)
{ {
<div class="row"> <div class="row">
<div class="col"> <div class="col">
@@ -64,13 +66,12 @@ else
@code @code
{ {
[CascadingParameter]
public User User { get; set; }
private async Task RemoveLink() private async Task RemoveLink()
{ {
User.DiscordId = 0; IdentityService.User.DiscordId = 0;
UserRepository.Update(User); UserRepository.Update(IdentityService.User);
await InvokeAsync(StateHasChanged); await InvokeAsync(StateHasChanged);
} }

View File

@@ -7,15 +7,17 @@
@using Mappy.Net @using Mappy.Net
@using Moonlight.App.Exceptions @using Moonlight.App.Exceptions
@using Moonlight.App.Helpers @using Moonlight.App.Helpers
@using Moonlight.App.Services.Sessions
@inject UserRepository UserRepository @inject Repository<User> UserRepository
@inject IdentityService IdentityService
<ProfileNavigation Index="0" /> <ProfileNavigation Index="0" />
<LazyLoader Load="Load"> <LazyLoader Load="Load">
<SmartForm OnValidSubmit="Save" Model="Model"> <SmartForm OnValidSubmit="Save" Model="Model">
<div class="card mb-5 mb-xl-10"> <div class="card mb-5 mb-xl-10">
<div class="card-body p-9 @(CurrentUser.StreamerMode ? "blur" : "")"> <div class="card-body p-9 @(IdentityService.User.StreamerMode ? "blur" : "")">
<div class="row"> <div class="row">
<div class="col-lg-6 fv-row fv-plugins-icon-container"> <div class="col-lg-6 fv-row fv-plugins-icon-container">
<div class="mb-3"> <div class="mb-3">
@@ -78,13 +80,9 @@
{ {
private UserDataModel Model = new(); private UserDataModel Model = new();
[CascadingParameter]
public User CurrentUser { get; set; }
private Task Load(LazyLoader loader) private Task Load(LazyLoader loader)
{ {
Model = Mapper.Map<UserDataModel>(CurrentUser); Model = Mapper.Map<UserDataModel>(IdentityService.User);
return Task.CompletedTask; return Task.CompletedTask;
} }
@@ -98,15 +96,15 @@
.Get() .Get()
.FirstOrDefault(x => x.Email == Model.Email); .FirstOrDefault(x => x.Email == Model.Email);
if (userWithThatEmail != null && CurrentUser.Id != userWithThatEmail.Id) if (userWithThatEmail != null && IdentityService.User.Id != userWithThatEmail.Id)
{ {
Logger.Warn($"A user tried to lock another user out by changing the email. Email: {Model.Email}", "security"); Logger.Warn($"A user tried to lock another user out by changing the email. Email: {Model.Email}", "security");
throw new DisplayException("A user with that email does already exist"); throw new DisplayException("A user with that email does already exist");
} }
CurrentUser = Mapper.Map(CurrentUser, Model); var user = Mapper.Map(IdentityService.User, Model);
UserRepository.Update(CurrentUser); UserRepository.Update(user);
return Task.CompletedTask; return Task.CompletedTask;
} }

View File

@@ -8,6 +8,7 @@
@using Mappy.Net @using Mappy.Net
@using Moonlight.App.Models.Forms @using Moonlight.App.Models.Forms
@using Moonlight.App.Repositories @using Moonlight.App.Repositories
@using Moonlight.App.Services.Sessions
@inject TotpService TotpService @inject TotpService TotpService
@inject UserService UserService @inject UserService UserService
@@ -15,6 +16,7 @@
@inject ModalService ModalService @inject ModalService ModalService
@inject Repository<User> UserRepository @inject Repository<User> UserRepository
@inject SmartTranslateService SmartTranslateService @inject SmartTranslateService SmartTranslateService
@inject IdentityService IdentityService
<ProfileNavigation Index="2"/> <ProfileNavigation Index="2"/>
@@ -31,7 +33,7 @@
<TL>2fa adds another layer of security to your account. You have to enter a 6 digit code in order to login.</TL> <TL>2fa adds another layer of security to your account. You have to enter a 6 digit code in order to login.</TL>
</p> </p>
<div class="d-flex justify-content-center"> <div class="d-flex justify-content-center">
@if (User.TotpEnabled) @if (IdentityService.User.TotpEnabled)
{ {
<WButton Text="@(SmartTranslateService.Translate("Disable"))" <WButton Text="@(SmartTranslateService.Translate("Disable"))"
WorkingText="" WorkingText=""
@@ -110,9 +112,9 @@
</h2> </h2>
</div> </div>
<div class="modal-body fs-6"> <div class="modal-body fs-6">
@if (!User.TotpEnabled) @if (!IdentityService.User.TotpEnabled)
{ {
if (string.IsNullOrEmpty(User.TotpSecret)) if (string.IsNullOrEmpty(IdentityService.User.TotpSecret))
{ {
<p> <p>
<TL>Make sure you have installed one of the following apps on your smartphone and press continue</TL> <TL>Make sure you have installed one of the following apps on your smartphone and press continue</TL>
@@ -147,7 +149,7 @@
var qrCodeData = qrGenerator.CreateQrCode var qrCodeData = qrGenerator.CreateQrCode
( (
$"otpauth://totp/{Uri.EscapeDataString(User.Email)}?secret={User.TotpSecret}&issuer={Uri.EscapeDataString("Moonlight")}", $"otpauth://totp/{Uri.EscapeDataString(IdentityService.User.Email)}?secret={IdentityService.User.TotpSecret}&issuer={Uri.EscapeDataString("Moonlight")}",
QRCodeGenerator.ECCLevel.Q QRCodeGenerator.ECCLevel.Q
); );
@@ -179,8 +181,7 @@
@code @code
{ {
[CascadingParameter]
public User User { get; set; }
private string TwoFactorCode = ""; private string TwoFactorCode = "";
private string Password = ""; private string Password = "";
@@ -188,7 +189,7 @@
protected override void OnParametersSet() protected override void OnParametersSet()
{ {
UserModel = Mapper.Map<UserPreferencesDataModel>(User); UserModel = Mapper.Map<UserPreferencesDataModel>(IdentityService.User);
} }
private async Task StartTwoFactorWizard() private async Task StartTwoFactorWizard()
@@ -219,14 +220,14 @@
private async Task ChangePassword() private async Task ChangePassword()
{ {
await UserService.ChangePassword(User, Password); await UserService.ChangePassword(IdentityService.User, Password);
NavigationManager.NavigateTo(NavigationManager.Uri, true); NavigationManager.NavigateTo(NavigationManager.Uri, true);
} }
private async Task SavePreferences() private async Task SavePreferences()
{ {
User = Mapper.Map(User, UserModel); var user = Mapper.Map(IdentityService.User, UserModel);
UserRepository.Update(User); UserRepository.Update(user);
await InvokeAsync(StateHasChanged); await InvokeAsync(StateHasChanged);
NavigationManager.NavigateTo(NavigationManager.Uri, true); NavigationManager.NavigateTo(NavigationManager.Uri, true);
} }

View File

@@ -7,6 +7,7 @@
@using Moonlight.App.Repositories @using Moonlight.App.Repositories
@using Moonlight.App.Services.Interop @using Moonlight.App.Services.Interop
@using Markdig @using Markdig
@using Moonlight.App.Services.Sessions
@inject BillingService BillingService @inject BillingService BillingService
@inject Repository<Subscription> SubscriptionRepository @inject Repository<Subscription> SubscriptionRepository
@@ -14,6 +15,7 @@
@inject PopupService PopupService @inject PopupService PopupService
@inject SubscriptionService SubscriptionService @inject SubscriptionService SubscriptionService
@inject SmartTranslateService SmartTranslateService @inject SmartTranslateService SmartTranslateService
@inject IdentityService IdentityService
<ProfileNavigation Index="3"/> <ProfileNavigation Index="3"/>
@@ -80,7 +82,7 @@
{ {
<div class="card"> <div class="card">
<div class="card-body"> <div class="card-body">
@if ((User.SubscriptionExpires - DateTime.UtcNow).TotalDays < 5) @if ((IdentityService.User.SubscriptionExpires - DateTime.UtcNow).TotalDays < 5)
{ {
<div class="notice d-flex bg-light-warning rounded border-warning border mb-12 p-6"> <div class="notice d-flex bg-light-warning rounded border-warning border mb-12 p-6">
<div class="d-flex flex-stack flex-grow-1 "> <div class="d-flex flex-stack flex-grow-1 ">
@@ -91,7 +93,7 @@
<div class="fs-6 text-gray-700 "> <div class="fs-6 text-gray-700 ">
<TL>Your subscription expires soon</TL> <TL>Your subscription expires soon</TL>
<span> <span>
@(Math.Round((User.SubscriptionExpires - DateTime.UtcNow).TotalDays)) <TL>left</TL> @(Math.Round((IdentityService.User.SubscriptionExpires - DateTime.UtcNow).TotalDays)) <TL>left</TL>
</span> </span>
</div> </div>
</div> </div>
@@ -101,7 +103,7 @@
<div class="row"> <div class="row">
<div class="col-lg-7"> <div class="col-lg-7">
<h3 class="mb-2"> <h3 class="mb-2">
<TL>Active until</TL> @(Formatter.FormatDateOnly(User.SubscriptionExpires)) <TL>Active until</TL> @(Formatter.FormatDateOnly(IdentityService.User.SubscriptionExpires))
</h3> </h3>
<p class="fs-6 text-gray-600 fw-semibold mb-6 mb-lg-15"> <p class="fs-6 text-gray-600 fw-semibold mb-6 mb-lg-15">
<TL>We will send you a email upon subscription expiration</TL> <TL>We will send you a email upon subscription expiration</TL>
@@ -134,8 +136,7 @@
@code @code
{ {
[CascadingParameter]
public User User { get; set; }
private Subscription[] Subscriptions; private Subscription[] Subscriptions;
private Subscription? CurrentSubscription; private Subscription? CurrentSubscription;
@@ -144,21 +145,21 @@
private async Task Load(LazyLoader lazyLoader) private async Task Load(LazyLoader lazyLoader)
{ {
Subscriptions = SubscriptionRepository.Get().ToArray(); Subscriptions = SubscriptionRepository.Get().ToArray();
CurrentSubscription = await SubscriptionService.GetActiveSubscription(User); CurrentSubscription = await SubscriptionService.GetActiveSubscription(IdentityService.User);
} }
private async Task Cancel() private async Task Cancel()
{ {
if (await AlertService.ConfirmMath()) if (await AlertService.ConfirmMath())
{ {
await SubscriptionService.CancelSubscription(User); await SubscriptionService.CancelSubscription(IdentityService.User);
await LazyLoader.Reload(); await LazyLoader.Reload();
} }
} }
private async Task StartCheckout(Subscription subscription) private async Task StartCheckout(Subscription subscription)
{ {
var url = await BillingService.StartCheckout(User, subscription); var url = await BillingService.StartCheckout(IdentityService.User, subscription);
await PopupService.ShowCentered( await PopupService.ShowCentered(
url, url,

View File

@@ -20,6 +20,7 @@
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@inject DynamicBackgroundService DynamicBackgroundService @inject DynamicBackgroundService DynamicBackgroundService
@inject SmartTranslateService SmartTranslateService @inject SmartTranslateService SmartTranslateService
@inject IdentityService IdentityService
@implements IDisposable @implements IDisposable
@@ -143,8 +144,7 @@
[Parameter] [Parameter]
public string ServerUuid { get; set; } public string ServerUuid { get; set; }
[CascadingParameter]
public User User { get; set; }
[Parameter] [Parameter]
public string? Route { get; set; } public string? Route { get; set; }
@@ -209,7 +209,7 @@
if (CurrentServer != null) if (CurrentServer != null)
{ {
if (CurrentServer.Owner.Id != User!.Id && !User.Admin) if (CurrentServer.Owner.Id != IdentityService.User.Id && !IdentityService.User.Admin)
CurrentServer = null; CurrentServer = null;
} }

View File

@@ -5,10 +5,12 @@
@using Moonlight.App.Services @using Moonlight.App.Services
@using Moonlight.App.ApiClients.Wings @using Moonlight.App.ApiClients.Wings
@using Moonlight.App.Helpers.Wings @using Moonlight.App.Helpers.Wings
@using Moonlight.App.Services.Sessions
@inject WingsApiHelper WingsApiHelper @inject WingsApiHelper WingsApiHelper
@inject WingsJwtHelper WingsJwtHelper @inject WingsJwtHelper WingsJwtHelper
@inject ConfigService ConfigService @inject ConfigService ConfigService
@inject IdentityService IdentityService
<FileManager Access="FileAccess"></FileManager> <FileManager Access="FileAccess"></FileManager>
@@ -17,13 +19,10 @@
[CascadingParameter] [CascadingParameter]
public Server CurrentServer { get; set; } public Server CurrentServer { get; set; }
[CascadingParameter]
public User User { get; set; }
private FileAccess FileAccess; private FileAccess FileAccess;
protected override void OnInitialized() protected override void OnInitialized()
{ {
FileAccess = new WingsFileAccess(WingsApiHelper, WingsJwtHelper, CurrentServer, ConfigService, User); FileAccess = new WingsFileAccess(WingsApiHelper, WingsJwtHelper, CurrentServer, ConfigService, IdentityService.User);
} }
} }

View File

@@ -3,8 +3,10 @@
@using Moonlight.App.Helpers @using Moonlight.App.Helpers
@using Moonlight.App.Helpers.Wings @using Moonlight.App.Helpers.Wings
@using Moonlight.App.Helpers.Wings.Enums @using Moonlight.App.Helpers.Wings.Enums
@using Moonlight.App.Services.Sessions
@inject SmartTranslateService TranslationService @inject SmartTranslateService TranslationService
@inject IdentityService IdentityService
<div class="align-items-center"> <div class="align-items-center">
<div class="row"> <div class="row">
@@ -53,12 +55,12 @@
<div class="row align-items-center"> <div class="row align-items-center">
<div class="col fs-5"> <div class="col fs-5">
<span class="fw-bold"><TL>Shared IP</TL>:</span> <span class="fw-bold"><TL>Shared IP</TL>:</span>
<span class="ms-1 text-muted @(User.StreamerMode ? "blur" : "")">@($"{CurrentServer.Node.Fqdn}:{CurrentServer.MainAllocation?.Port ?? 0}")</span> <span class="ms-1 text-muted @(IdentityService.User.StreamerMode ? "blur" : "")">@($"{CurrentServer.Node.Fqdn}:{CurrentServer.MainAllocation?.Port ?? 0}")</span>
</div> </div>
<div class="col fs-5"> <div class="col fs-5">
<span class="fw-bold"><TL>Server ID</TL>:</span> <span class="fw-bold"><TL>Server ID</TL>:</span>
<span class="ms-1 text-muted"> <span class="ms-1 text-muted">
@if (User.Admin) @if (IdentityService.User.Admin)
{ {
<a href="/admin/servers/view/@(CurrentServer.Id)">@(CurrentServer.Id)</a> <a href="/admin/servers/view/@(CurrentServer.Id)">@(CurrentServer.Id)</a>
} }
@@ -196,8 +198,7 @@
[CascadingParameter] [CascadingParameter]
public Server CurrentServer { get; set; } public Server CurrentServer { get; set; }
[CascadingParameter]
public User User { get; set; }
[CascadingParameter] [CascadingParameter]
public WingsConsole Console { get; set; } public WingsConsole Console { get; set; }

View File

@@ -7,6 +7,7 @@
@using Moonlight.App.Repositories.Servers @using Moonlight.App.Repositories.Servers
@using Microsoft.EntityFrameworkCore @using Microsoft.EntityFrameworkCore
@using Moonlight.App.Exceptions @using Moonlight.App.Exceptions
@using Moonlight.App.Services.Sessions
@inject SubscriptionService SubscriptionService @inject SubscriptionService SubscriptionService
@inject ImageRepository ImageRepository @inject ImageRepository ImageRepository
@@ -15,6 +16,7 @@
@inject ServerRepository ServerRepository @inject ServerRepository ServerRepository
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@inject ServerService ServerService @inject ServerService ServerService
@inject IdentityService IdentityService
<LazyLoader Load="Load"> <LazyLoader Load="Load">
@if (DeployNode == null) @if (DeployNode == null)
@@ -172,8 +174,7 @@
@code @code
{ {
[CascadingParameter]
public User User { get; set; }
private Node? DeployNode; private Node? DeployNode;
private Subscription? Subscription; private Subscription? Subscription;
@@ -190,7 +191,7 @@
Model = new(); Model = new();
await lazyLoader.SetText(SmartTranslateService.Translate("Loading your subscription")); await lazyLoader.SetText(SmartTranslateService.Translate("Loading your subscription"));
Subscription = await SubscriptionService.GetActiveSubscription(User); Subscription = await SubscriptionService.GetActiveSubscription(IdentityService.User);
await lazyLoader.SetText(SmartTranslateService.Translate("Searching for deploy node")); await lazyLoader.SetText(SmartTranslateService.Translate("Searching for deploy node"));
DeployNode = await SmartDeployService.GetNode(); DeployNode = await SmartDeployService.GetNode();
@@ -200,7 +201,7 @@
foreach (var image in images) foreach (var image in images)
{ {
var limit = await SubscriptionService.GetLimit(User, "image." + image.Id); var limit = await SubscriptionService.GetLimit(IdentityService.User, "image." + image.Id);
if (limit.Amount > 0) if (limit.Amount > 0)
{ {
@@ -208,7 +209,7 @@
.Get() .Get()
.Include(x => x.Owner) .Include(x => x.Owner)
.Include(x => x.Image) .Include(x => x.Image)
.Where(x => x.Owner.Id == User.Id) .Where(x => x.Owner.Id == IdentityService.User.Id)
.Count(x => x.Image.Id == image.Id); .Count(x => x.Image.Id == image.Id);
Images.Add(image, limit); Images.Add(image, limit);
@@ -219,7 +220,7 @@
private async Task OnValidSubmit() private async Task OnValidSubmit()
{ {
var limit = await SubscriptionService.GetLimit(User, "image." + Model.Image.Id); var limit = await SubscriptionService.GetLimit(IdentityService.User, "image." + Model.Image.Id);
if (limit.Amount > 0) if (limit.Amount > 0)
{ {
@@ -227,7 +228,7 @@
.Get() .Get()
.Include(x => x.Owner) .Include(x => x.Owner)
.Include(x => x.Image) .Include(x => x.Image)
.Where(x => x.Owner.Id == User.Id) .Where(x => x.Owner.Id == IdentityService.User.Id)
.Count(x => x.Image.Id == Model.Image.Id); .Count(x => x.Image.Id == Model.Image.Id);
if (serversCount < limit.Amount) if (serversCount < limit.Amount)
@@ -241,7 +242,7 @@
cpu, cpu,
memory, memory,
disk, disk,
User, IdentityService.User,
Model.Image, Model.Image,
DeployNode DeployNode
); );

View File

@@ -5,6 +5,7 @@
@using Moonlight.App.Models.Misc @using Moonlight.App.Models.Misc
@using Moonlight.App.Repositories @using Moonlight.App.Repositories
@using Moonlight.App.Services @using Moonlight.App.Services
@using Moonlight.App.Services.Sessions
@using Newtonsoft.Json @using Newtonsoft.Json
@inject Repository<Server> ServerRepository @inject Repository<Server> ServerRepository
@@ -12,6 +13,7 @@
@inject SmartTranslateService SmartTranslateService @inject SmartTranslateService SmartTranslateService
@inject IServiceScopeFactory ServiceScopeFactory @inject IServiceScopeFactory ServiceScopeFactory
@inject IJSRuntime JsRuntime @inject IJSRuntime JsRuntime
@inject IdentityService IdentityService
<LazyLoader @ref="LazyLoader" Load="Load"> <LazyLoader @ref="LazyLoader" Load="Load">
<div class="mx-auto"> <div class="mx-auto">
@@ -119,7 +121,7 @@
<span class="card-text fs-6"> <span class="card-text fs-6">
@(Math.Round(server.Memory / 1024D, 2)) GB / @(Math.Round(server.Disk / 1024D, 2)) GB / @(server.Node.Name) <span class="text-gray-700">- @(server.Image.Name)</span> @(Math.Round(server.Memory / 1024D, 2)) GB / @(Math.Round(server.Disk / 1024D, 2)) GB / @(server.Node.Name) <span class="text-gray-700">- @(server.Image.Name)</span>
</span> </span>
<div class="card-text my-1 fs-6 fw-bold @(User.StreamerMode ? "blur" : "")"> <div class="card-text my-1 fs-6 fw-bold @(IdentityService.User.StreamerMode ? "blur" : "")">
@(server.Node.Fqdn):@(server.MainAllocation.Port) @(server.Node.Fqdn):@(server.MainAllocation.Port)
</div> </div>
<div class="card-text fs-6"> <div class="card-text fs-6">
@@ -186,8 +188,7 @@
@code @code
{ {
[CascadingParameter]
public User User { get; set; }
private Server[] AllServers; private Server[] AllServers;
private LazyLoader LazyLoader; private LazyLoader LazyLoader;
@@ -204,12 +205,12 @@
.Include(x => x.MainAllocation) .Include(x => x.MainAllocation)
.Include(x => x.Node) .Include(x => x.Node)
.Include(x => x.Image) .Include(x => x.Image)
.Where(x => x.Owner.Id == User.Id) .Where(x => x.Owner.Id == IdentityService.User.Id)
.OrderBy(x => x.Name) .OrderBy(x => x.Name)
.ToArray(); .ToArray();
if (string.IsNullOrEmpty(User.ServerListLayoutJson)) if (string.IsNullOrEmpty(IdentityService.User.ServerListLayoutJson))
{ {
ServerGroups.Add(new() ServerGroups.Add(new()
{ {
@@ -220,7 +221,7 @@
else else
{ {
ServerGroups = (JsonConvert.DeserializeObject<ServerGroup[]>( ServerGroups = (JsonConvert.DeserializeObject<ServerGroup[]>(
User.ServerListLayoutJson) ?? Array.Empty<ServerGroup>()).ToList(); IdentityService.User.ServerListLayoutJson) ?? Array.Empty<ServerGroup>()).ToList();
await CheckServerGroups(); await CheckServerGroups();
} }
@@ -282,8 +283,8 @@
await CheckServerGroups(); await CheckServerGroups();
User.ServerListLayoutJson = json; IdentityService.User.ServerListLayoutJson = json;
UserRepository.Update(User); UserRepository.Update(IdentityService.User);
await LazyLoader.Reload(); await LazyLoader.Reload();
} }

View File

@@ -5,10 +5,12 @@
@using Moonlight.App.Services.SupportChat @using Moonlight.App.Services.SupportChat
@using System.Text.RegularExpressions @using System.Text.RegularExpressions
@using Moonlight.App.Services.Files @using Moonlight.App.Services.Files
@using Moonlight.App.Services.Sessions
@inject ResourceService ResourceService @inject ResourceService ResourceService
@inject SupportChatClientService ClientService @inject SupportChatClientService ClientService
@inject SmartTranslateService SmartTranslateService @inject SmartTranslateService SmartTranslateService
@inject IdentityService IdentityService
@implements IDisposable @implements IDisposable
@@ -20,7 +22,7 @@
<div class="scroll-y me-n5 pe-5" style="max-height: 55vh; display: flex; flex-direction: column-reverse;"> <div class="scroll-y me-n5 pe-5" style="max-height: 55vh; display: flex; flex-direction: column-reverse;">
@foreach (var message in Messages.ToArray()) @foreach (var message in Messages.ToArray())
{ {
if (message.Sender == null || message.Sender.Id != User.Id) if (message.Sender == null || message.Sender.Id != IdentityService.User.Id)
{ {
<div class="d-flex justify-content-start mb-10 "> <div class="d-flex justify-content-start mb-10 ">
<div class="d-flex flex-column align-items-start"> <div class="d-flex flex-column align-items-start">
@@ -199,9 +201,6 @@
@code @code
{ {
[CascadingParameter]
public User User { get; set; }
private List<SupportChatMessage> Messages = new(); private List<SupportChatMessage> Messages = new();
private string[] Typing = Array.Empty<string>(); private string[] Typing = Array.Empty<string>();

View File

@@ -4,10 +4,11 @@
@using Moonlight.App.Services @using Moonlight.App.Services
@using Moonlight.Shared.Components.WebsiteControl @using Moonlight.Shared.Components.WebsiteControl
@using Microsoft.EntityFrameworkCore @using Microsoft.EntityFrameworkCore
@using Moonlight.App.Services.Interop @using Moonlight.App.Services.Sessions
@inject Repository<WebSpace> WebSpaceRepository @inject Repository<WebSpace> WebSpaceRepository
@inject WebSpaceService WebSpaceService @inject WebSpaceService WebSpaceService
@inject IdentityService IdentityService
<LazyLoader Load="Load"> <LazyLoader Load="Load">
@if (CurrentWebspace == null) @if (CurrentWebspace == null)
@@ -97,9 +98,6 @@
[Parameter] [Parameter]
public string? Route { get; set; } public string? Route { get; set; }
[CascadingParameter]
public User User { get; set; }
private WebSpace? CurrentWebspace; private WebSpace? CurrentWebspace;
private bool HostOnline = false; private bool HostOnline = false;
@@ -113,7 +111,7 @@
if (CurrentWebspace != null) if (CurrentWebspace != null)
{ {
if (CurrentWebspace.Owner.Id != User!.Id && !User.Admin) if (CurrentWebspace.Owner.Id != IdentityService.User.Id && !IdentityService.User.Admin)
CurrentWebspace = null; CurrentWebspace = null;
} }

View File

@@ -4,6 +4,7 @@
@using Moonlight.App.Models.Forms @using Moonlight.App.Models.Forms
@using Moonlight.App.Repositories @using Moonlight.App.Repositories
@using Microsoft.EntityFrameworkCore @using Microsoft.EntityFrameworkCore
@using Moonlight.App.Services.Sessions
@inject SubscriptionService SubscriptionService @inject SubscriptionService SubscriptionService
@inject WebSpaceService WebSpaceService @inject WebSpaceService WebSpaceService
@@ -11,6 +12,7 @@
@inject SmartDeployService SmartDeployService @inject SmartDeployService SmartDeployService
@inject SmartTranslateService SmartTranslateService @inject SmartTranslateService SmartTranslateService
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@inject IdentityService IdentityService
<LazyLoader Load="Load"> <LazyLoader Load="Load">
@if (CloudPanel == null) @if (CloudPanel == null)
@@ -110,8 +112,7 @@
@code @code
{ {
[CascadingParameter]
public User User { get; set; }
private Subscription? Subscription; private Subscription? Subscription;
private CloudPanel? CloudPanel; private CloudPanel? CloudPanel;
@@ -125,7 +126,7 @@
Model = new(); Model = new();
await lazyLoader.SetText(SmartTranslateService.Translate("Loading your subscription")); await lazyLoader.SetText(SmartTranslateService.Translate("Loading your subscription"));
Subscription = await SubscriptionService.GetActiveSubscription(User); Subscription = await SubscriptionService.GetActiveSubscription(IdentityService.User);
await lazyLoader.SetText(SmartTranslateService.Translate("Searching for deploy web host")); await lazyLoader.SetText(SmartTranslateService.Translate("Searching for deploy web host"));
CloudPanel = await SmartDeployService.GetCloudPanel(); CloudPanel = await SmartDeployService.GetCloudPanel();
@@ -133,7 +134,7 @@
AllowOrder = WebSpaceRepository AllowOrder = WebSpaceRepository
.Get() .Get()
.Include(x => x.Owner) .Include(x => x.Owner)
.Count(x => x.Owner.Id == User.Id) < (await SubscriptionService.GetLimit(User, "websites")).Amount; .Count(x => x.Owner.Id == IdentityService.User.Id) < (await SubscriptionService.GetLimit(IdentityService.User, "websites")).Amount;
} }
private async Task OnValidSubmit() private async Task OnValidSubmit()
@@ -141,9 +142,9 @@
if (WebSpaceRepository if (WebSpaceRepository
.Get() .Get()
.Include(x => x.Owner) .Include(x => x.Owner)
.Count(x => x.Owner.Id == User.Id) < (await SubscriptionService.GetLimit(User, "websites")).Amount) .Count(x => x.Owner.Id == IdentityService.User.Id) < (await SubscriptionService.GetLimit(IdentityService.User, "websites")).Amount)
{ {
var webSpace = await WebSpaceService.Create(Model.BaseDomain, User, CloudPanel); var webSpace = await WebSpaceService.Create(Model.BaseDomain, IdentityService.User, CloudPanel);
NavigationManager.NavigateTo($"/webspace/{webSpace.Id}"); NavigationManager.NavigateTo($"/webspace/{webSpace.Id}");
} }

View File

@@ -2,8 +2,10 @@
@using Moonlight.App.Database.Entities @using Moonlight.App.Database.Entities
@using Moonlight.App.Repositories @using Moonlight.App.Repositories
@using Microsoft.EntityFrameworkCore @using Microsoft.EntityFrameworkCore
@using Moonlight.App.Services.Sessions
@inject Repository<WebSpace> WebSpaceRepository @inject Repository<WebSpace> WebSpaceRepository
@inject IdentityService IdentityService
<LazyLoader Load="Load"> <LazyLoader Load="Load">
@if (WebSpaces.Any()) @if (WebSpaces.Any())
@@ -50,8 +52,7 @@
@code @code
{ {
[CascadingParameter]
public User User { get; set; }
private WebSpace[] WebSpaces; private WebSpace[] WebSpaces;
@@ -61,7 +62,7 @@
.Get() .Get()
.Include(x => x.Owner) .Include(x => x.Owner)
.Include(x => x.CloudPanel) .Include(x => x.CloudPanel)
.Where(x => x.Owner.Id == User.Id) .Where(x => x.Owner.Id == IdentityService.User.Id)
.ToArray(); .ToArray();
return Task.CompletedTask; return Task.CompletedTask;

View File

@@ -9,7 +9,6 @@
@using Moonlight @using Moonlight
@using Moonlight.App.Perms @using Moonlight.App.Perms
@using Moonlight.Shared.Components @using Moonlight.Shared.Components
@using Moonlight.Shared.Components.StateLogic
@using Moonlight.Shared.Components.Alerts @using Moonlight.Shared.Components.Alerts
@using Moonlight.Shared.Components.Forms @using Moonlight.Shared.Components.Forms
@using Moonlight.Shared.Components.Partials @using Moonlight.Shared.Components.Partials