mirror of
https://gitlab.com/mysocialportal/relatica
synced 2024-10-18 18:13:31 +00:00
Change sign in screen to split apart username and servername, adds support for by email address
This commit is contained in:
parent
e12f88f771
commit
6b3824d19e
4 changed files with 56 additions and 48 deletions
|
@ -1,9 +1,5 @@
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:result_monad/result_monad.dart';
|
|
||||||
|
|
||||||
import 'exec_error.dart';
|
|
||||||
|
|
||||||
class Credentials {
|
class Credentials {
|
||||||
final String username;
|
final String username;
|
||||||
final String password;
|
final String password;
|
||||||
|
@ -59,25 +55,6 @@ class Credentials {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Result<Credentials, ExecError> buildFromHandle(
|
|
||||||
String handle, String password) {
|
|
||||||
final elements = handle.split('@');
|
|
||||||
if (elements.length != 2) {
|
|
||||||
return Result.error(ExecError(
|
|
||||||
type: ErrorType.authentication,
|
|
||||||
message: 'Handle has invalid format: $handle'));
|
|
||||||
}
|
|
||||||
final result = Credentials(
|
|
||||||
username: elements[0],
|
|
||||||
password: password,
|
|
||||||
serverName: elements[1],
|
|
||||||
userId: '',
|
|
||||||
avatar: '',
|
|
||||||
);
|
|
||||||
|
|
||||||
return Result.ok(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'Credentials{username: $username, password?: ${password.isNotEmpty}, serverName: $serverName, userId: $userId}';
|
return 'Credentials{username: $username, password?: ${password.isNotEmpty}, serverName: $serverName, userId: $userId}';
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import 'package:email_validator/email_validator.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:string_validator/string_validator.dart';
|
||||||
|
|
||||||
import '../controls/padding.dart';
|
import '../controls/padding.dart';
|
||||||
import '../globals.dart';
|
import '../globals.dart';
|
||||||
|
@ -16,6 +16,7 @@ class SignInScreen extends StatefulWidget {
|
||||||
class _SignInScreenState extends State<SignInScreen> {
|
class _SignInScreenState extends State<SignInScreen> {
|
||||||
final formKey = GlobalKey<FormState>();
|
final formKey = GlobalKey<FormState>();
|
||||||
final usernameController = TextEditingController();
|
final usernameController = TextEditingController();
|
||||||
|
final serverNameController = TextEditingController();
|
||||||
final passwordController = TextEditingController();
|
final passwordController = TextEditingController();
|
||||||
var hidePassword = true;
|
var hidePassword = true;
|
||||||
|
|
||||||
|
@ -27,8 +28,9 @@ class _SignInScreenState extends State<SignInScreen> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
usernameController.text = credentials.handle;
|
usernameController.text = credentials.username;
|
||||||
passwordController.text = credentials.password;
|
passwordController.text = credentials.password;
|
||||||
|
serverNameController.text = credentials.serverName;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,17 +51,51 @@ class _SignInScreenState extends State<SignInScreen> {
|
||||||
children: [
|
children: [
|
||||||
TextFormField(
|
TextFormField(
|
||||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||||
controller: usernameController,
|
controller: serverNameController,
|
||||||
keyboardType: TextInputType.emailAddress,
|
validator: (value) =>
|
||||||
validator: (value) => EmailValidator.validate(value ?? '')
|
isFQDN(value ?? '') ? null : 'Not a valid server name',
|
||||||
? null
|
|
||||||
: 'Not a valid Friendica Account Address',
|
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
prefixIcon: const Icon(Icons.alternate_email),
|
prefixIcon: const Icon(Icons.alternate_email),
|
||||||
hintText: 'Username (user@example.com)',
|
hintText: 'Username (user@example.com)',
|
||||||
border: OutlineInputBorder(
|
border: OutlineInputBorder(
|
||||||
borderSide: BorderSide(
|
borderSide: BorderSide(
|
||||||
color: Theme.of(context).backgroundColor,
|
color: Theme
|
||||||
|
.of(context)
|
||||||
|
.backgroundColor,
|
||||||
|
),
|
||||||
|
borderRadius: BorderRadius.circular(5.0),
|
||||||
|
),
|
||||||
|
labelText: 'Username',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const VerticalPadding(),
|
||||||
|
TextFormField(
|
||||||
|
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||||
|
controller: usernameController,
|
||||||
|
keyboardType: TextInputType.emailAddress,
|
||||||
|
validator: (value) {
|
||||||
|
if (value == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value.contains('@')) {
|
||||||
|
return isEmail(value ?? '')
|
||||||
|
? null
|
||||||
|
: 'Not a valid Friendica Account Address';
|
||||||
|
}
|
||||||
|
|
||||||
|
return isAlphanumeric(value.replaceAll('-', ''))
|
||||||
|
? null
|
||||||
|
: 'Username should be alpha-numeric';
|
||||||
|
},
|
||||||
|
decoration: InputDecoration(
|
||||||
|
prefixIcon: const Icon(Icons.alternate_email),
|
||||||
|
hintText: 'Username (user@example.com)',
|
||||||
|
border: OutlineInputBorder(
|
||||||
|
borderSide: BorderSide(
|
||||||
|
color: Theme
|
||||||
|
.of(context)
|
||||||
|
.backgroundColor,
|
||||||
),
|
),
|
||||||
borderRadius: BorderRadius.circular(5.0),
|
borderRadius: BorderRadius.circular(5.0),
|
||||||
),
|
),
|
||||||
|
@ -85,7 +121,9 @@ class _SignInScreenState extends State<SignInScreen> {
|
||||||
hintText: 'Password',
|
hintText: 'Password',
|
||||||
border: OutlineInputBorder(
|
border: OutlineInputBorder(
|
||||||
borderSide: BorderSide(
|
borderSide: BorderSide(
|
||||||
color: Theme.of(context).backgroundColor,
|
color: Theme
|
||||||
|
.of(context)
|
||||||
|
.backgroundColor,
|
||||||
),
|
),
|
||||||
borderRadius: BorderRadius.circular(5.0),
|
borderRadius: BorderRadius.circular(5.0),
|
||||||
),
|
),
|
||||||
|
@ -107,13 +145,14 @@ class _SignInScreenState extends State<SignInScreen> {
|
||||||
|
|
||||||
void _signIn(BuildContext context) async {
|
void _signIn(BuildContext context) async {
|
||||||
if (formKey.currentState?.validate() ?? false) {
|
if (formKey.currentState?.validate() ?? false) {
|
||||||
final result = await Credentials.buildFromHandle(
|
final creds = Credentials(
|
||||||
usernameController.text,
|
username: usernameController.text,
|
||||||
passwordController.text,
|
password: passwordController.text,
|
||||||
).andThenAsync((creds) async {
|
serverName: serverNameController.text,
|
||||||
return await getIt<AuthService>().signIn(creds);
|
userId: '',
|
||||||
});
|
avatar: '');
|
||||||
|
|
||||||
|
final result = await getIt<AuthService>().signIn(creds);
|
||||||
if (result.isFailure) {
|
if (result.isFailure) {
|
||||||
buildSnackbar(context, 'Error signing in: ${result.error}');
|
buildSnackbar(context, 'Error signing in: ${result.error}');
|
||||||
}
|
}
|
||||||
|
|
10
pubspec.lock
10
pubspec.lock
|
@ -265,14 +265,6 @@ packages:
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "7.0.0"
|
version: "7.0.0"
|
||||||
email_validator:
|
|
||||||
dependency: "direct main"
|
|
||||||
description:
|
|
||||||
name: email_validator
|
|
||||||
sha256: e9a90f27ab2b915a27d7f9c2a7ddda5dd752d6942616ee83529b686fc086221b
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "2.1.17"
|
|
||||||
fake_async:
|
fake_async:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -1054,7 +1046,7 @@ packages:
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.2.0"
|
version: "1.2.0"
|
||||||
string_validator:
|
string_validator:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: string_validator
|
name: string_validator
|
||||||
sha256: "50dd8ecf91db6a732f4a851eeae81ee12406eedc62d0da72f2d91a04a2d10dd8"
|
sha256: "50dd8ecf91db6a732f4a851eeae81ee12406eedc62d0da72f2d91a04a2d10dd8"
|
||||||
|
|
|
@ -13,7 +13,6 @@ dependencies:
|
||||||
cached_network_image: ^3.2.2
|
cached_network_image: ^3.2.2
|
||||||
cupertino_icons: ^1.0.2
|
cupertino_icons: ^1.0.2
|
||||||
desktop_window: ^0.4.0
|
desktop_window: ^0.4.0
|
||||||
email_validator: ^2.1.17
|
|
||||||
file_picker: ^5.2.4
|
file_picker: ^5.2.4
|
||||||
flutter_dotenv: ^5.0.2
|
flutter_dotenv: ^5.0.2
|
||||||
flutter_file_dialog: ^2.3.2
|
flutter_file_dialog: ^2.3.2
|
||||||
|
@ -44,6 +43,7 @@ dependencies:
|
||||||
path_provider: ^2.0.11
|
path_provider: ^2.0.11
|
||||||
carousel_slider: ^4.2.1
|
carousel_slider: ^4.2.1
|
||||||
device_info_plus: ^8.0.0
|
device_info_plus: ^8.0.0
|
||||||
|
string_validator: ^0.3.0
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|
Loading…
Reference in a new issue