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,67 +36,64 @@ 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) {
setState(() => passwordError = exception.errorMessage); if (exception.requireAdditionalAuthentication) {
return setState(() => loading = false); 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) { } catch (exception) {
print(exception); print(exception);
setState(() => passwordError = exception.toString()); setState(() => passwordError = exception.toString());
return setState(() => loading = false); return setState(() => loading = false);
} }
try {
if (response.containsKey("user_id") && await matrix.client.jsonRequest(
response.containsKey("access_token") && type: HTTPType.PUT,
response.containsKey("device_id")) { action: "/client/r0/profile/${matrix.client.userID}/displayname",
try { data: {"displayname": widget.displayname},
await matrix.client.jsonRequest( );
type: HTTPType.PUT, } catch (exception) {
action: "/client/r0/profile/${matrix.client.userID}/displayname", Toast.show("Could not set displayname", context, duration: 5);
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.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); 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