The only feasible exit was bypassing the system, hence my login page was as follows:
LoginPage.xaml.cs
public partial class LoginPage : TabbedPage
{
public LoginPage()
{
InitializeComponent();
NavigationPage.SetHasNavigationBar(this, false);
}
protected async void btnLogin_Clicked(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(emailEntry.Text))
{
await DisplayAlert("Erro", "Digite um usuário válido", "Aceitar");
emailEntry.Focus();
return;
}
if (string.IsNullOrEmpty(senhaEntry.Text))
{
await DisplayAlert("Erro", "Digite uma senha", "Aceitar");
senhaEntry.Focus();
return;
}
try
{
waitActivityIndicator.IsRunning = true;
var loginRequest = new Login
{
UserName = emailEntry.Text,
Password = senhaEntry.Text,
};
//invocar serviço
waitActivityIndicator.IsRunning = false;
Device.BeginInvokeOnMainThread(() => App.Current.MainPage = new MainPageRoot());
}
catch (Exception ex)
{
waitActivityIndicator.IsRunning = false;
await DisplayAlert("Erro", "Usuário ou Senha Incorretos", "Aceitar");
}
}
}
LoginService.cs
public async void Logar(Login login)
{
var jsonRequest = JsonConvert.SerializeObject(login);
var httpContent = new StringContent(jsonRequest, Encoding.UTF8, "application/json");
var resp = string.Empty;
try
{
var client = new HttpClient();
client.BaseAddress = new Uri($"{BaseAddress}/_signin.php?usuario={login.UserName}&senha={login.Password}");
var url = "";
var result = await client.PostAsync(url, httpContent);
if (!result.IsSuccessStatusCode)
{
throw new Exception(result.RequestMessage.Content.ToString());
}
resp = await result.Content.ReadAsStringAsync();
//verificar resposta do ws
var user = JsonConvert.DeserializeObject<Colaborador>(resp);
}
catch (Exception)
{
throw;
}
}