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 package ru.myitschool.work.core
object Constants { 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 AUTH_URL = "/auth"
const val INFO_URL = "/info" const val INFO_URL = "/info"
const val BOOKING_URL = "/booking" const val BOOKING_URL = "/booking"
const val BOOK_URL = "/book" 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.asStateFlow
import kotlinx.coroutines.flow.update import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import ru.myitschool.work.core.Constants
import ru.myitschool.work.data.repo.AuthRepository import ru.myitschool.work.data.repo.AuthRepository
import ru.myitschool.work.domain.auth.CheckAndSaveAuthCodeUseCase import ru.myitschool.work.domain.auth.CheckAndSaveAuthCodeUseCase
import ru.myitschool.work.domain.auth.CheckCodeFormatUseCase import ru.myitschool.work.domain.auth.CheckCodeFormatUseCase
@ -32,11 +33,14 @@ class AuthViewModel : ViewModel() {
private var authTries: Int = 0 private var authTries: Int = 0
private var timerSecs: Int = 0 private var timerSecs: Int = 0
private var login: String = ""
private var password: String = ""
fun onIntent(intent: AuthIntent) { fun onIntent(intent: AuthIntent) {
when (intent) { when (intent) {
is AuthIntent.Send -> { is AuthIntent.Send -> {
if (authTries >= 5) { if (authTries >= 5) {
timerSecs = 60 timerSecs = Constants.AUTH_DELAY
val timer = object : CountDownTimer((timerSecs * 1000).toLong(), 1000) { val timer = object : CountDownTimer((timerSecs * 1000).toLong(), 1000) {
override fun onTick(millisUntilFinished: Long) { override fun onTick(millisUntilFinished: Long) {
timerSecs -= 1 timerSecs -= 1
@ -53,8 +57,8 @@ class AuthViewModel : ViewModel() {
updateStateIfData { oldState -> updateStateIfData { oldState ->
oldState.copy( oldState.copy(
isEnabledSend = checkCodeFormatUseCase.invoke( isEnabledSend = checkCodeFormatUseCase.invoke(
login = intent.login, login = login,
password = intent.password password = password
), ),
error = null error = null
) )
@ -79,13 +83,15 @@ class AuthViewModel : ViewModel() {
} }
is AuthIntent.TextInput -> { is AuthIntent.TextInput -> {
login = intent.login
password = intent.password
updateStateIfData { oldState -> updateStateIfData { oldState ->
oldState.copy( oldState.copy(
isEnabledSend = checkCodeFormatUseCase.invoke( isEnabledSend = checkCodeFormatUseCase.invoke(
login = intent.login, login = intent.login,
password = intent.password password = intent.password
), ) && authTries <= 5,
error = null error = if (authTries >= 5) oldState.error else null
) )
} }
} }