Browse Source

создание пользователя по его почте

AlexMin 5 days ago
parent
commit
246638a3d5

BIN
.gradle/8.7/checksums/checksums.lock


BIN
.gradle/8.7/checksums/md5-checksums.bin


BIN
.gradle/8.7/checksums/sha1-checksums.bin


BIN
.gradle/8.7/executionHistory/executionHistory.bin


BIN
.gradle/8.7/executionHistory/executionHistory.lock


BIN
.gradle/8.7/fileHashes/fileHashes.bin


BIN
.gradle/8.7/fileHashes/fileHashes.lock


BIN
.gradle/8.7/fileHashes/resourceHashesCache.bin


BIN
.gradle/buildOutputCleanup/buildOutputCleanup.lock


BIN
.gradle/file-system.probe


+ 30 - 11
app/src/main/java/com/example/iplace/main/viewModel/MainViewModel.kt

@@ -8,6 +8,8 @@ import androidx.compose.runtime.getValue
 import androidx.compose.runtime.mutableStateOf
 import androidx.compose.runtime.remember
 import androidx.compose.runtime.setValue
+import androidx.lifecycle.LiveData
+import androidx.lifecycle.MutableLiveData
 import androidx.lifecycle.ViewModel
 import androidx.lifecycle.viewModelScope
 import androidx.navigation.NavHostController
@@ -25,6 +27,7 @@ import kotlinx.coroutines.flow.StateFlow
 import kotlinx.coroutines.flow.asStateFlow
 import kotlinx.coroutines.launch
 import kotlinx.coroutines.withContext
+import com.example.iplace.main.viewModel.SignUpViewModel
 
 class MainViewModel(): ViewModel() {
 
@@ -46,8 +49,6 @@ class MainViewModel(): ViewModel() {
             }
         }
     }
-
-
     fun onSignUpEmail(emailUser: String, passwordUser1: String, passwordUser2: String, navController: NavHostController) {
 
         if(emailUser != "" && passwordUser1 != "" && passwordUser2 != "" ) {
@@ -57,6 +58,8 @@ class MainViewModel(): ViewModel() {
 
                         viewModelScope.launch {
                             try{
+                                val signUpViewModel = SignUpViewModel(emailUser, passwordUser1)
+
                                 var  user =  Constants.supabase.auth.signUpWith(Email) {
                                     email = emailUser
                                     password = passwordUser1
@@ -66,7 +69,6 @@ class MainViewModel(): ViewModel() {
                                 println(Constants.supabase.auth.currentUserOrNull()!!.id)
                                 println("Success")
                                 navController.navigate("creatingUser")
-                                AddNewUserInTable(emailUser,passwordUser1, "as", "123",  "12312",  "1",  "dsad", navController)
                             }
                             catch (e: Exception) {
                                 println("Error")
@@ -85,15 +87,15 @@ class MainViewModel(): ViewModel() {
 
     }
 
-
-    suspend fun AddNewUserInTable(emailUser: String, passwordUser:String, nameUser: String, address: String, about_me: String, id_genderFK: String, img_user: String, navController: NavHostController){
+    fun AddNewUserInTable(nameUser: String, address: String, about_me: String, id_genderFK: String, img_user: String, navController: NavHostController){
+        viewModelScope.launch {
         try {
-//            Constants.supabase.auth.signInWith(Email) {
-//                email = emailUser
-//                password = passwordUser
-//            }
-            val idUser = Constants.supabase.auth.currentUserOrNull()?.id ?: return
-            val newUser = Users(id_UUID = idUser, name = "as", address = "123", about_me = "12312", id_genderFK = 1, img_user = "dsad")
+            Constants.supabase.auth.signInWith(Email) {
+                email = "signUpViewModel.email"  // Используем email из ViewModel
+                password = "signUpViewModel.password"// Используем password из ViewModel
+            }
+            val idUser = Constants.supabase.auth.currentUserOrNull()?.id ?: return@launch
+            val newUser = Users(id_UUID = idUser, name = nameUser, address = address, about_me = about_me, id_genderFK = 1, img_user = "dsad")
 
             Constants.supabase.from("users").insert(newUser)
 
@@ -101,6 +103,7 @@ class MainViewModel(): ViewModel() {
         } catch (e: Exception) {
             Log.e("AddNewUserInTable", "Error adding user: ${e.message}")
         }
+        }
     }
 
 
@@ -109,3 +112,19 @@ class MainViewModel(): ViewModel() {
 }
 
 
+//fun onSignUpEmail2(emailUser: String, passwordUser:String, nameUser: String, address: String, about_me: String, id_genderFK: String, img_user: String, navController: NavHostController) {
+//
+//    viewModelScope.launch {
+//        try{
+//            var  user =  Constants.supabase.auth.signUpWith(Email) {
+//                email = emailUser
+//            }
+//            AddNewUserInTable(emailUser,passwordUser, "as", "123",  "12312",  "1",  "dsad", navController)
+//        }
+//        catch (e: Exception) {
+//            println("Error")
+//            println(e.message.toString())
+//        }
+//    }
+
+

+ 6 - 0
app/src/main/java/com/example/iplace/main/viewModel/SignUpViewModel.kt

@@ -0,0 +1,6 @@
+package com.example.iplace.main.viewModel
+
+data class SignUpViewModel(
+    val email0: String = "",
+    val password0: String = ""
+)

+ 9 - 16
app/src/main/java/com/example/iplace/main/viewModel/mainView/CreatingUser.kt

@@ -156,8 +156,8 @@ fun CreatingUser(navController: NavHostController) {
                 Spacer(modifier = Modifier.height(40.dp)) // Отступ от заголовка
 
                 OutlinedTextField(
-                    value = "",
-                    onValueChange = {},
+                    value = nameUser.value,
+                    onValueChange = { newText -> nameUser.value = newText },
                     label = { Text("Имя") },
                     modifier = Modifier
                         .fillMaxWidth()
@@ -213,8 +213,8 @@ fun CreatingUser(navController: NavHostController) {
                 Spacer(modifier = Modifier.height(10.dp))
 
                 OutlinedTextField(
-                    value = "",
-                    onValueChange = {},
+                    value = address.value,
+                    onValueChange = { newText -> address.value = newText },
                     label = { Text("Адрес") },
                     modifier = Modifier
                         .fillMaxWidth()
@@ -225,7 +225,7 @@ fun CreatingUser(navController: NavHostController) {
 
                 OutlinedTextField(
                     value = "",
-                    onValueChange = {},
+                    onValueChange = {  },
                     label = { Text("Телефон") },
                     modifier = Modifier
                         .fillMaxWidth()
@@ -235,8 +235,8 @@ fun CreatingUser(navController: NavHostController) {
                 Spacer(modifier = Modifier.height(10.dp))
 
                 OutlinedTextField(
-                    value = "",
-                    onValueChange = {},
+                    value = about_me.value,
+                    onValueChange = { newText -> about_me.value = newText },
                     label = { Text("О себе") },
                     modifier = Modifier
                         .fillMaxWidth()
@@ -288,15 +288,8 @@ fun CreatingUser(navController: NavHostController) {
 
                 Button(
                     onClick = {
-//                        viewModel.AddNewUserInTable(
-//                            emailUser = emailUser.value,
-//                            passwordUser = passwordUser.value,
-//                            nameUser = nameUser.value,
-//                            address = address.value,
-//                            about_me = about_me.value,
-//                            id_genderFK = id_genderFK.value,
-//                            img_user = img_user.value,
-//                            navController = navController)
+                        viewModel.AddNewUserInTable(nameUser.value,  address.value , about_me.value,  "1",  "dsad", navController)
+
                               },
                     modifier = Modifier.width(290.dp).height(50.dp),
                     colors = ButtonDefaults.buttonColors(brown_contrast)