From dbf472665a56283e87ce50dd30e3dc7c87707f61 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Fri, 17 Jan 2020 09:18:05 +0100 Subject: [PATCH] Clean up --- lib/views/sign_up_password.dart | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/views/sign_up_password.dart b/lib/views/sign_up_password.dart index 34395a25..33b6efe5 100644 --- a/lib/views/sign_up_password.dart +++ b/lib/views/sign_up_password.dart @@ -24,7 +24,6 @@ class _SignUpPasswordState extends State { String passwordError; bool loading = false; bool showPassword = true; - int currentStage = 0; void _signUpAction(BuildContext context, {Map auth}) async { MatrixState matrix = Matrix.of(context); @@ -43,11 +42,6 @@ class _SignUpPasswordState extends State { setState(() => loading = true); Future waitForLogin = matrix.client.onLoginStateChanged.stream.first; - if (auth == null) { - currentStage = 0; - } else { - currentStage++; - } await matrix.client.register( username: widget.username, password: passwordController.text, @@ -63,9 +57,16 @@ class _SignUpPasswordState extends State { .firstWhere((a) => !a.stages.contains("m.login.email.identity")) .stages; - if (stages[currentStage] == "m.login.dummy") { + final String currentStage = + exception.completedAuthenticationFlows == null + ? stages.first + : stages.firstWhere((stage) => + !exception.completedAuthenticationFlows.contains(stage) ?? + true); + + if (currentStage == "m.login.dummy") { _signUpAction(context, auth: { - "type": stages[currentStage], + "type": currentStage, "session": exception.session, }); } else { @@ -73,7 +74,7 @@ class _SignUpPasswordState extends State { AppRoute.defaultRoute( context, AuthWebView( - stages[currentStage], + currentStage, exception.session, () => _signUpAction(context, auth: { "session": exception.session,