new_select_screen #9
@ -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"
|
||||
|
||||
@ -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))
|
||||
}
|
||||
}
|
||||
@ -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() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user