|
@@ -13,6 +13,7 @@ import androidx.compose.ui.tooling.preview.Preview
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
|
|
import androidx.compose.ui.text.input.TextFieldValue
|
|
|
+import androidx.compose.ui.unit.sp
|
|
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
|
|
import com.example.fitmarcetplacekuzminiv.MainViewModel
|
|
|
|
|
@@ -31,8 +32,9 @@ class AuthScreenActivity : ComponentActivity() {
|
|
|
|
|
|
@Composable
|
|
|
fun AuthScreen(mainViewModel: MainViewModel = viewModel()) {
|
|
|
- var email by remember { mutableStateOf(TextFieldValue("")) }
|
|
|
- var password by remember { mutableStateOf(TextFieldValue("")) }
|
|
|
+ val viewModel = MainViewModel()
|
|
|
+ val email = remember { mutableStateOf("") }
|
|
|
+ val password = remember { mutableStateOf("") }
|
|
|
var errorMessage by remember { mutableStateOf("") }
|
|
|
var successMessage by remember { mutableStateOf("") }
|
|
|
|
|
@@ -48,41 +50,26 @@ fun AuthScreen(mainViewModel: MainViewModel = viewModel()) {
|
|
|
.padding(16.dp)
|
|
|
) {
|
|
|
OutlinedTextField(
|
|
|
- value = email,
|
|
|
- onValueChange = { email = it },
|
|
|
+ value = email.value,
|
|
|
+ onValueChange = { newText -> email.value = newText },
|
|
|
label = { Text("Email") },
|
|
|
modifier = Modifier.fillMaxWidth()
|
|
|
)
|
|
|
Spacer(modifier = Modifier.height(16.dp))
|
|
|
OutlinedTextField(
|
|
|
- value = password,
|
|
|
- onValueChange = { password = it },
|
|
|
+ value = password.value,
|
|
|
+ onValueChange = { newText -> password.value = newText },
|
|
|
label = { Text("Password") },
|
|
|
visualTransformation = PasswordVisualTransformation(),
|
|
|
modifier = Modifier.fillMaxWidth()
|
|
|
)
|
|
|
Spacer(modifier = Modifier.height(24.dp))
|
|
|
Button(onClick = {
|
|
|
- // Вызов авторизации через email и пароль
|
|
|
- if (email.text.isNotEmpty() && password.text.isNotEmpty()) {
|
|
|
- mainViewModel.onSignInEmailPassword(email.text, password.text)
|
|
|
- } else {
|
|
|
- errorMessage = "Заполните все поля"
|
|
|
- }
|
|
|
- }) {
|
|
|
+ viewModel.onSignInEmailPassword(email.value,password.value)
|
|
|
+ }){
|
|
|
Text("Login")
|
|
|
}
|
|
|
|
|
|
- // Отображение ошибок или успешного входа
|
|
|
- if (errorMessage.isNotEmpty()) {
|
|
|
- Spacer(modifier = Modifier.height(16.dp))
|
|
|
- Text(text = errorMessage, color = MaterialTheme.colorScheme.error)
|
|
|
- }
|
|
|
-
|
|
|
- if (successMessage.isNotEmpty()) {
|
|
|
- Spacer(modifier = Modifier.height(16.dp))
|
|
|
- Text(text = successMessage, color = MaterialTheme.colorScheme.primary)
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
}
|