регистрация и вход
This commit is contained in:
parent
28fd92559c
commit
d709367774
@ -22,6 +22,7 @@ class CartViewModel(
|
|||||||
private val orderSessionRepository: OrderSessionRepository,
|
private val orderSessionRepository: OrderSessionRepository,
|
||||||
private val userRepository: UserRepository,
|
private val userRepository: UserRepository,
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
var isLoading: Boolean = false
|
||||||
var cartUiState by mutableStateOf(CartUiState())
|
var cartUiState by mutableStateOf(CartUiState())
|
||||||
private set
|
private set
|
||||||
|
|
||||||
@ -29,9 +30,13 @@ class CartViewModel(
|
|||||||
val userId: Int = LiveStore.user.value?.uid ?: return
|
val userId: Int = LiveStore.user.value?.uid ?: return
|
||||||
val cart = userRepository.getCartByUser(userId)
|
val cart = userRepository.getCartByUser(userId)
|
||||||
cartUiState = CartUiState(cart)
|
cartUiState = CartUiState(cart)
|
||||||
|
isLoading = false
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun addToOrder(sessions: List<SessionFromCart>) {
|
suspend fun addToOrder(sessions: List<SessionFromCart>) {
|
||||||
|
if (isLoading)
|
||||||
|
return
|
||||||
|
isLoading = true
|
||||||
val userId: Int = LiveStore.user.value?.uid ?: return
|
val userId: Int = LiveStore.user.value?.uid ?: return
|
||||||
if (sessions.isEmpty())
|
if (sessions.isEmpty())
|
||||||
return
|
return
|
||||||
@ -51,6 +56,9 @@ class CartViewModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
suspend fun removeFromCart(session: Session, count: Int = 0) {
|
suspend fun removeFromCart(session: Session, count: Int = 0) {
|
||||||
|
if (isLoading)
|
||||||
|
return
|
||||||
|
isLoading = true
|
||||||
val userId: Int = LiveStore.user.value?.uid ?: return
|
val userId: Int = LiveStore.user.value?.uid ?: return
|
||||||
userSessionRepository.deleteUserSession(UserSessionCrossRef(userId, session.uid, count))
|
userSessionRepository.deleteUserSession(UserSessionCrossRef(userId, session.uid, count))
|
||||||
refreshState()
|
refreshState()
|
||||||
@ -58,6 +66,9 @@ class CartViewModel(
|
|||||||
|
|
||||||
suspend fun updateFromCart(session: Session, count: Int, availableCount: Int)
|
suspend fun updateFromCart(session: Session, count: Int, availableCount: Int)
|
||||||
: Boolean {
|
: Boolean {
|
||||||
|
if (isLoading)
|
||||||
|
return false
|
||||||
|
isLoading = true
|
||||||
val userId: Int = LiveStore.user.value?.uid ?: return false
|
val userId: Int = LiveStore.user.value?.uid ?: return false
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
removeFromCart(session, count)
|
removeFromCart(session, count)
|
||||||
|
@ -75,6 +75,7 @@ fun SessionList(
|
|||||||
Box(modifier = Modifier
|
Box(modifier = Modifier
|
||||||
.padding(vertical = 7.dp)
|
.padding(vertical = 7.dp)
|
||||||
.clickable {
|
.clickable {
|
||||||
|
if (user.value?.role == UserRole.ADMIN)
|
||||||
navController.navigate(route)
|
navController.navigate(route)
|
||||||
}
|
}
|
||||||
.background(
|
.background(
|
||||||
|
@ -113,6 +113,32 @@ fun UserProfile(
|
|||||||
visualTransformation = PasswordVisualTransformation()
|
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) {
|
if (isRegistration) {
|
||||||
Button(
|
Button(
|
||||||
onClick = {
|
onClick = {
|
||||||
|
@ -24,6 +24,7 @@ class UserProfileViewModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
suspend fun signIn(dataStoreManager: DataStoreManager): Boolean {
|
suspend fun signIn(dataStoreManager: DataStoreManager): Boolean {
|
||||||
|
userUiState.details.passwordConfirm = userUiState.details.password
|
||||||
var errorId: Int? = validateInput(userUiState.details)
|
var errorId: Int? = validateInput(userUiState.details)
|
||||||
if (errorId == null) {
|
if (errorId == null) {
|
||||||
val overlap = userRepository.getUser(userUiState.details.login)
|
val overlap = userRepository.getUser(userUiState.details.login)
|
||||||
@ -61,12 +62,14 @@ class UserProfileViewModel(
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun validateInput(details: UserDetails = userUiState.details): Int? {
|
private fun validateInput(details: UserDetails = userUiState.details): Int? {
|
||||||
return if (details.login.isBlank()) {
|
return if (details.login.isBlank()) {
|
||||||
R.string.err_01
|
R.string.err_01
|
||||||
} else if (details.password.isBlank()) {
|
} else if (details.password.isBlank()) {
|
||||||
R.string.err_02
|
R.string.err_02
|
||||||
|
} else if (details.passwordConfirm.isBlank()
|
||||||
|
|| details.password != details.passwordConfirm) {
|
||||||
|
R.string.err_05
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
@ -75,7 +78,8 @@ class UserProfileViewModel(
|
|||||||
|
|
||||||
data class UserDetails(
|
data class UserDetails(
|
||||||
val login: String = "",
|
val login: String = "",
|
||||||
val password: String = ""
|
val password: String = "",
|
||||||
|
var passwordConfirm: String = ""
|
||||||
)
|
)
|
||||||
|
|
||||||
data class UserUiState(
|
data class UserUiState(
|
||||||
|
@ -23,4 +23,5 @@
|
|||||||
<string name="err_02">Введите пароль</string>
|
<string name="err_02">Введите пароль</string>
|
||||||
<string name="err_03">Логин занят</string>
|
<string name="err_03">Логин занят</string>
|
||||||
<string name="err_04">Неверный логин или пароль</string>
|
<string name="err_04">Неверный логин или пароль</string>
|
||||||
|
<string name="err_05">Не совпадают пароли</string>
|
||||||
</resources>
|
</resources>
|
@ -12,9 +12,14 @@
|
|||||||
"password": "qwe",
|
"password": "qwe",
|
||||||
"role": 0,
|
"role": 0,
|
||||||
"sessions": [
|
"sessions": [
|
||||||
|
{
|
||||||
|
"id": 5,
|
||||||
|
"count": 1,
|
||||||
|
"cinemaId": 2
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": 6,
|
"id": 6,
|
||||||
"count": 7,
|
"count": 1,
|
||||||
"cinemaId": 2
|
"cinemaId": 2
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -38,13 +43,13 @@
|
|||||||
{
|
{
|
||||||
"id": 3,
|
"id": 3,
|
||||||
"userId": 2,
|
"userId": 2,
|
||||||
"dateTime": "13.12.2023 19:03",
|
"dateTime": "13.12.2023 19:18",
|
||||||
"sessions": [
|
"sessions": [
|
||||||
{
|
{
|
||||||
"id": 5,
|
"id": 6,
|
||||||
"dateTime": "04.04.2004 00:00",
|
"dateTime": "22.02.2022 03:15",
|
||||||
"frozenPrice": 1234,
|
"frozenPrice": 100,
|
||||||
"count": 1,
|
"count": 7,
|
||||||
"cinemaId": 2
|
"cinemaId": 2
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user