|
|
|
@ -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.Logs.LogsUsers
|
|
|
|
|
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.model.Favorite
|
|
|
|
|
import com.example.what_the_fantasy.data.model.Quote
|
|
|
|
@ -20,14 +21,12 @@ class ServicesStub : IServices {
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
initialierCurrentUser(index)
|
|
|
|
|
navController(index)
|
|
|
|
|
logsUser.logInformationUserConnect(user, "UserConnect")
|
|
|
|
@ -97,7 +96,7 @@ class ServicesStub : IServices {
|
|
|
|
|
val nbUser = userStub.size
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
//Afficher tous les users
|
|
|
|
@ -110,7 +109,6 @@ class ServicesStub : IServices {
|
|
|
|
|
override fun getFavorite(user: User): List<Quote> {
|
|
|
|
|
val favorite = favorites
|
|
|
|
|
return favorite[0].quote
|
|
|
|
|
//return emptyList()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun getAllFavorite(): List<Favorite> = favorites
|
|
|
|
@ -143,8 +141,16 @@ class ServicesStub : IServices {
|
|
|
|
|
return date.toString()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun randomImage(usersImage : List<User>) : String{
|
|
|
|
|
return "https://img.freepik.com/vecteurs-libre/personnage-guerrier-homme-fantaisie_1045-194.jpg?size=338&ext=jpg"
|
|
|
|
|
fun randomImage() : String{
|
|
|
|
|
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{
|
|
|
|
|