коммит

This commit is contained in:
Татьяна Артамонова 2023-12-28 13:20:02 +04:00
parent cb69d513e0
commit aa53f465f0
4 changed files with 126 additions and 270 deletions

View File

@ -80,7 +80,7 @@ private fun FlightListItem(
flight: Flight, modifier: Modifier = Modifier flight: Flight, modifier: Modifier = Modifier
) { ) {
Card( Card(
modifier = modifier.fillMaxWidth(), modifier = modifier.fillMaxWidth().padding(10.dp),
elevation = CardDefaults.cardElevation(defaultElevation = 2.dp), elevation = CardDefaults.cardElevation(defaultElevation = 2.dp),
colors = CardDefaults.cardColors(containerColor = colorResource(id = R.color.lightlightBlue)) colors = CardDefaults.cardColors(containerColor = colorResource(id = R.color.lightlightBlue))
) { ) {

View File

@ -3,15 +3,11 @@ package ru.ulstu.`is`.airticketrentservice.screen.auth
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.util.Log import android.util.Log
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.navigationBarsPadding import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.requiredHeight
import androidx.compose.foundation.layout.requiredWidth
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.foundation.text.KeyboardOptions
@ -59,9 +55,9 @@ import ru.ulstu.`is`.airticketrentservice.viewModel.AppViewModelProvider
import ru.ulstu.`is`.airticketrentservice.viewModel.CurrentUserViewModel import ru.ulstu.`is`.airticketrentservice.viewModel.CurrentUserViewModel
import ru.ulstu.`is`.airticketrentservice.viewModel.LoginViewModel import ru.ulstu.`is`.airticketrentservice.viewModel.LoginViewModel
import ru.ulstu.`is`.airticketrentservice.R import ru.ulstu.`is`.airticketrentservice.R
import ru.ulstu.`is`.airticketrentservice.api.repository.RestUserRepository
import ru.ulstu.`is`.airticketrentservice.graphs.AuthScreen import ru.ulstu.`is`.airticketrentservice.graphs.AuthScreen
import ru.ulstu.`is`.airticketrentservice.graphs.Graph import ru.ulstu.`is`.airticketrentservice.graphs.Graph
import androidx.compose.material3.AlertDialog
@SuppressLint("UnrememberedMutableState") @SuppressLint("UnrememberedMutableState")
@OptIn(ExperimentalMaterial3Api::class) @OptIn(ExperimentalMaterial3Api::class)
@ -75,7 +71,23 @@ fun Login(navController: NavController, modifier: Modifier = Modifier, loginView
val argument = currentUserViewModel.argument.value val argument = currentUserViewModel.argument.value
var passwordVisibility by rememberSaveable { mutableStateOf(false) } var passwordVisibility by rememberSaveable { mutableStateOf(false) }
val emailRegex = "[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+".toRegex() val emailRegex = "[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+".toRegex()
val coroutineScope = rememberCoroutineScope()
val showInvalidPasswordDialog = remember { mutableStateOf(false) }
if (showInvalidPasswordDialog.value) {
AlertDialog(
onDismissRequest = { showInvalidPasswordDialog.value = false },
title = { Text(text = "Ошибка") },
text = { Text(text = "Такого пользователя не существует.") },
confirmButton = {
Button(
onClick = { showInvalidPasswordDialog.value = false },
) {
Text(text = "ОК")
}
}
)
}
Column( Column(
Modifier Modifier
@ -145,13 +157,18 @@ fun Login(navController: NavController, modifier: Modifier = Modifier, loginView
shape = RoundedCornerShape(15.dp), shape = RoundedCornerShape(15.dp),
onClick = { onClick = {
if (passwordValue.isNotEmpty() && isValidEmail(emailValue)) { if (passwordValue.isNotEmpty() && isValidEmail(emailValue)) {
var userExists = false
users.value.forEach { user -> users.value.forEach { user ->
if (user.password == passwordValue && user.email == emailValue) { if (user.password == passwordValue && user.email == emailValue) {
currentUserViewModel.setArgument(user.id.toString()) currentUserViewModel.setArgument(user.id.toString())
navController.navigate(route = Graph.passUserId(user.id.toString())) navController.navigate(route = Graph.passUserId(user.id.toString()))
Log.d("CurrentUserViewModel", "Текущий пользователь: $user") Log.d("CurrentUserViewModel", "Текущий пользователь: $user")
userExists = true
} }
} }
if (!userExists) {
showInvalidPasswordDialog.value = true
}
} }
}, },
colors = ButtonDefaults.buttonColors(containerColor = colorResource(R.color.lightBlue)), colors = ButtonDefaults.buttonColors(containerColor = colorResource(R.color.lightBlue)),
@ -178,4 +195,5 @@ fun Login(navController: NavController, modifier: Modifier = Modifier, loginView
} }
) )
} }
} }

View File

@ -4,186 +4,28 @@
"id": 1, "id": 1,
"passengers_count": 1, "passengers_count": 1,
"ticket_cost": 2680, "ticket_cost": 2680,
"flightId": 6 "flightId": 5
}, },
{ {
"id": 2, "id": 2,
"passengers_count": 2, "passengers_count": 2,
"ticket_cost": 4870, "ticket_cost": 4870,
"flightId": 5 "flightId": 6
}, },
{ {
"passengers_count": 5, "passengers_count": 6,
"ticket_cost": 54000, "ticket_cost": 21420,
"flightId": 10, "flightId": 14,
"id": 3 "id": 3
}, },
{ {
"passengers_count": 1, "passengers_count": 3,
"ticket_cost": 2680, "ticket_cost": 15000,
"flightId": 6, "flightId": 12,
"id": 4 "id": 4
},
{
"id": 5,
"passengers_count": 2,
"ticket_cost": 17440,
"flightId": 8
},
{
"passengers_count": 4,
"ticket_cost": 71200,
"flightId": 9,
"id": 7
},
{
"passengers_count": 6,
"ticket_cost": 106800,
"flightId": 9,
"id": 9
},
{
"passengers_count": 6,
"ticket_cost": 106800,
"flightId": 9,
"id": 10
},
{
"passengers_count": 11,
"ticket_cost": 29480,
"flightId": 6,
"id": 12
},
{
"passengers_count": 3,
"ticket_cost": 8040,
"flightId": 6,
"id": 13
},
{
"passengers_count": 8,
"ticket_cost": 142400,
"flightId": 9,
"id": 14
},
{
"passengers_count": 1,
"ticket_cost": 2680,
"flightId": 6,
"id": 15
},
{
"passengers_count": 1,
"ticket_cost": 2680,
"flightId": 6,
"id": 16
},
{
"passengers_count": 1,
"ticket_cost": 2680,
"flightId": 6,
"id": 17
},
{
"passengers_count": 1,
"ticket_cost": 17800,
"flightId": 9,
"id": 18
},
{
"passengers_count": 5,
"ticket_cost": 5000,
"flightId": 2,
"id": 19
},
{
"passengers_count": 6,
"ticket_cost": 6000,
"flightId": 2,
"id": 20
},
{
"passengers_count": 3,
"ticket_cost": 3000,
"flightId": 2,
"id": 21
},
{
"passengers_count": 10,
"ticket_cost": 10000,
"flightId": 2,
"id": 22
},
{
"passengers_count": 6,
"ticket_cost": 6000,
"flightId": 2,
"id": 23
},
{
"passengers_count": 9,
"ticket_cost": 160200,
"flightId": 9,
"id": 24
},
{
"passengers_count": 8,
"ticket_cost": 142400,
"flightId": 9,
"id": 25
},
{
"passengers_count": 3,
"ticket_cost": 53400,
"flightId": 9,
"id": 26
},
{
"passengers_count": 6,
"ticket_cost": 106800,
"flightId": 9,
"id": 27
},
{
"passengers_count": 5,
"ticket_cost": 89000,
"flightId": 9,
"id": 28
},
{
"passengers_count": 3,
"ticket_cost": 20610,
"flightId": 7,
"id": 29
},
{
"passengers_count": 5,
"ticket_cost": 5000,
"flightId": 2,
"id": 30
},
{
"passengers_count": 2,
"ticket_cost": 5360,
"flightId": 6,
"id": 31
},
{
"passengers_count": 3,
"ticket_cost": 7305,
"flightId": 5,
"id": 32
} }
], ],
"flights": [ "flights": [
{
"id": 2,
"direction_from": "a",
"direction_to": "b",
"departure_date": "1-1-2024",
"arrival_date": "1-1-2024",
"one_ticket_cost": 1000
},
{ {
"direction_from": "Санкт-Петербург", "direction_from": "Санкт-Петербург",
"direction_to": "Сочи", "direction_to": "Сочи",
@ -276,46 +118,6 @@
"password": "usertt", "password": "usertt",
"role": "User" "role": "User"
}, },
{
"surname": "а",
"name": "а",
"patronymic": "а",
"date_of_birth": "17-5-2000",
"email": "user@mail.ru",
"password": "user",
"role": "User",
"id": 3
},
{
"surname": "ыщылы",
"name": "шчшчгч",
"patronymic": "шчшчшч",
"date_of_birth": "10-12-2015",
"email": "aaa@mail.ru",
"password": "aaa",
"role": "User",
"id": 4
},
{
"surname": "фффф",
"name": "ффф",
"patronymic": "ффф",
"date_of_birth": "7-5-2005",
"email": "userff@mail.ru",
"password": "password",
"role": "User",
"id": 6
},
{
"surname": "ккк",
"name": "ккк",
"patronymic": "ккк",
"date_of_birth": "23-12-2011",
"email": "kkk@mail.ru",
"password": "kkk",
"role": "User",
"id": 7
},
{ {
"id": 8, "id": 8,
"surname": "Артамонова", "surname": "Артамонова",
@ -347,50 +149,20 @@
{ {
"id": 2, "id": 2,
"status": "Ожидает подтверждения", "status": "Ожидает подтверждения",
"userId": 2, "userId": 8,
"ticketId": 2 "ticketId": 2
}, },
{ {
"status": "Ожидает подтверждения", "status": "Ожидает подтверждения",
"userId": 2, "userId": 2,
"ticketId": 24, "ticketId": 3,
"id": 3 "id": 3
}, },
{
"status": "Ожидает подтверждения",
"userId": 2,
"ticketId": 25,
"id": 4
},
{
"status": "Ожидает подтверждения",
"userId": 2,
"ticketId": 26,
"id": 5
},
{
"status": "Ожидает подтверждения",
"userId": 2,
"ticketId": 28,
"id": 7
},
{ {
"status": "Ожидает подтверждения", "status": "Ожидает подтверждения",
"userId": 8, "userId": 8,
"ticketId": 29, "ticketId": 4,
"id": 8 "id": 4
},
{
"status": "Ожидает подтверждения",
"userId": 9,
"ticketId": 30,
"id": 9
},
{
"status": "Ожидает подтверждения",
"userId": 2,
"ticketId": 31,
"id": 10
} }
] ]
} }

View File

@ -25,16 +25,10 @@
"id": 4 "id": 4
}, },
{ {
"passengers_count": 3, "id": 5,
"ticket_cost": 26160, "passengers_count": 2,
"flightId": 8, "ticket_cost": 17440,
"id": 5 "flightId": 8
},
{
"passengers_count": 5,
"ticket_cost": 54000,
"flightId": 10,
"id": 6
}, },
{ {
"passengers_count": 4, "passengers_count": 4,
@ -54,12 +48,6 @@
"flightId": 9, "flightId": 9,
"id": 10 "id": 10
}, },
{
"passengers_count": 6,
"ticket_cost": 106800,
"flightId": 9,
"id": 11
},
{ {
"passengers_count": 11, "passengers_count": 11,
"ticket_cost": 29480, "ticket_cost": 29480,
@ -167,6 +155,30 @@
"ticket_cost": 20610, "ticket_cost": 20610,
"flightId": 7, "flightId": 7,
"id": 29 "id": 29
},
{
"passengers_count": 5,
"ticket_cost": 5000,
"flightId": 2,
"id": 30
},
{
"passengers_count": 2,
"ticket_cost": 5360,
"flightId": 6,
"id": 31
},
{
"passengers_count": 3,
"ticket_cost": 7305,
"flightId": 5,
"id": 32
},
{
"passengers_count": 3,
"ticket_cost": 15000,
"flightId": 12,
"id": 33
} }
], ],
"flights": [ "flights": [
@ -225,6 +237,38 @@
"arrival_date": "15-1-2024", "arrival_date": "15-1-2024",
"one_ticket_cost": 10800, "one_ticket_cost": 10800,
"id": 10 "id": 10
},
{
"direction_from": "Москва",
"direction_to": "Крым",
"departure_date": "24-12-2023",
"arrival_date": "31-12-2023",
"one_ticket_cost": 3850,
"id": 11
},
{
"direction_from": "Кострома",
"direction_to": "Хабаровск",
"departure_date": "29-12-2023",
"arrival_date": "29-12-2023",
"one_ticket_cost": 5000,
"id": 12
},
{
"direction_from": "Москва",
"direction_to": "Кострома",
"departure_date": "6-1-2024",
"arrival_date": "6-1-2024",
"one_ticket_cost": 35740,
"id": 13
},
{
"direction_from": "Москва",
"direction_to": "Ульяновск",
"departure_date": "13-1-2024",
"arrival_date": "14-1-2024",
"one_ticket_cost": 3570,
"id": 14
} }
], ],
"users": [ "users": [
@ -287,6 +331,16 @@
"email": "admin@mail.ru", "email": "admin@mail.ru",
"password": "admin", "password": "admin",
"role": "Admin" "role": "Admin"
},
{
"surname": "user",
"name": "user",
"patronymic": "user",
"date_of_birth": "13-9-2012",
"email": "user66@mail.ru",
"password": "user66",
"role": "User",
"id": 9
} }
], ],
"rents": [ "rents": [
@ -320,12 +374,6 @@
"ticketId": 26, "ticketId": 26,
"id": 5 "id": 5
}, },
{
"status": "Ожидает подтверждения",
"userId": 2,
"ticketId": 27,
"id": 6
},
{ {
"status": "Ожидает подтверждения", "status": "Ожидает подтверждения",
"userId": 2, "userId": 2,
@ -337,6 +385,24 @@
"userId": 8, "userId": 8,
"ticketId": 29, "ticketId": 29,
"id": 8 "id": 8
},
{
"status": "Ожидает подтверждения",
"userId": 9,
"ticketId": 30,
"id": 9
},
{
"status": "Ожидает подтверждения",
"userId": 2,
"ticketId": 31,
"id": 10
},
{
"status": "Ожидает подтверждения",
"userId": 2,
"ticketId": 33,
"id": 11
} }
] ]
} }