diff --git a/app/src/main/java/com/example/myapplication/composeui/CartViewModel.kt b/app/src/main/java/com/example/myapplication/composeui/CartViewModel.kt index d4c6e2e..a4f2ef7 100644 --- a/app/src/main/java/com/example/myapplication/composeui/CartViewModel.kt +++ b/app/src/main/java/com/example/myapplication/composeui/CartViewModel.kt @@ -22,6 +22,7 @@ class CartViewModel( private val orderSessionRepository: OrderSessionRepository, private val userRepository: UserRepository, ) : ViewModel() { + var isLoading: Boolean = false var cartUiState by mutableStateOf(CartUiState()) private set @@ -29,9 +30,13 @@ class CartViewModel( val userId: Int = LiveStore.user.value?.uid ?: return val cart = userRepository.getCartByUser(userId) cartUiState = CartUiState(cart) + isLoading = false } suspend fun addToOrder(sessions: List) { + if (isLoading) + return + isLoading = true val userId: Int = LiveStore.user.value?.uid ?: return if (sessions.isEmpty()) return @@ -51,6 +56,9 @@ class CartViewModel( } suspend fun removeFromCart(session: Session, count: Int = 0) { + if (isLoading) + return + isLoading = true val userId: Int = LiveStore.user.value?.uid ?: return userSessionRepository.deleteUserSession(UserSessionCrossRef(userId, session.uid, count)) refreshState() @@ -58,6 +66,9 @@ class CartViewModel( suspend fun updateFromCart(session: Session, count: Int, availableCount: Int) : Boolean { + if (isLoading) + return false + isLoading = true val userId: Int = LiveStore.user.value?.uid ?: return false if (count == 0) { removeFromCart(session, count) diff --git a/app/src/main/java/com/example/myapplication/database/entities/composeui/SessionList.kt b/app/src/main/java/com/example/myapplication/database/entities/composeui/SessionList.kt index 2b62273..2ef10b8 100644 --- a/app/src/main/java/com/example/myapplication/database/entities/composeui/SessionList.kt +++ b/app/src/main/java/com/example/myapplication/database/entities/composeui/SessionList.kt @@ -75,7 +75,8 @@ fun SessionList( Box(modifier = Modifier .padding(vertical = 7.dp) .clickable { - navController.navigate(route) + if (user.value?.role == UserRole.ADMIN) + navController.navigate(route) } .background( color = MaterialTheme.colorScheme.secondary, diff --git a/app/src/main/java/com/example/myapplication/database/entities/composeui/UserProfile.kt b/app/src/main/java/com/example/myapplication/database/entities/composeui/UserProfile.kt index e4731cc..f6dc6f0 100644 --- a/app/src/main/java/com/example/myapplication/database/entities/composeui/UserProfile.kt +++ b/app/src/main/java/com/example/myapplication/database/entities/composeui/UserProfile.kt @@ -113,6 +113,32 @@ fun UserProfile( visualTransformation = PasswordVisualTransformation() ) + if (!isRegistration) { + Text( + text = "Подтверждение пароля", + modifier = Modifier.align(Alignment.CenterHorizontally) + ) + BasicTextField( + value = viewModel.userUiState.details.passwordConfirm, + onValueChange = { + viewModel.updateUiState( + viewModel.userUiState.details.copy( + passwordConfirm = it + ) + ) + }, + modifier = Modifier + .fillMaxWidth() + .size(36.dp) + .background( + MaterialTheme.colorScheme.secondary, + RoundedCornerShape(18.dp) + ) + .padding(start = 13.dp, top = 8.dp), + visualTransformation = PasswordVisualTransformation() + ) + } + if (isRegistration) { Button( onClick = { diff --git a/app/src/main/java/com/example/myapplication/database/entities/composeui/UserProfileViewModel.kt b/app/src/main/java/com/example/myapplication/database/entities/composeui/UserProfileViewModel.kt index 1b77cbe..9374b05 100644 --- a/app/src/main/java/com/example/myapplication/database/entities/composeui/UserProfileViewModel.kt +++ b/app/src/main/java/com/example/myapplication/database/entities/composeui/UserProfileViewModel.kt @@ -24,6 +24,7 @@ class UserProfileViewModel( } suspend fun signIn(dataStoreManager: DataStoreManager): Boolean { + userUiState.details.passwordConfirm = userUiState.details.password var errorId: Int? = validateInput(userUiState.details) if (errorId == null) { val overlap = userRepository.getUser(userUiState.details.login) @@ -61,12 +62,14 @@ class UserProfileViewModel( return false } - private fun validateInput(details: UserDetails = userUiState.details): Int? { return if (details.login.isBlank()) { R.string.err_01 } else if (details.password.isBlank()) { R.string.err_02 + } else if (details.passwordConfirm.isBlank() + || details.password != details.passwordConfirm) { + R.string.err_05 } else { null } @@ -75,7 +78,8 @@ class UserProfileViewModel( data class UserDetails( val login: String = "", - val password: String = "" + val password: String = "", + var passwordConfirm: String = "" ) data class UserUiState( diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index dc2204c..21d1c72 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -23,4 +23,5 @@ Введите пароль Логин занят Неверный логин или пароль + Не совпадают пароли \ No newline at end of file diff --git a/server/data.json b/server/data.json index 6884290..94a17ea 100644 --- a/server/data.json +++ b/server/data.json @@ -12,9 +12,14 @@ "password": "qwe", "role": 0, "sessions": [ + { + "id": 5, + "count": 1, + "cinemaId": 2 + }, { "id": 6, - "count": 7, + "count": 1, "cinemaId": 2 } ] @@ -38,13 +43,13 @@ { "id": 3, "userId": 2, - "dateTime": "13.12.2023 19:03", + "dateTime": "13.12.2023 19:18", "sessions": [ { - "id": 5, - "dateTime": "04.04.2004 00:00", - "frozenPrice": 1234, - "count": 1, + "id": 6, + "dateTime": "22.02.2022 03:15", + "frozenPrice": 100, + "count": 7, "cinemaId": 2 } ]