kopia lustrzana https://gitlab.com/mysocialportal/relatica
Restore sign-in changes to fix username/email confusion
rodzic
f5baecc87c
commit
ea13e1129c
|
@ -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,249 +140,259 @@ class _SignInScreenState extends State<SignInScreen> {
|
||||||
child: Form(
|
child: Form(
|
||||||
key: formKey,
|
key: formKey,
|
||||||
child: Center(
|
child: Center(
|
||||||
child: ListView(
|
child: AutofillGroup(
|
||||||
children: [
|
child: ListView(
|
||||||
Center(
|
children: [
|
||||||
child: DropdownButton<String>(
|
Center(
|
||||||
value: authType,
|
child: DropdownButton<String>(
|
||||||
items: authTypes
|
value: authType,
|
||||||
.map(
|
items: authTypes
|
||||||
(a) => DropdownMenuItem(value: a, child: Text(a)))
|
.map((a) =>
|
||||||
.toList(),
|
DropdownMenuItem(value: a, child: Text(a)))
|
||||||
onChanged: existingAccount
|
.toList(),
|
||||||
? null
|
onChanged: existingAccount
|
||||||
: (value) {
|
? null
|
||||||
if (existingAccount) {
|
: (value) {
|
||||||
buildSnackbar(context,
|
if (existingAccount) {
|
||||||
"Can't change the type on an existing account");
|
buildSnackbar(context,
|
||||||
return;
|
"Can't change the type on an existing account");
|
||||||
}
|
return;
|
||||||
authType = value!;
|
}
|
||||||
setState(() {});
|
authType = value!;
|
||||||
}),
|
setState(() {});
|
||||||
),
|
}),
|
||||||
const VerticalPadding(),
|
|
||||||
TextFormField(
|
|
||||||
autocorrect: false,
|
|
||||||
readOnly: existingAccount,
|
|
||||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
|
||||||
controller: serverNameController,
|
|
||||||
validator: (value) =>
|
|
||||||
isFQDN(value ?? '') ? null : 'Not a valid server name',
|
|
||||||
decoration: InputDecoration(
|
|
||||||
hintText: 'Server Name (friendica.example.com)',
|
|
||||||
border: OutlineInputBorder(
|
|
||||||
borderSide: BorderSide(
|
|
||||||
color: Theme
|
|
||||||
.of(context)
|
|
||||||
.colorScheme
|
|
||||||
.surface,
|
|
||||||
),
|
|
||||||
borderRadius: BorderRadius.circular(5.0),
|
|
||||||
),
|
|
||||||
labelText: 'Server Name',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const VerticalPadding(),
|
|
||||||
if (!showUsernameAndPasswordFields) ...[
|
|
||||||
Text(
|
|
||||||
existingAccount
|
|
||||||
? 'Configured to sign in as user ${existingProfile
|
|
||||||
?.handle}'
|
|
||||||
: 'Relatica will open the requested Friendica site in a web browser where you will be asked to authorize this client.',
|
|
||||||
softWrap: true,
|
|
||||||
),
|
),
|
||||||
const VerticalPadding(),
|
const VerticalPadding(),
|
||||||
],
|
|
||||||
if (showUsernameAndPasswordFields) ...[
|
|
||||||
TextFormField(
|
TextFormField(
|
||||||
|
autocorrect: false,
|
||||||
readOnly: existingAccount,
|
readOnly: existingAccount,
|
||||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||||
controller: usernameController,
|
controller: serverNameController,
|
||||||
keyboardType: TextInputType.emailAddress,
|
validator: (value) =>
|
||||||
validator: (value) {
|
isFQDN(value ?? '') ? null : 'Not a valid server name',
|
||||||
if (value == null) {
|
decoration: InputDecoration(
|
||||||
return null;
|
hintText: 'Server Name (friendica.example.com)',
|
||||||
}
|
border: OutlineInputBorder(
|
||||||
|
borderSide: BorderSide(
|
||||||
|
color: Theme.of(context).colorScheme.surface,
|
||||||
|
),
|
||||||
|
borderRadius: BorderRadius.circular(5.0),
|
||||||
|
),
|
||||||
|
labelText: 'Server Name',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const VerticalPadding(),
|
||||||
|
if (!showUsernameAndPasswordFields) ...[
|
||||||
|
Text(
|
||||||
|
existingAccount
|
||||||
|
? 'Configured to sign in as user ${existingProfile?.handle}'
|
||||||
|
: 'Relatica will open the requested Friendica site in a web browser where you will be asked to authorize this client.',
|
||||||
|
softWrap: true,
|
||||||
|
),
|
||||||
|
const VerticalPadding(),
|
||||||
|
],
|
||||||
|
if (showUsernameAndPasswordFields) ...[
|
||||||
|
TextFormField(
|
||||||
|
readOnly: existingAccount,
|
||||||
|
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||||
|
autofillHints: const [AutofillHints.username],
|
||||||
|
controller: usernameController,
|
||||||
|
keyboardType: TextInputType.emailAddress,
|
||||||
|
validator: (value) {
|
||||||
|
if (value == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (value.contains('@')) {
|
if (value.contains('@')) {
|
||||||
return isEmail(value)
|
final properFormat = isEmail(value);
|
||||||
|
if (!properFormat) {
|
||||||
|
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('-', ''))
|
||||||
? null
|
? null
|
||||||
: 'Not a valid Friendica Account Address';
|
: 'Username should be alpha-numeric';
|
||||||
}
|
},
|
||||||
|
decoration: InputDecoration(
|
||||||
return isAlphanumeric(value.replaceAll('-', ''))
|
prefixIcon: const Icon(Icons.alternate_email),
|
||||||
? null
|
hintText:
|
||||||
: 'Username should be alpha-numeric';
|
'Your username on the server (not email address)',
|
||||||
},
|
border: OutlineInputBorder(
|
||||||
decoration: InputDecoration(
|
borderSide: BorderSide(
|
||||||
prefixIcon: const Icon(Icons.alternate_email),
|
color: Theme.of(context).colorScheme.surface,
|
||||||
hintText: 'Username (user@example.com)',
|
),
|
||||||
border: OutlineInputBorder(
|
borderRadius: BorderRadius.circular(5.0),
|
||||||
borderSide: BorderSide(
|
|
||||||
color: Theme
|
|
||||||
.of(context)
|
|
||||||
.colorScheme
|
|
||||||
.surface,
|
|
||||||
),
|
),
|
||||||
borderRadius: BorderRadius.circular(5.0),
|
labelText: 'Username',
|
||||||
),
|
),
|
||||||
labelText: 'Username',
|
|
||||||
),
|
),
|
||||||
),
|
const VerticalPadding(),
|
||||||
const VerticalPadding(),
|
TextFormField(
|
||||||
TextFormField(
|
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';
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
prefixIcon: const Icon(Icons.password),
|
prefixIcon: const Icon(Icons.password),
|
||||||
suffixIcon: IconButton(
|
suffixIcon: IconButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
hidePassword = !hidePassword;
|
hidePassword = !hidePassword;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
icon: hidePassword
|
icon: hidePassword
|
||||||
? const Icon(Icons.remove_red_eye_outlined)
|
? const Icon(Icons.remove_red_eye_outlined)
|
||||||
: const Icon(Icons.remove_red_eye),
|
: const Icon(Icons.remove_red_eye),
|
||||||
),
|
|
||||||
hintText: 'Password',
|
|
||||||
border: OutlineInputBorder(
|
|
||||||
borderSide: BorderSide(
|
|
||||||
color: Theme
|
|
||||||
.of(context)
|
|
||||||
.colorScheme
|
|
||||||
.surface,
|
|
||||||
),
|
),
|
||||||
borderRadius: BorderRadius.circular(5.0),
|
hintText: 'Password',
|
||||||
|
border: OutlineInputBorder(
|
||||||
|
borderSide: BorderSide(
|
||||||
|
color: Theme.of(context).colorScheme.surface,
|
||||||
|
),
|
||||||
|
borderRadius: BorderRadius.circular(5.0),
|
||||||
|
),
|
||||||
|
labelText: 'Password',
|
||||||
),
|
),
|
||||||
labelText: 'Password',
|
|
||||||
),
|
),
|
||||||
),
|
const VerticalPadding(),
|
||||||
|
],
|
||||||
|
signInButtonEnabled
|
||||||
|
? ElevatedButton(
|
||||||
|
onPressed: () async => await _signIn(context),
|
||||||
|
child: const Text('Signin'),
|
||||||
|
)
|
||||||
|
: SizedBox(),
|
||||||
const VerticalPadding(),
|
const VerticalPadding(),
|
||||||
|
Text(
|
||||||
|
'Logged out:',
|
||||||
|
style: Theme.of(context).textTheme.headlineSmall,
|
||||||
|
),
|
||||||
|
loggedOutProfiles.isEmpty
|
||||||
|
? const Text(
|
||||||
|
'No logged out profiles',
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
)
|
||||||
|
: Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
borderRadius: BorderRadius.circular(10),
|
||||||
|
border: Border.all(
|
||||||
|
width: 0.5,
|
||||||
|
)),
|
||||||
|
child: Column(
|
||||||
|
children: loggedOutProfiles.map((p) {
|
||||||
|
return ListTile(
|
||||||
|
onTap: () {
|
||||||
|
setCredentials(context, p);
|
||||||
|
setState(() {});
|
||||||
|
},
|
||||||
|
title: Text(p.handle),
|
||||||
|
subtitle: Text(p.credentials is BasicCredentials
|
||||||
|
? usernamePasswordType
|
||||||
|
: oauthType),
|
||||||
|
trailing: ElevatedButton(
|
||||||
|
onPressed: () async {
|
||||||
|
final confirm = await showYesNoDialog(
|
||||||
|
context,
|
||||||
|
'Remove login information from app?');
|
||||||
|
if (confirm ?? false) {
|
||||||
|
await service.removeProfile(p);
|
||||||
|
}
|
||||||
|
setState(() {});
|
||||||
|
},
|
||||||
|
child: const Text('Remove'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const VerticalPadding(),
|
||||||
|
Text(
|
||||||
|
'Logged in:',
|
||||||
|
style: Theme.of(context).textTheme.headlineSmall,
|
||||||
|
),
|
||||||
|
loggedInProfiles.isEmpty
|
||||||
|
? const Text(
|
||||||
|
'No logged in profiles',
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
)
|
||||||
|
: Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
borderRadius: BorderRadius.circular(10),
|
||||||
|
border: Border.all(
|
||||||
|
width: 0.5,
|
||||||
|
)),
|
||||||
|
child: Column(
|
||||||
|
children: loggedInProfiles.map((p) {
|
||||||
|
final active = service.loggedIn
|
||||||
|
? p.id == service.currentProfile.id
|
||||||
|
: false;
|
||||||
|
return ListTile(
|
||||||
|
onTap: () async {
|
||||||
|
setCredentials(context, p);
|
||||||
|
setState(() {});
|
||||||
|
},
|
||||||
|
title: Text(
|
||||||
|
p.handle,
|
||||||
|
style: active
|
||||||
|
? const TextStyle(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
fontStyle: FontStyle.italic)
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
subtitle: Text(
|
||||||
|
p.credentials is BasicCredentials
|
||||||
|
? usernamePasswordType
|
||||||
|
: oauthType,
|
||||||
|
style: active
|
||||||
|
? const TextStyle(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
fontStyle: FontStyle.italic)
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
trailing: ElevatedButton(
|
||||||
|
onPressed: () async {
|
||||||
|
final confirm = await showYesNoDialog(
|
||||||
|
context, 'Log out account?');
|
||||||
|
if (confirm == true) {
|
||||||
|
await getIt<AccountsService>().signOut(p);
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: const Text('Sign out'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}).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')),
|
||||||
],
|
],
|
||||||
signInButtonEnabled
|
),
|
||||||
? ElevatedButton(
|
|
||||||
onPressed: () async => await _signIn(context),
|
|
||||||
child: const Text('Signin'),
|
|
||||||
)
|
|
||||||
: const SizedBox(),
|
|
||||||
const VerticalPadding(),
|
|
||||||
Text(
|
|
||||||
'Logged out:',
|
|
||||||
style: Theme
|
|
||||||
.of(context)
|
|
||||||
.textTheme
|
|
||||||
.headlineSmall,
|
|
||||||
),
|
|
||||||
loggedOutProfiles.isEmpty
|
|
||||||
? const Text(
|
|
||||||
'No logged out profiles',
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
)
|
|
||||||
: Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
borderRadius: BorderRadius.circular(10),
|
|
||||||
border: Border.all(
|
|
||||||
width: 0.5,
|
|
||||||
)),
|
|
||||||
child: Column(
|
|
||||||
children: loggedOutProfiles.map((p) {
|
|
||||||
return ListTile(
|
|
||||||
onTap: () {
|
|
||||||
setCredentials(context, p);
|
|
||||||
setState(() {});
|
|
||||||
},
|
|
||||||
title: Text(p.handle),
|
|
||||||
subtitle: Text(p.credentials is BasicCredentials
|
|
||||||
? usernamePasswordType
|
|
||||||
: oauthType),
|
|
||||||
trailing: ElevatedButton(
|
|
||||||
onPressed: () async {
|
|
||||||
final confirm = await showYesNoDialog(context,
|
|
||||||
'Remove login information from app?');
|
|
||||||
if (confirm ?? false) {
|
|
||||||
await service.removeProfile(p);
|
|
||||||
}
|
|
||||||
setState(() {});
|
|
||||||
},
|
|
||||||
child: const Text('Remove'),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}).toList(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const VerticalPadding(),
|
|
||||||
Text(
|
|
||||||
'Logged in:',
|
|
||||||
style: Theme
|
|
||||||
.of(context)
|
|
||||||
.textTheme
|
|
||||||
.headlineSmall,
|
|
||||||
),
|
|
||||||
loggedInProfiles.isEmpty
|
|
||||||
? const Text(
|
|
||||||
'No logged in profiles',
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
)
|
|
||||||
: Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
borderRadius: BorderRadius.circular(10),
|
|
||||||
border: Border.all(
|
|
||||||
width: 0.5,
|
|
||||||
)),
|
|
||||||
child: Column(
|
|
||||||
children: loggedInProfiles.map((p) {
|
|
||||||
final active = service.loggedIn
|
|
||||||
? p.id == service.currentProfile.id
|
|
||||||
: false;
|
|
||||||
return ListTile(
|
|
||||||
onTap: () async {
|
|
||||||
setCredentials(context, p);
|
|
||||||
setState(() {});
|
|
||||||
},
|
|
||||||
title: Text(
|
|
||||||
p.handle,
|
|
||||||
style: active
|
|
||||||
? const TextStyle(
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
fontStyle: FontStyle.italic)
|
|
||||||
: null,
|
|
||||||
),
|
|
||||||
subtitle: Text(
|
|
||||||
p.credentials is BasicCredentials
|
|
||||||
? usernamePasswordType
|
|
||||||
: oauthType,
|
|
||||||
style: active
|
|
||||||
? const TextStyle(
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
fontStyle: FontStyle.italic)
|
|
||||||
: null,
|
|
||||||
),
|
|
||||||
trailing: ElevatedButton(
|
|
||||||
onPressed: () async {
|
|
||||||
final confirm = await showYesNoDialog(
|
|
||||||
context, 'Log out account?');
|
|
||||||
if (confirm == true) {
|
|
||||||
await getIt<AccountsService>().signOut(p);
|
|
||||||
setState(() {});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
child: const Text('Sign out'),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}).toList(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -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;
|
||||||
|
|
Ładowanie…
Reference in New Issue