removed encr

This commit is contained in:
student-d-sherstnev 2026-02-25 14:29:14 +03:00
parent 17fd20fb6a
commit 16b77a1f26
3 changed files with 4 additions and 22 deletions

View File

@ -1,7 +1,7 @@
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 = "/login"
const val INFO_URL = "/info"
const val BOOKING_URL = "/booking"

View File

@ -1,14 +0,0 @@
package ru.myitschool.work.data
import java.util.Base64
object Base64Encoder {
fun encrypt(strToEncrypt: String): String? {
return Base64.getEncoder().encodeToString(strToEncrypt.toByteArray())
}
fun decrypt(strToDecrypt: String): String {
return String(Base64.getDecoder().decode(strToDecrypt))
}
}

View File

@ -8,7 +8,6 @@ import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.datastore.preferences.preferencesDataStore
import kotlinx.coroutines.flow.firstOrNull
import ru.myitschool.work.App
import ru.myitschool.work.data.Base64Encoder
import ru.myitschool.work.data.dto.AuthRequestDto
import ru.myitschool.work.data.dto.AuthResponseDto
import ru.myitschool.work.data.source.NetworkDataSource
@ -22,12 +21,10 @@ object AuthRepository {
suspend fun checkAndSave(login: String, password: String): Result<AuthResponseDto> {
val data = AuthRequestDto(login=login, password=password)
return NetworkDataSource.checkAuth(data).onSuccess { success ->
val encryptedTokenCache = Base64Encoder.encrypt(success.token)
tokenCache = encryptedTokenCache
if (encryptedTokenCache != null) {
if (tokenCache != null) {
App.context.userDataStore.edit { preferences ->
val prefKey = stringPreferencesKey(TOKEN_KEY)
preferences[prefKey] = encryptedTokenCache
preferences[prefKey] = success.token
}
}
}
@ -41,8 +38,7 @@ object AuthRepository {
preferences[stringPreferencesKey(TOKEN_KEY)]
}
}
tokenCache?.let { return Base64Encoder.decrypt(it) }
return null
return tokenCache
}
suspend fun logout() {