Created
September 13, 2018 19:41
-
-
Save adrianhall/08a84ad69d2cd7bfdc978ef902f6df7a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@SuppressLint("InflateParams") | |
private fun handleLogin() { | |
model.initiateSignin { identityRequest, params, callback -> | |
when(identityRequest) { | |
IdentityRequest.NEED_CREDENTIALS -> { | |
callback(mapOf( | |
"username" to loginFormUsernameField.text.toString(), | |
"password" to loginFormPasswordField.text.toString() | |
)) | |
} | |
IdentityRequest.NEED_MULTIFACTORCODE -> { | |
val mfaDialog = layoutInflater.inflate(R.layout.dialog_multifactor_auth, null) | |
val mfaCodeInput = mfaDialog.find(R.id.dialog_mfa_code) as EditText | |
val mfaInstructions = mfaDialog.find(R.id.dialog_mfa_instructions) as TextView | |
params?.let { | |
val deliveryTo = it.getOrDefault("deliveryTo", "UNKNOWN") | |
mfaInstructions.text = getString(R.string.specific_mfa_instructions, deliveryTo) | |
} | |
alert { | |
title = "Enter Secondary Code" | |
customView = mfaDialog | |
positiveButton("OK") { callback(mapOf("mfaCode" to mfaCodeInput.text.toString())) } | |
}.show() | |
} | |
IdentityRequest.NEED_NEWPASSWORD -> { | |
val newPasswordDialog = layoutInflater.inflate(R.layout.dialog_new_password, null) | |
val passwordInput = newPasswordDialog.find(R.id.new_password_form_password) as EditText | |
alert { | |
title = "Enter New Password" | |
customView = newPasswordDialog | |
positiveButton("OK") { callback(mapOf("password" to passwordInput.text.toString())) } | |
}.show() | |
} | |
IdentityRequest.SUCCESS -> { | |
analyticsService.recordSuccessfulLogin(loginFormUsernameField.text.toString()) | |
[email protected]() | |
} | |
IdentityRequest.FAILURE -> { | |
analyticsService.recordFailedLogin() | |
alert(params?.get("message") ?: "Error submitting credentials") { | |
title = "Login Denied" | |
positiveButton("Close") { /* Do Nothing */ } | |
}.show() | |
} | |
else -> { | |
analyticsService.recordEvent("ERROR", mapOf("error" to "unexpected identity request")) | |
alert("Unknown or unexpected identity request") { | |
title = "Something went wrong!" | |
positiveButton("Close") { /* Do Nothing */ } | |
}.show() | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment