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