Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
2920734991
@ -9,6 +9,7 @@ import dagger.Lazy
|
|||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.firstOrNull
|
import kotlinx.coroutines.flow.firstOrNull
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
import ru.myitschool.work.data.dto.LoginDto
|
||||||
|
|
||||||
@Reusable
|
@Reusable
|
||||||
class AuthorizationRepositoryImpl @Inject constructor(
|
class AuthorizationRepositoryImpl @Inject constructor(
|
||||||
@ -16,11 +17,11 @@ class AuthorizationRepositoryImpl @Inject constructor(
|
|||||||
private val authorizationNetworkDataSource: Lazy<AuthorizationNetworkDataSource>,
|
private val authorizationNetworkDataSource: Lazy<AuthorizationNetworkDataSource>,
|
||||||
): AuthorizationRepository {
|
): AuthorizationRepository {
|
||||||
|
|
||||||
override suspend fun login(username: String): Result<Unit> {
|
override suspend fun login(data: LoginDto): Result<Unit> {
|
||||||
return withContext(Dispatchers.IO) {
|
return withContext(Dispatchers.IO) {
|
||||||
authorizationNetworkDataSource.get().checkLogin(username)
|
authorizationNetworkDataSource.get().checkLogin(data.username!!)
|
||||||
.onSuccess {
|
.onSuccess {
|
||||||
authorizationStorageDataSource.get().updateLogin(username)
|
authorizationStorageDataSource.get().updateLogin(data.username)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,17 @@
|
|||||||
package ru.myitschool.work.domain.auth
|
package ru.myitschool.work.domain.auth
|
||||||
|
|
||||||
|
import ru.myitschool.work.data.dto.LoginDto
|
||||||
import ru.myitschool.work.domain.auth.repo.AuthorizationRepository
|
import ru.myitschool.work.domain.auth.repo.AuthorizationRepository
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class LoginUseCase @Inject constructor(
|
class LoginUseCase @Inject constructor(
|
||||||
private val repo: AuthorizationRepository,
|
private val repo: AuthorizationRepository,
|
||||||
) {
|
) {
|
||||||
suspend operator fun invoke(login: String): Result<Unit> {
|
// suspend operator fun invoke(login: String): Result<Unit> {
|
||||||
return repo.login(username = login)
|
// return repo.login(username = login)
|
||||||
|
// }
|
||||||
|
suspend operator fun invoke(data: LoginDto): Result<Unit>{
|
||||||
|
return repo.login(data=data)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,7 +1,11 @@
|
|||||||
package ru.myitschool.work.domain.auth.repo
|
package ru.myitschool.work.domain.auth.repo
|
||||||
|
|
||||||
|
import ru.myitschool.work.data.dto.LoginDto
|
||||||
|
|
||||||
interface AuthorizationRepository {
|
interface AuthorizationRepository {
|
||||||
suspend fun login(username: String): Result<Unit>
|
//br
|
||||||
|
//suspend fun login(username: String): Result<Unit>
|
||||||
|
suspend fun login(data: LoginDto): Result<Unit>
|
||||||
suspend fun logout()
|
suspend fun logout()
|
||||||
|
|
||||||
suspend fun getLogin(): Result<String>
|
suspend fun getLogin(): Result<String>
|
||||||
|
@ -64,11 +64,7 @@ class LoginFragment : Fragment(R.layout.fragment_login) {
|
|||||||
viewModel.inputLogin(s.toString())
|
viewModel.inputLogin(s.toString())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
binding.password.addTextChangedListener(object : TextChangedListener() {
|
|
||||||
override fun afterTextChanged(s: Editable?) {
|
|
||||||
viewModel.inputLogin(s.toString())
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
|
@ -12,6 +12,7 @@ import kotlinx.coroutines.flow.asStateFlow
|
|||||||
import kotlinx.coroutines.flow.update
|
import kotlinx.coroutines.flow.update
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import ru.myitschool.work.R
|
import ru.myitschool.work.R
|
||||||
|
import ru.myitschool.work.data.dto.LoginDto
|
||||||
import ru.myitschool.work.domain.auth.CheckValidLoginUseCase
|
import ru.myitschool.work.domain.auth.CheckValidLoginUseCase
|
||||||
import ru.myitschool.work.domain.auth.LoginUseCase
|
import ru.myitschool.work.domain.auth.LoginUseCase
|
||||||
import ru.myitschool.work.utils.MutablePublishFlow
|
import ru.myitschool.work.utils.MutablePublishFlow
|
||||||
@ -31,11 +32,13 @@ class LoginViewModel @Inject constructor(
|
|||||||
val state = _state.asStateFlow()
|
val state = _state.asStateFlow()
|
||||||
|
|
||||||
private var login: String = ""
|
private var login: String = ""
|
||||||
|
private var password: String = "123"//пока пароль по дефалту
|
||||||
|
|
||||||
fun clickLogin() {
|
fun clickLogin() {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
_state.update { State.Loading }
|
_state.update { State.Loading }
|
||||||
loginUseCase.get().invoke(login = login).fold(
|
val data = LoginDto(login,password)
|
||||||
|
loginUseCase.get().invoke(data).fold(
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
_action.emit(Action.OpenProfile)
|
_action.emit(Action.OpenProfile)
|
||||||
},
|
},
|
||||||
@ -51,6 +54,9 @@ class LoginViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//Чек пароля на правильность
|
||||||
fun inputLogin(login: String) {
|
fun inputLogin(login: String) {
|
||||||
this.login = login
|
this.login = login
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
@ -61,6 +67,9 @@ class LoginViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fun passwordCheck(password: String){
|
||||||
|
this.password = password
|
||||||
|
}
|
||||||
|
|
||||||
sealed interface Action {
|
sealed interface Action {
|
||||||
data object OpenProfile : Action
|
data object OpenProfile : Action
|
||||||
|
@ -79,10 +79,10 @@
|
|||||||
style="@style/Theme.UiTemplate.Input.Text"
|
style="@style/Theme.UiTemplate.Input.Text"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="@string/login_password_hint"
|
||||||
android:inputType="textPassword"
|
android:inputType="textPassword"
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
android:hint="@string/login_password_hint">
|
android:password="true"></com.google.android.material.textfield.TextInputEditText>
|
||||||
</com.google.android.material.textfield.TextInputEditText>
|
|
||||||
</com.google.android.material.textfield.TextInputLayout>
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user