Bobarik41p 1 місяць тому
батько
коміт
4bb0cd4cb4

+ 16 - 0
app/src/main/java/com/example/tasks/model/User.kt

@@ -0,0 +1,16 @@
+package com.example.tasks.model
+
+import kotlinx.serialization.Serializable
+import java.sql.Date
+import java.util.UUID
+
+@Serializable
+data class User (
+    val id: Int,
+    val first_name: String,
+    val last_name:String,
+    val patronymic:String?,
+    val date_of_birth: Date,
+    val gender: Int,
+    val UID: UUID
+)

+ 6 - 0
app/src/main/java/com/example/tasks/navigation/Navigation.kt

@@ -8,6 +8,7 @@ import androidx.navigation.compose.rememberNavController
 import androidx.navigation.navArgument
 import com.example.tasks.screens.CreateProfile
 import com.example.tasks.screens.EnterOTP
+import com.example.tasks.screens.Profile
 import com.example.tasks.screens.SignIn
 import com.example.tasks.screens.Start
 import com.example.tasks.viewModels.AuthViewModel
@@ -42,5 +43,10 @@ fun Navigation(viewModel: AuthViewModel) {
             CreateProfile()
 
         }
+        composable(Screen.Profile.route)
+        {
+            Profile()
+
+        }
     }
 }

+ 1 - 0
app/src/main/java/com/example/tasks/navigation/Screen.kt

@@ -6,6 +6,7 @@ sealed class Screen(val route:String) {
     object SignIn:Screen("sinIn")
     object EnterOTP: Screen("enterOTP")
     object  CreateProfile: Screen("createProfile")
+    object Profile:Screen("profile")
 
     fun withArg(vararg args: String): String {
         return buildString {

+ 5 - 0
app/src/main/java/com/example/tasks/screens/CreateProfile.kt

@@ -1,7 +1,12 @@
 package com.example.tasks.screens
 
+import androidx.compose.foundation.layout.Column
+import androidx.compose.material3.Text
 import androidx.compose.runtime.Composable
 
 @Composable
 fun CreateProfile() {
+    Column {
+        Text(text = "криейт профиль")
+    }
 }

+ 24 - 2
app/src/main/java/com/example/tasks/screens/EnterOTP.kt

@@ -1,6 +1,7 @@
 package com.example.tasks.screens
 
 import android.health.connect.datatypes.units.Length
+import android.util.Log
 import android.widget.Toast
 import androidx.compose.foundation.background
 import androidx.compose.foundation.border
@@ -61,19 +62,34 @@ import androidx.compose.ui.text.style.TextAlign
 import androidx.compose.ui.unit.dp
 import androidx.compose.ui.unit.sp
 import androidx.navigation.NavController
+import com.example.tasks.components.Constants
+import com.example.tasks.model.User
 import com.example.tasks.model.UserState
 import com.example.tasks.navigation.Screen
 import com.example.tasks.viewModels.AuthViewModel
+import io.github.jan.supabase.postgrest.from
+import io.github.jan.supabase.postgrest.query.Columns
+import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.delay
+import kotlinx.coroutines.withContext
 
 @Composable
 fun EnterOTP(navController: NavController,email:String,viewModel: AuthViewModel) {
+    var users by remember { mutableStateOf<List<User>>(listOf()) }
     val userState by viewModel.userState
     var currentUserState by remember { mutableStateOf("") }
     val focusManager = LocalFocusManager.current
     var flag = remember { mutableStateOf(false) }
     val context = LocalContext.current
     val keyboardController = LocalSoftwareKeyboardController.current
+    LaunchedEffect(Unit) {
+        withContext(Dispatchers.IO) {
+             users = Constants.supabase.from("Users")
+                .select(columns = Columns.list("UID")){
+                    filter { User::UID eq viewModel.userID
+                }}.decodeList<User>()
+        }
+    }
     val textList = listOf(
         remember {
             mutableStateOf(
@@ -225,7 +241,7 @@ fun EnterOTP(navController: NavController,email:String,viewModel: AuthViewModel)
             onClick = {
                 val token = token(textList)
                 viewModel.verifyOTP(email, token)
-                 flag.value = true     },
+                flag.value = true },
             Modifier
                 .fillMaxWidth()
                 .height(50.dp),
@@ -249,7 +265,13 @@ fun EnterOTP(navController: NavController,email:String,viewModel: AuthViewModel)
                is UserState.Success -> {
                    val message = (userState as UserState.Success).message
                    currentUserState = message
-                   navController.navigate(Screen.CreateProfile.route)
+                   if(users.isNotEmpty()){
+                       navController.navigate(Screen.Profile.route)
+                   }
+                   else{
+                       navController.navigate(Screen.CreateProfile.route)
+                   }
+
                    flag.value = false
                }
 

+ 12 - 0
app/src/main/java/com/example/tasks/screens/Profile.kt

@@ -0,0 +1,12 @@
+package com.example.tasks.screens
+
+import androidx.compose.foundation.layout.Column
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+
+@Composable
+fun Profile() {
+    Column {
+        Text(text = "профайл")
+    }
+}

+ 3 - 1
app/src/main/java/com/example/tasks/viewModels/AuthViewModel.kt

@@ -19,15 +19,17 @@ import kotlinx.coroutines.launch
 class AuthViewModel : ViewModel() {
     private val _userState = mutableStateOf<UserState>(UserState.Loading)
     val userState: State<UserState> = _userState
+    var userID = ""
     fun onSignInEmailCode(context: Context, emailUser: String) {
         viewModelScope.launch {
             try {
                 _userState.value = UserState.Loading
-                Constants.supabase.auth.signInWith(OTP) {
+                 Constants.supabase.auth.signInWith(OTP) {
                     email = emailUser
                     createUser = false
                 }
                 saveToken(context)
+                userID = Constants.supabase.auth.currentUserOrNull()!!.id
                 _userState.value = UserState.Success("Successful sign in")
 
             } catch (e: Exception) {