x1tosi 1 mesiac pred
rodič
commit
b3f09cab87

+ 41 - 0
.idea/inspectionProfiles/Project_Default.xml

@@ -0,0 +1,41 @@
+<component name="InspectionProjectProfileManager">
+  <profile version="1.0">
+    <option name="myName" value="Project Default" />
+    <inspection_tool class="PreviewAnnotationInFunctionWithParameters" enabled="true" level="ERROR" enabled_by_default="true">
+      <option name="composableFile" value="true" />
+      <option name="previewFile" value="true" />
+    </inspection_tool>
+    <inspection_tool class="PreviewApiLevelMustBeValid" enabled="true" level="ERROR" enabled_by_default="true">
+      <option name="composableFile" value="true" />
+      <option name="previewFile" value="true" />
+    </inspection_tool>
+    <inspection_tool class="PreviewDimensionRespectsLimit" enabled="true" level="WARNING" enabled_by_default="true">
+      <option name="composableFile" value="true" />
+      <option name="previewFile" value="true" />
+    </inspection_tool>
+    <inspection_tool class="PreviewFontScaleMustBeGreaterThanZero" enabled="true" level="ERROR" enabled_by_default="true">
+      <option name="composableFile" value="true" />
+      <option name="previewFile" value="true" />
+    </inspection_tool>
+    <inspection_tool class="PreviewMultipleParameterProviders" enabled="true" level="ERROR" enabled_by_default="true">
+      <option name="composableFile" value="true" />
+      <option name="previewFile" value="true" />
+    </inspection_tool>
+    <inspection_tool class="PreviewMustBeTopLevelFunction" enabled="true" level="ERROR" enabled_by_default="true">
+      <option name="composableFile" value="true" />
+      <option name="previewFile" value="true" />
+    </inspection_tool>
+    <inspection_tool class="PreviewNeedsComposableAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
+      <option name="composableFile" value="true" />
+      <option name="previewFile" value="true" />
+    </inspection_tool>
+    <inspection_tool class="PreviewNotSupportedInUnitTestFiles" enabled="true" level="ERROR" enabled_by_default="true">
+      <option name="composableFile" value="true" />
+      <option name="previewFile" value="true" />
+    </inspection_tool>
+    <inspection_tool class="PreviewPickerAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
+      <option name="composableFile" value="true" />
+      <option name="previewFile" value="true" />
+    </inspection_tool>
+  </profile>
+</component>

+ 1 - 0
app/build.gradle.kts

@@ -60,6 +60,7 @@ dependencies {
     implementation(libs.androidx.ui.tooling.preview)
     implementation(libs.androidx.material3)
     implementation(libs.androidx.navigation.compose)
+    implementation(libs.play.services.auth)
     testImplementation(libs.junit)
     androidTestImplementation(libs.androidx.junit)
     androidTestImplementation(libs.androidx.espresso.core)

+ 45 - 0
app/src/main/java/com/example/fitmarcetplacekuzminiv/MainViewModel.kt

@@ -0,0 +1,45 @@
+package com.example.fitmarcetplacekuzminiv
+
+import androidx.lifecycle.ViewModel
+import androidx.lifecycle.viewModelScope
+import com.example.fitmarcetplacekuzminiv.domain.Constants
+import io.github.jan.supabase.gotrue.auth
+import io.github.jan.supabase.gotrue.providers.builtin.Email
+import io.github.jan.supabase.gotrue.providers.builtin.OTP
+import kotlinx.coroutines.launch
+
+class MainViewModel():ViewModel() {
+
+    fun onSignInEmailCode(emailUser: String) {
+        viewModelScope.launch {
+            try {
+                Constants.supabase.auth.signInWith(OTP) {
+                    email = emailUser
+                    createUser = false
+                }
+
+            } catch (e: Exception) {
+                println(e.message.toString())
+
+            }
+
+        }
+    }
+
+    fun onSignInEmailPassword(emailUser: String, passwordUser: String) {
+        viewModelScope.launch {
+            try {
+                val user = Constants.supabase.auth.signInWith(Email) {
+                    email = emailUser
+                    password = passwordUser
+                }
+                println(user.toString())
+                println(Constants.supabase.auth.currentUserOrNull()!!.id)
+                println("Success")
+            } catch (e: Exception) {
+                println("Error")
+                println(e.message.toString())
+            }
+        }
+    }
+}

+ 28 - 4
app/src/main/java/com/example/fitmarcetplacekuzminiv/Screens/authScreen.kt

@@ -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)
+            }
         }
     }
 }

+ 1 - 1
app/src/main/java/com/example/fitmarcetplacekuzminiv/Screens/firstScreen.kt

@@ -29,7 +29,7 @@ fun FirstScreen(onNavigateToAuthScreen: () -> Unit) {
     Box(
         modifier = Modifier.fillMaxSize()
             .background(Brush.verticalGradient(
-                colors = listOf(Color.Black, Color.Cyan, Color. White)
+                colors = listOf(Color.Gray, Color.Cyan, Color. White)
             )),
         contentAlignment = Alignment.Center
 

+ 2 - 0
app/src/main/java/com/example/fitmarcetplacekuzminiv/domain/Constants.kt

@@ -1,5 +1,7 @@
 package com.example.fitmarcetplacekuzminiv.domain
 
+import android.net.http.HttpResponseCache.install
+//import com.google.android.gms.auth.api.Auth
 import io.github.jan.supabase.createSupabaseClient
 import io.github.jan.supabase.gotrue.Auth
 import io.github.jan.supabase.gotrue.SessionSource

+ 2 - 0
gradle/libs.versions.toml

@@ -11,6 +11,7 @@ lifecycleRuntimeKtx = "2.8.4"
 activityCompose = "1.9.1"
 composeBom = "2024.04.01"
 navigationCompose = "2.8.0"
+playServicesAuth = "21.2.0"
 
 [libraries]
 androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
@@ -33,6 +34,7 @@ ktor-ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref =
 supabase-realtime-kt = { module = "io.github.jan-tennert.supabase:realtime-kt" }
 supabase-gotrue-kt = { module = "io.github.jan-tennert.supabase:gotrue-kt" }
 supabase-postgrest-kt = { module = "io.github.jan-tennert.supabase:postgrest-kt" }
+play-services-auth = { group = "com.google.android.gms", name = "play-services-auth", version.ref = "playServicesAuth" }
 
 [plugins]
 android-application = { id = "com.android.application", version.ref = "agp" }