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 { 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 EditUsername(username : String, index : Int) : Boolean
fun EditEmail(email : String, index : Int) : Boolean fun EditEmail(email : String, index : Int) : Boolean
fun EditPasswd(passwd : String, index : Int) fun EditPasswd(passwd : String, index : Int)

@ -18,12 +18,17 @@ class ServicesStub : IServices {
val logsUser = LogsUsers() //gestion des logs pour les utilisateurs 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 -> users.forEachIndexed { index, user ->
val hashPassWd = hashPassword(passwd) val hashPassWd = hashPassword(passwd)
if (user.username == username && user.password == hashPassWd) { if (user.username == username && user.password == hashPassWd) {
userSession.value.id = index //userSession.value.id = index
initialierCurrentUser(index)
navController(index) navController(index)
logsUser.logInformationUserConnect(user, "UserConnect") logsUser.logInformationUserConnect(user, "UserConnect")
return true return true

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

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

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

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

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

Loading…
Cancel
Save