Merge pull request 'Lien entre le stub est la maj des données des utilisateur sur la page profil (seul image n'a pas encore été fait)' (#23) from LienProfilStub into master

Reviewed-on: #23
pull/24/head^2
Leni BEAULATON 2 months ago
commit 27dfe302c3

@ -6,5 +6,5 @@ class User(
var email:String, var email:String,
var date:String, var date:String,
val imgUrl: String, val imgUrl: String,
val password: String var password: String
) )

@ -4,10 +4,10 @@ import com.example.what_the_fantasy.data.local.UserStub.users
import com.example.what_the_fantasy.data.model.User import com.example.what_the_fantasy.data.model.User
interface IServices { interface IServices {
fun EditUsername(username : String) fun EditUsername(username : String, index : Int)
fun EditEmail(email : String) fun EditEmail(email : String, index : Int)
fun EditPasswd(passwd : String, passwdValid : String) fun EditPasswd(passwd : String, index : Int)
fun EditImage(imageURL : String) fun EditImage(imageURL : String, index : Int)
fun CreateUser(username : String, email : String, passwd : String, imageURL: String, services : IServices) : Boolean fun CreateUser(username : String, email : String, passwd : String, imageURL: String, services : IServices) : Boolean
fun getFavorite(username: String) fun getFavorite(username: String)

@ -3,19 +3,19 @@ package com.example.what_the_fantasy.data.services
import com.example.what_the_fantasy.data.model.User import com.example.what_the_fantasy.data.model.User
class ServicesAPI : IServices { class ServicesAPI : IServices {
override fun EditUsername(username: String) { override fun EditUsername(username: String, index : Int) {
TODO("Not yet implemented") TODO("Not yet implemented")
} }
override fun EditEmail(email: String) { override fun EditEmail(email: String, index : Int) {
TODO("Not yet implemented") TODO("Not yet implemented")
} }
override fun EditPasswd(passwd: String, passwdValid: String) { override fun EditPasswd(passwd: String, index : Int) {
TODO("Not yet implemented") TODO("Not yet implemented")
} }
override fun EditImage(imageURL: String) { override fun EditImage(imageURL: String, index : Int) {
TODO("Not yet implemented") TODO("Not yet implemented")
} }

@ -9,19 +9,33 @@ import com.example.what_the_fantasy.ui.components.hashPassword
import java.time.LocalDate import java.time.LocalDate
class ServicesStub : IServices { class ServicesStub : IServices {
override fun EditUsername(username: String) { override fun EditUsername(username: String, index : Int) {
TODO("Not yet implemented") val user = getUserById(index)
user?.username = username
//Afficher tous les users
debugDisplayUser(getAllUsers(), "UsernameUpdate")
} }
override fun EditEmail(email: String) { override fun EditEmail(email: String,index : Int) {
TODO("Not yet implemented") val user = getUserById(index)
user?.email = email
//Afficher tous les users
debugDisplayUser(getAllUsers(), "EmailUpdate")
} }
override fun EditPasswd(passwd: String, passwdValid: String) { override fun EditPasswd(passwd: String,index : Int) {
TODO("Not yet implemented") 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") TODO("Not yet implemented")
} }
@ -29,7 +43,6 @@ class ServicesStub : IServices {
val date =dateDuJour() val date =dateDuJour()
val passwordhash = hashPassword(passwd) val passwordhash = hashPassword(passwd)
//Check si user existe déjà
val userStub = services.getAllUsers() val userStub = services.getAllUsers()
val nbUser = userStub.size val nbUser = userStub.size
for (user in userStub) { for (user in userStub) {
@ -41,20 +54,10 @@ class ServicesStub : IServices {
users.add(user)//ajout au stub users.add(user)//ajout au stub
//Afficher tous les users //Afficher tous les users
for(user in userStub){ debugDisplayUser(users, "CreateUser")
Log.e("CreateUser", "User created: ${user.username} => ${user.password}")
}
return true return true
} }
@SuppressLint("NewApi")
fun dateDuJour(): String {
val date = LocalDate.now()
return date.toString()
}
// Récupérer tous les utilisateurs
override fun getAllUsers(): List<User> = users override fun getAllUsers(): List<User> = users
override fun getUserById(id: Int): User? { override fun getUserById(id: Int): User? {
@ -68,4 +71,19 @@ class ServicesStub : IServices {
override fun getFavorite(username: String) { override fun getFavorite(username: String) {
TODO("Not yet implemented") TODO("Not yet implemented")
} }
//------------------------------------------------------
@SuppressLint("NewApi")
fun dateDuJour(): String {
val date = LocalDate.now()
return date.toString()
}
private fun debugDisplayUser(users : List<User>, titleLog : String){
for(user in users){
Log.e(titleLog, "User created: ${user.username} => ${user.email} => ${user.password}")
}
}
} }

@ -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.model.User
import com.example.what_the_fantasy.data.services.IServices import com.example.what_the_fantasy.data.services.IServices
import com.example.what_the_fantasy.data.services.ServicesStub 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.SpaceHeightComponent
import com.example.what_the_fantasy.ui.components.TitlePageComponent import com.example.what_the_fantasy.ui.components.TitlePageComponent
import com.example.what_the_fantasy.ui.components.hashPassword import com.example.what_the_fantasy.ui.components.hashPassword
@ -128,6 +129,7 @@ fun PassWdTextField(textpasswdResId : Int) : String{
@Composable @Composable
fun ConnexionButtonLogin(userStub : List<User>, id : String, passwd : String, titleResId : Int, size : Int, colorButton : Color, colorText : Color, navController: (Int) -> Unit){ fun ConnexionButtonLogin(userStub : List<User>, id : String, passwd : String, titleResId : Int, size : Int, colorButton : Color, colorText : Color, navController: (Int) -> Unit){
val title = stringResource(id = titleResId) val title = stringResource(id = titleResId)
Button( Button(
onClick = { validLogin(id, passwd, userStub, navController) }, onClick = { validLogin(id, passwd, userStub, navController) },
colors = ButtonDefaults.buttonColors(containerColor = colorButton), colors = ButtonDefaults.buttonColors(containerColor = colorButton),
@ -140,6 +142,7 @@ fun ConnexionButtonLogin(userStub : List<User>, id : String, passwd : String, ti
fun validLogin(identifiant : String, passwd : String, users : List<User>, navController: (Int) -> Unit){ fun validLogin(identifiant : String, passwd : String, users : List<User>, navController: (Int) -> Unit){
users.forEachIndexed { index, user -> users.forEachIndexed { index, user ->
val hashPassWd = hashPassword(passwd) val hashPassWd = hashPassword(passwd)
if (user.username == identifiant && user.password == hashPassWd) { if (user.username == identifiant && user.password == hashPassWd) {

@ -99,13 +99,13 @@ fun ProfilPage(index: Int, navController: NavController, services: IServices) {
ImageProfil(user.imgUrl, 120) ImageProfil(user.imgUrl, 120)
SpaceHeightComponent(16) SpaceHeightComponent(16)
EditUsername(user.username)// Édition du Username EditUsername(user.username, index, services)// Édition du Username
SpaceHeightComponent(16) SpaceHeightComponent(16)
EditEmail(user.email)// Édition du Email EditEmail(user.email,index, services)// Édition du Email
Spacer(modifier = Modifier.height(8.dp)) Spacer(modifier = Modifier.height(8.dp))
EditPasswd() EditPasswd(index, services)
SpaceHeightComponent(16) SpaceHeightComponent(16)
// Bouton // Bouton
@ -133,20 +133,27 @@ fun ImageProfil(imgProfil : String, size :Int){
} }
@Composable @Composable
fun EditEmail(userEmail: String) { fun EditEmail(userEmail: String, index: Int, service: IServices) {
var email by remember { mutableStateOf(userEmail) } var email by remember { mutableStateOf(userEmail) }
var isEditingEmail by remember { mutableStateOf(false) } var isEditingEmail by remember { mutableStateOf(false) }
var emailError by remember { mutableStateOf(false) } var emailError by remember { mutableStateOf(false) }
fun onDoneEditing() {
service.EditEmail(email, index)
isEditingEmail = false
}
if (isEditingEmail) { if (isEditingEmail) {
EmailEditingField( EmailEditingField(
email = email, email = email,
onEmailChange = { newEmail -> onEmailChange = { newEmail ->
email = newEmail email = newEmail
emailError = !Patterns.EMAIL_ADDRESS.matcher(newEmail).matches() emailError = !Patterns.EMAIL_ADDRESS.matcher(newEmail).matches() // Validation email
}, },
onDone = { onDone = {
if (!emailError) isEditingEmail = false if (!emailError) {
onDoneEditing()
}
}, },
emailError = emailError emailError = emailError
) )
@ -212,18 +219,21 @@ fun DisplayEmail(email: String, onEdit: () -> Unit) {
@Composable @Composable
fun EditUsername(userName: String) { fun EditUsername(userName: String, index: Int, service : IServices) {
var username by remember { mutableStateOf(userName) } var username by remember { mutableStateOf(userName) }
var isEditingUsername by remember { mutableStateOf(false) } var isEditingUsername by remember { mutableStateOf(false) }
fun onDoneEditing() {
service.EditUsername(username, index)
isEditingUsername = false
}
if (isEditingUsername) { if (isEditingUsername) {
UsernameEditingField( UsernameEditingField(
username = username, username = username,
onUsernameChange = { username = it }, onUsernameChange = { username = it },
onDone = { isEditingUsername = false } onDone = { onDoneEditing() }
) )
} else { } else {
DisplayUsername(username = username, onEdit = { isEditingUsername = true }) DisplayUsername(username = username, onEdit = { isEditingUsername = true })
@ -246,7 +256,7 @@ fun UsernameEditingField(
imeAction = ImeAction.Done imeAction = ImeAction.Done
), ),
keyboardActions = KeyboardActions( keyboardActions = KeyboardActions(
onDone = { onDone() } // Quand on appuie sur "Done", on met fin à l'édition onDone = { onDone() }
), ),
trailingIcon = { trailingIcon = {
IconButton(onClick = { onDone() }) { IconButton(onClick = { onDone() }) {
@ -279,18 +289,22 @@ fun DisplayUsername(username: String, onEdit: () -> Unit) {
@Composable @Composable
fun EditPasswd() { fun EditPasswd(index: Int, service: IServices) {
var password by remember { mutableStateOf("*******") } var password by remember { mutableStateOf("*******") } // Mot de passe actuel (affiché comme un masque)
var isEditingPassword by remember { mutableStateOf(false) } var isEditingPassword by remember { mutableStateOf(false) }
var newPassword by remember { mutableStateOf("") } var newPassword by remember { mutableStateOf("") }
var confirmPassword by remember { mutableStateOf("") } var confirmPassword by remember { mutableStateOf("") }
var passwordVisible by remember { mutableStateOf(false) } var passwordVisible by remember { mutableStateOf(false) }
var passwordError 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) { if (isEditingPassword) {
PasswordEditingFields( PasswordEditingFields(
newPassword = newPassword, newPassword = newPassword,
@ -298,20 +312,19 @@ fun EditPasswd() {
onNewPasswordChange = { newPassword = it }, onNewPasswordChange = { newPassword = it },
onConfirmPasswordChange = { onConfirmPasswordChange = {
confirmPassword = it confirmPassword = it
passwordError = newPassword != it passwordError = newPassword != it // Vérifier si les mots de passe correspondent
}, },
passwordVisible = passwordVisible, passwordVisible = passwordVisible,
onPasswordVisibilityChange = { passwordVisible = it }, onPasswordVisibilityChange = { passwordVisible = it },
passwordError = passwordError, passwordError = passwordError,
onDone = { onDone = {
if (!passwordError && newPassword.isNotEmpty()) { if (!passwordError && newPassword.isNotEmpty()) {
password = newPassword onDoneEditing() // Appeler la fonction onDoneEditing() pour mettre à jour le mot de passe
isEditingPassword = false
} }
} }
) )
} else { } else {
DisplayPassword(onEdit = { isEditingPassword = true }) DisplayPassword(onEdit = { isEditingPassword = true }) // Afficher l'option pour modifier le mot de passe
} }
} }

@ -11,6 +11,7 @@
<string name="PasswdLogin">Votre mot de passe*</string> <string name="PasswdLogin">Votre mot de passe*</string>
<string name="ButtonLogin">Se connecter</string> <string name="ButtonLogin">Se connecter</string>
<string name="ButtonCreateLogin">Créer son compte</string> <string name="ButtonCreateLogin">Créer son compte</string>
<string name="ErrorLogin">Identifiant ou mot de passe incorrect</string>
//Page Sign Up //Page Sign Up
<string name="titleSignUp">Inscription</string> <string name="titleSignUp">Inscription</string>

@ -10,6 +10,7 @@
<string name="PasswdLogin">Your password*</string> <string name="PasswdLogin">Your password*</string>
<string name="ButtonLogin">Login</string> <string name="ButtonLogin">Login</string>
<string name="ButtonCreateLogin">Create your account</string> <string name="ButtonCreateLogin">Create your account</string>
<string name="ErrorLogin">Incorrect username or password</string>
//Page Sign Up //Page Sign Up
<string name="titleSignUp">Account creation</string> <string name="titleSignUp">Account creation</string>

Loading…
Cancel
Save