diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/model/User.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/model/User.kt index ce4cb2f..febe20d 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/model/User.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/model/User.kt @@ -6,5 +6,5 @@ class User( var email:String, var date:String, val imgUrl: String, - val password: String + var password: String ) 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 d48fd2f..5f8ab42 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 @@ -4,10 +4,10 @@ import com.example.what_the_fantasy.data.local.UserStub.users import com.example.what_the_fantasy.data.model.User interface IServices { - fun EditUsername(username : String) - fun EditEmail(email : String) - fun EditPasswd(passwd : String, passwdValid : String) - fun EditImage(imageURL : String) + fun EditUsername(username : String, index : Int) + fun EditEmail(email : String, index : Int) + fun EditPasswd(passwd : String, index : Int) + fun EditImage(imageURL : String, index : Int) fun CreateUser(username : String, email : String, passwd : String, imageURL: String, services : IServices) : Boolean fun getFavorite(username: String) diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/ServicesAPI.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/ServicesAPI.kt index 5ac90ee..bf6d27e 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/ServicesAPI.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/services/ServicesAPI.kt @@ -3,19 +3,19 @@ package com.example.what_the_fantasy.data.services import com.example.what_the_fantasy.data.model.User class ServicesAPI : IServices { - override fun EditUsername(username: String) { + override fun EditUsername(username: String, index : Int) { TODO("Not yet implemented") } - override fun EditEmail(email: String) { + override fun EditEmail(email: String, index : Int) { TODO("Not yet implemented") } - override fun EditPasswd(passwd: String, passwdValid: String) { + override fun EditPasswd(passwd: String, index : Int) { TODO("Not yet implemented") } - override fun EditImage(imageURL: String) { + override fun EditImage(imageURL: String, index : Int) { TODO("Not yet implemented") } 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 d6cbfe3..c6c3ed1 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 @@ -9,19 +9,33 @@ import com.example.what_the_fantasy.ui.components.hashPassword import java.time.LocalDate class ServicesStub : IServices { - override fun EditUsername(username: String) { - TODO("Not yet implemented") + override fun EditUsername(username: String, index : Int) { + val user = getUserById(index) + user?.username = username + + //Afficher tous les users + debugDisplayUser(getAllUsers(), "UsernameUpdate") + } - override fun EditEmail(email: String) { - TODO("Not yet implemented") + override fun EditEmail(email: String,index : Int) { + val user = getUserById(index) + user?.email = email + + //Afficher tous les users + debugDisplayUser(getAllUsers(), "EmailUpdate") } - override fun EditPasswd(passwd: String, passwdValid: String) { - TODO("Not yet implemented") + override fun EditPasswd(passwd: String,index : Int) { + val user = getUserById(index) + val passwordhash = hashPassword(passwd) + user?.password = passwordhash + + //Afficher tous les users en log + debugDisplayUser(getAllUsers(), "PasswordUpdate") } - override fun EditImage(imageURL: String) { + override fun EditImage(imageURL: String,index : Int) { TODO("Not yet implemented") } @@ -29,7 +43,6 @@ class ServicesStub : IServices { val date =dateDuJour() val passwordhash = hashPassword(passwd) - //Check si user existe déjà val userStub = services.getAllUsers() val nbUser = userStub.size for (user in userStub) { @@ -41,20 +54,10 @@ class ServicesStub : IServices { users.add(user)//ajout au stub //Afficher tous les users - for(user in userStub){ - Log.e("CreateUser", "User created: ${user.username} => ${user.password}") - } + debugDisplayUser(users, "CreateUser") return true } - @SuppressLint("NewApi") - fun dateDuJour(): String { - val date = LocalDate.now() - return date.toString() - } - - - // Récupérer tous les utilisateurs override fun getAllUsers(): List = users override fun getUserById(id: Int): User? { @@ -68,4 +71,19 @@ class ServicesStub : IServices { override fun getFavorite(username: String) { TODO("Not yet implemented") } + + +//------------------------------------------------------ + @SuppressLint("NewApi") + fun dateDuJour(): String { + val date = LocalDate.now() + return date.toString() + } + + + private fun debugDisplayUser(users : List, titleLog : String){ + for(user in users){ + Log.e(titleLog, "User created: ${user.username} => ${user.email} => ${user.password}") + } + } } \ No newline at end of file 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 a824491..f4689c9 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 @@ -41,6 +41,7 @@ import com.example.what_the_fantasy.data.local.UserStub import com.example.what_the_fantasy.data.model.User import com.example.what_the_fantasy.data.services.IServices import com.example.what_the_fantasy.data.services.ServicesStub +import com.example.what_the_fantasy.ui.components.ErrorMessageProfileComponent import com.example.what_the_fantasy.ui.components.SpaceHeightComponent import com.example.what_the_fantasy.ui.components.TitlePageComponent import com.example.what_the_fantasy.ui.components.hashPassword @@ -128,6 +129,7 @@ fun PassWdTextField(textpasswdResId : Int) : String{ @Composable fun ConnexionButtonLogin(userStub : List, id : String, passwd : String, titleResId : Int, size : Int, colorButton : Color, colorText : Color, navController: (Int) -> Unit){ val title = stringResource(id = titleResId) + Button( onClick = { validLogin(id, passwd, userStub, navController) }, colors = ButtonDefaults.buttonColors(containerColor = colorButton), @@ -140,6 +142,7 @@ fun ConnexionButtonLogin(userStub : List, id : String, passwd : String, ti fun validLogin(identifiant : String, passwd : String, users : List, navController: (Int) -> Unit){ + users.forEachIndexed { index, user -> val hashPassWd = hashPassword(passwd) if (user.username == identifiant && user.password == hashPassWd) { diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/ProfilPage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/ProfilPage.kt index c8ee9aa..54b17af 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/ProfilPage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/ProfilPage.kt @@ -99,13 +99,13 @@ fun ProfilPage(index: Int, navController: NavController, services: IServices) { ImageProfil(user.imgUrl, 120) SpaceHeightComponent(16) - EditUsername(user.username)// Édition du Username + EditUsername(user.username, index, services)// Édition du Username SpaceHeightComponent(16) - EditEmail(user.email)// Édition du Email + EditEmail(user.email,index, services)// Édition du Email Spacer(modifier = Modifier.height(8.dp)) - EditPasswd() + EditPasswd(index, services) SpaceHeightComponent(16) // Bouton @@ -133,20 +133,27 @@ fun ImageProfil(imgProfil : String, size :Int){ } @Composable -fun EditEmail(userEmail: String) { +fun EditEmail(userEmail: String, index: Int, service: IServices) { var email by remember { mutableStateOf(userEmail) } var isEditingEmail by remember { mutableStateOf(false) } var emailError by remember { mutableStateOf(false) } + fun onDoneEditing() { + service.EditEmail(email, index) + isEditingEmail = false + } + if (isEditingEmail) { EmailEditingField( email = email, onEmailChange = { newEmail -> email = newEmail - emailError = !Patterns.EMAIL_ADDRESS.matcher(newEmail).matches() + emailError = !Patterns.EMAIL_ADDRESS.matcher(newEmail).matches() // Validation email }, onDone = { - if (!emailError) isEditingEmail = false + if (!emailError) { + onDoneEditing() + } }, emailError = emailError ) @@ -212,18 +219,21 @@ fun DisplayEmail(email: String, onEdit: () -> Unit) { - - @Composable -fun EditUsername(userName: String) { +fun EditUsername(userName: String, index: Int, service : IServices) { var username by remember { mutableStateOf(userName) } var isEditingUsername by remember { mutableStateOf(false) } + fun onDoneEditing() { + service.EditUsername(username, index) + isEditingUsername = false + } + if (isEditingUsername) { UsernameEditingField( username = username, onUsernameChange = { username = it }, - onDone = { isEditingUsername = false } + onDone = { onDoneEditing() } ) } else { DisplayUsername(username = username, onEdit = { isEditingUsername = true }) @@ -246,7 +256,7 @@ fun UsernameEditingField( imeAction = ImeAction.Done ), keyboardActions = KeyboardActions( - onDone = { onDone() } // Quand on appuie sur "Done", on met fin à l'édition + onDone = { onDone() } ), trailingIcon = { IconButton(onClick = { onDone() }) { @@ -279,18 +289,22 @@ fun DisplayUsername(username: String, onEdit: () -> Unit) { - - - @Composable -fun EditPasswd() { - var password by remember { mutableStateOf("*******") } +fun EditPasswd(index: Int, service: IServices) { + var password by remember { mutableStateOf("*******") } // Mot de passe actuel (affiché comme un masque) var isEditingPassword by remember { mutableStateOf(false) } var newPassword by remember { mutableStateOf("") } var confirmPassword by remember { mutableStateOf("") } var passwordVisible by remember { mutableStateOf(false) } var passwordError by remember { mutableStateOf(false) } + // Fonction pour finaliser l'édition du mot de passe et appeler la méthode EditPasswd2 + fun onDoneEditing() { + // Appeler EditPasswd2 pour mettre à jour le mot de passe de l'utilisateur + service.EditPasswd(newPassword, index) + isEditingPassword = false + } + if (isEditingPassword) { PasswordEditingFields( newPassword = newPassword, @@ -298,20 +312,19 @@ fun EditPasswd() { onNewPasswordChange = { newPassword = it }, onConfirmPasswordChange = { confirmPassword = it - passwordError = newPassword != it + passwordError = newPassword != it // Vérifier si les mots de passe correspondent }, passwordVisible = passwordVisible, onPasswordVisibilityChange = { passwordVisible = it }, passwordError = passwordError, onDone = { if (!passwordError && newPassword.isNotEmpty()) { - password = newPassword - isEditingPassword = false + onDoneEditing() // Appeler la fonction onDoneEditing() pour mettre à jour le mot de passe } } ) } else { - DisplayPassword(onEdit = { isEditingPassword = true }) + DisplayPassword(onEdit = { isEditingPassword = true }) // Afficher l'option pour modifier le mot de passe } } diff --git a/What_The_Fantasy/app/src/main/res/values-fr/strings.xml b/What_The_Fantasy/app/src/main/res/values-fr/strings.xml index 899a998..a9a859b 100644 --- a/What_The_Fantasy/app/src/main/res/values-fr/strings.xml +++ b/What_The_Fantasy/app/src/main/res/values-fr/strings.xml @@ -11,6 +11,7 @@ Votre mot de passe* Se connecter Créer son compte + Identifiant ou mot de passe incorrect //Page Sign Up Inscription diff --git a/What_The_Fantasy/app/src/main/res/values/strings.xml b/What_The_Fantasy/app/src/main/res/values/strings.xml index 4e02f70..b74a681 100644 --- a/What_The_Fantasy/app/src/main/res/values/strings.xml +++ b/What_The_Fantasy/app/src/main/res/values/strings.xml @@ -10,6 +10,7 @@ Your password* Login Create your account + Incorrect username or password //Page Sign Up Account creation