регистрация и вход
This commit is contained in:
parent
28fd92559c
commit
d709367774
@ -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<SessionFromCart>) {
|
||||
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)
|
||||
|
@ -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,
|
||||
|
@ -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 = {
|
||||
|
@ -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(
|
||||
|
@ -23,4 +23,5 @@
|
||||
<string name="err_02">Введите пароль</string>
|
||||
<string name="err_03">Логин занят</string>
|
||||
<string name="err_04">Неверный логин или пароль</string>
|
||||
<string name="err_05">Не совпадают пароли</string>
|
||||
</resources>
|
@ -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
|
||||
}
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user