Add user identity system with channel pairing and web /link command
Introduce Luna.Identity project with user identity service, pairing code generation, and channel linking. Channels (Telegram, CLI) now verify link status before routing messages and prompt users to pair via the web interface. WebChannel handles /link <channel-type> <code> commands to complete the pairing flow. Fix inverted expiration check in IsPairingCodeExpired that caused codes to be treated as expired immediately after creation.
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
using Luna.Channels.Abstractions;
|
||||
using Luna.Core.Abstractions;
|
||||
using Luna.Identity.Abstractions;
|
||||
using Luna.Shared;
|
||||
|
||||
namespace Luna.Channels.Cli;
|
||||
|
||||
public class CliChannel(string channelId, IChatHubContext hubContext) : IChannel
|
||||
public class CliChannel(
|
||||
string channelId,
|
||||
IChatHubContext hubContext,
|
||||
IUserIdentityService identityService)
|
||||
: IChannel
|
||||
{
|
||||
public string ChannelId { get; } = channelId;
|
||||
public string ChannelType => Abstractions.ChannelType.Cli;
|
||||
@@ -14,6 +19,26 @@ public class CliChannel(string channelId, IChatHubContext hubContext) : IChannel
|
||||
public event ChannelMessageReceivedEventHandler? MessageReceived;
|
||||
public event ChannelConnectionChangedEventHandler? ConnectionStateChanged;
|
||||
|
||||
public async Task<bool> VerifyChannelLinkAsync()
|
||||
{
|
||||
var currentUser = identityService.GetCurrentUser();
|
||||
|
||||
if (identityService.IsChannelLinked(currentUser.UserId, ChannelType))
|
||||
return true;
|
||||
|
||||
var pairingCode = identityService.StartChannelLink(currentUser.UserId, ChannelType);
|
||||
await SendMessageAsync(new ChannelMessage(
|
||||
MessageId: Guid.NewGuid().ToString(),
|
||||
ConversationId: Guid.NewGuid().ToString(),
|
||||
SenderId: Guid.NewGuid().ToString(),
|
||||
SenderName: "luna",
|
||||
Content:
|
||||
$"{ChannelType} channel is not linked to current user.\nGo to web interface and execute command \"/link [pairing code]\".\nYou will have to provide following PairingCode: {pairingCode}",
|
||||
Timestamp: DateTimeOffset.UtcNow));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public async Task SendStreamingMessageAsync(IAsyncEnumerable<ChatStreamUpdate> messageStream, CancellationToken cancellationToken = default)
|
||||
{
|
||||
await hubContext.SendStreamingResponseAsync(ChannelId, messageStream, cancellationToken);
|
||||
|
||||
Reference in New Issue
Block a user