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