@ -15,8 +15,11 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Check
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
@ -40,15 +43,23 @@ 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.data.services.IServices
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 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
@Composable
fun SignUpPage ( navController : NavController ) {
fun SignUpPage ( navController : NavController , 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
@ -67,14 +78,14 @@ fun SignUpPage(navController: NavController) {
) {
TitlePageComponent ( R . string . titleSignUp , 20 , Color . White )
IdentifiantTextFieldSign ( R . string . IdentifiantLogin )
EmailTextFieldSign ( " Email* " )
PassWdTextFieldSign ( R . string . PasswdLogin )
PassWdConfirmTextFieldSign ( R . string . ConfirmPassWdSignUp )
IdentifiantTextFieldSign ( R . string . IdentifiantLogin ,identifiant = username , onValueChange = { username = it } )
EmailTextFieldSign ( R . string . EmailSignUp , email , onValueChange = { email = it } )
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 )
ConnexionButtonSign ( R . string . ButtonSignUp , 18 , Color . White , Color . Black , username , email , password , confirmPassword , services , navController = navController )
SpaceHeightComponent ( 16 )
CreateAccountButtonSig n( R . string . ButtonLogin , 12 , Color . White , navController = navController )
ReturnLogi n( R . string . ButtonLogin , 12 , Color . White , navController = navController )
}
}
@ -84,50 +95,47 @@ fun SignUpPage(navController: NavController) {
@Composable
fun IdentifiantTextFieldSign ( textIdentifiantResId : Int ){
fun IdentifiantTextFieldSign ( textIdentifiantResId : Int , identifiant : String , onValueChange : ( String ) -> Unit ){
val textIdentifiant = stringResource ( id = textIdentifiantResId )
var identifiant by remember { mutableStateOf ( " " ) } // Stocke la valeur du champ
Column ( modifier = Modifier . padding ( top = 16. dp ) ) {
OutlinedTextField (
value = identifiant ,
onValueChange = { identifiant = it } ,
onValueChange = onValueChange ,
label = { Text ( textIdentifiant ) } ,
modifier = Modifier
. fillMaxWidth ( )
. padding ( top = 8. dp ) ,
keyboardOptions = KeyboardOptions ( keyboardType = KeyboardType . Text ) ,
shape = RoundedCornerShape ( 16. dp ) // 🔹 Bords arrondis
shape = RoundedCornerShape ( 16. dp )
)
}
}
@Composable
fun EmailTextFieldSign ( textIdentifiant : String ) {
va r identifiant by remember { mutableStateOf ( " " ) } // Stocke la valeur du champ
fun EmailTextFieldSign ( textIdentifiant ResId: Int , email : String , onValueChange : ( String ) -> Unit ) {
va l textIdentifiant = stringResource ( id = textIdentifiantResId )
Column ( modifier = Modifier . padding ( top = 16. dp ) ) {
OutlinedTextField (
value = identifiant ,
onValueChange = { identifiant = it } ,
value = email ,
onValueChange = onValueChange ,
label = { Text ( textIdentifiant ) } ,
modifier = Modifier
. fillMaxWidth ( )
. padding ( top = 8. dp ) ,
keyboardOptions = KeyboardOptions ( keyboardType = KeyboardType . Email ) ,
shape = RoundedCornerShape ( 16. dp ) // Bords arrondis
shape = RoundedCornerShape ( 16. dp )
)
}
}
@Composable
fun PassWdTextFieldSign ( textpasswdResId : Int ){
fun PassWdTextFieldSign ( textpasswdResId : Int , passwd : String , onValueChange : ( String ) -> Unit , passwordVisible : Boolean , onPasswordVisibilityChange : ( ) -> Unit ){
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
Column ( modifier = Modifier . padding ( top = 10. dp ) ) {
OutlinedTextField (
value = passwd ,
onValueChange = { passwd = it } ,
onValueChange = onValueChange ,
label = { Text ( textpasswd ) } ,
modifier = Modifier
. fillMaxWidth ( )
@ -135,23 +143,22 @@ fun PassWdTextFieldSign(textpasswdResId : Int){
keyboardOptions = KeyboardOptions ( keyboardType = KeyboardType . Password ) ,
visualTransformation = if ( passwordVisible ) VisualTransformation . None else PasswordVisualTransformation ( ) ,
trailingIcon = {
IconButton ( onClick = { passwordVisible = ! passwordVisible } ) {
IconButton ( onClick = onPasswordVisibilityChange ) {
Icon ( imageVector = Icons . Default . Check , contentDescription = " Valider " )
}
} ,
shape = RoundedCornerShape ( 16. dp ) // 🔹 Bords arrondis
shape = RoundedCornerShape ( 16. dp )
)
}
}
@Composable
fun PassWdConfirmTextFieldSign ( textpasswdResId : Int ){
fun PassWdConfirmTextFieldSign ( textpasswdResId : Int ,confirmPassword : String , onValueChange : ( String ) -> Unit , passwordVisible : Boolean , onPasswordVisibilityChange : ( ) -> Unit ){
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
Column ( modifier = Modifier . padding ( top = 10. dp ) ) {
OutlinedTextField (
value = passw d,
onValueChange = { passwd = it } ,
value = confirmPasswor d,
onValueChange = onValueChange ,
label = { Text ( textpasswd ) } ,
modifier = Modifier
. fillMaxWidth ( )
@ -159,31 +166,88 @@ fun PassWdConfirmTextFieldSign(textpasswdResId : Int){
keyboardOptions = KeyboardOptions ( keyboardType = KeyboardType . Password ) ,
visualTransformation = if ( passwordVisible ) VisualTransformation . None else PasswordVisualTransformation ( ) ,
trailingIcon = {
IconButton ( onClick = { passwordVisible = ! passwordVisible } ) {
IconButton ( onClick = onPasswordVisibilityChange ) {
Icon ( imageVector = Icons . Default . Check , contentDescription = " Valider " )
}
} ,
shape = RoundedCornerShape ( 16. dp ) // 🔹 Bords arrondis
shape = RoundedCornerShape ( 16. dp )
)
}
}
// Validation de email
fun isValidEmail ( email : String ) : Boolean {
val emailRegex = " [a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+ \\ .[a-zA-Z]{2,6} "
return email . matches ( emailRegex . toRegex ( ) )
}
// Vérification mots de passe
fun arePasswordsMatching ( password : String , confirmPassword : String ) : Boolean {
return password == confirmPassword
}
@Composable
fun ConnexionButtonSign ( titleResId : Int , size : Int , colorButton : Color , colorText : Color ) {
fun ConnexionButtonSign (
titleResId : Int ,
size : Int ,
colorButton : Color ,
colorText : Color ,
username : String ,
email : String ,
password : String ,
confirmPassword : String ,
service : IServices ,
navController : NavController
) {
val title = stringResource ( id = titleResId )
var emailError by remember { mutableStateOf ( false ) }
var passwordError by remember { mutableStateOf ( false ) }
var usernameErrorEmpty by remember { mutableStateOf ( false ) }
var usernameErrorExist by remember { mutableStateOf ( false ) }
Button (
onClick = { /* Action */ } ,
onClick = {
emailError = !is ValidEmail ( email )
passwordError = ! arePasswordsMatching ( password , confirmPassword )
usernameErrorEmpty = username . isBlank ( )
if ( ! emailError && ! passwordError && ! usernameErrorEmpty ) {
usernameErrorExist = ! service . CreateUser ( username , email , password , " https://img.freepik.com/vecteurs-libre/personnage-magicien-malefique-fantaisie_1045-193.jpg?size=338&ext=jpg " , service )
}
} ,
colors = ButtonDefaults . buttonColors ( containerColor = colorButton ) ,
modifier = Modifier
. fillMaxWidth ( ) ,
modifier = Modifier . fillMaxWidth ( ) ,
) {
Text ( title , fontSize = size . sp , color = colorText )
}
// Afficher erreurs
if ( usernameErrorEmpty ) {
ErrorMessageProfileComponent ( R . string . ErrorUserEmptySignUp )
}
if ( usernameErrorExist ) {
ErrorMessageProfileComponent ( R . string . ErrorUserExistSignUp )
}
if ( emailError ) {
ErrorMessageProfileComponent ( R . string . ErrorEmailSignUp )
}
if ( passwordError ) {
ErrorMessageProfileComponent ( R . string . ErrorPasswordSignUp )
}
}
@Composable
fun CreateAccountButtonSign ( titleResId : Int , size : Int , color : Color , navController : NavController ) {
fun ReturnLogi n( titleResId : Int , size : Int , color : Color , navController : NavController ) {
val title = stringResource ( id = titleResId )
Text (
text = title ,