diff --git a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/navigations/AppNavigator.kt b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/navigations/AppNavigator.kt index 529a1dc..f80a11c 100644 --- a/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/navigations/AppNavigator.kt +++ b/What_The_Fantasy/app/src/main/java/com/example/what_the_fantasy/ui/navigations/AppNavigator.kt @@ -50,13 +50,20 @@ fun AppNavigator() { val navController = rememberNavController() val services = ServicesStub() NavHost(navController, startDestination = Destination.Login.route) { - composable(Destination.Login.route) { LoginPage( - navControllerSignUp = { navController.navigate(Destination.SignUp.route) }, - navControllerProfil = { userIndex -> - navController.navigate(Destination.Profil.createRoute(userIndex)) // Passe l'index à Profil - }, - services - ) } + composable(Destination.Login.route) { + LoginPage( + navControllerSignUp = { + navController.navigate(Destination.SignUp.route) + }, + navControllerProfil = { userIndex -> + navController.navigate(Destination.Profil.createRoute(userIndex)) { + // Vider pile de navigation pour empêcher le retour à la page Login + popUpTo(Destination.Login.route) { inclusive = true } + } + }, + services + ) + } composable(Destination.Accueil.route) { val userIndex = it.arguments?.getString("userIndex")?.toInt() ?: -1 AccueilPage( @@ -104,7 +111,13 @@ fun AppNavigator() { } composable(Destination.Quote.route) { QuotePage() } composable(Destination.Search.route) { SearchPage() } - composable(Destination.SignUp.route) { SignUpPage(navController, services) } + composable(Destination.SignUp.route) { SignUpPage( + navControllerLogin = { + navController.navigate(Destination.Login.route){ + // Vider pile de navigation pour empêcher le retour à la page Sign up + popUpTo(Destination.Login.route) { inclusive = true } + } + },services) } composable(Destination.SubmitQuote.route) { SubmitQuotePage() } composable(Destination.QuizMenu.route) { 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 48c21b8..bb51217 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 @@ -51,15 +51,15 @@ import com.example.what_the_fantasy.ui.theme.colorBackground import com.example.what_the_fantasy.ui.theme.gradienBox 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.hashPassword @Composable -fun SignUpPage(navController: NavController, services : IServices) { +fun SignUpPage(navControllerLogin: () -> Unit, services : IServices) { var username by remember { mutableStateOf("") } var email by remember { mutableStateOf("") } var password by remember { mutableStateOf("") } var confirmPassword by remember { mutableStateOf("") } var passwordVisible by remember { mutableStateOf(false) } - //val servicesStub = ServicesStub() Box( modifier = Modifier @@ -83,9 +83,9 @@ fun SignUpPage(navController: NavController, services : IServices) { PassWdTextFieldSign(R.string.PasswdLogin,password, onValueChange = { password = it },passwordVisible,onPasswordVisibilityChange = { passwordVisible = !passwordVisible }) PassWdConfirmTextFieldSign(R.string.ConfirmPassWdSignUp,confirmPassword,onValueChange = { confirmPassword = it },passwordVisible,onPasswordVisibilityChange = { passwordVisible = !passwordVisible }) SpaceHeightComponent(16) - ConnexionButtonSign(R.string.ButtonSignUp,18, Color.White, Color.Black, username, email, password, confirmPassword, services, navController = navController) + ConnexionButtonSign(R.string.ButtonSignUp,18, Color.White, Color.Black, username, email, password, confirmPassword, services, navControllerLogin) SpaceHeightComponent(16) - ReturnLogin(R.string.ButtonLogin,12, Color.White, navController = navController) + ReturnLogin(R.string.ButtonLogin,12, Color.White, navController = navControllerLogin) } } @@ -198,25 +198,28 @@ fun ConnexionButtonSign( password: String, confirmPassword: String, service: IServices, - navController: NavController + navController: ()-> Unit ) { val title = stringResource(id = titleResId) var emailError by remember { mutableStateOf(false) } var passwordError by remember { mutableStateOf(false) } + var passwordErrorEmpty by remember { mutableStateOf(false) } var usernameErrorEmpty by remember { mutableStateOf(false) } var usernameErrorExist by remember { mutableStateOf(false) } - Button( onClick = { emailError = !isValidEmail(email) - passwordError = !arePasswordsMatching(password, confirmPassword) - usernameErrorEmpty = username.isBlank() + passwordErrorEmpty = password.isBlank() || confirmPassword.isBlank() - if (!emailError && !passwordError && !usernameErrorEmpty) { + if (!emailError && !passwordError && !usernameErrorEmpty && !passwordErrorEmpty) { usernameErrorExist = !service.CreateUser(username, email, password, "https://img.freepik.com/vecteurs-libre/personnage-magicien-malefique-fantaisie_1045-193.jpg?size=338&ext=jpg", service) + if(!usernameErrorExist){ + navController() // retour à la page login + } + } }, colors = ButtonDefaults.buttonColors(containerColor = colorButton), @@ -242,19 +245,26 @@ fun ConnexionButtonSign( ErrorMessageProfileComponent(R.string.ErrorPasswordSignUp) } + if (passwordErrorEmpty) { + ErrorMessageProfileComponent(R.string.ErrorPasswordEmpty) + } + + } + + @Composable -fun ReturnLogin(titleResId: Int, size: Int, color: Color, navController: NavController) { +fun ReturnLogin(titleResId: Int, size: Int, color: Color, navController: () -> Unit) { val title = stringResource(id = titleResId) Text( text = title, fontSize = size.sp, color = color, modifier = Modifier.clickable { - navController.popBackStack() // Revenir à la page précédente + navController() // Revenir à la page login } ) } 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 a9a859b..6485726 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 @@ -22,6 +22,7 @@ Les mots de passe ne correspondent pas Le nom d\'utilisateur ne peut pas être vide Le nom d\'utilisateur n\'est pas disponible + Vous devez mettre un mot de passe //Page Profil Profil 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 b74a681..254d478 100644 --- a/What_The_Fantasy/app/src/main/res/values/strings.xml +++ b/What_The_Fantasy/app/src/main/res/values/strings.xml @@ -21,6 +21,7 @@ Passwords do not match Username cannot be empty Username is not available + You must put a password //Page Profil Profile