|
|
|
@ -1,30 +1,19 @@
|
|
|
|
|
package com.example.what_the_fantasy.ui.screens
|
|
|
|
|
|
|
|
|
|
import android.os.Bundle
|
|
|
|
|
import android.text.style.BackgroundColorSpan
|
|
|
|
|
import android.util.Log
|
|
|
|
|
import androidx.activity.ComponentActivity
|
|
|
|
|
import androidx.activity.compose.setContent
|
|
|
|
|
import androidx.activity.enableEdgeToEdge
|
|
|
|
|
import androidx.compose.foundation.background
|
|
|
|
|
import androidx.compose.foundation.clickable
|
|
|
|
|
import androidx.compose.foundation.layout.Box
|
|
|
|
|
import androidx.compose.foundation.layout.Column
|
|
|
|
|
import androidx.compose.foundation.layout.Spacer
|
|
|
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
|
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
|
|
|
|
import androidx.compose.foundation.layout.height
|
|
|
|
|
import androidx.compose.foundation.layout.padding
|
|
|
|
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
|
|
|
import androidx.compose.foundation.text.KeyboardOptions
|
|
|
|
|
import androidx.compose.material.icons.Icons
|
|
|
|
|
import androidx.compose.material3.Button
|
|
|
|
|
import androidx.compose.material3.ButtonDefaults
|
|
|
|
|
import androidx.compose.material3.Icon
|
|
|
|
|
import androidx.compose.material3.IconButton
|
|
|
|
|
import androidx.compose.material3.OutlinedTextField
|
|
|
|
|
import androidx.compose.material3.Text
|
|
|
|
|
import androidx.compose.material3.TextField
|
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
|
import androidx.compose.runtime.getValue
|
|
|
|
|
import androidx.compose.runtime.mutableStateOf
|
|
|
|
@ -37,15 +26,12 @@ import androidx.compose.ui.geometry.Offset
|
|
|
|
|
import androidx.compose.ui.graphics.Brush
|
|
|
|
|
import androidx.compose.ui.graphics.Color
|
|
|
|
|
import androidx.compose.ui.res.stringResource
|
|
|
|
|
import androidx.compose.ui.text.font.FontWeight
|
|
|
|
|
import androidx.compose.ui.text.input.KeyboardType
|
|
|
|
|
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
|
|
|
|
import androidx.compose.ui.text.input.VisualTransformation
|
|
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
|
|
import com.example.what_the_fantasy.ui.theme.What_The_FantasyTheme
|
|
|
|
|
import androidx.navigation.NavController
|
|
|
|
|
import androidx.navigation.Navigation
|
|
|
|
|
import androidx.navigation.compose.rememberNavController
|
|
|
|
|
import androidx.navigation.compose.NavHost
|
|
|
|
|
import androidx.navigation.compose.composable
|
|
|
|
@ -54,11 +40,10 @@ import com.example.what_the_fantasy.data.local.UserStub
|
|
|
|
|
import com.example.what_the_fantasy.data.model.User
|
|
|
|
|
import com.example.what_the_fantasy.ui.components.SpaceHeightComponent
|
|
|
|
|
import com.example.what_the_fantasy.ui.components.TitlePageComponent
|
|
|
|
|
import org.mindrot.jbcrypt.BCrypt
|
|
|
|
|
import java.security.MessageDigest
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
fun LoginPage(navController : NavController) {
|
|
|
|
|
fun LoginPage(navControllerSignUp: () -> Unit, navControllerProfil: () -> Unit) {
|
|
|
|
|
|
|
|
|
|
val users = UserStub.allUsers;
|
|
|
|
|
val gradient = Brush.linearGradient(
|
|
|
|
@ -87,9 +72,9 @@ fun LoginPage(navController : NavController) {
|
|
|
|
|
val identifiant =IdentifiantTextField(R.string.IdentifiantLogin)
|
|
|
|
|
val passwd = PassWdTextField(R.string.PasswdLogin)
|
|
|
|
|
SpaceHeightComponent(16)
|
|
|
|
|
ConnexionButtonLogin(users,identifiant, passwd, R.string.ButtonLogin,18, Color.White, Color.Black,navController)
|
|
|
|
|
ConnexionButtonLogin(users,identifiant, passwd, R.string.ButtonLogin,18, Color.White, Color.Black,navControllerProfil)
|
|
|
|
|
SpaceHeightComponent(16)
|
|
|
|
|
CreateAccountButton(R.string.ButtonCreateLogin,12, Color.White, navController)
|
|
|
|
|
CreateAccountButton(R.string.ButtonCreateLogin,12, Color.White, navControllerSignUp)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -141,19 +126,9 @@ fun PassWdTextField(textpasswdResId : Int) : String{
|
|
|
|
|
return passwd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//@Composable
|
|
|
|
|
//fun TitlePage(titleResId : Int, size : Int, color : Color){
|
|
|
|
|
// val title = stringResource(id = titleResId)
|
|
|
|
|
// Text(
|
|
|
|
|
// text = title,
|
|
|
|
|
// fontSize = size.sp,
|
|
|
|
|
// fontWeight = FontWeight.Bold,
|
|
|
|
|
// color = color
|
|
|
|
|
// )
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
fun ConnexionButtonLogin(userStub : List<User>, id : String, passwd : String, titleResId : Int, size : Int, colorButton : Color, colorText : Color, navController: NavController){
|
|
|
|
|
fun ConnexionButtonLogin(userStub : List<User>, id : String, passwd : String, titleResId : Int, size : Int, colorButton : Color, colorText : Color, navController: () -> Unit){
|
|
|
|
|
val title = stringResource(id = titleResId)
|
|
|
|
|
Button(
|
|
|
|
|
onClick = { validLogin(id, passwd, userStub, navController) },
|
|
|
|
@ -166,13 +141,12 @@ fun ConnexionButtonLogin(userStub : List<User>, id : String, passwd : String, ti
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun validLogin(identifiant : String, passwd : String, users : List<User>, navController: NavController){
|
|
|
|
|
fun validLogin(identifiant : String, passwd : String, users : List<User>, navController: () -> Unit){
|
|
|
|
|
users.forEach { user ->
|
|
|
|
|
val hashPassWd = hashPassword(passwd)
|
|
|
|
|
|
|
|
|
|
if (user.username == identifiant && user.password == hashPassWd){
|
|
|
|
|
navController.navigate("profile")
|
|
|
|
|
//navController.navigate(ProfilPage(navController))
|
|
|
|
|
if (user.username == identifiant && user.password == hashPassWd) run {
|
|
|
|
|
navController()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -190,26 +164,14 @@ fun hashPassword(password: String): String {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
fun CreateAccountButton(titleResId : Int, size : Int, color : Color, navController: NavController){
|
|
|
|
|
fun CreateAccountButton(titleResId : Int, size : Int, color : Color, navController: () -> Unit){
|
|
|
|
|
val title = stringResource(id = titleResId)
|
|
|
|
|
Text(
|
|
|
|
|
text = title,
|
|
|
|
|
fontSize = size.sp,
|
|
|
|
|
color = color,
|
|
|
|
|
modifier = Modifier.clickable {
|
|
|
|
|
navController.navigate("signup")// rediriger vers la page de création de compte
|
|
|
|
|
navController()// rediriger vers la page de création de compte
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
fun AppNavigator() {
|
|
|
|
|
val navController = rememberNavController()
|
|
|
|
|
|
|
|
|
|
NavHost(navController, startDestination = "login") {
|
|
|
|
|
composable("login") { LoginPage(navController) }
|
|
|
|
|
composable("signup") { SignUpPage(navController) }
|
|
|
|
|
composable("profile") { ProfilPage(navController) }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|