|
|
@ -16,6 +16,7 @@ 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
|
|
|
|
|
|
|
|
import androidx.compose.runtime.collectAsState
|
|
|
|
import androidx.compose.runtime.getValue
|
|
|
|
import androidx.compose.runtime.getValue
|
|
|
|
import androidx.compose.runtime.mutableStateOf
|
|
|
|
import androidx.compose.runtime.mutableStateOf
|
|
|
|
import androidx.compose.runtime.remember
|
|
|
|
import androidx.compose.runtime.remember
|
|
|
@ -30,6 +31,7 @@ import androidx.compose.ui.text.input.PasswordVisualTransformation
|
|
|
|
import androidx.compose.ui.text.input.VisualTransformation
|
|
|
|
import androidx.compose.ui.text.input.VisualTransformation
|
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
|
|
|
|
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
|
|
|
import com.example.what_the_fantasy.Logs.LogsUsers
|
|
|
|
import com.example.what_the_fantasy.Logs.LogsUsers
|
|
|
|
import com.example.what_the_fantasy.R
|
|
|
|
import com.example.what_the_fantasy.R
|
|
|
|
import com.example.what_the_fantasy.data.model.User
|
|
|
|
import com.example.what_the_fantasy.data.model.User
|
|
|
@ -40,10 +42,13 @@ import com.example.what_the_fantasy.ui.components.TitlePageComponent
|
|
|
|
import com.example.what_the_fantasy.ui.components.hashPassword
|
|
|
|
import com.example.what_the_fantasy.ui.components.hashPassword
|
|
|
|
import com.example.what_the_fantasy.ui.theme.colorBackground
|
|
|
|
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.theme.gradienBox
|
|
|
|
|
|
|
|
import com.example.what_the_fantasy.ui.viewModels.AuthUserViewModel
|
|
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
@Composable
|
|
|
|
fun LoginPage(navControllerSignUp: () -> Unit, navControllerProfil: (Int) -> Unit, services : IServices) {
|
|
|
|
fun LoginPage(navControllerSignUp: () -> Unit, navControllerProfil: (Int) -> Unit, services : IServices) {
|
|
|
|
val users = services.getAllUsers()
|
|
|
|
val users = services.getAllUsers()
|
|
|
|
|
|
|
|
val authUserVM : AuthUserViewModel = viewModel()
|
|
|
|
|
|
|
|
val authState by authUserVM.userState.collectAsState()
|
|
|
|
|
|
|
|
|
|
|
|
Box(
|
|
|
|
Box(
|
|
|
|
modifier = Modifier
|
|
|
|
modifier = Modifier
|
|
|
@ -63,7 +68,9 @@ fun LoginPage(navControllerSignUp: () -> Unit, navControllerProfil: (Int) -> Uni
|
|
|
|
|
|
|
|
|
|
|
|
TitlePageComponent(R.string.titleLogin, MaterialTheme.colorScheme.primary)
|
|
|
|
TitlePageComponent(R.string.titleLogin, MaterialTheme.colorScheme.primary)
|
|
|
|
SpaceHeightComponent(20)
|
|
|
|
SpaceHeightComponent(20)
|
|
|
|
ConnexionButtonLogin(users,IdentifiantTextField(R.string.IdentifiantLogin), PassWdTextField(R.string.PasswdLogin), R.string.ButtonLogin,18, Color.White, Color.Black,navControllerProfil)
|
|
|
|
ConnexionButtonLogin(users,IdentifiantTextField(R.string.IdentifiantLogin, authState.username){
|
|
|
|
|
|
|
|
authUserVM.setUsername(it)
|
|
|
|
|
|
|
|
}, PassWdTextField(R.string.PasswdLogin), R.string.ButtonLogin,18,navControllerProfil)
|
|
|
|
SpaceHeightComponent(16)
|
|
|
|
SpaceHeightComponent(16)
|
|
|
|
CreateAccountButton(R.string.ButtonCreateLogin,12, MaterialTheme.colorScheme.primary, navControllerSignUp)
|
|
|
|
CreateAccountButton(R.string.ButtonCreateLogin,12, MaterialTheme.colorScheme.primary, navControllerSignUp)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -74,13 +81,14 @@ fun LoginPage(navControllerSignUp: () -> Unit, navControllerProfil: (Int) -> Uni
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
@Composable
|
|
|
|
fun IdentifiantTextField(textIdentifiantResId : Int) : String{
|
|
|
|
fun IdentifiantTextField(textIdentifiantResId : Int, username : String, onValueChange: (String) -> Unit ) : String{
|
|
|
|
val textIdentifiant = stringResource(id = textIdentifiantResId)
|
|
|
|
val textIdentifiant = stringResource(id = textIdentifiantResId)
|
|
|
|
var identifiant by remember { mutableStateOf("") }
|
|
|
|
//var identifiant by remember { mutableStateOf("") }
|
|
|
|
|
|
|
|
|
|
|
|
Column(modifier = Modifier.padding(top = 16.dp)) {
|
|
|
|
Column(modifier = Modifier.padding(top = 16.dp)) {
|
|
|
|
OutlinedTextField(
|
|
|
|
OutlinedTextField(
|
|
|
|
value = identifiant,
|
|
|
|
value = username,
|
|
|
|
onValueChange = { identifiant = it },
|
|
|
|
onValueChange = onValueChange,
|
|
|
|
label = { Text(textIdentifiant) },
|
|
|
|
label = { Text(textIdentifiant) },
|
|
|
|
modifier = Modifier
|
|
|
|
modifier = Modifier
|
|
|
|
.fillMaxWidth()
|
|
|
|
.fillMaxWidth()
|
|
|
@ -89,7 +97,7 @@ fun IdentifiantTextField(textIdentifiantResId : Int) : String{
|
|
|
|
shape = RoundedCornerShape(16.dp)
|
|
|
|
shape = RoundedCornerShape(16.dp)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return identifiant;
|
|
|
|
return username;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
@Composable
|
|
|
@ -119,11 +127,11 @@ 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(users : List<User>, username : String, passwd : String, titleResId : Int, size : Int, navController: (Int) -> Unit){
|
|
|
|
val title = stringResource(id = titleResId)
|
|
|
|
val title = stringResource(id = titleResId)
|
|
|
|
var showError by remember { mutableStateOf(false) }
|
|
|
|
var showError by remember { mutableStateOf(false) }
|
|
|
|
Button(
|
|
|
|
Button(
|
|
|
|
onClick = { showError = !validLogin(id, passwd, userStub, navController)
|
|
|
|
onClick = { showError = !validLogin(username, passwd, users, navController)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
colors = ButtonDefaults.buttonColors(containerColor = MaterialTheme.colorScheme.background),
|
|
|
|
colors = ButtonDefaults.buttonColors(containerColor = MaterialTheme.colorScheme.background),
|
|
|
|
modifier = Modifier
|
|
|
|
modifier = Modifier
|
|
|
@ -138,12 +146,12 @@ fun ConnexionButtonLogin(userStub : List<User>, id : String, passwd : String, ti
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun validLogin(identifiant : String, passwd : String, users : List<User>, navController: (Int) -> Unit): Boolean {
|
|
|
|
fun validLogin(username : String, passwd : String, users : List<User>, navController: (Int) -> Unit): Boolean {
|
|
|
|
val logsUser = LogsUsers() //gestion des logs pour les utilisateurs
|
|
|
|
val logsUser = LogsUsers() //gestion des logs pour les utilisateurs
|
|
|
|
|
|
|
|
|
|
|
|
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 == username && user.password == hashPassWd) {
|
|
|
|
navController(index)
|
|
|
|
navController(index)
|
|
|
|
logsUser.logInformationUserConnect(user, "UserConnect")
|
|
|
|
logsUser.logInformationUserConnect(user, "UserConnect")
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|