diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/IServices.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/IServices.kt index afa5cd6..af40ed1 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/IServices.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/IServices.kt @@ -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) diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/ServicesStub.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/ServicesStub.kt index 7e8eab0..4dcb5f9 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/ServicesStub.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/ServicesStub.kt @@ -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) diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/LoginPage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/LoginPage.kt index 243e9dd..58d610f 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/LoginPage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/LoginPage.kt @@ -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, 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 diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/viewModels/AuthUserViewModel.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/viewModels/AuthUserViewModel.kt index 59f1ef2..9fc6bfb 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/viewModels/AuthUserViewModel.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/viewModels/AuthUserViewModel.kt @@ -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) + } } \ No newline at end of file