Catch any failed auth/captcha decodes

This commit is contained in:
Kelvin 2024-01-16 21:11:11 +01:00
commit 568a0f6329

View file

@ -2,6 +2,9 @@ package com.futo.platformplayer.api.media.platforms.js
import com.futo.platformplayer.R import com.futo.platformplayer.R
import com.futo.platformplayer.constructs.Event0 import com.futo.platformplayer.constructs.Event0
import com.futo.platformplayer.logging.Logger
import com.futo.platformplayer.states.AnnouncementType
import com.futo.platformplayer.states.StateAnnouncement
import com.futo.platformplayer.views.fields.DropdownFieldOptions import com.futo.platformplayer.views.fields.DropdownFieldOptions
import com.futo.platformplayer.views.fields.FieldForm import com.futo.platformplayer.views.fields.FieldForm
import com.futo.platformplayer.views.fields.FormField import com.futo.platformplayer.views.fields.FormField
@ -55,16 +58,34 @@ class SourcePluginDescriptor {
onCaptchaChanged.emit(); onCaptchaChanged.emit();
} }
fun getCaptchaData(): SourceCaptchaData? { fun getCaptchaData(): SourceCaptchaData? {
try {
return SourceCaptchaData.fromEncrypted(captchaEncrypted); return SourceCaptchaData.fromEncrypted(captchaEncrypted);
} }
catch(ex: Throwable) {
Logger.e("SourcePluginDescriptor", "Captcha decode failed, disabling auth.", ex);
StateAnnouncement.instance.registerAnnouncement("CAP_BROKEN_" + config.id,
"Captcha corrupted for plugin [${config.name}]",
"Something went wrong in the stored captcha, you'll have to login again", AnnouncementType.SESSION);
return null;
}
}
fun updateAuth(str: SourceAuth?) { fun updateAuth(str: SourceAuth?) {
authEncrypted = str?.toEncrypted(); authEncrypted = str?.toEncrypted();
onAuthChanged.emit(); onAuthChanged.emit();
} }
fun getAuth(): SourceAuth? { fun getAuth(): SourceAuth? {
try {
return SourceAuth.fromEncrypted(authEncrypted); return SourceAuth.fromEncrypted(authEncrypted);
} }
catch(ex: Throwable) {
Logger.e("SourcePluginDescriptor", "Authentication decode failed, disabling auth.", ex);
StateAnnouncement.instance.registerAnnouncement("AUTH_BROKEN_" + config.id,
"Authentication corrupted for plugin [${config.name}]",
"Something went wrong in the stored authentication, you'll have to login again", AnnouncementType.SESSION);
return null;
}
}
@Serializable @Serializable
class AppPluginSettings { class AppPluginSettings {