IW4M-Admin/SharedLibraryCore/Commands/RequestTokenCommand.cs

36 lines
1.2 KiB
C#
Raw Normal View History

2022-01-26 11:32:16 -05:00
using System.Threading.Tasks;
using Data.Models.Client;
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Helpers;
using SharedLibraryCore.Interfaces;
namespace SharedLibraryCore.Commands
{
/// <summary>
2022-01-26 11:32:16 -05:00
/// Generates a token for use in webfront login
/// </summary>
public class RequestTokenCommand : Command
{
public RequestTokenCommand(CommandConfiguration config, ITranslationLookup lookup) : base(config, lookup)
{
Name = "requesttoken";
Description = lookup["COMMANDS_GENERATETOKEN_DESC"];
Alias = "rt";
Permission = EFClient.Permission.Trusted;
RequiresTarget = false;
}
public override Task ExecuteAsync(GameEvent gameEvent)
{
var state = gameEvent.Owner.Manager.TokenAuthenticator.GenerateNextToken(new TokenIdentifier
{
2022-06-16 11:07:03 -04:00
ClientId = gameEvent.Origin.ClientId
});
gameEvent.Origin.Tell(string.Format(_translationLookup["COMMANDS_GENERATETOKEN_SUCCESS"], state.Token,
$"{state.RemainingTime} {_translationLookup["GLOBAL_MINUTES"]}", gameEvent.Origin.ClientId));
return Task.CompletedTask;
}
}
}