From c4c92e6dd963217982982f46336e84ab27ba4e7d Mon Sep 17 00:00:00 2001 From: aminecmi Date: Tue, 6 Dec 2022 21:39:32 +0100 Subject: [PATCH] No need to login without password and username. --- .../amine/apps/readerforselfossv2/rest/SelfossApi.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/rest/SelfossApi.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/rest/SelfossApi.kt index 1c216c8..b27bf1a 100644 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/rest/SelfossApi.kt +++ b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/rest/SelfossApi.kt @@ -4,6 +4,7 @@ import bou.amine.apps.readerforselfossv2.model.* import bou.amine.apps.readerforselfossv2.service.AppSettingsService import io.github.aakira.napier.Napier import io.ktor.client.* +import io.ktor.client.call.* import io.ktor.client.plugins.* import io.ktor.client.plugins.cache.* import io.ktor.client.plugins.contentnegotiation.* @@ -76,10 +77,14 @@ class SelfossApi(private val appSettingsService: AppSettingsService) { private fun hasLoginInfo() = appSettingsService.getUserName() != null && appSettingsService.getPassword() != null suspend fun login(): SuccessResponse = - if (shouldHavePostLogin()) { - postLogin() + if (appSettingsService.getUserName().isNotEmpty() && appSettingsService.getPassword().isNotEmpty()) { + if (shouldHavePostLogin()) { + postLogin() + } else { + getLogin() + } } else { - getLogin() + SuccessResponse(true) } private suspend fun getLogin() = maybeResponse(client.get(url("/login")) {