[API/Login] Allow passing LoginStore params in user action requests.

This commit is contained in:
Kuba Szczodrzyński 2022-10-14 19:44:22 +02:00
parent 9f3aaf6e86
commit 6c96875c83
No known key found for this signature in database
GPG Key ID: 70CB8A85BA1633CB
3 changed files with 23 additions and 16 deletions

View File

@ -91,6 +91,11 @@ class LoginFormFragment : Fragment(), CoroutineScope {
val loginMode = arguments?.getInt("loginMode") ?: return val loginMode = arguments?.getInt("loginMode") ?: return
val mode = register.loginModes.firstOrNull { it.loginMode == loginMode } ?: return val mode = register.loginModes.firstOrNull { it.loginMode == loginMode } ?: return
if (mode.credentials.isEmpty()) {
login(loginType, loginMode)
return
}
b.title.setText(R.string.login_form_title_format, app.getString(register.registerName)) b.title.setText(R.string.login_form_title_format, app.getString(register.registerName))
b.subTitle.text = platformName ?: app.getString(mode.name) b.subTitle.text = platformName ?: app.getString(mode.name)
b.text.text = platformGuideText ?: app.getString(mode.guideText) b.text.text = platformGuideText ?: app.getString(mode.guideText)
@ -252,7 +257,7 @@ class LoginFormFragment : Fragment(), CoroutineScope {
} }
if (platformStoreKey == null) if (platformStoreKey == null)
payload.putAll(platformData?.toBundle()) payload.putAll(platformData?.toBundle() ?: Bundle())
else else
payload.putBundle(platformStoreKey, platformData?.toBundle()) payload.putBundle(platformStoreKey, platformData?.toBundle())

View File

@ -68,7 +68,7 @@ class LoginPlatformListFragment : Fragment(), CoroutineScope {
"platformName" to platform.name, "platformName" to platform.name,
"platformDescription" to platform.description, "platformDescription" to platform.description,
"platformFormFields" to platform.formFields.joinToString(";"), "platformFormFields" to platform.formFields.joinToString(";"),
"platformData" to platform.data, "platformData" to platform.data.toString(),
"platformStoreKey" to platform.storeKey, "platformStoreKey" to platform.storeKey,
), activity.navOptions) ), activity.navOptions)
} }

View File

@ -19,11 +19,9 @@ import pl.szczodrzynski.edziennik.data.api.ERROR_USOS_OAUTH_LOGIN_REQUEST
import pl.szczodrzynski.edziennik.data.api.edziennik.EdziennikTask import pl.szczodrzynski.edziennik.data.api.edziennik.EdziennikTask
import pl.szczodrzynski.edziennik.data.api.events.UserActionRequiredEvent import pl.szczodrzynski.edziennik.data.api.events.UserActionRequiredEvent
import pl.szczodrzynski.edziennik.data.api.models.ApiError import pl.szczodrzynski.edziennik.data.api.models.ApiError
import pl.szczodrzynski.edziennik.ext.Bundle import pl.szczodrzynski.edziennik.ext.*
import pl.szczodrzynski.edziennik.ext.Intent
import pl.szczodrzynski.edziennik.ext.JsonObject
import pl.szczodrzynski.edziennik.ext.pendingIntentFlag
import pl.szczodrzynski.edziennik.ui.captcha.LibrusCaptchaDialog import pl.szczodrzynski.edziennik.ui.captcha.LibrusCaptchaDialog
import pl.szczodrzynski.edziennik.utils.Utils.d
class UserActionManager(val app: App) { class UserActionManager(val app: App) {
companion object { companion object {
@ -90,8 +88,9 @@ class UserActionManager(val app: App) {
onSuccess: ((params: Bundle) -> Unit)? = null, onSuccess: ((params: Bundle) -> Unit)? = null,
onFailure: (() -> Unit)? = null onFailure: (() -> Unit)? = null
) { ) {
d(TAG, "Running user action ($type) with params: ${params?.toJsonObject()}")
when (type) { when (type) {
UserActionRequiredEvent.CAPTCHA_LIBRUS -> executeLibrus(activity, profileId, onSuccess, onFailure) UserActionRequiredEvent.CAPTCHA_LIBRUS -> executeLibrus(activity, profileId, params, onSuccess, onFailure)
UserActionRequiredEvent.OAUTH_USOS -> executeOauth(activity, profileId, params, onSuccess, onFailure) UserActionRequiredEvent.OAUTH_USOS -> executeOauth(activity, profileId, params, onSuccess, onFailure)
} }
} }
@ -99,27 +98,29 @@ class UserActionManager(val app: App) {
private fun executeLibrus( private fun executeLibrus(
activity: AppCompatActivity, activity: AppCompatActivity,
profileId: Int?, profileId: Int?,
params: Bundle?,
onSuccess: ((params: Bundle) -> Unit)?, onSuccess: ((params: Bundle) -> Unit)?,
onFailure: (() -> Unit)?, onFailure: (() -> Unit)?,
) { ) {
if (profileId == null) if (profileId == null)
return return
val extras = params?.getBundle("extras")
// show captcha dialog // show captcha dialog
// use passed onSuccess listener, else sync profile // use passed onSuccess listener, else sync profile
LibrusCaptchaDialog( LibrusCaptchaDialog(
activity = activity, activity = activity,
onSuccess = { code -> onSuccess = { code ->
val args = Bundle(
"recaptchaCode" to code,
"recaptchaTime" to System.currentTimeMillis(),
)
if (extras != null)
args.putAll(extras)
if (onSuccess != null) { if (onSuccess != null) {
val params = Bundle( onSuccess(args)
"recaptchaCode" to code,
"recaptchaTime" to System.currentTimeMillis(),
)
onSuccess(params)
} else { } else {
EdziennikTask.syncProfile(profileId, arguments = JsonObject( EdziennikTask.syncProfile(profileId, arguments = args.toJsonObject()).enqueue(activity)
"recaptchaCode" to code,
"recaptchaTime" to System.currentTimeMillis(),
)).enqueue(activity)
} }
}, },
onFailure = onFailure onFailure = onFailure
@ -135,6 +136,7 @@ class UserActionManager(val app: App) {
) { ) {
if (profileId == null || params == null) if (profileId == null || params == null)
return return
val extras = params.getBundle("extras")
} }
} }