Вроде бы сделал регистрацию, но я не знаю, как ее проверить то...
This commit is contained in:
parent
1984f32b8a
commit
4b3c61ca06
@ -13,6 +13,7 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.navigation.NavHostController
|
||||
import com.example.labwork.database.DAO.BicycleDao
|
||||
import com.example.labwork.database.DAO.UserDao
|
||||
import com.example.labwork.models.Bicycle
|
||||
import com.example.labwork.pages.ListInfo
|
||||
import com.example.labwork.pages.product.FormNewProduct
|
||||
@ -27,8 +28,8 @@ fun ScreenInfo() {
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ScreenProfile() {
|
||||
RegisteryOrLogin()
|
||||
fun ScreenProfile(userDao: UserDao, navHostController: NavHostController) {
|
||||
RegisteryOrLogin(userDao, navHostController)
|
||||
}
|
||||
|
||||
|
||||
|
@ -18,7 +18,7 @@ fun SlideGraph(
|
||||
NavHost(navController = navHostController, startDestination = "Profile"){
|
||||
|
||||
composable("Profile"){
|
||||
ScreenProfile()
|
||||
ScreenProfile(userDao, navHostController = navHostController)
|
||||
}
|
||||
composable("Info"){
|
||||
ScreenInfo()
|
||||
|
@ -51,8 +51,8 @@ abstract class AppDatabase : RoomDatabase() {
|
||||
val bicycleDao = database.bicycleDao()
|
||||
|
||||
// Создание пользователей
|
||||
val user1 = User(1, "John Doe", "john.doe@example.com", "password123")
|
||||
val user2 = User(2, "Jane Smith", "jane.smith@example.com", "password456")
|
||||
val user1 = User(null, "John Doe", "john.doe@example.com", "password123")
|
||||
val user2 = User(null, "Jane Smith", "jane.smith@example.com", "password456")
|
||||
|
||||
// Вставка пользователей в базу данных
|
||||
userDao.insertUser(user1)
|
||||
|
@ -6,7 +6,8 @@ import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "users")
|
||||
data class User(
|
||||
@PrimaryKey val id: Int,
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
val id: Int?,
|
||||
val name: String,
|
||||
val email: String,
|
||||
val password: String,
|
||||
|
@ -30,14 +30,17 @@ 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 androidx.navigation.compose.NavHost
|
||||
import androidx.navigation.compose.composable
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import com.example.labwork.R
|
||||
import com.example.labwork.database.DAO.BicycleDao
|
||||
import com.example.labwork.database.DAO.UserDao
|
||||
import com.example.labwork.ui.theme.LightBluePolitech
|
||||
|
||||
@Composable
|
||||
fun RegisteryOrLogin() {
|
||||
fun RegisteryOrLogin(userDao: UserDao, navHostController: NavHostController) {
|
||||
val navController = rememberNavController()
|
||||
|
||||
NavHost(navController, startDestination = "login") {
|
||||
@ -45,7 +48,7 @@ fun RegisteryOrLogin() {
|
||||
LoginPage(navController)
|
||||
}
|
||||
composable("register") {
|
||||
RegisteryPage(navController)
|
||||
RegisteryPage(navController, userDao, navHostController)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,14 +28,22 @@ import androidx.compose.ui.text.input.PasswordVisualTransformation
|
||||
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.BicycleDao
|
||||
import com.example.labwork.database.DAO.UserDao
|
||||
import com.example.labwork.models.Bicycle
|
||||
import com.example.labwork.models.User
|
||||
import com.example.labwork.ui.theme.LightBluePolitech
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@Composable
|
||||
fun RegisteryPage(navController: NavController) {
|
||||
fun RegisteryPage(navController: NavController, userDao: UserDao, navHostController: NavHostController) {
|
||||
var username by remember { mutableStateOf("") }
|
||||
var password by remember { mutableStateOf("") }
|
||||
var confirmPassword by remember { mutableStateOf("") }
|
||||
var email by remember { mutableStateOf("") }
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
@ -72,6 +80,27 @@ fun RegisteryPage(navController: NavController) {
|
||||
)
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
TextField(
|
||||
value = email,
|
||||
onValueChange = { email = it },
|
||||
label = { Text("Почта") },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp),
|
||||
textStyle = TextStyle(fontSize = 16.sp),
|
||||
colors = TextFieldDefaults.textFieldColors(
|
||||
cursorColor = LightBluePolitech,
|
||||
backgroundColor = Color.White,
|
||||
textColor = LightBluePolitech,
|
||||
unfocusedLabelColor = LightBluePolitech,
|
||||
focusedIndicatorColor = LightBluePolitech,
|
||||
unfocusedIndicatorColor = LightBluePolitech,
|
||||
focusedLabelColor = LightBluePolitech
|
||||
),
|
||||
singleLine = true
|
||||
)
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
TextField(
|
||||
value = password,
|
||||
onValueChange = { password = it },
|
||||
@ -115,7 +144,15 @@ fun RegisteryPage(navController: NavController) {
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
Button(
|
||||
onClick = { /* Register logic */ },
|
||||
onClick = {
|
||||
if (password == confirmPassword) {
|
||||
GlobalScope.launch {
|
||||
val newUser = User(null, name = username, email = email, password = password)
|
||||
userDao.insertUser(newUser)
|
||||
}
|
||||
navController.navigate("login")
|
||||
}
|
||||
},
|
||||
colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
|
Loading…
Reference in New Issue
Block a user