-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #434 from Moonlight-Panel/v2_UpgradeMoonCore
Upgrade to new MoonCore version
- Loading branch information
Showing
122 changed files
with
2,491 additions
and
1,575 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
using MoonCore.Helpers; | ||
using MoonCore.Attributes; | ||
using MoonCore.Helpers; | ||
|
||
namespace Moonlight.Core.Events; | ||
|
||
[Singleton] | ||
public class CoreEvents | ||
{ | ||
public static SmartEventHandler OnMoonlightRestart { get; set; } = new(); | ||
public CoreEvents(ILogger<SmartEventHandler> logger) | ||
{ | ||
OnMoonlightRestart = new(logger); | ||
} | ||
|
||
public SmartEventHandler OnMoonlightRestart { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using MoonCore.Abstractions; | ||
using MoonCore.Services; | ||
using Moonlight.Core.Database.Entities; | ||
|
||
namespace Moonlight.Core.Extensions; | ||
|
||
public static class IdentityServiceExtensions | ||
{ | ||
public static User GetUser(this IdentityService identityService) | ||
{ | ||
return identityService.Storage.Get<User>(); | ||
} | ||
|
||
public static Task<bool> HasFlag(this IdentityService identityService, string flag) | ||
{ | ||
if (!identityService.IsAuthenticated) | ||
return Task.FromResult(false); | ||
|
||
var result = identityService.GetUser().Flags.Split(";").Contains(flag); | ||
return Task.FromResult(result); | ||
} | ||
|
||
public static Task SetFlag(this IdentityService identityService, string flag, bool toggle) | ||
{ | ||
if (!identityService.IsAuthenticated) | ||
return Task.CompletedTask; | ||
|
||
var user = identityService.GetUser(); | ||
|
||
// Rebuild flags | ||
var flags = user.Flags.Split(";").ToList(); | ||
|
||
if (toggle) | ||
{ | ||
if(!flags.Contains(flag)) | ||
flags.Add(flag); | ||
} | ||
else | ||
{ | ||
if (flags.Contains(flag)) | ||
flags.Remove(flag); | ||
} | ||
|
||
user.Flags = string.Join(';', flags); | ||
|
||
// Save changes | ||
var serviceProvider = identityService.Storage.Get<IServiceProvider>(); | ||
var userRepo = serviceProvider.GetRequiredService<Repository<User>>(); | ||
|
||
userRepo.Update(user); | ||
|
||
return Task.CompletedTask; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using MoonCore.Abstractions; | ||
using MoonCore.Helpers; | ||
using Moonlight.Core.Database.Entities; | ||
|
||
namespace Moonlight.Core.Helpers; | ||
|
||
public class AuthenticationStateProvider : MoonCore.Abstractions.AuthenticationStateProvider | ||
{ | ||
public override Task<bool> IsValidIdentifier(IServiceProvider provider, string identifier) | ||
{ | ||
if(!int.TryParse(identifier, out int searchId)) | ||
return Task.FromResult(false); | ||
|
||
var userRepo = provider.GetRequiredService<Repository<User>>(); | ||
var result = userRepo.Get().Any(x => x.Id == searchId); | ||
|
||
return Task.FromResult(result); | ||
} | ||
|
||
public override Task LoadFromIdentifier(IServiceProvider provider, string identifier, DynamicStorage storage) | ||
{ | ||
if(!int.TryParse(identifier, out int searchId)) | ||
return Task.CompletedTask; | ||
|
||
var userRepo = provider.GetRequiredService<Repository<User>>(); | ||
var user = userRepo.Get().FirstOrDefault(x => x.Id == searchId); | ||
|
||
if(user == null) | ||
return Task.CompletedTask; | ||
|
||
storage.Set("User", user); | ||
storage.Set("ServiceProvider", provider); | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
public override Task<DateTime> DetermineTokenValidTimestamp(IServiceProvider provider, string identifier) | ||
{ | ||
if(!int.TryParse(identifier, out int searchId)) | ||
return Task.FromResult(DateTime.MaxValue); | ||
|
||
var userRepo = provider.GetRequiredService<Repository<User>>(); | ||
var user = userRepo.Get().FirstOrDefault(x => x.Id == searchId); | ||
|
||
if(user == null) | ||
return Task.FromResult(DateTime.MaxValue); | ||
|
||
return Task.FromResult(user.TokenValidTimestamp); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.