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;
}
Map<String, dynamic> response;
try {
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,
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);
}

View File

@ -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"

View File

@ -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