Merge pull request 'Auth delay + bug fixes' (#5) from auth-delay into main
Reviewed-on: Minipigi-org/NTO-2026-Android-TeamTask-Template#5
This commit is contained in:
commit
28b87c7d89
@ -1,9 +1,10 @@
|
||||
package ru.myitschool.work.core
|
||||
|
||||
object Constants {
|
||||
const val HOST = "http://10.0.0.103:49165"
|
||||
const val HOST = "http://10.0.0.12:49165"
|
||||
const val AUTH_URL = "/auth"
|
||||
const val INFO_URL = "/info"
|
||||
const val BOOKING_URL = "/booking"
|
||||
const val BOOK_URL = "/book"
|
||||
const val AUTH_DELAY = 60
|
||||
}
|
||||
@ -10,6 +10,7 @@ import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import ru.myitschool.work.core.Constants
|
||||
import ru.myitschool.work.data.repo.AuthRepository
|
||||
import ru.myitschool.work.domain.auth.CheckAndSaveAuthCodeUseCase
|
||||
import ru.myitschool.work.domain.auth.CheckCodeFormatUseCase
|
||||
@ -32,11 +33,14 @@ class AuthViewModel : ViewModel() {
|
||||
private var authTries: Int = 0
|
||||
private var timerSecs: Int = 0
|
||||
|
||||
private var login: String = ""
|
||||
private var password: String = ""
|
||||
|
||||
fun onIntent(intent: AuthIntent) {
|
||||
when (intent) {
|
||||
is AuthIntent.Send -> {
|
||||
if (authTries >= 5) {
|
||||
timerSecs = 60
|
||||
timerSecs = Constants.AUTH_DELAY
|
||||
val timer = object : CountDownTimer((timerSecs * 1000).toLong(), 1000) {
|
||||
override fun onTick(millisUntilFinished: Long) {
|
||||
timerSecs -= 1
|
||||
@ -53,8 +57,8 @@ class AuthViewModel : ViewModel() {
|
||||
updateStateIfData { oldState ->
|
||||
oldState.copy(
|
||||
isEnabledSend = checkCodeFormatUseCase.invoke(
|
||||
login = intent.login,
|
||||
password = intent.password
|
||||
login = login,
|
||||
password = password
|
||||
),
|
||||
error = null
|
||||
)
|
||||
@ -79,13 +83,15 @@ class AuthViewModel : ViewModel() {
|
||||
}
|
||||
|
||||
is AuthIntent.TextInput -> {
|
||||
login = intent.login
|
||||
password = intent.password
|
||||
updateStateIfData { oldState ->
|
||||
oldState.copy(
|
||||
isEnabledSend = checkCodeFormatUseCase.invoke(
|
||||
login = intent.login,
|
||||
password = intent.password
|
||||
),
|
||||
error = null
|
||||
) && authTries <= 5,
|
||||
error = if (authTries >= 5) oldState.error else null
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user