Вроде бы сделал регистрацию, но я не знаю, как ее проверить то...

This commit is contained in:
Кашин Максим 2023-11-20 23:55:47 +04:00
parent 1984f32b8a
commit 4b3c61ca06
6 changed files with 52 additions and 10 deletions

View File

@ -13,6 +13,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.navigation.NavHostController import androidx.navigation.NavHostController
import com.example.labwork.database.DAO.BicycleDao 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.Bicycle
import com.example.labwork.pages.ListInfo import com.example.labwork.pages.ListInfo
import com.example.labwork.pages.product.FormNewProduct import com.example.labwork.pages.product.FormNewProduct
@ -27,8 +28,8 @@ fun ScreenInfo() {
} }
@Composable @Composable
fun ScreenProfile() { fun ScreenProfile(userDao: UserDao, navHostController: NavHostController) {
RegisteryOrLogin() RegisteryOrLogin(userDao, navHostController)
} }

View File

@ -18,7 +18,7 @@ fun SlideGraph(
NavHost(navController = navHostController, startDestination = "Profile"){ NavHost(navController = navHostController, startDestination = "Profile"){
composable("Profile"){ composable("Profile"){
ScreenProfile() ScreenProfile(userDao, navHostController = navHostController)
} }
composable("Info"){ composable("Info"){
ScreenInfo() ScreenInfo()

View File

@ -51,8 +51,8 @@ abstract class AppDatabase : RoomDatabase() {
val bicycleDao = database.bicycleDao() val bicycleDao = database.bicycleDao()
// Создание пользователей // Создание пользователей
val user1 = User(1, "John Doe", "john.doe@example.com", "password123") val user1 = User(null, "John Doe", "john.doe@example.com", "password123")
val user2 = User(2, "Jane Smith", "jane.smith@example.com", "password456") val user2 = User(null, "Jane Smith", "jane.smith@example.com", "password456")
// Вставка пользователей в базу данных // Вставка пользователей в базу данных
userDao.insertUser(user1) userDao.insertUser(user1)

View File

@ -6,7 +6,8 @@ import androidx.room.PrimaryKey
@Entity(tableName = "users") @Entity(tableName = "users")
data class User( data class User(
@PrimaryKey val id: Int, @PrimaryKey(autoGenerate = true)
val id: Int?,
val name: String, val name: String,
val email: String, val email: String,
val password: String, val password: String,

View File

@ -30,14 +30,17 @@ import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.navigation.NavController import androidx.navigation.NavController
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController import androidx.navigation.compose.rememberNavController
import com.example.labwork.R 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 import com.example.labwork.ui.theme.LightBluePolitech
@Composable @Composable
fun RegisteryOrLogin() { fun RegisteryOrLogin(userDao: UserDao, navHostController: NavHostController) {
val navController = rememberNavController() val navController = rememberNavController()
NavHost(navController, startDestination = "login") { NavHost(navController, startDestination = "login") {
@ -45,7 +48,7 @@ fun RegisteryOrLogin() {
LoginPage(navController) LoginPage(navController)
} }
composable("register") { composable("register") {
RegisteryPage(navController) RegisteryPage(navController, userDao, navHostController)
} }
} }
} }

View File

@ -28,14 +28,22 @@ import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.navigation.NavController import androidx.navigation.NavController
import androidx.navigation.NavHostController
import com.example.labwork.R 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 com.example.labwork.ui.theme.LightBluePolitech
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
@Composable @Composable
fun RegisteryPage(navController: NavController) { fun RegisteryPage(navController: NavController, userDao: UserDao, navHostController: NavHostController) {
var username by remember { mutableStateOf("") } var username by remember { mutableStateOf("") }
var password by remember { mutableStateOf("") } var password by remember { mutableStateOf("") }
var confirmPassword by remember { mutableStateOf("") } var confirmPassword by remember { mutableStateOf("") }
var email by remember { mutableStateOf("") }
Column( Column(
modifier = Modifier modifier = Modifier
@ -72,6 +80,27 @@ fun RegisteryPage(navController: NavController) {
) )
Spacer(modifier = Modifier.height(8.dp)) 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( TextField(
value = password, value = password,
onValueChange = { password = it }, onValueChange = { password = it },
@ -115,7 +144,15 @@ fun RegisteryPage(navController: NavController) {
Spacer(modifier = Modifier.height(8.dp)) Spacer(modifier = Modifier.height(8.dp))
Button( 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), colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech),
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()