|
@@ -1,11 +1,15 @@
|
|
|
package com.example.wabi.view.screeens.logIn
|
|
|
|
|
|
+import android.content.Context
|
|
|
+import android.graphics.Bitmap
|
|
|
+import android.graphics.BitmapFactory
|
|
|
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.R
|
|
|
import com.example.wabi.domain.navigation.NavigationProvider
|
|
|
import com.example.wabi.domain.navigation.Routes
|
|
|
import com.example.wabi.domain.repository.PrefManager
|
|
@@ -13,11 +17,13 @@ import com.example.wabi.domain.repository.UserShareDate
|
|
|
import com.example.wabi.domain.supabase.SupabaseServiceImpl
|
|
|
import com.example.wabi.models.screens.SignInState
|
|
|
import com.example.wabi.models.screens.SignUpState
|
|
|
+import com.example.wabi.models.screens.SignUpUser
|
|
|
import com.example.wabi.view.screeens.logIn.items.signUpItems.SignUpStateDestination
|
|
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
|
|
import kotlinx.coroutines.flow.MutableStateFlow
|
|
|
import kotlinx.coroutines.flow.asStateFlow
|
|
|
import kotlinx.coroutines.launch
|
|
|
+import java.io.ByteArrayOutputStream
|
|
|
import javax.inject.Inject
|
|
|
|
|
|
@HiltViewModel
|
|
@@ -31,6 +37,9 @@ class LogInViewModel @Inject constructor(
|
|
|
private val _signUpData = mutableStateOf(SignUpState())
|
|
|
val signUpData: SignUpState get() = _signUpData.value
|
|
|
|
|
|
+ private val _signUpUser = mutableStateOf(SignUpUser())
|
|
|
+ val signUpUser: SignUpUser get() = _signUpUser.value
|
|
|
+
|
|
|
private var _emailExists = MutableStateFlow<Boolean>(false)
|
|
|
val emailExists = _emailExists.asStateFlow()
|
|
|
|
|
@@ -42,6 +51,10 @@ class LogInViewModel @Inject constructor(
|
|
|
_signUpData.value = newData
|
|
|
}
|
|
|
|
|
|
+ fun updateUserDataSignUp(newData: SignUpUser) {
|
|
|
+ _signUpUser.value = newData
|
|
|
+ }
|
|
|
+
|
|
|
fun signIn(navController: NavHostController, printError: MutableState<Boolean>) {
|
|
|
if (_signInData.value.email != "" && _signInData.value.password != "") {
|
|
|
viewModelScope.launch {
|
|
@@ -79,8 +92,27 @@ class LogInViewModel @Inject constructor(
|
|
|
}
|
|
|
|
|
|
fun signUp(
|
|
|
- printError: MutableState<Int>, stationChanger: MutableState<Int>
|
|
|
) {
|
|
|
+ viewModelScope.launch {
|
|
|
+ val response = supabase.signUp(
|
|
|
+ userEmail = _signUpData.value.email, userPasword = _signUpData.value.passwordOne
|
|
|
+ )
|
|
|
+
|
|
|
+ if (response.error == "") {
|
|
|
+
|
|
|
+ UserShareDate.userIsLogging.value = true
|
|
|
+ PrefManager.initPrefManager(UserShareDate.context!!)
|
|
|
+ PrefManager.saveDataCurrentUser(
|
|
|
+ _signInData.value.email, _signInData.value.password
|
|
|
+ )
|
|
|
+
|
|
|
+ } else {
|
|
|
+ Log.d("signUn", "Error registration!")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fun switchSignUpStation(printError: MutableState<Int>, stationChanger: MutableState<Int>) {
|
|
|
if (_signUpData.value.email != "" && _signUpData.value.passwordOne != "" && _signUpData.value.passwordTwo != "") {
|
|
|
if (checkCorrectPassword(_signUpData.value.passwordOne) && checkCorrectPassword(
|
|
|
_signUpData.value.passwordTwo
|
|
@@ -92,25 +124,9 @@ class LogInViewModel @Inject constructor(
|
|
|
if (!checkEmail) {
|
|
|
printError.value = 0
|
|
|
|
|
|
- val response = supabase.signUp(
|
|
|
- userEmail = _signUpData.value.email,
|
|
|
- userPasword = _signUpData.value.passwordOne
|
|
|
- )
|
|
|
-
|
|
|
- if (response.error == "") {
|
|
|
-
|
|
|
- //UserShareDate.userIsLogging.value = true
|
|
|
- PrefManager.initPrefManager(UserShareDate.context!!)
|
|
|
- PrefManager.saveDataCurrentUser(
|
|
|
- _signInData.value.email, _signInData.value.password
|
|
|
- )
|
|
|
+ stationChanger.value = SignUpStateDestination.createProfile
|
|
|
|
|
|
- stationChanger.value = SignUpStateDestination.createProfile
|
|
|
-
|
|
|
- Log.d("signUn", "go to created profile")
|
|
|
- } else {
|
|
|
- Log.d("signUn", "Error registration!")
|
|
|
- }
|
|
|
+ Log.d("signUn", "go to created profile")
|
|
|
} else {
|
|
|
printError.value = 1
|
|
|
}
|
|
@@ -126,11 +142,17 @@ class LogInViewModel @Inject constructor(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
private fun checkCorrectPassword(password: String): Boolean {
|
|
|
return password.length > 5
|
|
|
}
|
|
|
|
|
|
+ private fun converterBitMapToByteArray(context: Context): ByteArray {
|
|
|
+ val bitmap = BitmapFactory.decodeResource(context.resources, R.drawable.man_vector)
|
|
|
+ val byteArrayInputStream = ByteArrayOutputStream()
|
|
|
+ bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayInputStream)
|
|
|
+ return byteArrayInputStream.toByteArray()
|
|
|
+ }
|
|
|
+
|
|
|
fun sendEmailForResetPassword(email: String): Boolean {
|
|
|
var result = false
|
|
|
viewModelScope.launch {
|