Sikeres POST az eszközről
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.Net.Http;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http.Json;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using WorkFlowCheck.Common.DTO;
|
||||
using System.Text.Json.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace WorkFlowCheck.MAUI.Services
|
||||
{
|
||||
@@ -46,20 +50,37 @@ namespace WorkFlowCheck.MAUI.Services
|
||||
};
|
||||
}
|
||||
}
|
||||
public async Task<ApiResponseDTO<UserDTO>> Login(string username, string password)
|
||||
public async Task<ApiResponseDTO<UserDTO>> Authenticate(string username, string password)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Az API végpont meghatározása
|
||||
string endpoint = $"{_httpClient.BaseAddress}api/User/Login";
|
||||
string endpoint = $"{_httpClient.BaseAddress}api/user/authenticate";
|
||||
|
||||
// HTTP GET kérés küldése
|
||||
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<UserDTO>>(endpoint);
|
||||
|
||||
return response ?? new ApiResponseDTO<UserDTO>
|
||||
var userDTO = new UserDTO()
|
||||
{
|
||||
IsSuccess = false,
|
||||
Email = "",
|
||||
FirstName = "",
|
||||
LastName = "",
|
||||
Id = 0,
|
||||
UserName = username,
|
||||
Password = password,
|
||||
};
|
||||
|
||||
// HTTP POST kérés küldése
|
||||
|
||||
using (HttpResponseMessage httpResponseMessage = await _httpClient.PostAsJsonAsync(endpoint, userDTO))
|
||||
{
|
||||
httpResponseMessage.EnsureSuccessStatusCode();
|
||||
|
||||
var jsonString = await httpResponseMessage.Content.ReadAsStringAsync();
|
||||
var response = JsonConvert.DeserializeObject<ApiResponseDTO<UserDTO>>(jsonString);
|
||||
|
||||
return response ?? new ApiResponseDTO<UserDTO>
|
||||
{
|
||||
IsSuccess = false,
|
||||
};
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user