Сделал шуточную авторизацию
This commit is contained in:
parent
4b3c61ca06
commit
0b8c882823
@ -27,6 +27,9 @@ interface UserDao {
|
||||
@Query("SELECT * FROM users WHERE email = :email")
|
||||
suspend fun getUserByEmail(email: String): User
|
||||
|
||||
@Query("SELECT password FROM users WHERE email = :email")
|
||||
suspend fun getPasswordByEmail(email: String): String
|
||||
|
||||
@Query("SELECT * FROM users WHERE email = :email AND password = :password")
|
||||
suspend fun getUserByEmailAndPassword(email: String, password: String): User?
|
||||
}
|
@ -30,14 +30,20 @@ import androidx.compose.ui.text.input.VisualTransformation
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.navigation.NavController
|
||||
import androidx.navigation.NavHostController
|
||||
import com.example.labwork.R
|
||||
import com.example.labwork.database.DAO.UserDao
|
||||
import com.example.labwork.ui.theme.LightBluePolitech
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@Composable
|
||||
fun LoginPage(navController: NavController) {
|
||||
var username by remember { mutableStateOf("") }
|
||||
fun LoginPage(navController: NavController, userDao: UserDao, navHostController: NavHostController) {
|
||||
var email by remember { mutableStateOf("") }
|
||||
var password by remember { mutableStateOf("") }
|
||||
var userPassword by remember { mutableStateOf("") }
|
||||
var showPassword by remember { mutableStateOf(false) }
|
||||
var acceptLogin by remember { mutableStateOf(false) }
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
@ -54,9 +60,9 @@ fun LoginPage(navController: NavController) {
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
TextField(
|
||||
value = username,
|
||||
onValueChange = { username = it },
|
||||
label = { Text("Логин") },
|
||||
value = email,
|
||||
onValueChange = { email = it },
|
||||
label = { Text("Почта") },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp),
|
||||
@ -109,7 +115,14 @@ fun LoginPage(navController: NavController) {
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
Button(
|
||||
onClick = { /* Login logic */ },
|
||||
onClick = {
|
||||
GlobalScope.launch {
|
||||
userPassword = userDao.getPasswordByEmail(email)
|
||||
}
|
||||
if(userPassword == password) {
|
||||
navHostController.navigate("ListProduct")
|
||||
}
|
||||
},
|
||||
colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech, ),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
|
@ -45,7 +45,7 @@ fun RegisteryOrLogin(userDao: UserDao, navHostController: NavHostController) {
|
||||
|
||||
NavHost(navController, startDestination = "login") {
|
||||
composable("login") {
|
||||
LoginPage(navController)
|
||||
LoginPage(navController, userDao, navHostController)
|
||||
}
|
||||
composable("register") {
|
||||
RegisteryPage(navController, userDao, navHostController)
|
||||
|
Loading…
Reference in New Issue
Block a user