Skip to content

Commit b2a62f0

Browse files
committed
login: Explicitly handle both values of requireEmailFormatUsernames, mostly
(Leaving a TODO to actually do form validation that the username is an email address, when appropriate.) Fixes-partly: zulip#35
1 parent 726a9de commit b2a62f0

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

lib/widgets/login.dart

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,24 +327,32 @@ class _PasswordLoginPageState extends State<PasswordLoginPage> {
327327
@override
328328
Widget build(BuildContext context) {
329329
assert(!PerAccountStoreWidget.debugExistsOf(context));
330+
final requireEmailFormatUsernames = widget.serverSettings.requireEmailFormatUsernames;
330331

331332
final usernameField = TextFormField(
332333
key: _usernameKey,
333-
autofillHints: const [AutofillHints.email],
334+
autofillHints: [
335+
if (!requireEmailFormatUsernames) AutofillHints.username,
336+
AutofillHints.email,
337+
],
334338
keyboardType: TextInputType.emailAddress,
335339
// TODO(upstream?): Apparently pressing "next" doesn't count
336340
// as user interaction, and validation isn't done.
337341
autovalidateMode: AutovalidateMode.onUserInteraction,
338342
validator: (value) {
339343
if (value == null || value.trim().isEmpty) {
340-
return 'Please enter your email.';
344+
return requireEmailFormatUsernames
345+
? 'Please enter your email.'
346+
: 'Please enter your username.';
347+
}
348+
if (requireEmailFormatUsernames) {
349+
// TODO(#35): validate is in the shape of an email
341350
}
342-
// TODO(#35): validate is in the shape of an email
343351
return null;
344352
},
345353
textInputAction: TextInputAction.next,
346-
decoration: const InputDecoration(
347-
labelText: 'Email address',
354+
decoration: InputDecoration(
355+
labelText: requireEmailFormatUsernames ? 'Email address' : 'Username',
348356
helperText: kLayoutPinningHelperText,
349357
));
350358

0 commit comments

Comments
 (0)