Restore sign-in changes to fix username/email confusion

merge-requests/67/merge
Hank Grabowski 2024-07-26 09:59:53 -04:00
rodzic f5baecc87c
commit ea13e1129c
1 zmienionych plików z 240 dodań i 230 usunięć

Wyświetl plik

@ -61,8 +61,7 @@ class _SignInScreenState extends State<SignInScreen> {
void _updateSignInButtonStatus() { void _updateSignInButtonStatus() {
setState(() { setState(() {
signInButtonEnabled = switch (oauthType) { signInButtonEnabled = switch (oauthType) {
usernamePasswordType => usernamePasswordType => serverNameController.text.isNotEmpty &&
serverNameController.text.isNotEmpty &&
usernameController.text.isNotEmpty && usernameController.text.isNotEmpty &&
passwordController.text.isNotEmpty, passwordController.text.isNotEmpty,
oauthType => serverNameController.text.isNotEmpty, oauthType => serverNameController.text.isNotEmpty,
@ -141,14 +140,15 @@ class _SignInScreenState extends State<SignInScreen> {
child: Form( child: Form(
key: formKey, key: formKey,
child: Center( child: Center(
child: AutofillGroup(
child: ListView( child: ListView(
children: [ children: [
Center( Center(
child: DropdownButton<String>( child: DropdownButton<String>(
value: authType, value: authType,
items: authTypes items: authTypes
.map( .map((a) =>
(a) => DropdownMenuItem(value: a, child: Text(a))) DropdownMenuItem(value: a, child: Text(a)))
.toList(), .toList(),
onChanged: existingAccount onChanged: existingAccount
? null ? null
@ -174,10 +174,7 @@ class _SignInScreenState extends State<SignInScreen> {
hintText: 'Server Name (friendica.example.com)', hintText: 'Server Name (friendica.example.com)',
border: OutlineInputBorder( border: OutlineInputBorder(
borderSide: BorderSide( borderSide: BorderSide(
color: Theme color: Theme.of(context).colorScheme.surface,
.of(context)
.colorScheme
.surface,
), ),
borderRadius: BorderRadius.circular(5.0), borderRadius: BorderRadius.circular(5.0),
), ),
@ -188,8 +185,7 @@ class _SignInScreenState extends State<SignInScreen> {
if (!showUsernameAndPasswordFields) ...[ if (!showUsernameAndPasswordFields) ...[
Text( Text(
existingAccount existingAccount
? 'Configured to sign in as user ${existingProfile ? 'Configured to sign in as user ${existingProfile?.handle}'
?.handle}'
: 'Relatica will open the requested Friendica site in a web browser where you will be asked to authorize this client.', : 'Relatica will open the requested Friendica site in a web browser where you will be asked to authorize this client.',
softWrap: true, softWrap: true,
), ),
@ -199,6 +195,7 @@ class _SignInScreenState extends State<SignInScreen> {
TextFormField( TextFormField(
readOnly: existingAccount, readOnly: existingAccount,
autovalidateMode: AutovalidateMode.onUserInteraction, autovalidateMode: AutovalidateMode.onUserInteraction,
autofillHints: const [AutofillHints.username],
controller: usernameController, controller: usernameController,
keyboardType: TextInputType.emailAddress, keyboardType: TextInputType.emailAddress,
validator: (value) { validator: (value) {
@ -207,9 +204,15 @@ class _SignInScreenState extends State<SignInScreen> {
} }
if (value.contains('@')) { if (value.contains('@')) {
return isEmail(value) final properFormat = isEmail(value);
? null if (!properFormat) {
: 'Not a valid Friendica Account Address'; return 'Not a valid Friendica Account Address';
}
final elements = value.split('@');
if (elements.last != serverNameController.text) {
return 'Server name must match above field.\nUsername should be the *Friendica* username.\nThis is not the email address of the account.';
}
return null;
} }
return isAlphanumeric(value.replaceAll('-', '')) return isAlphanumeric(value.replaceAll('-', ''))
@ -218,13 +221,11 @@ class _SignInScreenState extends State<SignInScreen> {
}, },
decoration: InputDecoration( decoration: InputDecoration(
prefixIcon: const Icon(Icons.alternate_email), prefixIcon: const Icon(Icons.alternate_email),
hintText: 'Username (user@example.com)', hintText:
'Your username on the server (not email address)',
border: OutlineInputBorder( border: OutlineInputBorder(
borderSide: BorderSide( borderSide: BorderSide(
color: Theme color: Theme.of(context).colorScheme.surface,
.of(context)
.colorScheme
.surface,
), ),
borderRadius: BorderRadius.circular(5.0), borderRadius: BorderRadius.circular(5.0),
), ),
@ -236,6 +237,7 @@ class _SignInScreenState extends State<SignInScreen> {
readOnly: existingAccount, readOnly: existingAccount,
obscureText: hidePassword, obscureText: hidePassword,
controller: passwordController, controller: passwordController,
autofillHints: const [AutofillHints.password],
validator: (value) { validator: (value) {
if (value == null || value.isEmpty) { if (value == null || value.isEmpty) {
return 'Password field cannot be empty'; return 'Password field cannot be empty';
@ -258,10 +260,7 @@ class _SignInScreenState extends State<SignInScreen> {
hintText: 'Password', hintText: 'Password',
border: OutlineInputBorder( border: OutlineInputBorder(
borderSide: BorderSide( borderSide: BorderSide(
color: Theme color: Theme.of(context).colorScheme.surface,
.of(context)
.colorScheme
.surface,
), ),
borderRadius: BorderRadius.circular(5.0), borderRadius: BorderRadius.circular(5.0),
), ),
@ -275,14 +274,11 @@ class _SignInScreenState extends State<SignInScreen> {
onPressed: () async => await _signIn(context), onPressed: () async => await _signIn(context),
child: const Text('Signin'), child: const Text('Signin'),
) )
: const SizedBox(), : SizedBox(),
const VerticalPadding(), const VerticalPadding(),
Text( Text(
'Logged out:', 'Logged out:',
style: Theme style: Theme.of(context).textTheme.headlineSmall,
.of(context)
.textTheme
.headlineSmall,
), ),
loggedOutProfiles.isEmpty loggedOutProfiles.isEmpty
? const Text( ? const Text(
@ -308,7 +304,8 @@ class _SignInScreenState extends State<SignInScreen> {
: oauthType), : oauthType),
trailing: ElevatedButton( trailing: ElevatedButton(
onPressed: () async { onPressed: () async {
final confirm = await showYesNoDialog(context, final confirm = await showYesNoDialog(
context,
'Remove login information from app?'); 'Remove login information from app?');
if (confirm ?? false) { if (confirm ?? false) {
await service.removeProfile(p); await service.removeProfile(p);
@ -324,10 +321,7 @@ class _SignInScreenState extends State<SignInScreen> {
const VerticalPadding(), const VerticalPadding(),
Text( Text(
'Logged in:', 'Logged in:',
style: Theme style: Theme.of(context).textTheme.headlineSmall,
.of(context)
.textTheme
.headlineSmall,
), ),
loggedInProfiles.isEmpty loggedInProfiles.isEmpty
? const Text( ? const Text(
@ -383,11 +377,26 @@ class _SignInScreenState extends State<SignInScreen> {
}).toList(), }).toList(),
), ),
), ),
const VerticalPadding(),
ElevatedButton(
onPressed: () async {
final confirm = await showYesNoDialog(context,
'Are you sure you want to logout and delete *all* accounts? This cannot be undone.') ??
false;
print(confirm);
if (!confirm) {
return;
}
await getIt<AccountsService>().clearAllProfiles();
},
child: Text('Clear All')),
], ],
), ),
), ),
), ),
), ),
),
); );
} }
@ -405,8 +414,9 @@ class _SignInScreenState extends State<SignInScreen> {
} else { } else {
switch (authType) { switch (authType) {
case usernamePasswordType: case usernamePasswordType:
final username = usernameController.text.split('@').first;
creds = BasicCredentials( creds = BasicCredentials(
username: usernameController.text, username: username,
password: passwordController.text, password: passwordController.text,
serverName: serverNameController.text); serverName: serverNameController.text);
break; break;