mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 11:44:56 +00:00
b42c7d6de6
- I implemented a command-based architecture for Govor.Console. - Each of your actions (e.g., login, send friend request, list friends) is now encapsulated in its own command class inheriting from BaseCommand. - I integrated friend-related functionalities (search, list, send/accept/reject request, block/unblock) using a mix of SignalR Hub and REST API calls. - I included admin functionalities for managing friendships (list all, list user's, remove). - I added a /help (-h) command to display available commands and their usage. - I refactored Program.cs to handle command parsing and execution. - I updated FriendsClient.cs, removing methods now handled directly by commands via SignalR. - I added SignalR event handlers for real-time notifications (friend requests, accepts, etc.).
54 lines
2.2 KiB
C#
54 lines
2.2 KiB
C#
using System;
|
|
using System.Net.Http.Headers;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Govor.ConsoleClient.Commands
|
|
{
|
|
public class RegisterCommand : BaseCommand
|
|
{
|
|
public override async Task ExecuteAsync(string? argument)
|
|
{
|
|
Console.Write("username: ");
|
|
var regUsername = Console.ReadLine();
|
|
|
|
Console.Write("password: ");
|
|
var regPassword = Console.ReadLine();
|
|
|
|
Console.Write("invitation code: ");
|
|
var inviteCode = Console.ReadLine();
|
|
|
|
if (string.IsNullOrWhiteSpace(regUsername) || string.IsNullOrWhiteSpace(regPassword) || string.IsNullOrWhiteSpace(inviteCode))
|
|
{
|
|
Console.WriteLine("[Ошибка] Имя пользователя, пароль и код приглашения не могут быть пустыми.");
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
var authToken = await HttpClientService.RegisterAsync(regUsername, regPassword, inviteCode);
|
|
SetAuthToken(authToken);
|
|
|
|
// Initialize FriendsClient after successful registration
|
|
var sharedClient = new HttpClient { BaseAddress = new Uri(HttpClientService.GetBaseUrl()) };
|
|
sharedClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authToken);
|
|
var friendsClient = new FriendsClient(sharedClient);
|
|
|
|
// Re-initialize services in BaseCommand with the new FriendsClient
|
|
InitializeServices(friendsClient, HttpClientService, GetAuthToken, SetAuthToken, InitializeHubConnectionAsync, HubConnection);
|
|
|
|
await InitializeHubConnectionAsync();
|
|
Console.WriteLine("[Успех] Регистрация завершена. Токен сохранен.");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"[Ошибка] {ex.Message}");
|
|
}
|
|
}
|
|
|
|
public override string GetHelp()
|
|
{
|
|
return "/reg - Зарегистрировать новый аккаунт с помощью кода приглашения.";
|
|
}
|
|
}
|
|
}
|