Finish registration

This commit is contained in:
Christian Pauly 2020-01-09 23:15:32 +01:00
parent fddf026cd0
commit 4549f92914

View file

@ -5,6 +5,7 @@ import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/components/matrix.dart';
import 'package:fluffychat/utils/app_route.dart';
import 'package:flutter/material.dart';
import 'package:toast/toast.dart';
import 'chat_list.dart';
@ -35,17 +36,47 @@ class _SignUpPasswordState extends State<SignUpPassword> {
return;
}
Map<String, dynamic> response;
try {
print("[Sign Up] Create account...");
final Map<String, dynamic> response = await matrix.client.register(
response = await matrix.client.register(
username: widget.username,
password: passwordController.text,
initialDeviceDisplayName: matrix.widget.clientName,
auth: auth,
);
} on MatrixException catch (exception) {
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")) {
@ -61,14 +92,7 @@ class _SignUpPasswordState extends State<SignUpPassword> {
}
}
}
} on MatrixException catch (exception) {
setState(() => passwordError = exception.errorMessage);
return setState(() => loading = false);
} catch (exception) {
print(exception);
setState(() => passwordError = exception.toString());
return setState(() => loading = false);
}
setState(() => loading = false);
}