Fix registration

This commit is contained in:
Christian Pauly 2020-01-14 13:21:15 +01:00
parent a1eba21da0
commit b6ff2483f0
3 changed files with 47 additions and 50 deletions

View file

@ -36,28 +36,43 @@ class _SignUpPasswordState extends State<SignUpPassword> {
return; return;
} }
Map<String, dynamic> response;
try { try {
print("[Sign Up] Create account..."); print("[Sign Up] Create account...");
response = await matrix.client.register( Future<LoginState> waitForLogin =
matrix.client.onLoginStateChanged.stream.first;
await matrix.client.register(
username: widget.username, username: widget.username,
password: passwordController.text, password: passwordController.text,
initialDeviceDisplayName: matrix.widget.clientName, initialDeviceDisplayName: matrix.widget.clientName,
auth: auth, auth: auth,
); );
await waitForLogin;
} on MatrixException catch (exception) { } on MatrixException catch (exception) {
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); setState(() => passwordError = exception.errorMessage);
return setState(() => loading = false); return setState(() => loading = false);
}
} catch (exception) { } catch (exception) {
print(exception); print(exception);
setState(() => passwordError = exception.toString()); setState(() => passwordError = exception.toString());
return setState(() => loading = false); return setState(() => loading = false);
} }
if (response.containsKey("user_id") &&
response.containsKey("access_token") &&
response.containsKey("device_id")) {
try { try {
await matrix.client.jsonRequest( await matrix.client.jsonRequest(
type: HTTPType.PUT, type: HTTPType.PUT,
@ -79,24 +94,6 @@ class _SignUpPasswordState extends State<SignUpPassword> {
} }
await Navigator.of(context).pushAndRemoveUntil( await Navigator.of(context).pushAndRemoveUntil(
AppRoute.defaultRoute(context, ChatListView()), (r) => false); 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;
}
setState(() => loading = false); setState(() => loading = false);
} }

View file

@ -82,8 +82,8 @@ packages:
dependency: "direct main" dependency: "direct main"
description: description:
path: "." path: "."
ref: cc1be6bd18a5a3f73949f5448a301096ad62ee1b ref: c8633111e5f016cc3dd95f644a4e8767be5559f6
resolved-ref: cc1be6bd18a5a3f73949f5448a301096ad62ee1b resolved-ref: c8633111e5f016cc3dd95f644a4e8767be5559f6
url: "https://gitlab.com/famedly/famedlysdk.git" url: "https://gitlab.com/famedly/famedlysdk.git"
source: git source: git
version: "0.0.1" version: "0.0.1"

View file

@ -27,7 +27,7 @@ dependencies:
famedlysdk: famedlysdk:
git: git:
url: https://gitlab.com/famedly/famedlysdk.git url: https://gitlab.com/famedly/famedlysdk.git
ref: cc1be6bd18a5a3f73949f5448a301096ad62ee1b ref: c8633111e5f016cc3dd95f644a4e8767be5559f6
localstorage: ^3.0.1+4 localstorage: ^3.0.1+4
bubble: ^1.1.9+1 bubble: ^1.1.9+1