|
|
|
@ -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
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|