I'm developing an application that is a shortened version of a web system, this system was developed in PHP. For the application, I am developing in xamarin forms, however via web api I am trying to make the login screen, but when entering any login or password it is logging in, and this could not happen, it should log in only when entering user data saved in the database. Below my code:
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 nome de usuário válido", "Aceitar");
emailEntry.Focus();
return;
}
if (string.IsNullOrEmpty(senhaEntry.Text))
{
await DisplayAlert("Erro", "Digite uma senha", "Aceitar");
emailEntry.Focus();
return;
}
this.logar();
App.Current.MainPage = new MainPageRoot();
}
private async void logar()
{
waitActivityIndicator.IsRunning = true;
var loginRequest = new LoginRequest
{
Usuario = emailEntry.Text,
Senha = senhaEntry.Text,
};
var JsonRequest = JsonConvert.SerializeObject(loginRequest);
var httpContent = new StringContent(JsonRequest);
var resp = string.Empty;
try
{
var client = new HttpClient();
client.BaseAddress = new Uri("http://ativoproject.ebasesistemas.com.br");
var url = "http://ativoproject.ebasesistemas.com.br/login.php";
var result = await client.PostAsync(url, httpContent);
if (!result.IsSuccessStatusCode)
{
await DisplayAlert("Erro", "Usuario ou senha incorretos", "Aceitar");
waitActivityIndicator.IsRunning = false;
return;
}
resp = await result.Content.ReadAsStringAsync();
}
catch (Exception ex)
{
await DisplayAlert("Erro", ex.Message, "Aceitar");
waitActivityIndicator.IsRunning = false;
return;
}
var user = JsonConvert.DeserializeObject<Colaborador>(resp);
waitActivityIndicator.IsRunning = false;
await DisplayAlert("Bem vindo","vc esta logado", "Aceitar");
}
}
Contributor.cs
public class Colaborador
{
public int ColaboradorID { get; set; }
public string Nome { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
public bool Inativo { get; set; }
}
LoginRequest.cs
class LoginRequest
{
public string Usuario { get; set; }
public string Senha { get; set; }
}
And this is the system link on the web: link