Skip to content

Commit 701d286

Browse files
committed
login: Hide email/password fields if email auth is disabled
Fixes zulip#1991. Use the email_auth_enabled server setting to conditionally render the username/password fields and the alternative auth divider.
1 parent 896c8b3 commit 701d286

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

lib/widgets/login.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,11 +446,14 @@ class _LoginPageState extends State<LoginPage> {
446446
final zulipLocalizations = ZulipLocalizations.of(context);
447447

448448
final externalAuthenticationMethods = widget.serverSettings.externalAuthenticationMethods;
449+
final emailAuthEnabled = widget.serverSettings.emailAuthEnabled;
449450

450451
final loginContent = Column(mainAxisAlignment: MainAxisAlignment.center, children: [
451-
_UsernamePasswordForm(loginPageState: this),
452+
if (emailAuthEnabled)
453+
_UsernamePasswordForm(loginPageState: this),
452454
if (externalAuthenticationMethods.isNotEmpty) ...[
453-
_AlternativeAuthDivider(),
455+
if (emailAuthEnabled)
456+
_AlternativeAuthDivider(),
454457
...externalAuthenticationMethods.map((method) {
455458
final icon = method.displayIcon;
456459
return OutlinedButton.icon(

test/widgets/login_test.dart

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'dart:async';
33
import 'package:checks/checks.dart';
44
import 'package:flutter/material.dart';
55
import 'package:flutter/services.dart';
6+
import 'package:flutter_checks/flutter_checks.dart';
67
import 'package:flutter_test/flutter_test.dart';
78
import 'package:http/http.dart' as http;
89
import 'package:zulip/api/core.dart';
@@ -356,6 +357,56 @@ void main() {
356357
// TODO test _inProgress logic
357358
});
358359

360+
group('email auth disabled', () {
361+
testWidgets('hides username/password fields and login button', (tester) async {
362+
final serverSettings = eg.serverSettings(emailAuthEnabled: false);
363+
await prepare(tester, serverSettings);
364+
check(findUsernameInput).findsNothing();
365+
check(findPasswordInput).findsNothing();
366+
check(findSubmitButton).findsNothing();
367+
});
368+
369+
testWidgets('shows external auth methods without divider', (tester) async {
370+
final method = ExternalAuthenticationMethod(
371+
name: 'google',
372+
displayName: 'Google',
373+
displayIcon: null,
374+
loginUrl: '/accounts/login/social/google',
375+
signupUrl: '/accounts/register/social/google',
376+
);
377+
final serverSettings = eg.serverSettings(
378+
emailAuthEnabled: false,
379+
externalAuthenticationMethods: [method]);
380+
await prepare(tester, serverSettings);
381+
check(findUsernameInput).findsNothing();
382+
check(findPasswordInput).findsNothing();
383+
check(findSubmitButton).findsNothing();
384+
check(find.textContaining('Google')).findsOne();
385+
final zulipLocalizations = GlobalLocalizations.zulipLocalizations;
386+
check(find.text(zulipLocalizations.loginMethodDivider)).findsNothing();
387+
});
388+
389+
testWidgets('shows divider when email auth enabled with external methods', (tester) async {
390+
final method = ExternalAuthenticationMethod(
391+
name: 'google',
392+
displayName: 'Google',
393+
displayIcon: null,
394+
loginUrl: '/accounts/login/social/google',
395+
signupUrl: '/accounts/register/social/google',
396+
);
397+
final serverSettings = eg.serverSettings(
398+
emailAuthEnabled: true,
399+
externalAuthenticationMethods: [method]);
400+
await prepare(tester, serverSettings);
401+
check(findUsernameInput).findsOne();
402+
check(findPasswordInput).findsOne();
403+
check(findSubmitButton).findsOne();
404+
check(find.textContaining('Google')).findsOne();
405+
final zulipLocalizations = GlobalLocalizations.zulipLocalizations;
406+
check(find.text(zulipLocalizations.loginMethodDivider)).findsOne();
407+
});
408+
});
409+
359410
group('web auth', () {
360411
testWidgets('basic happy case', (tester) async {
361412
final method = ExternalAuthenticationMethod(

0 commit comments

Comments
 (0)