main #8
BIN
Client_v1.apk
Normal file
BIN
Client_v1.apk
Normal file
Binary file not shown.
@ -16,13 +16,13 @@ object AuthRepository {
|
||||
|
||||
private var codeCache: String? = null
|
||||
|
||||
suspend fun checkAndSave(textLogin: String, textPassword: String): Result<Boolean> {
|
||||
return NetworkDataSource.checkAuth(textLogin, textPassword).onSuccess { success ->
|
||||
suspend fun checkAndSave(text: String): Result<Boolean> {
|
||||
return NetworkDataSource.checkAuth(text).onSuccess { success ->
|
||||
if (success) {
|
||||
codeCache = textLogin // TODO(переделать под отправку и логина и пароля в api)
|
||||
codeCache = text
|
||||
App.context.userDataStore.edit { preferences ->
|
||||
val prefKey = stringPreferencesKey(CODE_KEY)
|
||||
preferences[prefKey] = textLogin // TODO(переделать под отправку и логина и пароля в api)
|
||||
preferences[prefKey] = text
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,9 +36,12 @@ object NetworkDataSource {
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun checkAuth(login: String, password: String): Result<Boolean> = withContext(Dispatchers.IO) {
|
||||
suspend fun checkAuth(text: String): Result<Boolean> = withContext(Dispatchers.IO) {
|
||||
return@withContext runCatching {
|
||||
val response = client.post(getUrl(login, Constants.AUTH_URL))
|
||||
val response = client.post(
|
||||
getUrl(text, Constants.AUTH_URL)) {
|
||||
|
||||
}
|
||||
when (response.status) {
|
||||
HttpStatusCode.OK -> true
|
||||
else -> false
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user