From b6ff2483f060c909ab10e32f0426a764ad9905b7 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Tue, 14 Jan 2020 13:21:15 +0100 Subject: [PATCH] Fix registration --- lib/views/sign_up_password.dart | 91 ++++++++++++++++----------------- pubspec.lock | 4 +- pubspec.yaml | 2 +- 3 files changed, 47 insertions(+), 50 deletions(-) diff --git a/lib/views/sign_up_password.dart b/lib/views/sign_up_password.dart index 2612b420..fa764da0 100644 --- a/lib/views/sign_up_password.dart +++ b/lib/views/sign_up_password.dart @@ -36,67 +36,64 @@ class _SignUpPasswordState extends State { return; } - Map response; - try { print("[Sign Up] Create account..."); - response = await matrix.client.register( + Future waitForLogin = + matrix.client.onLoginStateChanged.stream.first; + await matrix.client.register( username: widget.username, password: passwordController.text, initialDeviceDisplayName: matrix.widget.clientName, auth: auth, ); + await waitForLogin; } on MatrixException catch (exception) { - setState(() => passwordError = exception.errorMessage); - return setState(() => loading = false); + if (exception.requireAdditionalAuthentication) { + print(exception.raw); + + if (exception.authenticationFlows.indexWhere((a) => + a.stages.length == 1 && a.stages.first == "m.login.dummy") != + -1) { + _signUpAction(context, auth: { + "type": "m.login.dummy", + "session": exception.session, + }); + } else { + setState(() => passwordError = + "The server requires unsupported authentication flows"); + setState(() => loading = false); + return; + } + } else { + setState(() => passwordError = exception.errorMessage); + return setState(() => loading = false); + } } catch (exception) { print(exception); setState(() => passwordError = exception.toString()); return setState(() => loading = false); } - - if (response.containsKey("user_id") && - response.containsKey("access_token") && - response.containsKey("device_id")) { - try { - await matrix.client.jsonRequest( - type: HTTPType.PUT, - action: "/client/r0/profile/${matrix.client.userID}/displayname", - data: {"displayname": widget.displayname}, - ); - } catch (exception) { - Toast.show("Could not set displayname", context, duration: 5); - } - try { - await matrix.client.setAvatar( - MatrixFile( - bytes: await widget.avatar.readAsBytes(), - path: widget.avatar.path, - ), - ); - } catch (exception) { - Toast.show("Could not set profile picture", context, duration: 5); - } - await Navigator.of(context).pushAndRemoveUntil( - AppRoute.defaultRoute(context, ChatListView()), (r) => false); - } else if (response.containsKey("flows")) { - final List stages = response["flows"][0]["stages"]; - for (int i = 0; i < stages.length; i++) { - print("Check stage $i: ${stages[i]}"); - if (stages[i] == "m.login.dummy") { - print("[Sign Up] Process m.login.dummy stage"); - _signUpAction(context, auth: { - "type": stages[i], - "session": response["session"], - }); - return; - } - } - setState(() => passwordError = - "The server requires unsupported authentication flows"); - setState(() => loading = false); - return; + try { + await matrix.client.jsonRequest( + type: HTTPType.PUT, + action: "/client/r0/profile/${matrix.client.userID}/displayname", + data: {"displayname": widget.displayname}, + ); + } catch (exception) { + Toast.show("Could not set displayname", context, duration: 5); } + try { + await matrix.client.setAvatar( + MatrixFile( + bytes: await widget.avatar.readAsBytes(), + path: widget.avatar.path, + ), + ); + } catch (exception) { + Toast.show("Could not set profile picture", context, duration: 5); + } + await Navigator.of(context).pushAndRemoveUntil( + AppRoute.defaultRoute(context, ChatListView()), (r) => false); setState(() => loading = false); } diff --git a/pubspec.lock b/pubspec.lock index 1e872199..3c50442f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -82,8 +82,8 @@ packages: dependency: "direct main" description: path: "." - ref: cc1be6bd18a5a3f73949f5448a301096ad62ee1b - resolved-ref: cc1be6bd18a5a3f73949f5448a301096ad62ee1b + ref: c8633111e5f016cc3dd95f644a4e8767be5559f6 + resolved-ref: c8633111e5f016cc3dd95f644a4e8767be5559f6 url: "https://gitlab.com/famedly/famedlysdk.git" source: git version: "0.0.1" diff --git a/pubspec.yaml b/pubspec.yaml index 882e901d..8cfbecd0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -27,7 +27,7 @@ dependencies: famedlysdk: git: url: https://gitlab.com/famedly/famedlysdk.git - ref: cc1be6bd18a5a3f73949f5448a301096ad62ee1b + ref: c8633111e5f016cc3dd95f644a4e8767be5559f6 localstorage: ^3.0.1+4 bubble: ^1.1.9+1