61 lines
2.5 KiB
C#
61 lines
2.5 KiB
C#
using System;
|
|
using System.Net.Http;
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Seeds_Lab_SVN_Dashboard.Commands
|
|
{
|
|
internal class Deluseringroup
|
|
{
|
|
public static async Task SVNDelUserInGroup(string groupName, string username)
|
|
{
|
|
try
|
|
{
|
|
// Construire l'URL de l'API
|
|
string apiUrl = $"{logon.host}/action/deleteuseringroup";
|
|
|
|
using (HttpClientHandler handler = new HttpClientHandler())
|
|
{
|
|
// Ignorer les erreurs de certificat SSL
|
|
handler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true;
|
|
|
|
using (HttpClient client = new HttpClient(handler))
|
|
{
|
|
// Ajouter le token API dans les headers
|
|
client.DefaultRequestHeaders.Add("x-api-key", logon.token);
|
|
|
|
// Créer le corps de la requête en JSON
|
|
var requestBody = new
|
|
{
|
|
groupName = groupName,
|
|
username = username
|
|
};
|
|
string jsonBody = JsonSerializer.Serialize(requestBody);
|
|
HttpContent content = new StringContent(jsonBody, Encoding.UTF8, "application/json");
|
|
|
|
// Envoyer la requête POST
|
|
HttpResponseMessage response = await client.PostAsync(apiUrl, content);
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
// Lire la réponse JSON
|
|
string jsonResponse = await response.Content.ReadAsStringAsync();
|
|
MessageBox.Show($"Utilisateur '{username}' supprimé du groupe '{groupName}'.", "Succès", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show($"Erreur API: {response.StatusCode} - {await response.Content.ReadAsStringAsync()}", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show($"Erreur lors de la suppression de l'utilisateur: {ex.Message}", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
}
|
|
}
|