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
|
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
|
||||||
}
|
}
|
||||||
@ -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
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user