Skip to content

Commit

Permalink
Updated login.
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelcanosantana committed Nov 26, 2023
1 parent 353a548 commit 9d18f10
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
17 changes: 15 additions & 2 deletions Pages/Login.razor
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!-- Bindings explained: https://stackoverflow.com/questions/58221915/difference-between-bind-and-bind-value -->

@inject Services.UserService UserService
@inject NavigationManager NavigationManager
@page "/login"

<PageTitle>Iniciar Sesión | Cirsa</PageTitle>
Expand Down Expand Up @@ -34,7 +35,7 @@
<input @bind="isRememberingUser" type="checkbox" class="form-check-input" id="rememberUserCheck">
<label class="form-check-label" for="exampleCheck1">Recordar usuario</label>
</div>
<button class="btn button-gold-a">Continuar</button>
<button type="submit" @onclick="TryLogin" class="btn button-gold-a">Continuar</button>

</form>

Expand All @@ -50,5 +51,17 @@
private String email = "";
private String password = "";
private bool isRememberingUser = false;


private void TryLogin()
{

var result = UserService.TryLoginUser(email, password);

if (result.Item1 == true)
{
NavigationManager.NavigateTo("weather");
}
}
}

17 changes: 13 additions & 4 deletions Services/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,27 @@ public Tuple<bool, String> TryRegisterUser(User user)
return new Tuple<bool, string>(true, "Registro completado!");
}

public Tuple<bool, String> TryLoginUser(User user) {
public Tuple<bool, String> TryLoginUser(String mail, String password) {

User? retrievedUser = GetUserByMail(user.GetMail());
if (String.IsNullOrEmpty(mail))
return new Tuple<bool, string>(false, "Ha ocurrido un error: No se ha proporcionado ningún correo electrónico");

User? retrievedUser = GetUserByMail(mail);

if (retrievedUser == null)
return new Tuple<bool, string>(false, "Ha ocurrido un error: No existe ningún usuario con este correo");

if (!user.GetPassword().Equals(retrievedUser.GetPassword()))
if (String.IsNullOrEmpty(password))
return new Tuple<bool, string>(false, "Ha ocurrido un error: No se ha proporcionado ninguna contraseña");

if (password.Length < 8)
return new Tuple<bool, string>(false, "Ha ocurrido un error: La contraseña debe de tener al menos 8 caracteres");

if (!password.Equals(retrievedUser.GetPassword()))
return new Tuple<bool, string>(false, "Ha ocurrido un error: La contraseña es incorrecta");

//Log user when success
loggedUser = user;
loggedUser = retrievedUser;

return new Tuple<bool, string>(true, "Sesión iniciada!");
}
Expand Down

0 comments on commit 9d18f10

Please sign in to comment.