Lien avec le profil

pull/51/head
Leni BEAULATON 3 weeks ago
parent 210d8c575f
commit 2e98af2450

@ -9,7 +9,12 @@ import kotlinx.coroutines.flow.StateFlow
interface IServices {
fun validLogin(username : String, passwd : String, userSession : StateFlow<AuthUserState>, navController: (Int) -> Unit): Boolean
fun validLogin(username : String,
passwd : String,
userSession : StateFlow<AuthUserState>,
navController: (Int) -> Unit,
initialierCurrentUser : (Int) ->Unit): Boolean
fun EditUsername(username : String, index : Int) : Boolean
fun EditEmail(email : String, index : Int) : Boolean
fun EditPasswd(passwd : String, index : Int)

@ -18,12 +18,17 @@ class ServicesStub : IServices {
val logsUser = LogsUsers() //gestion des logs pour les utilisateurs
override fun validLogin(username : String, passwd : String, userSession : StateFlow<AuthUserState>, navController: (Int) -> Unit): Boolean{
override fun validLogin(username : String,
passwd : String,
userSession : StateFlow<AuthUserState>,
navController: (Int) -> Unit,
initialierCurrentUser : (Int) ->Unit): Boolean{
users.forEachIndexed { index, user ->
val hashPassWd = hashPassword(passwd)
if (user.username == username && user.password == hashPassWd) {
userSession.value.id = index
//userSession.value.id = index
initialierCurrentUser(index)
navController(index)
logsUser.logInformationUserConnect(user, "UserConnect")
return true

@ -97,7 +97,8 @@ fun AppNavigator() {
}
},
authUserVM = authUserVM,
authState = authState
authState = authState,
initialierCurrentUser ={currentUserVM.initialiseCurrentUser(it)}
)
}
@ -140,7 +141,6 @@ fun AppNavigator() {
composable<Profil> {
val profil: Profil = it.toRoute()
ProfilPage(
index = profil.userIndex,
navFavorite = { navController.navigate(Favorite(profil.userIndex)) },
navAccueil = { navController.navigate(Accueil(profil.userIndex)) },
navQuiz = { navController.navigate(QuizMenu(profil.userIndex)) },
@ -150,6 +150,8 @@ fun AppNavigator() {
popUpTo(profil) { inclusive = true }
}
},
currentUserVM = currentUserVM,
currentUserState = currentUserState,
)
}
composable<OneQuote> {

@ -47,7 +47,12 @@ import com.example.what_the_fantasy.ui.theme.gradienBox
import com.example.what_the_fantasy.ui.viewModels.AuthUserViewModel
@Composable
fun LoginPage(navControllerSignUp: () -> Unit, navControllerProfil: (Int) -> Unit, authUserVM : AuthUserViewModel, authState : AuthUserState) {
fun LoginPage(navControllerSignUp: () -> Unit,
navControllerProfil: (Int) -> Unit,
authUserVM : AuthUserViewModel,
authState : AuthUserState,
initialierCurrentUser : (Int) -> Unit) {
// val authUserVM : AuthUserViewModel = viewModel()
// val authState by authUserVM.userState.collectAsState()
@ -69,11 +74,15 @@ fun LoginPage(navControllerSignUp: () -> Unit, navControllerProfil: (Int) -> Uni
TitlePageComponent(R.string.titleLogin, MaterialTheme.colorScheme.primary)
SpaceHeightComponent(20)
ConnexionButtonLogin(authUserVM,IdentifiantTextField(R.string.IdentifiantLogin, authState.username){
ConnexionButtonLogin(authUserVM,
IdentifiantTextField(R.string.IdentifiantLogin, authState.username){
authUserVM.setUsername(it)
}, PassWdTextField(R.string.PasswdLogin, authState.password){
authUserVM.setPassword(it)
}, R.string.ButtonLogin,18,navControllerProfil)
}, R.string.ButtonLogin,18,navControllerProfil){
initialierCurrentUser(it)
}
SpaceHeightComponent(16)
CreateAccountButton(R.string.ButtonCreateLogin,12, MaterialTheme.colorScheme.primary, navControllerSignUp)
}
@ -130,11 +139,11 @@ fun PassWdTextField(textpasswdResId : Int, password : String, onValueChange: (St
@Composable
fun ConnexionButtonLogin(authUserVM : AuthUserViewModel, username : String, passwd : String, titleResId : Int, size : Int, navController: (Int) -> Unit){
fun ConnexionButtonLogin(authUserVM : AuthUserViewModel, username : String, passwd : String, titleResId : Int, size : Int, navController: (Int) -> Unit, initialierCurrentUser : (Int) -> Unit){
val title = stringResource(id = titleResId)
var showError by remember { mutableStateOf(false) }
Button(
onClick = { showError = !authUserVM.validLogin(username, passwd, navController)
onClick = { showError = !authUserVM.validLogin(username, passwd, navController, initialierCurrentUser)
},
colors = ButtonDefaults.buttonColors(containerColor = MaterialTheme.colorScheme.background),
modifier = Modifier

@ -1,5 +1,6 @@
package com.example.what_the_fantasy.ui.screens
import android.util.Log
import android.util.Patterns
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
@ -58,16 +59,17 @@ import com.example.what_the_fantasy.ui.states.CurrentUserState
import com.example.what_the_fantasy.ui.viewModels.CurrentUserViewModel
@Composable
fun ProfilPage(index: Int,
navFavorite: (Int) -> Unit,
fun ProfilPage(navFavorite: (Int) -> Unit,
navAccueil: (Int) -> Unit,
navQuiz: (Int) -> Unit,
navUnLog: () -> Unit,
navSubmitQuote: () -> Unit,
currentUserVM : CurrentUserViewModel,
currentUserState : CurrentUserState,
) {
val currentUserVM : CurrentUserViewModel = viewModel()
val currentUserState by currentUserVM.currentUserState.collectAsState()
// val currentUserVM : CurrentUserViewModel = viewModel()
// val currentUserState by currentUserVM.currentUserState.collectAsState()
Log.e("Profil","${currentUserState.id}")
NavBar(onProfile = true,
index = currentUserState.id,
navControllerFavorite = navFavorite,

@ -25,7 +25,7 @@ class AuthUserViewModel : ViewModel(){
_userState.update { it.copy(password=password) }
}
fun validLogin(username : String, passwd : String, navController: (Int) -> Unit) : Boolean{
return services.validLogin(username,passwd,userState, navController)
fun validLogin(username : String, passwd : String, navController: (Int) -> Unit, initialierCurrentUser : (Int) -> Unit) : Boolean{
return services.validLogin(username,passwd,userState, navController, initialierCurrentUser)
}
}

@ -1,5 +1,6 @@
package com.example.what_the_fantasy.ui.viewModels
import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.what_the_fantasy.data.model.SrcLanguage
@ -16,9 +17,21 @@ class CurrentUserViewModel : ViewModel(){
private val _currentUserState = MutableStateFlow(CurrentUserState())
var currentUserState : StateFlow<CurrentUserState> = _currentUserState.asStateFlow()
init{
viewModelScope.launch {
services.getUserById(10)?.let { // A changer : renvoie le meme user pour le moment
// init{
// viewModelScope.launch {
// services.getUserById(10)?.let { // A changer : renvoie le meme user pour le moment
// setId(it.id)
// setUsername(it.username)
// setEmail(it.email)
// setPassword(it.password)
// setLangue(it.langage)
// setImage(it.imgUrl)
// }
// }
// }
fun initialiseCurrentUser(index : Int){
services.getUserById(index)?.let {
setId(it.id)
setUsername(it.username)
setEmail(it.email)
@ -26,7 +39,7 @@ class CurrentUserViewModel : ViewModel(){
setLangue(it.langage)
setImage(it.imgUrl)
}
}
Log.e("ProfilInit", "${currentUserState.value.id}")
}
fun setId(id : Int){

Loading…
Cancel
Save