random image lors de la création de compte

pull/51/head
Leni BEAULATON 3 weeks ago
parent 2e98af2450
commit 9d54fce591

@ -11,7 +11,6 @@ interface IServices {
fun validLogin(username : String, fun validLogin(username : String,
passwd : String, passwd : String,
userSession : StateFlow<AuthUserState>,
navController: (Int) -> Unit, navController: (Int) -> Unit,
initialierCurrentUser : (Int) ->Unit): Boolean initialierCurrentUser : (Int) ->Unit): Boolean

@ -5,6 +5,7 @@ import com.example.what_the_fantasy.data.local.UserStub.users
import com.example.what_the_fantasy.data.model.User import com.example.what_the_fantasy.data.model.User
import com.example.what_the_fantasy.Logs.LogsUsers import com.example.what_the_fantasy.Logs.LogsUsers
import com.example.what_the_fantasy.data.local.FavoriteStub.favorites import com.example.what_the_fantasy.data.local.FavoriteStub.favorites
import com.example.what_the_fantasy.data.local.ImageStub.allImages
import com.example.what_the_fantasy.data.local.QuoteStub.quotes import com.example.what_the_fantasy.data.local.QuoteStub.quotes
import com.example.what_the_fantasy.data.model.Favorite import com.example.what_the_fantasy.data.model.Favorite
import com.example.what_the_fantasy.data.model.Quote import com.example.what_the_fantasy.data.model.Quote
@ -20,14 +21,12 @@ class ServicesStub : IServices {
override fun validLogin(username : String, override fun validLogin(username : String,
passwd : String, passwd : String,
userSession : StateFlow<AuthUserState>,
navController: (Int) -> Unit, navController: (Int) -> Unit,
initialierCurrentUser : (Int) ->Unit): Boolean{ 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
initialierCurrentUser(index) initialierCurrentUser(index)
navController(index) navController(index)
logsUser.logInformationUserConnect(user, "UserConnect") logsUser.logInformationUserConnect(user, "UserConnect")
@ -97,7 +96,7 @@ class ServicesStub : IServices {
val nbUser = userStub.size val nbUser = userStub.size
if(!isUsernameExist(username) && !isEmailExist(email)){ if(!isUsernameExist(username) && !isEmailExist(email)){
val user = User(nbUser+1,username, email, date,randomImage(userStub), passwordhash, SrcLanguage.vo) val user = User(nbUser,username, email, date,randomImage(), passwordhash, SrcLanguage.vo)
users.add(user)//ajout au stub users.add(user)//ajout au stub
//Afficher tous les users //Afficher tous les users
@ -110,7 +109,6 @@ class ServicesStub : IServices {
override fun getFavorite(user: User): List<Quote> { override fun getFavorite(user: User): List<Quote> {
val favorite = favorites val favorite = favorites
return favorite[0].quote return favorite[0].quote
//return emptyList()
} }
override fun getAllFavorite(): List<Favorite> = favorites override fun getAllFavorite(): List<Favorite> = favorites
@ -143,8 +141,16 @@ class ServicesStub : IServices {
return date.toString() return date.toString()
} }
fun randomImage(usersImage : List<User>) : String{ fun randomImage() : String{
return "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg" val sizeList = allImages.size
val randomNb = (0..sizeList).random()
allImages.forEach{image ->
if(image.id == randomNb){
return image.url
}
}
return allImages[0].url
} }
fun isUsernameExist(username : String) : Boolean{ fun isUsernameExist(username : String) : Boolean{

@ -52,8 +52,7 @@ import com.example.what_the_fantasy.ui.viewModels.SignInUserViewModel
@Composable @Composable
fun SignUpPage(navControllerLogin: () -> Unit, signInUserVM :SignInUserViewModel,signInState : SignInUserState) { fun SignUpPage(navControllerLogin: () -> Unit, signInUserVM :SignInUserViewModel,signInState : SignInUserState) {
// val signInUserVM : SignInUserViewModel = viewModel()
// val signInState by signInUserVM.userState.collectAsState()
Box( Box(
modifier = Modifier modifier = Modifier

@ -4,7 +4,6 @@ import com.example.what_the_fantasy.data.model.SrcLanguage
import com.example.what_the_fantasy.data.model.User import com.example.what_the_fantasy.data.model.User
data class AuthUserState ( data class AuthUserState (
var id : Int = -1,
val username : String = "", val username : String = "",
val password: String = "", val password: String = "",
) )

@ -14,9 +14,7 @@ class AuthUserViewModel : ViewModel(){
val userState : StateFlow<AuthUserState> = _userState.asStateFlow() val userState : StateFlow<AuthUserState> = _userState.asStateFlow()
fun setId(id : Int){
_userState.update { it.copy(id=id) }
}
fun setUsername(username : String){ fun setUsername(username : String){
_userState.update { it.copy(username=username) } _userState.update { it.copy(username=username) }
} }
@ -26,6 +24,6 @@ class AuthUserViewModel : ViewModel(){
} }
fun validLogin(username : String, passwd : String, navController: (Int) -> Unit, initialierCurrentUser : (Int) -> Unit) : Boolean{ fun validLogin(username : String, passwd : String, navController: (Int) -> Unit, initialierCurrentUser : (Int) -> Unit) : Boolean{
return services.validLogin(username,passwd,userState, navController, initialierCurrentUser) return services.validLogin(username,passwd, navController, initialierCurrentUser)
} }
} }
Loading…
Cancel
Save