removed encr
This commit is contained in:
parent
17fd20fb6a
commit
16b77a1f26
@ -1,7 +1,7 @@
|
|||||||
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 = "/login"
|
const val AUTH_URL = "/login"
|
||||||
const val INFO_URL = "/info"
|
const val INFO_URL = "/info"
|
||||||
const val BOOKING_URL = "/booking"
|
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 androidx.datastore.preferences.preferencesDataStore
|
||||||
import kotlinx.coroutines.flow.firstOrNull
|
import kotlinx.coroutines.flow.firstOrNull
|
||||||
import ru.myitschool.work.App
|
import ru.myitschool.work.App
|
||||||
import ru.myitschool.work.data.Base64Encoder
|
|
||||||
import ru.myitschool.work.data.dto.AuthRequestDto
|
import ru.myitschool.work.data.dto.AuthRequestDto
|
||||||
import ru.myitschool.work.data.dto.AuthResponseDto
|
import ru.myitschool.work.data.dto.AuthResponseDto
|
||||||
import ru.myitschool.work.data.source.NetworkDataSource
|
import ru.myitschool.work.data.source.NetworkDataSource
|
||||||
@ -22,12 +21,10 @@ object AuthRepository {
|
|||||||
suspend fun checkAndSave(login: String, password: String): Result<AuthResponseDto> {
|
suspend fun checkAndSave(login: String, password: String): Result<AuthResponseDto> {
|
||||||
val data = AuthRequestDto(login=login, password=password)
|
val data = AuthRequestDto(login=login, password=password)
|
||||||
return NetworkDataSource.checkAuth(data).onSuccess { success ->
|
return NetworkDataSource.checkAuth(data).onSuccess { success ->
|
||||||
val encryptedTokenCache = Base64Encoder.encrypt(success.token)
|
if (tokenCache != null) {
|
||||||
tokenCache = encryptedTokenCache
|
|
||||||
if (encryptedTokenCache != null) {
|
|
||||||
App.context.userDataStore.edit { preferences ->
|
App.context.userDataStore.edit { preferences ->
|
||||||
val prefKey = stringPreferencesKey(TOKEN_KEY)
|
val prefKey = stringPreferencesKey(TOKEN_KEY)
|
||||||
preferences[prefKey] = encryptedTokenCache
|
preferences[prefKey] = success.token
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -41,8 +38,7 @@ object AuthRepository {
|
|||||||
preferences[stringPreferencesKey(TOKEN_KEY)]
|
preferences[stringPreferencesKey(TOKEN_KEY)]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tokenCache?.let { return Base64Encoder.decrypt(it) }
|
return tokenCache
|
||||||
return null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun logout() {
|
suspend fun logout() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user