kopia lustrzana https://gitlab.com/mysocialportal/relatica
				
				
				
			Change sign in screen to split apart username and servername, adds support for by email address
							rodzic
							
								
									e12f88f771
								
							
						
					
					
						commit
						6b3824d19e
					
				| 
						 | 
				
			
			@ -1,9 +1,5 @@
 | 
			
		|||
import 'dart:convert';
 | 
			
		||||
 | 
			
		||||
import 'package:result_monad/result_monad.dart';
 | 
			
		||||
 | 
			
		||||
import 'exec_error.dart';
 | 
			
		||||
 | 
			
		||||
class Credentials {
 | 
			
		||||
  final String username;
 | 
			
		||||
  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
 | 
			
		||||
  String toString() {
 | 
			
		||||
    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:string_validator/string_validator.dart';
 | 
			
		||||
 | 
			
		||||
import '../controls/padding.dart';
 | 
			
		||||
import '../globals.dart';
 | 
			
		||||
| 
						 | 
				
			
			@ -16,6 +16,7 @@ class SignInScreen extends StatefulWidget {
 | 
			
		|||
class _SignInScreenState extends State<SignInScreen> {
 | 
			
		||||
  final formKey = GlobalKey<FormState>();
 | 
			
		||||
  final usernameController = TextEditingController();
 | 
			
		||||
  final serverNameController = TextEditingController();
 | 
			
		||||
  final passwordController = TextEditingController();
 | 
			
		||||
  var hidePassword = true;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -27,8 +28,9 @@ class _SignInScreenState extends State<SignInScreen> {
 | 
			
		|||
        return;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      usernameController.text = credentials.handle;
 | 
			
		||||
      usernameController.text = credentials.username;
 | 
			
		||||
      passwordController.text = credentials.password;
 | 
			
		||||
      serverNameController.text = credentials.serverName;
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -49,17 +51,51 @@ class _SignInScreenState extends State<SignInScreen> {
 | 
			
		|||
              children: [
 | 
			
		||||
                TextFormField(
 | 
			
		||||
                  autovalidateMode: AutovalidateMode.onUserInteraction,
 | 
			
		||||
                  controller: usernameController,
 | 
			
		||||
                  keyboardType: TextInputType.emailAddress,
 | 
			
		||||
                  validator: (value) => EmailValidator.validate(value ?? '')
 | 
			
		||||
                      ? null
 | 
			
		||||
                      : 'Not a valid Friendica Account Address',
 | 
			
		||||
                  controller: serverNameController,
 | 
			
		||||
                  validator: (value) =>
 | 
			
		||||
                  isFQDN(value ?? '') ? null : 'Not a valid server name',
 | 
			
		||||
                  decoration: InputDecoration(
 | 
			
		||||
                    prefixIcon: const Icon(Icons.alternate_email),
 | 
			
		||||
                    hintText: 'Username (user@example.com)',
 | 
			
		||||
                    border: OutlineInputBorder(
 | 
			
		||||
                      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),
 | 
			
		||||
                    ),
 | 
			
		||||
| 
						 | 
				
			
			@ -85,7 +121,9 @@ class _SignInScreenState extends State<SignInScreen> {
 | 
			
		|||
                    hintText: 'Password',
 | 
			
		||||
                    border: OutlineInputBorder(
 | 
			
		||||
                      borderSide: BorderSide(
 | 
			
		||||
                        color: Theme.of(context).backgroundColor,
 | 
			
		||||
                        color: Theme
 | 
			
		||||
                            .of(context)
 | 
			
		||||
                            .backgroundColor,
 | 
			
		||||
                      ),
 | 
			
		||||
                      borderRadius: BorderRadius.circular(5.0),
 | 
			
		||||
                    ),
 | 
			
		||||
| 
						 | 
				
			
			@ -107,13 +145,14 @@ class _SignInScreenState extends State<SignInScreen> {
 | 
			
		|||
 | 
			
		||||
  void _signIn(BuildContext context) async {
 | 
			
		||||
    if (formKey.currentState?.validate() ?? false) {
 | 
			
		||||
      final result = await Credentials.buildFromHandle(
 | 
			
		||||
        usernameController.text,
 | 
			
		||||
        passwordController.text,
 | 
			
		||||
      ).andThenAsync((creds) async {
 | 
			
		||||
        return await getIt<AuthService>().signIn(creds);
 | 
			
		||||
      });
 | 
			
		||||
      final creds = Credentials(
 | 
			
		||||
          username: usernameController.text,
 | 
			
		||||
          password: passwordController.text,
 | 
			
		||||
          serverName: serverNameController.text,
 | 
			
		||||
          userId: '',
 | 
			
		||||
          avatar: '');
 | 
			
		||||
 | 
			
		||||
      final result = await getIt<AuthService>().signIn(creds);
 | 
			
		||||
      if (result.isFailure) {
 | 
			
		||||
        buildSnackbar(context, 'Error signing in: ${result.error}');
 | 
			
		||||
      }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										10
									
								
								pubspec.lock
								
								
								
								
							
							
						
						
									
										10
									
								
								pubspec.lock
								
								
								
								
							| 
						 | 
				
			
			@ -265,14 +265,6 @@ packages:
 | 
			
		|||
      url: "https://pub.dev"
 | 
			
		||||
    source: hosted
 | 
			
		||||
    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:
 | 
			
		||||
    dependency: transitive
 | 
			
		||||
    description:
 | 
			
		||||
| 
						 | 
				
			
			@ -1054,7 +1046,7 @@ packages:
 | 
			
		|||
    source: hosted
 | 
			
		||||
    version: "1.2.0"
 | 
			
		||||
  string_validator:
 | 
			
		||||
    dependency: transitive
 | 
			
		||||
    dependency: "direct main"
 | 
			
		||||
    description:
 | 
			
		||||
      name: string_validator
 | 
			
		||||
      sha256: "50dd8ecf91db6a732f4a851eeae81ee12406eedc62d0da72f2d91a04a2d10dd8"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,7 +13,6 @@ dependencies:
 | 
			
		|||
  cached_network_image: ^3.2.2
 | 
			
		||||
  cupertino_icons: ^1.0.2
 | 
			
		||||
  desktop_window: ^0.4.0
 | 
			
		||||
  email_validator: ^2.1.17
 | 
			
		||||
  file_picker: ^5.2.4
 | 
			
		||||
  flutter_dotenv: ^5.0.2
 | 
			
		||||
  flutter_file_dialog: ^2.3.2
 | 
			
		||||
| 
						 | 
				
			
			@ -44,6 +43,7 @@ dependencies:
 | 
			
		|||
  path_provider: ^2.0.11
 | 
			
		||||
  carousel_slider: ^4.2.1
 | 
			
		||||
  device_info_plus: ^8.0.0
 | 
			
		||||
  string_validator: ^0.3.0
 | 
			
		||||
 | 
			
		||||
dev_dependencies:
 | 
			
		||||
  flutter_test:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Ładowanie…
	
		Reference in New Issue