|
|
@ -5,14 +5,18 @@ import androidx.compose.foundation.background
|
|
|
|
import androidx.compose.foundation.clickable
|
|
|
|
import androidx.compose.foundation.clickable
|
|
|
|
import androidx.compose.foundation.layout.Box
|
|
|
|
import androidx.compose.foundation.layout.Box
|
|
|
|
import androidx.compose.foundation.layout.Column
|
|
|
|
import androidx.compose.foundation.layout.Column
|
|
|
|
|
|
|
|
import androidx.compose.foundation.layout.Row
|
|
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
|
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
|
|
|
|
|
|
|
import androidx.compose.foundation.layout.height
|
|
|
|
import androidx.compose.foundation.layout.padding
|
|
|
|
import androidx.compose.foundation.layout.padding
|
|
|
|
|
|
|
|
import androidx.compose.foundation.layout.width
|
|
|
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
|
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
|
|
import androidx.compose.foundation.text.KeyboardOptions
|
|
|
|
import androidx.compose.foundation.text.KeyboardOptions
|
|
|
|
import androidx.compose.material3.Button
|
|
|
|
import androidx.compose.material3.Button
|
|
|
|
import androidx.compose.material3.ButtonDefaults
|
|
|
|
import androidx.compose.material3.ButtonDefaults
|
|
|
|
import androidx.compose.material3.IconButton
|
|
|
|
import androidx.compose.material3.IconButton
|
|
|
|
|
|
|
|
import androidx.compose.material3.MaterialTheme
|
|
|
|
import androidx.compose.material3.OutlinedTextField
|
|
|
|
import androidx.compose.material3.OutlinedTextField
|
|
|
|
import androidx.compose.material3.Text
|
|
|
|
import androidx.compose.material3.Text
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
@ -81,6 +85,8 @@ fun LoginPage(navControllerSignUp: () -> Unit, navControllerProfil: (Int) -> Uni
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
@Composable
|
|
|
|
fun IdentifiantTextField(textIdentifiantResId : Int) : String{
|
|
|
|
fun IdentifiantTextField(textIdentifiantResId : Int) : String{
|
|
|
|
val textIdentifiant = stringResource(id = textIdentifiantResId)
|
|
|
|
val textIdentifiant = stringResource(id = textIdentifiantResId)
|
|
|
@ -129,29 +135,47 @@ fun PassWdTextField(textpasswdResId : Int) : String{
|
|
|
|
@Composable
|
|
|
|
@Composable
|
|
|
|
fun ConnexionButtonLogin(userStub : List<User>, id : String, passwd : String, titleResId : Int, size : Int, colorButton : Color, colorText : Color, navController: (Int) -> Unit){
|
|
|
|
fun ConnexionButtonLogin(userStub : List<User>, id : String, passwd : String, titleResId : Int, size : Int, colorButton : Color, colorText : Color, navController: (Int) -> Unit){
|
|
|
|
val title = stringResource(id = titleResId)
|
|
|
|
val title = stringResource(id = titleResId)
|
|
|
|
|
|
|
|
var showError by remember { mutableStateOf(false) }
|
|
|
|
Button(
|
|
|
|
Button(
|
|
|
|
onClick = { validLogin(id, passwd, userStub, navController) },
|
|
|
|
onClick = { showError = !validLogin(id, passwd, userStub, navController)
|
|
|
|
|
|
|
|
},
|
|
|
|
colors = ButtonDefaults.buttonColors(containerColor = colorButton),
|
|
|
|
colors = ButtonDefaults.buttonColors(containerColor = colorButton),
|
|
|
|
modifier = Modifier
|
|
|
|
modifier = Modifier
|
|
|
|
.fillMaxWidth(),
|
|
|
|
.fillMaxWidth(),
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
Text(title, fontSize = size.sp, color = colorText)
|
|
|
|
Text(title, fontSize = size.sp, color = colorText)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( showError){
|
|
|
|
|
|
|
|
ErrorMessage()
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun validLogin(identifiant : String, passwd : String, users : List<User>, navController: (Int) -> Unit){
|
|
|
|
fun validLogin(identifiant : String, passwd : String, users : List<User>, navController: (Int) -> Unit): Boolean {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
users.forEachIndexed { index, user ->
|
|
|
|
users.forEachIndexed { index, user ->
|
|
|
|
val hashPassWd = hashPassword(passwd)
|
|
|
|
val hashPassWd = hashPassword(passwd)
|
|
|
|
if (user.username == identifiant && user.password == hashPassWd) {
|
|
|
|
if (user.username == identifiant && user.password == hashPassWd) {
|
|
|
|
// Utilise l'index pour naviguer à la position correspondante
|
|
|
|
// Utilise l'index pour naviguer à la position correspondante
|
|
|
|
navController(index) // Passer l'index à la fonction navController
|
|
|
|
navController(index) // Passer l'index à la fonction navController
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
|
|
|
fun ErrorMessage() {
|
|
|
|
|
|
|
|
Text(
|
|
|
|
|
|
|
|
text = "Username or Password does not exist.",
|
|
|
|
|
|
|
|
color = Color.Red,
|
|
|
|
|
|
|
|
modifier = Modifier.padding(top = 8.dp)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
@Composable
|
|
|
|
@Composable
|
|
|
|
fun CreateAccountButton(titleResId : Int, size : Int, color : Color, navController: () -> Unit) {
|
|
|
|
fun CreateAccountButton(titleResId : Int, size : Int, color : Color, navController: () -> Unit) {
|
|
|
|
val title = stringResource(id = titleResId)
|
|
|
|
val title = stringResource(id = titleResId)
|
|
|
|