Auth delay + bug fixes

This commit is contained in:
student-d-sherstnev 2026-02-25 12:17:33 +03:00
parent eef1033293
commit f309b2ec59
2 changed files with 13 additions and 6 deletions

View File

@ -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
}

View File

@ -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
)
}
}