|
@@ -3,6 +3,7 @@ package com.example.fitmarcetplacekuzminiv.Screens
|
|
|
import android.os.Bundle
|
|
|
import androidx.activity.ComponentActivity
|
|
|
import androidx.activity.compose.setContent
|
|
|
+import androidx.activity.viewModels
|
|
|
import androidx.compose.foundation.layout.*
|
|
|
import androidx.compose.material3.*
|
|
|
import androidx.compose.runtime.*
|
|
@@ -12,21 +13,28 @@ 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.lifecycle.viewmodel.compose.viewModel
|
|
|
+import com.example.fitmarcetplacekuzminiv.MainViewModel
|
|
|
|
|
|
class AuthScreenActivity : ComponentActivity() {
|
|
|
+
|
|
|
+ // Инициализируем ViewModel
|
|
|
+ private val mainViewModel: MainViewModel by viewModels()
|
|
|
+
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
super.onCreate(savedInstanceState)
|
|
|
setContent {
|
|
|
- AuthScreen()
|
|
|
+ AuthScreen(mainViewModel)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Composable
|
|
|
-fun AuthScreen() {
|
|
|
+fun AuthScreen(mainViewModel: MainViewModel = viewModel()) {
|
|
|
var email by remember { mutableStateOf(TextFieldValue("")) }
|
|
|
var password by remember { mutableStateOf(TextFieldValue("")) }
|
|
|
+ var errorMessage by remember { mutableStateOf("") }
|
|
|
+ var successMessage by remember { mutableStateOf("") }
|
|
|
|
|
|
Box(
|
|
|
modifier = Modifier.fillMaxSize(),
|
|
@@ -55,10 +63,26 @@ fun AuthScreen() {
|
|
|
)
|
|
|
Spacer(modifier = Modifier.height(24.dp))
|
|
|
Button(onClick = {
|
|
|
- // Обработка нажатия кнопки "Login"
|
|
|
+ // Вызов авторизации через email и пароль
|
|
|
+ if (email.text.isNotEmpty() && password.text.isNotEmpty()) {
|
|
|
+ mainViewModel.onSignInEmailPassword(email.text, password.text)
|
|
|
+ } else {
|
|
|
+ errorMessage = "Заполните все поля"
|
|
|
+ }
|
|
|
}) {
|
|
|
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)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|