refactor: Homeserver picker

onboarding
Krille Fear 4 years ago
parent 205c4a7220
commit 4bc45a75c5

@ -137,6 +137,17 @@ class HomeserverPickerController extends State<HomeserverPicker> {
.setItem(SettingKeys.jitsiInstance, jitsi); .setItem(SettingKeys.jitsiInstance, jitsi);
AppConfig.jitsiInstance = jitsi; AppConfig.jitsiInstance = jitsi;
} }
_rawLoginTypes = await Matrix.of(context).getLoginClient().request(
RequestType.GET,
'/client/r0/login',
);
try {
await Matrix.of(context).getLoginClient().register();
registrationSupported = true;
} on MatrixException catch (e) {
registrationSupported = e.requireAdditionalAuthentication ?? false;
}
} catch (e) { } catch (e) {
setState(() => error = (e as Object).toLocalizedString(context)); setState(() => error = (e as Object).toLocalizedString(context));
} finally { } finally {
@ -181,22 +192,6 @@ class HomeserverPickerController extends State<HomeserverPicker> {
.tryGetList('flows') .tryGetList('flows')
.any((flow) => flow['type'] == AuthenticationTypes.sso); .any((flow) => flow['type'] == AuthenticationTypes.sso);
Future<Map<String, dynamic>> getLoginTypes() async {
_rawLoginTypes ??= await Matrix.of(context).getLoginClient().request(
RequestType.GET,
'/client/r0/login',
);
if (registrationSupported == null) {
try {
await Matrix.of(context).getLoginClient().register();
registrationSupported = true;
} on MatrixException catch (e) {
registrationSupported = e.requireAdditionalAuthentication ?? false;
}
}
return _rawLoginTypes;
}
ChromeSafariBrowser browser; ChromeSafariBrowser browser;
static const String ssoHomeserverKey = 'sso-homeserver'; static const String ssoHomeserverKey = 'sso-homeserver';

@ -13,7 +13,6 @@ import 'package:fluffychat/utils/platform_infos.dart';
import 'package:fluffychat/widgets/default_app_bar_search_field.dart'; import 'package:fluffychat/widgets/default_app_bar_search_field.dart';
import 'package:fluffychat/widgets/layouts/one_page_card.dart'; import 'package:fluffychat/widgets/layouts/one_page_card.dart';
import 'package:fluffychat/widgets/matrix.dart'; import 'package:fluffychat/widgets/matrix.dart';
import '../../utils/localized_exception_extension.dart';
import 'homeserver_picker.dart'; import 'homeserver_picker.dart';
class HomeserverPickerView extends StatelessWidget { class HomeserverPickerView extends StatelessWidget {
@ -48,117 +47,92 @@ class HomeserverPickerView extends StatelessWidget {
? 'assets/banner_dark.png' ? 'assets/banner_dark.png'
: 'assets/banner.png', : 'assets/banner.png',
), ),
controller.isLoading if (controller.isLoading)
? const Center( const Center(
child: CircularProgressIndicator.adaptive(strokeWidth: 2)) child: CircularProgressIndicator.adaptive(strokeWidth: 2))
: controller.error != null else if (controller.error != null)
? Center( Center(
child: Padding( child: Padding(
padding: const EdgeInsets.all(12.0),
child: Text(
controller.error,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 18,
color: Colors.red[900],
),
),
),
)
else
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 12.0,
vertical: 4.0,
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
if (controller.ssoLoginSupported)
Row(children: [
const Expanded(child: Divider()),
Padding(
padding: const EdgeInsets.all(12.0), padding: const EdgeInsets.all(12.0),
child: Text( child: Text(L10n.of(context).loginWithOneClick),
controller.error, ),
textAlign: TextAlign.center, const Expanded(child: Divider()),
style: TextStyle( ]),
fontSize: 18, Wrap(
color: Colors.red[900], children: [
if (controller.ssoLoginSupported) ...{
for (final identityProvider
in controller.identityProviders)
_SsoButton(
onPressed: () =>
controller.ssoLoginAction(identityProvider.id),
identityProvider: identityProvider,
), ),
},
].toList(),
),
if (controller.ssoLoginSupported &&
(controller.registrationSupported ||
controller.passwordLoginSupported))
Row(children: [
const Expanded(child: Divider()),
Padding(
padding: const EdgeInsets.all(12.0),
child: Text(L10n.of(context).or),
),
const Expanded(child: Divider()),
]),
if (controller.passwordLoginSupported) ...[
Center(
child: _LoginButton(
onPressed: () => VRouter.of(context).to('login'),
icon: Icon(
CupertinoIcons.lock_open_fill,
color: Theme.of(context).textTheme.bodyText1.color,
), ),
labelText: L10n.of(context).login,
), ),
) ),
: FutureBuilder( const SizedBox(height: 12),
future: controller.getLoginTypes(), ],
builder: (context, snapshot) { if (controller.registrationSupported)
if (snapshot.hasError) { Center(
return Center( child: _LoginButton(
child: Text( onPressed: controller.signUpAction,
snapshot.error.toLocalizedString(context), icon: Icon(
textAlign: TextAlign.center, CupertinoIcons.person_add,
), color: Theme.of(context).textTheme.bodyText1.color,
); ),
} labelText: L10n.of(context).register,
if (!snapshot.hasData) { ),
return const Center( ),
child: CircularProgressIndicator.adaptive( ],
strokeWidth: 2)); ),
} ),
return Padding(
padding: const EdgeInsets.symmetric(
horizontal: 12.0,
vertical: 4.0,
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
if (controller.ssoLoginSupported)
Row(children: [
const Expanded(child: Divider()),
Padding(
padding: const EdgeInsets.all(12.0),
child: Text(
L10n.of(context).loginWithOneClick),
),
const Expanded(child: Divider()),
]),
Wrap(
children: [
if (controller.ssoLoginSupported) ...{
for (final identityProvider
in controller.identityProviders)
_SsoButton(
onPressed: () =>
controller.ssoLoginAction(
identityProvider.id),
identityProvider: identityProvider,
),
},
].toList(),
),
if (controller.ssoLoginSupported &&
(controller.registrationSupported ||
controller.passwordLoginSupported))
Row(children: [
const Expanded(child: Divider()),
Padding(
padding: const EdgeInsets.all(12.0),
child: Text(L10n.of(context).or),
),
const Expanded(child: Divider()),
]),
if (controller.passwordLoginSupported) ...[
Center(
child: _LoginButton(
onPressed: () =>
VRouter.of(context).to('login'),
icon: Icon(
CupertinoIcons.lock_open_fill,
color: Theme.of(context)
.textTheme
.bodyText1
.color,
),
labelText: L10n.of(context).login,
),
),
const SizedBox(height: 12),
],
if (controller.registrationSupported)
Center(
child: _LoginButton(
onPressed: controller.signUpAction,
icon: Icon(
CupertinoIcons.person_add,
color: Theme.of(context)
.textTheme
.bodyText1
.color,
),
labelText: L10n.of(context).register,
),
),
],
),
);
}),
]), ]),
bottomNavigationBar: Material( bottomNavigationBar: Material(
elevation: 6, elevation: 6,

@ -80,8 +80,8 @@ abstract class ClientManager {
legacyDatabaseBuilder: FlutterMatrixHiveStore.hiveDatabaseBuilder, legacyDatabaseBuilder: FlutterMatrixHiveStore.hiveDatabaseBuilder,
supportedLoginTypes: { supportedLoginTypes: {
AuthenticationTypes.password, AuthenticationTypes.password,
//if (PlatformInfos.isMobile || PlatformInfos.isWeb) if (PlatformInfos.isMobile || PlatformInfos.isWeb)
AuthenticationTypes.sso AuthenticationTypes.sso
}, },
compute: compute, compute: compute,
); );

Loading…
Cancel
Save