diff --git a/Moonlight/App/Models/Misc/Session.cs b/Moonlight/App/Models/Misc/Session.cs index 3342021f..50676b0c 100644 --- a/Moonlight/App/Models/Misc/Session.cs +++ b/Moonlight/App/Models/Misc/Session.cs @@ -1,14 +1,15 @@ using Microsoft.AspNetCore.Components; +using Moonlight.App.Database.Entities; using Moonlight.App.Services.Interop; namespace Moonlight.App.Models.Misc; public class Session { - public string Ip { get; set; } - public string Url { get; set; } - public string Device { get; set; } - public int UserId { get; set; } + public string Ip { get; set; } = "N/A"; + public string Url { get; set; } = "N/A"; + public string Device { get; set; } = "N/A"; + public User? User { get; set; } public DateTime CreatedAt { get; set; } public NavigationManager Navigation { get; set; } public AlertService AlertService { get; set; } diff --git a/Moonlight/App/Services/Interop/AlertService.cs b/Moonlight/App/Services/Interop/AlertService.cs index f64e2214..d03d4ef9 100644 --- a/Moonlight/App/Services/Interop/AlertService.cs +++ b/Moonlight/App/Services/Interop/AlertService.cs @@ -67,7 +67,7 @@ public class AlertService return result.IsConfirmed; } - public async Task Text(string title, string desciption, string setValue) + public async Task Text(string title, string desciption, string setValue) { var result = await SweetAlertService.FireAsync(new SweetAlertOptions() { diff --git a/Moonlight/App/Services/Sessions/SessionService.cs b/Moonlight/App/Services/Sessions/SessionService.cs index b6b07fd9..1ecbd67d 100644 --- a/Moonlight/App/Services/Sessions/SessionService.cs +++ b/Moonlight/App/Services/Sessions/SessionService.cs @@ -13,7 +13,7 @@ public class SessionService private readonly NavigationManager NavigationManager; private readonly AlertService AlertService; - private Session OwnSession; + private Session? OwnSession; public SessionService( SessionRepository sessionRepository, @@ -30,18 +30,14 @@ public class SessionService public async Task Register() { var user = await IdentityService.Get(); - var userId = -1; - - if (user != null) - userId = user.Id; - + OwnSession = new Session() { Ip = IdentityService.GetIp(), Url = NavigationManager.Uri, Device = IdentityService.GetDevice(), CreatedAt = DateTime.Now, - UserId = userId, + User = user, Navigation = NavigationManager, AlertService = AlertService }; @@ -68,7 +64,7 @@ public class SessionService { foreach (var session in SessionRepository.Get()) { - if (session.UserId == user.Id) + if (session.User.Id == user.Id) { session.Navigation.NavigateTo(session.Navigation.Uri, true); } diff --git a/Moonlight/Shared/Components/Navigations/AdminSessionNavigation.razor b/Moonlight/Shared/Components/Navigations/AdminSessionNavigation.razor new file mode 100644 index 00000000..58313635 --- /dev/null +++ b/Moonlight/Shared/Components/Navigations/AdminSessionNavigation.razor @@ -0,0 +1,22 @@ +
+
+ +
+
+ +@code +{ + [Parameter] + public int Index { get; set; } = 0; +} \ No newline at end of file diff --git a/Moonlight/Shared/Views/Admin/Users/Index.razor b/Moonlight/Shared/Views/Admin/Users/Index.razor new file mode 100644 index 00000000..a104f71b --- /dev/null +++ b/Moonlight/Shared/Views/Admin/Users/Index.razor @@ -0,0 +1,7 @@ +@page "/admin/users" + +@using Moonlight.Shared.Components.Navigations + + + + \ No newline at end of file diff --git a/Moonlight/Shared/Views/Admin/Users/Sessions.razor b/Moonlight/Shared/Views/Admin/Users/Sessions.razor new file mode 100644 index 00000000..bd4b593a --- /dev/null +++ b/Moonlight/Shared/Views/Admin/Users/Sessions.razor @@ -0,0 +1,185 @@ +@page "/admin/users/sessions" + +@using Moonlight.Shared.Components.Navigations +@using Moonlight.App.Services.Sessions +@using BlazorTable +@using Logging.Net +@using Moonlight.App.Helpers +@using Moonlight.App.Models.Misc +@using Moonlight.App.Services +@using Moonlight.App.Services.Interop + +@inject SessionService SessionService +@inject SmartTranslateService SmartTranslateService +@inject AlertService AlertService + + + + +
+ + + + + @if (AllSessions == null) + { +
+ + Loading sessions +
+ } + else + { + + + + + + + + + + + + + + + + + +
+ } +
+
+
+ +@code +{ + private Session[]? AllSessions; + + private Task Load(LazyLoader arg) + { + AllSessions = SessionService.GetAll(); + + Task.Run(async () => + { + while (true) + { + try + { + await Refresh(); + await Task.Delay(1000); + } + catch (Exception e) + { + Logger.Warn("Error autorefreshing sessions"); + Logger.Warn(e); + } + } + }); + + return Task.CompletedTask; + } + + private async Task Refresh() + { + AllSessions = SessionService.GetAll(); + await InvokeAsync(StateHasChanged); + } + + private async Task Navigate(Session session) + { + var url = await AlertService.Text("URL", SmartTranslateService.Translate("Enter url"), ""); + + if(url == null) + return; + + if (url == "") + return; + + if (url == "null") + return; + + session.Navigation.NavigateTo(url, true); + } + + private async Task MessageAll() + { + var message = await AlertService.Text( + SmartTranslateService.Translate("Enter message"), + SmartTranslateService.Translate("Enter the message to send"), + "" + ); + + var b = await AlertService.YesNo( + SmartTranslateService.Translate("Confirm"), + SmartTranslateService.Translate("Are you sure?"), + SmartTranslateService.Translate("Yes"), + SmartTranslateService.Translate("No") + ); + + if (b) + { + foreach (var session in SessionService.GetAll()) + { + try + { + await session.AlertService.Warning("Admin Message", message); + } + catch (Exception e) + { + Logger.Warn("Error sending user a alert"); + Logger.Warn(e); + } + } + } + } + + private async Task Message(Session session) + { + var message = await AlertService.Text( + SmartTranslateService.Translate("Enter message"), + SmartTranslateService.Translate("Enter the message to send"), + "" + ); + + var b = await AlertService.YesNo( + SmartTranslateService.Translate("Confirm"), + SmartTranslateService.Translate("Are you sure?"), + SmartTranslateService.Translate("Yes"), + SmartTranslateService.Translate("No") + ); + + if (b) + { + try + { + await session.AlertService.Warning("Admin Message", message); + } + catch (Exception e) + { + Logger.Warn("Error sending user a alert"); + Logger.Warn(e); + } + } + } +} \ No newline at end of file diff --git a/Moonlight/obj/Debug/net6.0/Moonlight.GeneratedMSBuildEditorConfig.editorconfig b/Moonlight/obj/Debug/net6.0/Moonlight.GeneratedMSBuildEditorConfig.editorconfig index f6afa011..52b9b6f9 100644 --- a/Moonlight/obj/Debug/net6.0/Moonlight.GeneratedMSBuildEditorConfig.editorconfig +++ b/Moonlight/obj/Debug/net6.0/Moonlight.GeneratedMSBuildEditorConfig.editorconfig @@ -83,6 +83,10 @@ build_metadata.AdditionalFiles.CssScope = build_metadata.AdditionalFiles.TargetPath = U2hhcmVkXENvbXBvbmVudHNcRm9ybXNcV0J1dHRvbi5yYXpvcg== build_metadata.AdditionalFiles.CssScope = +[C:/Users/marce/GitHub/Moonlight-Panel/Moonlight/Moonlight/Shared/Components/Navigations/AdminSessionNavigation.razor] +build_metadata.AdditionalFiles.TargetPath = U2hhcmVkXENvbXBvbmVudHNcTmF2aWdhdGlvbnNcQWRtaW5TZXNzaW9uTmF2aWdhdGlvbi5yYXpvcg== +build_metadata.AdditionalFiles.CssScope = + [C:/Users/marce/GitHub/Moonlight-Panel/Moonlight/Moonlight/Shared/Components/Navigations/AdminSystemNavigation.razor] build_metadata.AdditionalFiles.TargetPath = U2hhcmVkXENvbXBvbmVudHNcTmF2aWdhdGlvbnNcQWRtaW5TeXN0ZW1OYXZpZ2F0aW9uLnJhem9y build_metadata.AdditionalFiles.CssScope = @@ -259,6 +263,14 @@ build_metadata.AdditionalFiles.CssScope = build_metadata.AdditionalFiles.TargetPath = U2hhcmVkXFZpZXdzXEFkbWluXFN5c1xMb2dzLnJhem9y build_metadata.AdditionalFiles.CssScope = +[C:/Users/marce/GitHub/Moonlight-Panel/Moonlight/Moonlight/Shared/Views/Admin/Users/Index.razor] +build_metadata.AdditionalFiles.TargetPath = U2hhcmVkXFZpZXdzXEFkbWluXFVzZXJzXEluZGV4LnJhem9y +build_metadata.AdditionalFiles.CssScope = + +[C:/Users/marce/GitHub/Moonlight-Panel/Moonlight/Moonlight/Shared/Views/Admin/Users/Sessions.razor] +build_metadata.AdditionalFiles.TargetPath = U2hhcmVkXFZpZXdzXEFkbWluXFVzZXJzXFNlc3Npb25zLnJhem9y +build_metadata.AdditionalFiles.CssScope = + [C:/Users/marce/GitHub/Moonlight-Panel/Moonlight/Moonlight/Shared/Views/Domains.razor] build_metadata.AdditionalFiles.TargetPath = U2hhcmVkXFZpZXdzXERvbWFpbnMucmF6b3I= build_metadata.AdditionalFiles.CssScope = diff --git a/Moonlight/resources/lang/de_de.lang b/Moonlight/resources/lang/de_de.lang index df3125aa..20e451e6 100644 --- a/Moonlight/resources/lang/de_de.lang +++ b/Moonlight/resources/lang/de_de.lang @@ -278,3 +278,15 @@ Memory usage;Memory usage Moonlight is using;Moonlight is using of memory;of memory Cpu usage;Cpu usage +Refresh;Refresh +Send a message to all users;Send a message to all users +IP;IP +URL;URL +Device;Device +Change url;Change url +Message;Message +Enter message;Enter message +Enter the message to send;Enter the message to send +Confirm;Confirm +Are you sure?;Are you sure? +Enter url;Enter url