From d102a7f3d8517ab34602aa17b50e41eb6d7e9733 Mon Sep 17 00:00:00 2001 From: beaulaton Date: Fri, 14 Feb 2025 15:24:44 +0100 Subject: [PATCH 1/6] Stub en cours pour la page profil, pb pour l'image url --- .../app/src/main/AndroidManifest.xml | 3 ++ .../example/what_the_fantasy/MainActivity.kt | 4 +-- .../what_the_fantasy/ui/screens/ProfilPage.kt | 30 ++++++++++++------- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/What_The_Fantasy/app/src/main/AndroidManifest.xml b/What_The_Fantasy/app/src/main/AndroidManifest.xml index 1aef3bb..5dbf082 100644 --- a/What_The_Fantasy/app/src/main/AndroidManifest.xml +++ b/What_The_Fantasy/app/src/main/AndroidManifest.xml @@ -1,6 +1,9 @@ + + + Date: Fri, 14 Feb 2025 19:03:35 +0100 Subject: [PATCH 2/6] Ajout de l'url de l'image (AsyncImage) --- What_The_Fantasy/app/build.gradle.kts | 2 ++ .../example/what_the_fantasy/ui/screens/ProfilPage.kt | 10 +++++----- What_The_Fantasy/gradle/libs.versions.toml | 2 ++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/What_The_Fantasy/app/build.gradle.kts b/What_The_Fantasy/app/build.gradle.kts index 994366b..e884189 100644 --- a/What_The_Fantasy/app/build.gradle.kts +++ b/What_The_Fantasy/app/build.gradle.kts @@ -68,4 +68,6 @@ dependencies { androidTestImplementation(libs.androidx.ui.test.junit4) debugImplementation(libs.androidx.ui.tooling) debugImplementation(libs.androidx.ui.test.manifest) + implementation(libs.coil.compose) + } \ No newline at end of file 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 de8c577..7d287df 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 @@ -56,6 +56,7 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.navigation.NavController +import coil.compose.AsyncImage import com.example.what_the_fantasy.R import com.example.what_the_fantasy.data.local.QuestionStub import com.example.what_the_fantasy.data.local.UserStub @@ -69,7 +70,7 @@ fun ProfilPage() { end = Offset(1000f, 0f) // Fin en haut à droite ) val user = UserStub.allUsers - val index = 5 // Pour changer l'utilisateur pour le moment + val index = 2 // Pour changer l'utilisateur pour le moment Box( modifier = Modifier @@ -139,15 +140,14 @@ fun TitleProfil(titleResId : Int, size : Int, color : Color){ @Composable fun ImageProfil(imgProfil : String, size :Int, sizeBorber : Int, colorBorder : Color){ - - Image( - painter = painterResource(imgProfil), + AsyncImage( + model = imgProfil, contentDescription = "Photo de profil", modifier = Modifier .size(size.dp) .clip(CircleShape) - .border(sizeBorber.dp, colorBorder, CircleShape) ) + } diff --git a/What_The_Fantasy/gradle/libs.versions.toml b/What_The_Fantasy/gradle/libs.versions.toml index 302bb60..251a75f 100644 --- a/What_The_Fantasy/gradle/libs.versions.toml +++ b/What_The_Fantasy/gradle/libs.versions.toml @@ -1,5 +1,6 @@ [versions] agp = "8.6.0" +coilCompose = "2.2.1" kotlin = "1.9.0" coreKtx = "1.10.1" junit = "4.13.2" @@ -13,6 +14,7 @@ navigationCommonAndroid = "2.9.0-alpha05" [libraries] androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" } +coil-compose = { module = "io.coil-kt:coil-compose", version.ref = "coilCompose" } junit = { group = "junit", name = "junit", version.ref = "junit" } androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" } androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" } From bb712a0e86de233ea8ab508c3be2ac12764221a3 Mon Sep 17 00:00:00 2001 From: "leni.beaulaton" Date: Sat, 15 Feb 2025 00:19:30 +0100 Subject: [PATCH 3/6] Commencement du lien login --- .../example/what_the_fantasy/MainActivity.kt | 4 +- .../what_the_fantasy/data/local/UserStub.kt | 39 ++++++++++--------- .../what_the_fantasy/data/model/User.kt | 3 +- .../what_the_fantasy/ui/screens/LoginPage.kt | 29 ++++++++++---- .../what_the_fantasy/ui/screens/ProfilPage.kt | 2 +- 5 files changed, 47 insertions(+), 30 deletions(-) diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/MainActivity.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/MainActivity.kt index 5dd132b..f3676f0 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/MainActivity.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/MainActivity.kt @@ -31,8 +31,8 @@ class MainActivity : ComponentActivity() { ) } } - //AppNavigator() // Accès à la page login et SingUp (pour le moment) - ProfilPage() //Accès à la page profil + AppNavigator() // Accès à la page login et SingUp (pour le moment) + //ProfilPage() //Accès à la page profil //QuizPage() } } diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/UserStub.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/UserStub.kt index b05fbb3..48a3f0e 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/UserStub.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/UserStub.kt @@ -8,71 +8,72 @@ object UserStub { username = "Aragorn123", email = "aragorn@example.com", date = "2022-01-15", - imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-guerrier-fantaisie_1045-185.jpg?size=338&ext=jpg" + imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-guerrier-fantaisie_1045-185.jpg?size=338&ext=jpg", + password = "password123" ) val user2 = User( id = 2, username = "Legolas456", email = "legolas@example.com", date = "2021-05-23", - imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-elfe-fantaisie_1045-186.jpg?size=338&ext=jpg" - ) + imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-elfe-fantaisie_1045-186.jpg?size=338&ext=jpg", + password = "password123") val user3 = User( id = 3, username = "Gandalf789", email = "gandalf@example.com", date = "2020-09-10", - imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-magicien-fantaisie_1045-187.jpg?size=338&ext=jpg" - ) + imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-magicien-fantaisie_1045-187.jpg?size=338&ext=jpg", + password = "password123") val user4 = User( id = 4, username = "FrodoBaggins", email = "frodo@example.com", date = "2023-03-18", - imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-hobbit-fantaisie_1045-188.jpg?size=338&ext=jpg" - ) + imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-hobbit-fantaisie_1045-188.jpg?size=338&ext=jpg", + password = "password123") val user5 = User( id = 5, username = "Gimli999", email = "gimli@example.com", date = "2022-07-04", - imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-nain-fantaisie_1045-189.jpg?size=338&ext=jpg" - ) + imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-nain-fantaisie_1045-189.jpg?size=338&ext=jpg", + password = "password123") val user6 = User( id = 6, username = "Galadriel321", email = "galadriel@example.com", date = "2021-11-30", - imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-elfe-femme-fantaisie_1045-190.jpg?size=338&ext=jpg" - ) + imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-elfe-femme-fantaisie_1045-190.jpg?size=338&ext=jpg", + password = "password123") val user7 = User( id = 7, username = "Boromir654", email = "boromir@example.com", date = "2023-06-22", - imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-191.jpg?size=338&ext=jpg" - ) + imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-191.jpg?size=338&ext=jpg", + password = "password123") val user8 = User( id = 8, username = "Eowyn777", email = "eowyn@example.com", date = "2022-04-11", - imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-guerriere-femme-fantaisie_1045-192.jpg?size=338&ext=jpg" - ) + imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-guerriere-femme-fantaisie_1045-192.jpg?size=338&ext=jpg", + password = "password123") val user9 = User( id = 9, username = "Saruman888", email = "saruman@example.com", date = "2021-08-15", - imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-magicien-malefique-fantaisie_1045-193.jpg?size=338&ext=jpg" - ) + imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-magicien-malefique-fantaisie_1045-193.jpg?size=338&ext=jpg", + password = "password123") val user10 = User( id = 10, username = "Faramir222", email = "faramir@example.com", date = "2023-02-08", - imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg" - ) + imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg", + password = "password123") val allUsers: List = listOf( user1, user2, user3, user4, user5, user6, user7, user8, user9, user10 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 10af186..ce4cb2f 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 @@ -5,5 +5,6 @@ class User( var username:String, var email:String, var date:String, - val imgUrl: String + val imgUrl: String, + val password: String ) 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 2596711..cf17cd1 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 @@ -44,14 +44,18 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.example.what_the_fantasy.ui.theme.What_The_FantasyTheme import androidx.navigation.NavController +import androidx.navigation.Navigation import androidx.navigation.compose.rememberNavController import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import com.example.what_the_fantasy.R +import com.example.what_the_fantasy.data.local.UserStub +import com.example.what_the_fantasy.data.model.User @Composable fun LoginPage(navController : NavController) { + val users = UserStub.allUsers; val gradient = Brush.linearGradient( colors = listOf(Color(0xFF7B1FA2), Color(0xFF311B92)), // Violet clair → Violet foncé start = Offset(0f, 1000f), // Départ en bas à gauche @@ -75,10 +79,10 @@ fun LoginPage(navController : NavController) { ) { TitlePage(R.string.titleLogin, 20,Color.White) - IdentifiantTextField(R.string.IdentifiantLogin) - PassWdTextField(R.string.PasswdLogin) + val identifiant =IdentifiantTextField(R.string.IdentifiantLogin) + val passwd = PassWdTextField(R.string.PasswdLogin) Space(16) - ConnexionButtonLogin(R.string.ButtonLogin,18, Color.White, Color.Black) + ConnexionButtonLogin(users,identifiant, passwd, R.string.ButtonLogin,18, Color.White, Color.Black,navController) Space(16) CreateAccountButton(R.string.ButtonCreateLogin,12, Color.White, navController) @@ -95,7 +99,7 @@ fun Space(height : Int){ @Composable -fun IdentifiantTextField(textIdentifiantResId : Int){ +fun IdentifiantTextField(textIdentifiantResId : Int) : String{ val textIdentifiant = stringResource(id = textIdentifiantResId) var identifiant by remember { mutableStateOf("") } // Stocke la valeur du champ Column(modifier = Modifier.padding(top = 16.dp)) { @@ -110,10 +114,11 @@ fun IdentifiantTextField(textIdentifiantResId : Int){ shape = RoundedCornerShape(16.dp) // 🔹 Bords arrondis ) } + return identifiant; } @Composable -fun PassWdTextField(textpasswdResId : Int){ +fun PassWdTextField(textpasswdResId : Int) : String{ val textpasswd = stringResource(id = textpasswdResId) var passwd by remember { mutableStateOf("") } // Stocke la valeur du champ var passwordVisible by remember { mutableStateOf(false) } // État pour afficher/masquer @@ -134,6 +139,7 @@ fun PassWdTextField(textpasswdResId : Int){ shape = RoundedCornerShape(16.dp) // 🔹 Bords arrondis ) } + return passwd; } @Composable @@ -148,10 +154,10 @@ fun TitlePage(titleResId : Int, size : Int, color : Color){ } @Composable -fun ConnexionButtonLogin(titleResId : Int, size : Int, colorButton : Color, colorText : Color){ +fun ConnexionButtonLogin(userStub : List, id : String, passwd : String, titleResId : Int, size : Int, colorButton : Color, colorText : Color, navController: NavController){ val title = stringResource(id = titleResId) Button( - onClick = { /* Action */ }, + onClick = { ValidLogin(id, passwd, userStub, navController) }, colors = ButtonDefaults.buttonColors(containerColor = colorButton), modifier = Modifier .fillMaxWidth(), @@ -160,6 +166,14 @@ fun ConnexionButtonLogin(titleResId : Int, size : Int, colorButton : Color, colo } } +fun ValidLogin(identifiant : String, passwd : String, users : List, navController: NavController){ + users.forEach { user -> + if (user.username == identifiant && user.password == passwd){ + navController.navigate("profile") + } + } +} + @Composable fun CreateAccountButton(titleResId : Int, size : Int, color : Color, navController: NavController){ val title = stringResource(id = titleResId) @@ -180,6 +194,7 @@ fun AppNavigator() { NavHost(navController, startDestination = "login") { composable("login") { LoginPage(navController) } composable("signup") { SignUpPage(navController) } + composable("profile") { ProfilPage(navController) } } } \ No newline at end of file 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 7d287df..be9ef85 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 @@ -63,7 +63,7 @@ import com.example.what_the_fantasy.data.local.UserStub import com.example.what_the_fantasy.ui.theme.What_The_FantasyTheme @Composable -fun ProfilPage() { +fun ProfilPage(navController: NavController) { val gradient = Brush.linearGradient( colors = listOf(Color(0xFF7B1FA2), Color(0xFF311B92)), // Violet clair → Violet foncé start = Offset(0f, 1000f), // Départ en bas à gauche From 657da2d024ba746718efde963285aa293f41977e Mon Sep 17 00:00:00 2001 From: beaulaton Date: Mon, 17 Feb 2025 14:24:26 +0100 Subject: [PATCH 4/6] En cours de hachage --- What_The_Fantasy/app/build.gradle.kts | 4 ++-- .../com/example/what_the_fantasy/ui/screens/LoginPage.kt | 7 +++++-- .../com/example/what_the_fantasy/ui/screens/ProfilPage.kt | 5 ++--- What_The_Fantasy/gradle/libs.versions.toml | 5 +++++ 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/What_The_Fantasy/app/build.gradle.kts b/What_The_Fantasy/app/build.gradle.kts index e884189..5c11806 100644 --- a/What_The_Fantasy/app/build.gradle.kts +++ b/What_The_Fantasy/app/build.gradle.kts @@ -50,7 +50,7 @@ android { } dependencies { - + implementation(libs.bcrypt) // pour hacher les mdp implementation(libs.androidx.core.ktx) implementation(libs.androidx.lifecycle.runtime.ktx) implementation(libs.androidx.activity.compose) @@ -68,6 +68,6 @@ dependencies { androidTestImplementation(libs.androidx.ui.test.junit4) debugImplementation(libs.androidx.ui.tooling) debugImplementation(libs.androidx.ui.test.manifest) - implementation(libs.coil.compose) + implementation(libs.coil.compose) //gére les url des image } \ 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 cf17cd1..9f94e86 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 @@ -157,7 +157,7 @@ fun TitlePage(titleResId : Int, size : Int, color : Color){ fun ConnexionButtonLogin(userStub : List, id : String, passwd : String, titleResId : Int, size : Int, colorButton : Color, colorText : Color, navController: NavController){ val title = stringResource(id = titleResId) Button( - onClick = { ValidLogin(id, passwd, userStub, navController) }, + onClick = { validLogin(id, passwd, userStub, navController) }, colors = ButtonDefaults.buttonColors(containerColor = colorButton), modifier = Modifier .fillMaxWidth(), @@ -166,14 +166,17 @@ fun ConnexionButtonLogin(userStub : List, id : String, passwd : String, ti } } -fun ValidLogin(identifiant : String, passwd : String, users : List, navController: NavController){ + +fun validLogin(identifiant : String, passwd : String, users : List, navController: NavController){ users.forEach { user -> if (user.username == identifiant && user.password == passwd){ navController.navigate("profile") + //navController.navigate(ProfilPage(navController)) } } } + @Composable fun CreateAccountButton(titleResId : Int, size : Int, color : Color, navController: NavController){ val title = stringResource(id = titleResId) 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 be9ef85..7d07b7e 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 @@ -2,6 +2,7 @@ package com.example.what_the_fantasy.ui.screens import android.content.Context import android.os.Bundle +import android.util.Patterns import android.widget.ImageView import androidx.activity.ComponentActivity import androidx.activity.compose.setContent @@ -151,8 +152,6 @@ fun ImageProfil(imgProfil : String, size :Int, sizeBorber : Int, colorBorder : C } - - @Composable fun EditEmail(userEmail : String){ var email by remember { mutableStateOf(userEmail) } @@ -164,7 +163,7 @@ fun EditEmail(userEmail : String){ value = email, onValueChange = { email = it - emailError = !android.util.Patterns.EMAIL_ADDRESS.matcher(it).matches() + emailError = !Patterns.EMAIL_ADDRESS.matcher(it).matches() }, modifier = Modifier.fillMaxWidth(), textStyle = TextStyle(color = Color.White, fontSize = 18.sp), diff --git a/What_The_Fantasy/gradle/libs.versions.toml b/What_The_Fantasy/gradle/libs.versions.toml index 251a75f..ae80aff 100644 --- a/What_The_Fantasy/gradle/libs.versions.toml +++ b/What_The_Fantasy/gradle/libs.versions.toml @@ -1,6 +1,8 @@ [versions] agp = "8.6.0" +bcrypt = "2.2.0" coilCompose = "2.2.1" +coilComposeVersion = "3.1.0" kotlin = "1.9.0" coreKtx = "1.10.1" junit = "4.13.2" @@ -14,7 +16,10 @@ navigationCommonAndroid = "2.9.0-alpha05" [libraries] androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" } +bcrypt = { module = "de.nycode:bcrypt", version.ref = "bcrypt" } coil-compose = { module = "io.coil-kt:coil-compose", version.ref = "coilCompose" } +coil-network-okhttp = { module = "io.coil-kt.coil3:coil-network-okhttp", version.ref = "coilComposeVersion" } +coil3-coil-compose = { module = "io.coil-kt.coil3:coil-compose", version.ref = "coilComposeVersion" } junit = { group = "junit", name = "junit", version.ref = "junit" } androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" } androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" } From 5a1949aca1718e85ce51cf4592b44bd188f365cd Mon Sep 17 00:00:00 2001 From: beaulaton Date: Mon, 17 Feb 2025 16:44:06 +0100 Subject: [PATCH 5/6] Hashage mdp --- .../what_the_fantasy/data/local/UserStub.kt | 40 +++++++++++++------ .../what_the_fantasy/ui/screens/LoginPage.kt | 21 ++++++++-- .../what_the_fantasy/ui/screens/SignUpPage.kt | 11 +---- What_The_Fantasy/gradle/libs.versions.toml | 9 ++--- 4 files changed, 52 insertions(+), 29 deletions(-) diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/UserStub.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/UserStub.kt index 48a3f0e..5bc2351 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/UserStub.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/data/local/UserStub.kt @@ -9,73 +9,89 @@ object UserStub { email = "aragorn@example.com", date = "2022-01-15", imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-guerrier-fantaisie_1045-185.jpg?size=338&ext=jpg", - password = "password123" - ) + password = "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4") // 1234 + val user2 = User( id = 2, username = "Legolas456", email = "legolas@example.com", date = "2021-05-23", imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-elfe-fantaisie_1045-186.jpg?size=338&ext=jpg", - password = "password123") + password = "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4") // 1234 + val user3 = User( id = 3, username = "Gandalf789", email = "gandalf@example.com", date = "2020-09-10", imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-magicien-fantaisie_1045-187.jpg?size=338&ext=jpg", - password = "password123") + password = "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4") // 1234 + val user4 = User( id = 4, username = "FrodoBaggins", email = "frodo@example.com", date = "2023-03-18", imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-hobbit-fantaisie_1045-188.jpg?size=338&ext=jpg", - password = "password123") + password = "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4") // 1234 + val user5 = User( id = 5, username = "Gimli999", email = "gimli@example.com", date = "2022-07-04", imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-nain-fantaisie_1045-189.jpg?size=338&ext=jpg", - password = "password123") + password = "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4") // 1234 + val user6 = User( id = 6, username = "Galadriel321", email = "galadriel@example.com", date = "2021-11-30", imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-elfe-femme-fantaisie_1045-190.jpg?size=338&ext=jpg", - password = "password123") + password = "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4") // 1234 + val user7 = User( id = 7, username = "Boromir654", email = "boromir@example.com", date = "2023-06-22", imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-191.jpg?size=338&ext=jpg", - password = "password123") + password = "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4") // 1234 + val user8 = User( id = 8, username = "Eowyn777", email = "eowyn@example.com", date = "2022-04-11", imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-guerriere-femme-fantaisie_1045-192.jpg?size=338&ext=jpg", - password = "password123") + password = "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4") // 1234 + val user9 = User( id = 9, username = "Saruman888", email = "saruman@example.com", date = "2021-08-15", imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-magicien-malefique-fantaisie_1045-193.jpg?size=338&ext=jpg", - password = "password123") + password = "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4") // 1234 + val user10 = User( id = 10, username = "Faramir222", email = "faramir@example.com", date = "2023-02-08", imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg", - password = "password123") + password = "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4") // 1234 + + val user11 = User( + id = 10, + username = "testeur", + email = "testeur@example.com", + date = "2023-02-08", + imgUrl = "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg", + password = "03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4") // 1234 val allUsers: List = listOf( - user1, user2, user3, user4, user5, user6, user7, user8, user9, user10 + user1, user2, user3, user4, user5, user6, user7, user8, user9, user10, user11 ) } \ 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 9f94e86..fc883f4 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 @@ -2,6 +2,7 @@ package com.example.what_the_fantasy.ui.screens import android.os.Bundle import android.text.style.BackgroundColorSpan +import android.util.Log import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge @@ -51,6 +52,8 @@ import androidx.navigation.compose.composable import com.example.what_the_fantasy.R import com.example.what_the_fantasy.data.local.UserStub import com.example.what_the_fantasy.data.model.User +import org.mindrot.jbcrypt.BCrypt +import java.security.MessageDigest @Composable fun LoginPage(navController : NavController) { @@ -85,7 +88,6 @@ fun LoginPage(navController : NavController) { ConnexionButtonLogin(users,identifiant, passwd, R.string.ButtonLogin,18, Color.White, Color.Black,navController) Space(16) CreateAccountButton(R.string.ButtonCreateLogin,12, Color.White, navController) - } } } @@ -136,7 +138,7 @@ fun PassWdTextField(textpasswdResId : Int) : String{ IconButton(onClick = { passwordVisible = !passwordVisible }) { } }, - shape = RoundedCornerShape(16.dp) // 🔹 Bords arrondis + shape = RoundedCornerShape(16.dp) // Bords arrondis ) } return passwd; @@ -169,13 +171,26 @@ fun ConnexionButtonLogin(userStub : List, id : String, passwd : String, ti fun validLogin(identifiant : String, passwd : String, users : List, navController: NavController){ users.forEach { user -> - if (user.username == identifiant && user.password == passwd){ + val hashPassWd = hashPassword(passwd) + + if (user.username == identifiant && user.password == hashPassWd){ navController.navigate("profile") //navController.navigate(ProfilPage(navController)) } } } +fun hashPassword(password: String): String { + // Créer un objet MessageDigest pour SHA-256 + val digest = MessageDigest.getInstance("SHA-256") + + // Convertir le mot de passe en bytes et appliquer le hash + val hashedBytes = digest.digest(password.toByteArray()) + + // Convertir le tableau de bytes en une chaîne hexadécimale + return hashedBytes.joinToString("") { "%02x".format(it) } +} + @Composable fun CreateAccountButton(titleResId : Int, size : Int, color : Color, navController: NavController){ diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SignUpPage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SignUpPage.kt index 7ed5121..5f87056 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SignUpPage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SignUpPage.kt @@ -41,6 +41,7 @@ import androidx.compose.ui.unit.sp import androidx.navigation.NavController import com.example.what_the_fantasy.R import com.example.what_the_fantasy.ui.theme.What_The_FantasyTheme +import org.mindrot.jbcrypt.BCrypt @Composable fun SignUpPage(navController: NavController) { @@ -172,15 +173,7 @@ fun PassWdConfirmTextFieldSign(textpasswdResId : Int){ } } -//@Composable -//fun TitleSign(title : String, size : Int, color : Color){ -// Text( -// text = title, -// fontSize = size.sp, -// fontWeight = FontWeight.Bold, -// color = color -// ) -//} + @Composable fun ConnexionButtonSign(titleResId : Int, size : Int, colorButton : Color, colorText : Color){ diff --git a/What_The_Fantasy/gradle/libs.versions.toml b/What_The_Fantasy/gradle/libs.versions.toml index ae80aff..258393f 100644 --- a/What_The_Fantasy/gradle/libs.versions.toml +++ b/What_The_Fantasy/gradle/libs.versions.toml @@ -1,8 +1,8 @@ [versions] agp = "8.6.0" -bcrypt = "2.2.0" +bcrypt = "0.4" coilCompose = "2.2.1" -coilComposeVersion = "3.1.0" + kotlin = "1.9.0" coreKtx = "1.10.1" junit = "4.13.2" @@ -16,10 +16,9 @@ navigationCommonAndroid = "2.9.0-alpha05" [libraries] androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" } -bcrypt = { module = "de.nycode:bcrypt", version.ref = "bcrypt" } +bcrypt = { module = "org.mindrot:jbcrypt", version.ref = "bcrypt" } coil-compose = { module = "io.coil-kt:coil-compose", version.ref = "coilCompose" } -coil-network-okhttp = { module = "io.coil-kt.coil3:coil-network-okhttp", version.ref = "coilComposeVersion" } -coil3-coil-compose = { module = "io.coil-kt.coil3:coil-compose", version.ref = "coilComposeVersion" } + junit = { group = "junit", name = "junit", version.ref = "junit" } androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" } androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" } From f6ceb44e29b1b797c22d22343132e5ae938a8ce5 Mon Sep 17 00:00:00 2001 From: beaulaton Date: Mon, 17 Feb 2025 17:37:23 +0100 Subject: [PATCH 6/6] =?UTF-8?q?Mdp=20hach=C3=A9=20+=20cr=C3=A9ation=20comp?= =?UTF-8?q?onents?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/what_the_fantasy/MainActivity.kt | 17 +- .../ui/components/ErrorMessageComponent.kt | 22 + .../ui/components/SpaceComponent.kt | 15 + .../ui/components/TitleComponents.kt | 21 + .../what_the_fantasy/ui/screens/LoginPage.kt | 39 +- .../what_the_fantasy/ui/screens/ProfilPage.kt | 471 ++++++++++-------- .../what_the_fantasy/ui/screens/SignUpPage.kt | 17 +- 7 files changed, 355 insertions(+), 247 deletions(-) create mode 100644 What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/ErrorMessageComponent.kt create mode 100644 What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/SpaceComponent.kt create mode 100644 What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/TitleComponents.kt diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/MainActivity.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/MainActivity.kt index f3676f0..1c0f0a5 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/MainActivity.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/MainActivity.kt @@ -11,6 +11,7 @@ import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier +import androidx.navigation.NavController import com.example.what_the_fantasy.ui.screens.AppNavigator import com.example.what_the_fantasy.ui.theme.What_The_FantasyTheme import com.example.what_the_fantasy.ui.screens.LoginPage @@ -23,14 +24,7 @@ class MainActivity : ComponentActivity() { enableEdgeToEdge() setContent { What_The_FantasyTheme { - Column { - Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding -> - Title( - title = "What The Fantasy", - modifier = Modifier.padding(innerPadding) - ) - } - } + AppNavigator() // Accès à la page login et SingUp (pour le moment) //ProfilPage() //Accès à la page profil //QuizPage() @@ -39,11 +33,4 @@ class MainActivity : ComponentActivity() { } } -@Composable -fun Title(title: String, modifier: Modifier = Modifier) { - Text( - text = "Welcome to $title!", - modifier = modifier - ) -} diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/ErrorMessageComponent.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/ErrorMessageComponent.kt new file mode 100644 index 0000000..6498a73 --- /dev/null +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/ErrorMessageComponent.kt @@ -0,0 +1,22 @@ +package com.example.what_the_fantasy.ui.components + +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp + + +@Composable +fun ErrorMessageProfileComponent(titleResId : Int) { + val textError = stringResource(id = titleResId) + Text( + text = textError, + color = Color.Red, + fontSize = 12.sp, + modifier = Modifier.padding(top = 4.dp) + ) +} \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/SpaceComponent.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/SpaceComponent.kt new file mode 100644 index 0000000..d9a69d7 --- /dev/null +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/SpaceComponent.kt @@ -0,0 +1,15 @@ +package com.example.what_the_fantasy.ui.components + +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.width +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp + +@Composable +fun SpaceHeightComponent(height : Int){ + Spacer( + modifier = Modifier + .height(height.dp)) // Ajoute un espacement +} \ No newline at end of file diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/TitleComponents.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/TitleComponents.kt new file mode 100644 index 0000000..86aad8f --- /dev/null +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/components/TitleComponents.kt @@ -0,0 +1,21 @@ +package com.example.what_the_fantasy.ui.components + +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.sp + + + +@Composable +fun TitlePageComponent(titleResId : Int, size : Int, color : Color) { + val title = stringResource(id = titleResId) + Text( + text = title, + fontSize = size.sp, + fontWeight = FontWeight.Bold, + color = color + ) +} 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 fc883f4..78343ea 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 @@ -52,6 +52,8 @@ import androidx.navigation.compose.composable import com.example.what_the_fantasy.R import com.example.what_the_fantasy.data.local.UserStub import com.example.what_the_fantasy.data.model.User +import com.example.what_the_fantasy.ui.components.SpaceHeightComponent +import com.example.what_the_fantasy.ui.components.TitlePageComponent import org.mindrot.jbcrypt.BCrypt import java.security.MessageDigest @@ -81,23 +83,18 @@ fun LoginPage(navController : NavController) { horizontalAlignment = Alignment.CenterHorizontally ) { - TitlePage(R.string.titleLogin, 20,Color.White) + TitlePageComponent(R.string.titleLogin, 20,Color.White) val identifiant =IdentifiantTextField(R.string.IdentifiantLogin) val passwd = PassWdTextField(R.string.PasswdLogin) - Space(16) + SpaceHeightComponent(16) ConnexionButtonLogin(users,identifiant, passwd, R.string.ButtonLogin,18, Color.White, Color.Black,navController) - Space(16) + SpaceHeightComponent(16) CreateAccountButton(R.string.ButtonCreateLogin,12, Color.White, navController) } } } -@Composable -fun Space(height : Int){ - Spacer( - modifier = Modifier - .height(height.dp)) // Ajoute un espacement -} + @Composable @@ -144,16 +141,16 @@ fun PassWdTextField(textpasswdResId : Int) : String{ return passwd; } -@Composable -fun TitlePage(titleResId : Int, size : Int, color : Color){ - val title = stringResource(id = titleResId) - Text( - text = title, - fontSize = size.sp, - fontWeight = FontWeight.Bold, - color = color - ) -} +//@Composable +//fun TitlePage(titleResId : Int, size : Int, color : Color){ +// val title = stringResource(id = titleResId) +// Text( +// text = title, +// fontSize = size.sp, +// fontWeight = FontWeight.Bold, +// color = color +// ) +//} @Composable fun ConnexionButtonLogin(userStub : List, id : String, passwd : String, titleResId : Int, size : Int, colorButton : Color, colorText : Color, navController: NavController){ @@ -181,10 +178,10 @@ fun validLogin(identifiant : String, passwd : String, users : List, navCon } fun hashPassword(password: String): String { - // Créer un objet MessageDigest pour SHA-256 + // SHA-256 val digest = MessageDigest.getInstance("SHA-256") - // Convertir le mot de passe en bytes et appliquer le hash + // Convertir mdp en bytes et appliquer le hash val hashedBytes = digest.digest(password.toByteArray()) // Convertir le tableau de bytes en une chaîne hexadécimale 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 7d07b7e..cdfbec9 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 @@ -61,6 +61,9 @@ import coil.compose.AsyncImage import com.example.what_the_fantasy.R import com.example.what_the_fantasy.data.local.QuestionStub import com.example.what_the_fantasy.data.local.UserStub +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.theme.What_The_FantasyTheme @Composable @@ -90,28 +93,27 @@ fun ProfilPage(navController: NavController) { ) { // Titre - TitleProfil(R.string.titleProfile, 20, Color.White) - SpaceProfil(16) + TitlePageComponent(R.string.titleProfile, 20, Color.White) + SpaceHeightComponent(16) // Image de profil - //val id = R.drawable.ic_launcher_foreground ImageProfil(user[index].imgUrl, 120, 2, Color.White) - SpaceProfil(16) + SpaceHeightComponent(16) EditUsername(user[index].username)// Édition du Username - SpaceProfil(16) + SpaceHeightComponent(16) EditEmail(user[index].email)// Édition du Email Spacer(modifier = Modifier.height(8.dp)) EditPasswd() - SpaceProfil(16) + SpaceHeightComponent(16) // Bouton ButtonProfile(R.string.ButtonAddQuoteprofile,18, Color.Black, Color.White) - SpaceProfil(16) + SpaceHeightComponent(16) ButtonProfile(R.string.ButtonLanguageprofile,18, Color.Black, Color.White) - SpaceProfil(16) + SpaceHeightComponent(16) ButtonProfile(R.string.ButtonUnlogprofile, 18, Color.Black, Color.White) } @@ -119,24 +121,8 @@ fun ProfilPage(navController: NavController) { } -@Composable -fun SpaceProfil(height : Int){ - Spacer( - modifier = Modifier - .height(height.dp)) // Ajoute un espacement -} -@Composable -fun TitleProfil(titleResId : Int, size : Int, color : Color){ - val title = stringResource(id = titleResId) - Text( - text = title, - fontSize = size.sp, - fontWeight = FontWeight.Bold, - color = color - ) -} @Composable fun ImageProfil(imgProfil : String, size :Int, sizeBorber : Int, colorBorder : Color){ @@ -148,226 +134,309 @@ fun ImageProfil(imgProfil : String, size :Int, sizeBorber : Int, colorBorder : C .size(size.dp) .clip(CircleShape) ) - } @Composable -fun EditEmail(userEmail : String){ +fun EditEmail(userEmail: String) { var email by remember { mutableStateOf(userEmail) } - var isEditingEmail by remember { mutableStateOf(false) } // État d'édition + var isEditingEmail by remember { mutableStateOf(false) } var emailError by remember { mutableStateOf(false) } if (isEditingEmail) { - OutlinedTextField( - value = email, - onValueChange = { - email = it - emailError = !Patterns.EMAIL_ADDRESS.matcher(it).matches() + EmailEditingField( + email = email, + onEmailChange = { newEmail -> + email = newEmail + emailError = !Patterns.EMAIL_ADDRESS.matcher(newEmail).matches() }, - modifier = Modifier.fillMaxWidth(), - textStyle = TextStyle(color = Color.White, fontSize = 18.sp), - singleLine = true, - keyboardOptions = KeyboardOptions.Default.copy( - keyboardType = KeyboardType.Email, // ✅ Clavier spécialisé pour email - imeAction = ImeAction.Done - ), - keyboardActions = KeyboardActions( - onDone = { if (!emailError) isEditingEmail = false } // ✅ Fermer si l'email est valide - ), - trailingIcon = { - IconButton(onClick = { if (!emailError) isEditingEmail = false }) { - Icon(imageVector = Icons.Default.Check, contentDescription = "Valider") - } + onDone = { + if (!emailError) isEditingEmail = false }, - isError = emailError // ✅ Afficher l'erreur si l'email est invalide + emailError = emailError ) - if (emailError) { - val text = stringResource(id = R.string.ErrorEmailprofile) - Text( - text = text, - color = Color.Red, - fontSize = 12.sp, - modifier = Modifier.padding(top = 4.dp) - ) - } } else { - Row( - verticalAlignment = Alignment.CenterVertically, - modifier = Modifier.clickable { isEditingEmail = true } - ) { - Text( - text = email, - fontSize = 18.sp, - fontWeight = FontWeight.Bold, - color = Color.White - ) - Icon( - imageVector = Icons.Default.Edit, - contentDescription = "Modifier", - tint = Color.White, - modifier = Modifier.size(16.dp).padding(start = 8.dp) - ) - } + DisplayEmail(email = email, onEdit = { isEditingEmail = true }) + } +} + +@Composable +fun EmailEditingField( + email: String, + onEmailChange: (String) -> Unit, + onDone: () -> Unit, + emailError: Boolean +) { + OutlinedTextField( + value = email, + onValueChange = onEmailChange, + modifier = Modifier.fillMaxWidth(), + textStyle = TextStyle(color = Color.White, fontSize = 18.sp), + singleLine = true, + keyboardOptions = KeyboardOptions.Default.copy( + keyboardType = KeyboardType.Email, + imeAction = ImeAction.Done + ), + keyboardActions = KeyboardActions( + onDone = { onDone() } + ), + trailingIcon = { + IconButton(onClick = { if (!emailError) onDone() }) { + Icon(imageVector = Icons.Default.Check, contentDescription = "Valider") + } + }, + isError = emailError + ) + + if (emailError) { + ErrorMessageProfileComponent(R.string.ErrorEmailprofile) + } +} + + +@Composable +fun DisplayEmail(email: String, onEdit: () -> Unit) { + Row( + verticalAlignment = Alignment.CenterVertically, + modifier = Modifier.clickable { onEdit() } + ) { + Text( + text = email, + fontSize = 18.sp, + fontWeight = FontWeight.Bold, + color = Color.White + ) + Icon( + imageVector = Icons.Default.Edit, + contentDescription = "Modifier", + tint = Color.White, + modifier = Modifier.size(16.dp).padding(start = 8.dp) + ) } } + + + @Composable -fun EditUsername(userName : String){ +fun EditUsername(userName: String) { var username by remember { mutableStateOf(userName) } - var isEditingUsername by remember { mutableStateOf(false) } // État d'édition + var isEditingUsername by remember { mutableStateOf(false) } if (isEditingUsername) { - OutlinedTextField( - value = username, - onValueChange = { username = it }, - modifier = Modifier.fillMaxWidth(), - textStyle = TextStyle(color = Color.White, fontSize = 18.sp), - singleLine = true, - keyboardOptions = KeyboardOptions.Default.copy( - imeAction = ImeAction.Done - ), - keyboardActions = KeyboardActions( - onDone = { isEditingUsername = false } // Quand on appuie sur "Done" - ), - trailingIcon = { - IconButton(onClick = { isEditingUsername = false }) { - Icon(imageVector = Icons.Default.Check, contentDescription = "Valider") - } - } + UsernameEditingField( + username = username, + onUsernameChange = { username = it }, + onDone = { isEditingUsername = false } ) } else { - Row( - verticalAlignment = Alignment.CenterVertically, - modifier = Modifier.clickable { isEditingUsername = true } - ) { - Text( - text = username, - fontSize = 18.sp, - fontWeight = FontWeight.Bold, - color = Color.White - ) - Icon( - imageVector = Icons.Default.Edit, - contentDescription = "Modifier", - tint = Color.White, - modifier = Modifier.size(16.dp).padding(start = 8.dp) - ) + DisplayUsername(username = username, onEdit = { isEditingUsername = true }) + } +} + +@Composable +fun UsernameEditingField( + username: String, + onUsernameChange: (String) -> Unit, + onDone: () -> Unit +) { + OutlinedTextField( + value = username, + onValueChange = onUsernameChange, + modifier = Modifier.fillMaxWidth(), + textStyle = TextStyle(color = Color.White, fontSize = 18.sp), + singleLine = true, + keyboardOptions = KeyboardOptions.Default.copy( + imeAction = ImeAction.Done + ), + keyboardActions = KeyboardActions( + onDone = { onDone() } // Quand on appuie sur "Done", on met fin à l'édition + ), + trailingIcon = { + IconButton(onClick = { onDone() }) { + Icon(imageVector = Icons.Default.Check, contentDescription = "Valider") + } } + ) +} + +@Composable +fun DisplayUsername(username: String, onEdit: () -> Unit) { + Row( + verticalAlignment = Alignment.CenterVertically, + modifier = Modifier.clickable { onEdit() } + ) { + Text( + text = username, + fontSize = 18.sp, + fontWeight = FontWeight.Bold, + color = Color.White + ) + Icon( + imageVector = Icons.Default.Edit, + contentDescription = "Modifier", + tint = Color.White, + modifier = Modifier.size(16.dp).padding(start = 8.dp) + ) } } + + + + @Composable -fun EditPasswd(){ +fun EditPasswd() { var password by remember { mutableStateOf("*******") } 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) } + if (isEditingPassword) { - Column { - val text = stringResource(id = R.string.NewPasswdprofile) - OutlinedTextField( - value = newPassword, - onValueChange = { newPassword = it }, - label = { Text(text) }, - modifier = Modifier.fillMaxWidth(), - textStyle = TextStyle(color = Color.White, fontSize = 18.sp), - singleLine = true, - keyboardOptions = KeyboardOptions.Default.copy( - keyboardType = KeyboardType.Password, - imeAction = ImeAction.Next - ), - visualTransformation = if (passwordVisible) VisualTransformation.None else PasswordVisualTransformation(), - trailingIcon = { - IconButton(onClick = { passwordVisible = !passwordVisible }) { - - } + PasswordEditingFields( + newPassword = newPassword, + confirmPassword = confirmPassword, + onNewPasswordChange = { newPassword = it }, + onConfirmPasswordChange = { + confirmPassword = it + passwordError = newPassword != it + }, + passwordVisible = passwordVisible, + onPasswordVisibilityChange = { passwordVisible = it }, + passwordError = passwordError, + onDone = { + if (!passwordError && newPassword.isNotEmpty()) { + password = newPassword + isEditingPassword = false } - ) - - Spacer(modifier = Modifier.height(8.dp)) - val textConfirm = stringResource(id = R.string.ConfirmNewPasswdprofile) - OutlinedTextField( - value = confirmPassword, - onValueChange = { - confirmPassword = it - passwordError = newPassword != it - }, - - label = { Text(textConfirm) }, - modifier = Modifier.fillMaxWidth(), - textStyle = TextStyle(color = Color.White, fontSize = 18.sp), - singleLine = true, - keyboardOptions = KeyboardOptions.Default.copy( - keyboardType = KeyboardType.Password, - imeAction = ImeAction.Done - ), - keyboardActions = KeyboardActions( - onDone = { if (!passwordError && newPassword.isNotEmpty()) { - password = newPassword - isEditingPassword = false - }} - ), - visualTransformation = if (passwordVisible) VisualTransformation.None else PasswordVisualTransformation(), - trailingIcon = { - IconButton(onClick = { passwordVisible = !passwordVisible }) { - - } - }, - isError = passwordError - ) - - if (passwordError) { - val text = stringResource(id = R.string.Errorpasswdprofile) - Text( - text = text, - color = Color.Red, - fontSize = 12.sp, - modifier = Modifier.padding(top = 4.dp) - ) } + ) + } else { + DisplayPassword(onEdit = { isEditingPassword = true }) + } +} - Spacer(modifier = Modifier.height(8.dp)) +@Composable +fun PasswordEditingFields( + newPassword: String, + confirmPassword: String, + onNewPasswordChange: (String) -> Unit, + onConfirmPasswordChange: (String) -> Unit, + passwordVisible: Boolean, + onPasswordVisibilityChange: (Boolean) -> Unit, + passwordError: Boolean, + onDone: () -> Unit +) { + Column { + val text = stringResource(id = R.string.NewPasswdprofile) + PasswordTextField( + value = newPassword, + onValueChange = onNewPasswordChange, + label = text, + passwordVisible = passwordVisible, + onPasswordVisibilityChange = onPasswordVisibilityChange + ) - Button( - onClick = { - if (!passwordError && newPassword.isNotEmpty()) { - password = newPassword - isEditingPassword = false - } - }, - colors = ButtonDefaults.buttonColors(containerColor = Color.White), - modifier = Modifier.fillMaxWidth() - ) { - val text = stringResource(id = R.string.ButtonSaveprofile) - Text(text, fontSize = 18.sp, color = Color.Black) - } - } - } else { - Row( - verticalAlignment = Alignment.CenterVertically, - modifier = Modifier.clickable { isEditingPassword = true } - ) { - Text( - text = password, - fontSize = 18.sp, - fontWeight = FontWeight.Bold, - color = Color.White - ) - Icon( - imageVector = Icons.Default.Edit, - contentDescription = "Modifier", - tint = Color.White, - modifier = Modifier.size(16.dp).padding(start = 8.dp) - ) + Spacer(modifier = Modifier.height(8.dp)) + + val textConfirm = stringResource(id = R.string.ConfirmNewPasswdprofile) + PasswordTextField( + value = confirmPassword, + onValueChange = onConfirmPasswordChange, + label = textConfirm, + passwordVisible = passwordVisible, + onPasswordVisibilityChange = onPasswordVisibilityChange, + isError = passwordError, + onDone = onDone + ) + + if (passwordError) { + ErrorMessageProfileComponent(R.string.Errorpasswdprofile) } + + Spacer(modifier = Modifier.height(8.dp)) + + SaveButton(onClick = onDone) } } +@Composable +fun PasswordTextField( + value: String, + onValueChange: (String) -> Unit, + label: String, + passwordVisible: Boolean, + onPasswordVisibilityChange: (Boolean) -> Unit, + isError: Boolean = false, + onDone: (() -> Unit)? = null +) { + OutlinedTextField( + value = value, + onValueChange = onValueChange, + label = { Text(label) }, + modifier = Modifier.fillMaxWidth(), + textStyle = TextStyle(color = Color.White, fontSize = 18.sp), + singleLine = true, + keyboardOptions = KeyboardOptions.Default.copy( + keyboardType = KeyboardType.Password, + imeAction = if (onDone != null) ImeAction.Done else ImeAction.Next + ), + keyboardActions = onDone?.let { + KeyboardActions(onDone = { it() }) + } ?: KeyboardActions.Default, + visualTransformation = if (passwordVisible) VisualTransformation.None else PasswordVisualTransformation(), + trailingIcon = { + IconButton(onClick = { onPasswordVisibilityChange(!passwordVisible) }) { + // Ajout d'une icône pour montrer/masquer le mot de passe + } + }, + isError = isError + ) +} + +@Composable +fun SaveButton(onClick: () -> Unit) { + Button( + onClick = onClick, + colors = ButtonDefaults.buttonColors(containerColor = Color.White), + modifier = Modifier.fillMaxWidth() + ) { + val text = stringResource(id = R.string.ButtonSaveprofile) + Text(text, + fontSize = 18.sp, + color = Color.Black) + } +} + +@Composable +fun DisplayPassword(onEdit: () -> Unit) { + Row( + verticalAlignment = Alignment.CenterVertically, + modifier = Modifier.clickable { onEdit() } + ) { + Text( + text = "*****", + fontSize = 18.sp, + fontWeight = FontWeight.Bold, + color = Color.White + ) + Icon( + imageVector = Icons.Default.Edit, + contentDescription = "Modifier", + tint = Color.White, + modifier = Modifier.size(16.dp).padding(start = 8.dp) + ) + } +} + + + + + @Composable fun ButtonProfile(textResId : Int, size :Int, colorTexte : Color, colorButton : Color){ diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SignUpPage.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SignUpPage.kt index 5f87056..ef18e31 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SignUpPage.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/screens/SignUpPage.kt @@ -40,6 +40,8 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.navigation.NavController import com.example.what_the_fantasy.R +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.theme.What_The_FantasyTheme import org.mindrot.jbcrypt.BCrypt @@ -67,26 +69,21 @@ fun SignUpPage(navController: NavController) { horizontalAlignment = Alignment.CenterHorizontally ) { - TitlePage(R.string.titleSignUp, 20,Color.White) + TitlePageComponent(R.string.titleSignUp, 20,Color.White) IdentifiantTextFieldSign(R.string.IdentifiantLogin) EmailTextFieldSign("Email*") PassWdTextFieldSign(R.string.PasswdLogin) PassWdConfirmTextFieldSign(R.string.ConfirmPassWdSignUp) - SpaceSign(16) + SpaceHeightComponent(16) ConnexionButtonSign(R.string.ButtonSignUp,18, Color.White, Color.Black) - SpaceSign(16) + SpaceHeightComponent(16) CreateAccountButtonSign(R.string.ButtonLogin,12, Color.White, navController = navController) } } } -@Composable -fun SpaceSign(height : Int){ - Spacer( - modifier = Modifier - .height(height.dp)) // Ajoute un espacement -} + @Composable @@ -120,7 +117,7 @@ fun EmailTextFieldSign(textIdentifiant : String){ .fillMaxWidth() .padding(top = 8.dp), keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Email), - shape = RoundedCornerShape(16.dp) // 🔹 Bords arrondis + shape = RoundedCornerShape(16.dp) // Bords arrondis ) } }