|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package com.example.what_the_fantasy.ui.screens
|
|
|
|
|
|
|
|
|
|
import android.util.Log
|
|
|
|
|
import androidx.compose.foundation.background
|
|
|
|
|
import androidx.compose.foundation.clickable
|
|
|
|
|
import androidx.compose.foundation.layout.Box
|
|
|
|
@ -20,6 +21,7 @@ import androidx.compose.material3.IconButton
|
|
|
|
|
import androidx.compose.material3.OutlinedTextField
|
|
|
|
|
import androidx.compose.material3.Text
|
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
|
import androidx.compose.runtime.collectAsState
|
|
|
|
|
import androidx.compose.runtime.getValue
|
|
|
|
|
import androidx.compose.runtime.mutableStateOf
|
|
|
|
|
import androidx.compose.runtime.remember
|
|
|
|
@ -34,21 +36,25 @@ import androidx.compose.ui.text.input.PasswordVisualTransformation
|
|
|
|
|
import androidx.compose.ui.text.input.VisualTransformation
|
|
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
|
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
|
|
|
|
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.colorBackground
|
|
|
|
|
import com.example.what_the_fantasy.ui.theme.gradienBox
|
|
|
|
|
import com.example.what_the_fantasy.ui.components.ErrorMessageProfileComponent
|
|
|
|
|
import com.example.what_the_fantasy.ui.states.SignInUserState
|
|
|
|
|
import com.example.what_the_fantasy.ui.viewModels.SignInUserViewModel
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
fun SignUpPage(navControllerLogin: () -> Unit, services : IServices) {
|
|
|
|
|
fun SignUpPage(navControllerLogin: () -> Unit) {
|
|
|
|
|
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 signInUserVM : SignInUserViewModel = viewModel()
|
|
|
|
|
val signInState by signInUserVM.userState.collectAsState()
|
|
|
|
|
|
|
|
|
|
Box(
|
|
|
|
|
modifier = Modifier
|
|
|
|
@ -67,14 +73,28 @@ fun SignUpPage(navControllerLogin: () -> Unit, services : IServices) {
|
|
|
|
|
horizontalAlignment = Alignment.CenterHorizontally
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
|
|
TitlePageComponent(R.string.titleSignUp,Color.White)
|
|
|
|
|
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 })
|
|
|
|
|
TitlePageComponent(R.string.titleSignUp,Color.White) // Page Title
|
|
|
|
|
|
|
|
|
|
IdentifiantTextFieldSign(R.string.IdentifiantLogin,signInState.username){ // Username
|
|
|
|
|
signInUserVM.setUsername(it)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EmailTextFieldSign(R.string.EmailSignUp, signInState.email){ // Email
|
|
|
|
|
signInUserVM.setEmail(it)
|
|
|
|
|
}
|
|
|
|
|
PassWdTextFieldSign(R.string.PasswdLogin,signInState.password){ // Password
|
|
|
|
|
signInUserVM.setPassword(it)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PassWdConfirmTextFieldSign(R.string.ConfirmPassWdSignUp,signInState.confirmPassword){ // confirm Password
|
|
|
|
|
signInUserVM.setConfirmPassword(it)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SpaceHeightComponent(16)
|
|
|
|
|
ConnexionButtonSign(R.string.ButtonSignUp,18, Color.White, Color.Black, username, email, password, confirmPassword, services, navControllerLogin)
|
|
|
|
|
|
|
|
|
|
ConnexionButtonSign(R.string.ButtonSignUp,18, Color.White, Color.Black, signInState.username, signInState.email, signInState.password, signInState.confirmPassword, signInUserVM, navControllerLogin)
|
|
|
|
|
SpaceHeightComponent(16)
|
|
|
|
|
|
|
|
|
|
ReturnLogin(R.string.ButtonLogin,12, Color.White, navController = navControllerLogin)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -82,8 +102,6 @@ fun SignUpPage(navControllerLogin: () -> Unit, services : IServices) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
fun IdentifiantTextFieldSign(textIdentifiantResId : Int, identifiant: String, onValueChange: (String) -> Unit){
|
|
|
|
|
val textIdentifiant = stringResource(id = textIdentifiantResId)
|
|
|
|
@ -120,8 +138,10 @@ fun EmailTextFieldSign(textIdentifiantResId: Int, email: String, onValueChange:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
fun PassWdTextFieldSign(textpasswdResId : Int, passwd: String, onValueChange: (String) -> Unit, passwordVisible: Boolean, onPasswordVisibilityChange: () -> Unit){
|
|
|
|
|
fun PassWdTextFieldSign(textpasswdResId : Int, passwd: String, onValueChange: (String) -> Unit){
|
|
|
|
|
val textpasswd = stringResource(id = textpasswdResId)
|
|
|
|
|
var passwordVisible by remember { mutableStateOf(false) }
|
|
|
|
|
|
|
|
|
|
Column(modifier = Modifier.padding(top = 10.dp)) {
|
|
|
|
|
OutlinedTextField(
|
|
|
|
|
value = passwd,
|
|
|
|
@ -133,7 +153,9 @@ fun PassWdTextFieldSign(textpasswdResId : Int, passwd: String, onValueChange: (S
|
|
|
|
|
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password),
|
|
|
|
|
visualTransformation = if (passwordVisible) VisualTransformation.None else PasswordVisualTransformation(),
|
|
|
|
|
trailingIcon = {
|
|
|
|
|
IconButton(onClick = onPasswordVisibilityChange) {
|
|
|
|
|
IconButton(onClick = {
|
|
|
|
|
passwordVisible = !passwordVisible
|
|
|
|
|
}) {
|
|
|
|
|
Icon(imageVector = Icons.Default.Check, contentDescription = "Valider")
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
@ -143,8 +165,10 @@ fun PassWdTextFieldSign(textpasswdResId : Int, passwd: String, onValueChange: (S
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
fun PassWdConfirmTextFieldSign(textpasswdResId : Int,confirmPassword: String, onValueChange: (String) -> Unit, passwordVisible: Boolean, onPasswordVisibilityChange: () -> Unit){
|
|
|
|
|
fun PassWdConfirmTextFieldSign(textpasswdResId : Int,confirmPassword: String, onValueChange: (String) -> Unit){
|
|
|
|
|
val textpasswd = stringResource(id = textpasswdResId)
|
|
|
|
|
var passwordVisible by remember { mutableStateOf(false) }
|
|
|
|
|
|
|
|
|
|
Column(modifier = Modifier.padding(top = 10.dp)) {
|
|
|
|
|
OutlinedTextField(
|
|
|
|
|
value = confirmPassword,
|
|
|
|
@ -156,7 +180,7 @@ fun PassWdConfirmTextFieldSign(textpasswdResId : Int,confirmPassword: String, on
|
|
|
|
|
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password),
|
|
|
|
|
visualTransformation = if (passwordVisible) VisualTransformation.None else PasswordVisualTransformation(),
|
|
|
|
|
trailingIcon = {
|
|
|
|
|
IconButton(onClick = onPasswordVisibilityChange) {
|
|
|
|
|
IconButton(onClick = {passwordVisible = !passwordVisible}) {
|
|
|
|
|
Icon(imageVector = Icons.Default.Check, contentDescription = "Valider")
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
@ -187,7 +211,7 @@ fun ConnexionButtonSign(
|
|
|
|
|
email: String,
|
|
|
|
|
password: String,
|
|
|
|
|
confirmPassword: String,
|
|
|
|
|
service: IServices,
|
|
|
|
|
viewModel: SignInUserViewModel,
|
|
|
|
|
navController: ()-> Unit
|
|
|
|
|
) {
|
|
|
|
|
val title = stringResource(id = titleResId)
|
|
|
|
@ -207,7 +231,7 @@ fun ConnexionButtonSign(
|
|
|
|
|
passwordErrorEmpty = password.isBlank() || confirmPassword.isBlank()
|
|
|
|
|
|
|
|
|
|
if (!emailError && !passwordError && !usernameError && !passwordErrorEmpty) {
|
|
|
|
|
usernameErrorExist = !service.CreateUser(username, email, password, service)
|
|
|
|
|
usernameErrorExist = !viewModel.createUser(username, email, password)
|
|
|
|
|
if(!usernameErrorExist){
|
|
|
|
|
navController() // retour à la page login
|
|
|
|
|
}
|
|
|
|
|