Déplacement de la fonction login dans service

pull/51/head
Leni BEAULATON 1 month ago
parent 819ef8d739
commit 619526be17

@ -5,6 +5,8 @@ import com.example.what_the_fantasy.data.model.Quote
import com.example.what_the_fantasy.data.model.User
interface IServices {
fun validLogin(username : String, passwd : String, navController: (Int) -> Unit): Boolean
fun EditUsername(username : String, index : Int) : Boolean
fun EditEmail(email : String, index : Int) : Boolean
fun EditPasswd(passwd : String, index : Int)

@ -15,6 +15,21 @@ import java.time.LocalDate
class ServicesStub : IServices {
val logsUser = LogsUsers() //gestion des logs pour les utilisateurs
override fun validLogin(username : String, passwd : String, navController: (Int) -> Unit): Boolean{
users.forEachIndexed { index, user ->
val hashPassWd = hashPassword(passwd)
if (user.username == username && user.password == hashPassWd) {
navController(index)
logsUser.logInformationUserConnect(user, "UserConnect")
return true
}
}
return false
}
override fun EditUsername(username: String, index : Int) : Boolean{
val user = getUserById(index)

@ -68,7 +68,7 @@ fun LoginPage(navControllerSignUp: () -> Unit, navControllerProfil: (Int) -> Uni
TitlePageComponent(R.string.titleLogin, MaterialTheme.colorScheme.primary)
SpaceHeightComponent(20)
ConnexionButtonLogin(users,IdentifiantTextField(R.string.IdentifiantLogin, authState.username){
ConnexionButtonLogin(authUserVM,IdentifiantTextField(R.string.IdentifiantLogin, authState.username){
authUserVM.setUsername(it)
}, PassWdTextField(R.string.PasswdLogin, authState.password){
authUserVM.setPassword(it)
@ -128,11 +128,11 @@ fun PassWdTextField(textpasswdResId : Int, password : String, onValueChange: (St
@Composable
fun ConnexionButtonLogin(users : List<User>, username : String, passwd : String, titleResId : Int, size : Int, navController: (Int) -> Unit){
fun ConnexionButtonLogin(authUserVM : AuthUserViewModel, username : String, passwd : String, titleResId : Int, size : Int, navController: (Int) -> Unit){
val title = stringResource(id = titleResId)
var showError by remember { mutableStateOf(false) }
Button(
onClick = { showError = !validLogin(username, passwd, users, navController)
onClick = { showError = !authUserVM.validLogin(username, passwd, navController)
},
colors = ButtonDefaults.buttonColors(containerColor = MaterialTheme.colorScheme.background),
modifier = Modifier

@ -21,4 +21,8 @@ class AuthUserViewModel : ViewModel(){
fun setPassword(password : String){
_userState.update { it.copy(password=password) }
}
fun validLogin(username : String, passwd : String, navController: (Int) -> Unit) : Boolean{
return services.validLogin(username,passwd,navController)
}
}
Loading…
Cancel
Save