Browse Source

update: process creatin sognIn

Bax 6 days ago
parent
commit
22c5ab05a4

+ 4 - 1
mobile_app/new/wabi/app/src/main/java/com/example/wabi/domain/repository/UserShareDate.kt

@@ -2,10 +2,13 @@ package com.example.wabi.domain.repository
 
 import android.annotation.SuppressLint
 import android.content.Context
+import androidx.compose.runtime.MutableState
+import androidx.compose.runtime.mutableStateOf
 import com.example.wabi.domain.navigation.Routes
 
 @SuppressLint("StaticFieldLeak")
 object UserShareDate {
     var context: Context? = null
-    val currentRoute: String = Routes.BASKET
+    var currentRoute: String = Routes.BASKET
+    val userIsLogging: MutableState<Boolean> = mutableStateOf(false)
 }

+ 7 - 0
mobile_app/new/wabi/app/src/main/java/com/example/wabi/models/screens/SignInState.kt

@@ -0,0 +1,7 @@
+package com.example.wabi.models.screens
+
+data class SignInState(
+    var email: String = "",
+    var password: String = ""
+)
+

+ 1 - 1
mobile_app/new/wabi/app/src/main/java/com/example/wabi/view/MainActivity.kt

@@ -47,7 +47,7 @@ class MainActivity : ComponentActivity() {
                     bottomBar = {
                         if (isBottomBar.value) {
                             BottomBar(
-                                navHostController = navHostController, isSession = false
+                                navHostController = navHostController
                             )
                         }
                     },

+ 18 - 0
mobile_app/new/wabi/app/src/main/java/com/example/wabi/view/MainActivityViewModel.kt

@@ -1,12 +1,30 @@
 package com.example.wabi.view
 
 import androidx.lifecycle.ViewModel
+import androidx.lifecycle.viewModelScope
+import com.example.wabi.domain.repository.PrefManager
+import com.example.wabi.domain.repository.UserShareDate
 import com.example.wabi.domain.supabase.SupabaseServiceImpl
 import dagger.hilt.android.lifecycle.HiltViewModel
+import kotlinx.coroutines.launch
 import javax.inject.Inject
 
 @HiltViewModel
 class MainActivityViewModel @Inject constructor(private val supabase: SupabaseServiceImpl) :
     ViewModel() {
 
+    init {
+        val email = PrefManager.getDataCurrentUser()[0]
+        val password = PrefManager.getDataCurrentUser()[1]
+
+        viewModelScope.launch {
+            if (email != null && password != null && email.isNotEmpty() && password.isNotEmpty()) {
+                val response = supabase.signIn(email, password)
+
+                if (response.error == "") {
+                    UserShareDate.userIsLogging.value == true
+                }
+            }
+        }
+    }
 }

+ 3 - 4
mobile_app/new/wabi/app/src/main/java/com/example/wabi/view/components/bars/bottom/BottomBar.kt

@@ -28,7 +28,6 @@ import com.example.wabi.ui.theme.WabiTheme
 fun BottomBar(
     navHostController: NavHostController,
     modifier: Modifier = Modifier,
-    isSession: Boolean,
     vm: BottomBarViewModel = hiltViewModel()
 ) {
     val screens = listOf(
@@ -46,13 +45,13 @@ fun BottomBar(
             modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceAround
         ) {
             screens.forEach { screen ->
-                if (screen.route == currentRoute || screen.anotherRoute == currentRoute) {
+                if (screen.route == currentRoute) {
                     Button(
                         onClick = {
                             vm.changeScreen(
                                 navHostController = navHostController,
                                 whereFrom = currentRoute,
-                                where = if (isSession) screen.route else screen.anotherRoute
+                                where = screen.route
                             )
                         },
                         contentPadding = PaddingValues(10.dp),
@@ -79,7 +78,7 @@ fun BottomBar(
                             vm.changeScreen(
                                 navHostController = navHostController,
                                 whereFrom = currentRoute!!,
-                                where = if (isSession) screen.route else screen.anotherRoute
+                                where = screen.route
                             )
                         },
                         contentPadding = PaddingValues(10.dp),

+ 9 - 4
mobile_app/new/wabi/app/src/main/java/com/example/wabi/view/components/bars/bottom/DestinationBB.kt

@@ -2,19 +2,24 @@ package com.example.wabi.view.components.bars.bottom
 
 import com.example.wabi.R
 import com.example.wabi.domain.navigation.Routes
+import com.example.wabi.domain.repository.UserShareDate
 
 sealed class DestinationBB(
-    val route: String, val anotherRoute: String, val iconId: Int
+    val route: String, val iconId: Int
 ) {
     data object Basket : DestinationBB(
-        route = Routes.BASKET, anotherRoute = Routes.BASKET, iconId = R.drawable.user_basket_vector
+        route = Routes.BASKET, iconId = R.drawable.user_basket_vector
     )
 
     data object Catalog : DestinationBB(
-        route = Routes.CATALOG, anotherRoute = Routes.CATALOG, iconId = R.drawable.catalog_vector
+        route = Routes.CATALOG, iconId = R.drawable.catalog_vector
     )
 
     data object Profile : DestinationBB(
-        route = Routes.PROFILE, anotherRoute = Routes.SIGNIN, iconId = R.drawable.man_vector
+        route = if (UserShareDate.userIsLogging.value) {
+            Routes.PROFILE
+        } else {
+            Routes.SIGNIN
+        }, iconId = R.drawable.man_vector
     )
 }

+ 2 - 2
mobile_app/new/wabi/app/src/main/java/com/example/wabi/view/screeens/profile/Profile.kt

@@ -1,10 +1,10 @@
 package com.example.wabi.view.screeens.profile
 
+import androidx.compose.material3.Text
 import androidx.compose.runtime.Composable
-import androidx.compose.ui.Modifier
 import androidx.navigation.NavHostController
 
 @Composable
 fun Profile(navHostController: NavHostController) {
-
+    Text("Профиль")
 }

+ 2 - 2
mobile_app/new/wabi/app/src/main/java/com/example/wabi/view/screeens/signIn/SignIn.kt

@@ -1,10 +1,10 @@
 package com.example.wabi.view.screeens.signIn
 
+import androidx.compose.material3.Text
 import androidx.compose.runtime.Composable
-import androidx.compose.ui.Modifier
 import androidx.navigation.NavHostController
 
 @Composable
 fun SignIn(navHostController: NavHostController) {
-
+    Text("Вход")
 }

+ 50 - 0
mobile_app/new/wabi/app/src/main/java/com/example/wabi/view/screeens/signIn/SignInViewModel.kt

@@ -0,0 +1,50 @@
+package com.example.wabi.view.screeens.signIn
+
+import android.util.Log
+import androidx.compose.runtime.MutableState
+import androidx.compose.runtime.mutableStateOf
+import androidx.lifecycle.ViewModel
+import androidx.lifecycle.viewModelScope
+import androidx.navigation.NavHostController
+import com.example.wabi.domain.navigation.NavigationProvider
+import com.example.wabi.domain.navigation.Routes
+import com.example.wabi.domain.repository.UserShareDate
+import com.example.wabi.domain.supabase.SupabaseServiceImpl
+import com.example.wabi.models.screens.SignInState
+import dagger.hilt.android.lifecycle.HiltViewModel
+import kotlinx.coroutines.launch
+import javax.inject.Inject
+
+@HiltViewModel
+class SignInViewModel @Inject constructor(
+    private val supabase: SupabaseServiceImpl, private val nav: NavigationProvider
+) : ViewModel() {
+    private val _data = mutableStateOf(SignInState())
+    val data: SignInState get() = _data.value
+
+    fun updateData(newData: SignInState) {
+        _data.value = newData
+    }
+
+    fun signIn(navController: NavHostController, printError: MutableState<Boolean>) {
+        if (data.email != "" && data.password != "") {
+            viewModelScope.launch {
+                val response = supabase.signIn(_data.value.email, _data.value.password)
+                if (response.error == "") {
+                    UserShareDate.userIsLogging.value = true
+                    printError.value = false
+                    nav.goToNextScreen(
+                        navHostController = navController, Routes.SIGNIN, Routes.BASKET
+                    )
+                } else {
+                    Log.d("signIn", "Ошибка входа!")
+                    printError.value = true
+                }
+            }
+        }
+    }
+
+    fun validateEmail(email: String): Boolean {
+        return email != "" && android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches()
+    }
+}

+ 65 - 0
mobile_app/new/wabi/app/src/main/java/com/example/wabi/view/screeens/signIn/items/EmailForReset.kt

@@ -0,0 +1,65 @@
+package com.example.wabi.view.screeens.signIn.items
+
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.padding
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.MutableState
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.unit.dp
+import com.example.wabi.ui.theme.WabiTheme
+import com.example.wabi.view.common_elements.button.MainButton
+import com.example.wabi.view.common_elements.textfields.MainTextField
+import com.example.wabi.view.components.buttons.ButtonBack
+import com.example.wabi.view.components.buttons.MainButton
+import com.example.wabi.view.components.texts.Error.ErrorList
+import com.example.wabi.view.components.texts.Error.ErrorPrint
+import com.example.wabi.view.screeens.signIn.SignInViewModel
+
+@Composable
+fun EmailForReset(email: String, vm: SignInViewModel, visible: MutableState<Boolean>) {
+    var correctEmail = remember { mutableStateOf(false) }
+    val currentEmail = remember { mutableStateOf(email) }
+    Row(
+        modifier = Modifier.fillMaxWidth()
+    ) {
+        ButtonBack(onClick = {
+            visible.value = true
+        }, modifier = Modifier.padding(10.dp))
+    }
+    Text(
+        text = "Восстановите\nпароль",
+        style = WabiTheme.fonts.headerFont,
+        maxLines = 2,
+        minLines = 2,
+        color = WabiTheme.colors.mainColor
+    )
+    Text(
+        text = "Для восстановления\nпароля введите\nсвою почту",
+        style = WabiTheme.fonts.mainFont,
+        color = WabiTheme.colors.mainColor
+    )
+    ErrorPrint(text = if (correctEmail.value) ErrorList.emailNotExists else "")
+
+    Column() {
+        MainTextField(
+            value = currentEmail.value,
+            input = { currentEmail.value = it },
+            placeholder = "Почта",
+            lable = "Введите почту:",
+            trailingText = ""
+        )
+    }
+
+    MainButton(
+        onClick = {},
+        enabled = vm.validateEmail(currentEmail.value),
+        textContent = "Отправить код",
+        modifier = Modifier.padding(30.dp, 0.dp)
+    )
+
+}

+ 98 - 0
mobile_app/new/wabi/app/src/main/java/com/example/wabi/view/screeens/signIn/items/Login.kt

@@ -0,0 +1,98 @@
+package com.example.wabi.view.screens.signIn.states
+
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.Spacer
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.offset
+import androidx.compose.foundation.layout.padding
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.MutableState
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.unit.dp
+import androidx.navigation.NavHostController
+import com.example.wabi.model.screens.SignInState
+import com.example.wabi.ui.theme.WabiTheme
+import com.example.wabi.view.common_elements.button.ButtonLink
+import com.example.wabi.view.common_elements.button.MainButton
+import com.example.wabi.view.common_elements.text.error.ErrorList
+import com.example.wabi.view.common_elements.text.error.ErrorPrint
+import com.example.wabi.view.common_elements.textfields.MainTextField
+import com.example.wabi.view.common_elements.textfields.PasswordTextField
+import com.example.wabi.view.screens.signIn.SignInViewModel
+
+@Composable
+fun Login(
+    navController: NavHostController,
+    printError: MutableState<Boolean>,
+    visible: MutableState<Boolean>,
+    data: SignInState,
+    vm: SignInViewModel
+) {
+    Text(
+        text = "Добро\nпожаловать!",
+        style = WabiTheme.fonts.headerFont,
+        maxLines = 2,
+        minLines = 2,
+        color = WabiTheme.colors.mainColor
+    )
+    Text(
+        text = "Войдите, чтобы\nпользоваться функциями приложения",
+        style = WabiTheme.fonts.mainFont,
+        color = WabiTheme.colors.mainColor
+    )
+    ErrorPrint(text = if (printError.value) ErrorList.errorPassOrEmail else "")
+    Column(
+        modifier = Modifier.fillMaxWidth()
+    ) {
+        MainTextField(
+            value = data.email,
+            input = { vm.updateData(data.copy(email = it)) },
+            placeholder = "Почта",
+            lable = "Введите почту:",
+            trailingText = ""
+        )
+        Spacer(modifier = Modifier.height(10.dp))
+        PasswordTextField(
+            value = data.password,
+            input = { vm.updateData(data.copy(password = it)) },
+            placeholder = "Пароль",
+            lable = "Введите пароль:"
+        )
+    }
+    Column(
+        horizontalAlignment = Alignment.CenterHorizontally
+    ) {
+        Text(
+            text = "Нет аккаунта?",
+            style = WabiTheme.fonts.acentFont,
+            color = WabiTheme.colors.mainColor
+        )
+        ButtonLink(
+            onClick = {
+                vm.goToRegistration(navController = navController)
+            },
+            textContent = "Зарегистирируйтесь!",
+            modifierButton = Modifier.offset(y = (-15).dp),
+            colorContent = WabiTheme.colors.mainColor
+        )
+        MainButton(
+            onClick = {
+                vm.signIn(navController = navController, printError = printError)
+            },
+            enabled = data.password != "" && vm.validateEmail(data.email),
+            textContent = "Войти",
+            modifierButton = Modifier
+                .padding(30.dp, 0.dp)
+                .fillMaxWidth()
+        )
+        Spacer(Modifier.height(5.dp))
+        ButtonLink(
+            onClick = {
+                visible.value = false
+            }, textContent = "Забыли пароль?", colorContent = WabiTheme.colors.mainColor
+        )
+    }
+}

+ 2 - 2
mobile_app/new/wabi/app/src/main/java/com/example/wabi/view/screeens/signUp/SignUp.kt

@@ -1,10 +1,10 @@
 package com.example.wabi.view.screeens.signUp
 
+import androidx.compose.material3.Text
 import androidx.compose.runtime.Composable
-import androidx.compose.ui.Modifier
 import androidx.navigation.NavHostController
 
 @Composable
 fun SignUp(navHostController: NavHostController) {
-
+    Text("Регистрация")
 }