main #7

Closed
student-i-skokov wants to merge 3 commits from (deleted):main into main
13 changed files with 63 additions and 14 deletions

4
app/readme.md Normal file
View File

@ -0,0 +1,4 @@
**Команда: 1511 строк кода**
*Penpot*

View File

@ -1,7 +1,7 @@
package ru.myitschool.work.core package ru.myitschool.work.core
object Constants { object Constants {
const val HOST = "http://localhost:8090" const val HOST = "http://10.0.0.165:49181"
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"

View File

@ -4,7 +4,8 @@ object TestIds {
object Auth { object Auth {
const val ERROR = "auth_error" const val ERROR = "auth_error"
const val SIGN_BUTTON = "auth_sign_button" const val SIGN_BUTTON = "auth_sign_button"
const val CODE_INPUT = "auth_code_input" const val LOGIN_INPUT = "auth_login_input"
const val PASSWORD_INPUT = "auth_pass_input"
} }
object Main { object Main {
const val ERROR = "main_error" const val ERROR = "main_error"

View File

@ -0,0 +1,19 @@
package ru.myitschool.work.data.dto
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class AuthRequestDto(
@SerialName("login")
val login: String,
@SerialName("password")
val password: String,
)
@Serializable
data class AuthResponseDto(
@SerialName("token")
val token: String,
@SerialName("expired")
val expired: Int,
)

View File

@ -13,6 +13,7 @@ import ru.myitschool.work.data.source.NetworkDataSource
object AuthRepository { object AuthRepository {
private const val STORE = "AUTH-STORE" private const val STORE = "AUTH-STORE"
private const val CODE_KEY = "CODE" private const val CODE_KEY = "CODE"
private const val LOGIN = "PASS"
private var codeCache: String? = null private var codeCache: String? = null
@ -22,7 +23,9 @@ object AuthRepository {
codeCache = text codeCache = text
App.context.userDataStore.edit { preferences -> App.context.userDataStore.edit { preferences ->
val prefKey = stringPreferencesKey(CODE_KEY) val prefKey = stringPreferencesKey(CODE_KEY)
val logPass = stringPreferencesKey(LOGIN)
preferences[prefKey] = text preferences[prefKey] = text
preferences[logPass] = text
} }
} }
} }
@ -43,7 +46,9 @@ object AuthRepository {
codeCache = null codeCache = null
App.context.userDataStore.edit { preferences -> App.context.userDataStore.edit { preferences ->
val prefKey = stringPreferencesKey(CODE_KEY) val prefKey = stringPreferencesKey(CODE_KEY)
val logKey = stringPreferencesKey(LOGIN)
preferences.remove(prefKey) preferences.remove(prefKey)
preferences.remove(logKey)
} }
} }

View File

@ -9,7 +9,7 @@ class CheckAndSaveAuthCodeUseCase(
text: String text: String
): Result<Unit> { ): Result<Unit> {
return repository.checkAndSave(text).mapCatching { success -> return repository.checkAndSave(text).mapCatching { success ->
if (!success) error("Code is incorrect") if (!success) error("login or password is incorrect")
} }
} }
} }

View File

@ -4,7 +4,7 @@ class CheckCodeFormatUseCase {
operator fun invoke( operator fun invoke(
text: String text: String
): Boolean { ): Boolean {
return text.length == 4 && text.all { char -> return text.length >= 8 && text.all { char ->
char.isLetterOrDigit() && char.isLetterOrDigit() &&
((char >= 'A' && char <= 'Z') || (char >= 'a' && char <= 'z') || char.isDigit()) ((char >= 'A' && char <= 'Z') || (char >= 'a' && char <= 'z') || char.isDigit())
} }

View File

@ -3,4 +3,5 @@ package ru.myitschool.work.ui.screen.auth
sealed interface AuthIntent { sealed interface AuthIntent {
data class Send(val text: String): AuthIntent data class Send(val text: String): AuthIntent
data class TextInput(val text: String): AuthIntent data class TextInput(val text: String): AuthIntent
data class PassInput(val text: String): AuthIntent
} }

View File

@ -79,7 +79,7 @@ private fun Content(
var inputText by remember { mutableStateOf("") } var inputText by remember { mutableStateOf("") }
Spacer(modifier = Modifier.size(16.dp)) Spacer(modifier = Modifier.size(16.dp))
TextField( TextField(
modifier = Modifier.testTag(TestIds.Auth.CODE_INPUT).fillMaxWidth(), modifier = Modifier.testTag(TestIds.Auth.LOGIN_INPUT).fillMaxWidth(),
value = inputText, value = inputText,
onValueChange = { onValueChange = {
inputText = it inputText = it
@ -87,6 +87,18 @@ private fun Content(
}, },
label = { Text(stringResource(R.string.auth_label)) } label = { Text(stringResource(R.string.auth_label)) }
) )
var inputPass by remember { mutableStateOf("") }
Spacer(modifier = Modifier.size(16.dp))
TextField(
modifier = Modifier.testTag(TestIds.Auth.PASSWORD_INPUT).fillMaxWidth(),
value = inputPass,
onValueChange = {
inputPass = it
viewModel.onIntent(AuthIntent.PassInput(it))
},
label = { Text(stringResource(R.string.auth_pass)) }
)
Spacer(modifier = Modifier.size(16.dp)) Spacer(modifier = Modifier.size(16.dp))
Button( Button(
modifier = Modifier.testTag(TestIds.Auth.SIGN_BUTTON).fillMaxWidth(), modifier = Modifier.testTag(TestIds.Auth.SIGN_BUTTON).fillMaxWidth(),

View File

@ -46,7 +46,7 @@ class AuthViewModel : ViewModel() {
) )
} }
} }
is AuthIntent.TextInput -> { is AuthIntent.PassInput -> {
updateStateIfData { oldState -> updateStateIfData { oldState ->
oldState.copy( oldState.copy(
isEnabledSend = checkCodeFormatUseCase.invoke(intent.text), isEnabledSend = checkCodeFormatUseCase.invoke(intent.text),
@ -54,6 +54,11 @@ class AuthViewModel : ViewModel() {
) )
} }
} }
is AuthIntent.TextInput -> {
updateStateIfData { oldState ->
oldState.copy()
}
}
} }
} }

View File

@ -2,10 +2,10 @@ package ru.myitschool.work.ui.theme
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
val Purple80 = Color(0xFFD0BCFF) val Purple80 = Color(0xFFE46962)
val PurpleGrey80 = Color(0xFFCCC2DC) val PurpleGrey80 = Color(0xFF663906)
val Pink80 = Color(0xFFEFB8C8) val Pink80 = Color(0xFF135944)
val Purple40 = Color(0xFF6650a4) val Purple40 = Color(0xFF6750A4)
val PurpleGrey40 = Color(0xFF625b71) val PurpleGrey40 = Color(0xFFFFFFFF)
val Pink40 = Color(0xFF7D5260) val Pink40 = Color(0xFFE46962)

View File

@ -1,9 +1,11 @@
<resources> <resources>
<string name="app_name">Work</string> <string name="app_name">Work</string>
<string name="title_activity_root">RootActivity</string> <string name="title_activity_root">RootActivity</string>
<string name="auth_title">Привет! Введи код для авторизации</string> <string name="auth_title">Привет! Введи логин и пароль для авторизации</string>
<string name="auth_label">Код</string> <string name="auth_label">Логин</string>
<string name="auth_sign_in">Войти</string> <string name="auth_sign_in">Войти</string>
<string name="auth_pass">Пароль</string>
<string name="main_refresh">Обновить</string> <string name="main_refresh">Обновить</string>
<string name="main_logout">Выйти</string> <string name="main_logout">Выйти</string>