improve usernames

This commit is contained in:
zoe 2022-06-17 11:50:07 +02:00
parent 98798fa14f
commit 40d57fb245
10 changed files with 106 additions and 0 deletions

View file

@ -1 +1,8 @@
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'dart:io';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:oauth2/oauth2.dart' as oauth2;
// Future<http.Client> authorize({required String userid}) {
// }

View file

@ -19,3 +19,20 @@ Uri urlFromUsername({required String name}) {
name = cleanUpUsername(name: name); name = cleanUpUsername(name: name);
return Uri.parse("https://${name.substring(name.indexOf("@") + 1)}"); return Uri.parse("https://${name.substring(name.indexOf("@") + 1)}");
} }
String userFromUsername({required String name}) {
name = cleanUpUsername(name: name);
return name.substring(0, name.indexOf("@"));
}
// A fully qualified and valid username for example (@)hello@world.com
// The first @ is ignored
class Username {
late final String user;
late final Uri url;
Username(String username) {
assert(isValidUsername(name: username));
user = userFromUsername(name: username);
url = urlFromUsername(name: username);
}
}

View file

@ -6,6 +6,10 @@
#include "generated_plugin_registrant.h" #include "generated_plugin_registrant.h"
#include <flutter_secure_storage_linux/flutter_secure_storage_linux_plugin.h>
void fl_register_plugins(FlPluginRegistry* registry) { void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) flutter_secure_storage_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterSecureStorageLinuxPlugin");
flutter_secure_storage_linux_plugin_register_with_registrar(flutter_secure_storage_linux_registrar);
} }

View file

@ -3,6 +3,7 @@
# #
list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_PLUGIN_LIST
flutter_secure_storage_linux
) )
list(APPEND FLUTTER_FFI_PLUGIN_LIST list(APPEND FLUTTER_FFI_PLUGIN_LIST

View file

@ -5,6 +5,8 @@
import FlutterMacOS import FlutterMacOS
import Foundation import Foundation
import flutter_secure_storage_macos
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FlutterSecureStorageMacosPlugin.register(with: registry.registrar(forPlugin: "FlutterSecureStorageMacosPlugin"))
} }

View file

@ -76,11 +76,58 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.1" version: "2.0.1"
flutter_secure_storage:
dependency: "direct main"
description:
name: flutter_secure_storage
url: "https://pub.dartlang.org"
source: hosted
version: "5.0.2"
flutter_secure_storage_linux:
dependency: transitive
description:
name: flutter_secure_storage_linux
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
flutter_secure_storage_macos:
dependency: transitive
description:
name: flutter_secure_storage_macos
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
flutter_secure_storage_platform_interface:
dependency: transitive
description:
name: flutter_secure_storage_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
flutter_secure_storage_web:
dependency: transitive
description:
name: flutter_secure_storage_web
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
flutter_secure_storage_windows:
dependency: transitive
description:
name: flutter_secure_storage_windows
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.2"
flutter_test: flutter_test:
dependency: "direct dev" dependency: "direct dev"
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.0" version: "0.0.0"
flutter_web_plugins:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
http: http:
dependency: "direct main" dependency: "direct main"
description: description:
@ -95,6 +142,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "4.0.1" version: "4.0.1"
js:
dependency: transitive
description:
name: js
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.4"
lints: lints:
dependency: transitive dependency: transitive
description: description:
@ -137,6 +191,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.8.1" version: "1.8.1"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.2"
settings_ui: settings_ui:
dependency: "direct main" dependency: "direct main"
description: description:
@ -207,3 +268,4 @@ packages:
version: "2.1.2" version: "2.1.2"
sdks: sdks:
dart: ">=2.17.3 <3.0.0" dart: ">=2.17.3 <3.0.0"
flutter: ">=2.0.0"

View file

@ -37,6 +37,7 @@ dependencies:
settings_ui: ^2.0.2 settings_ui: ^2.0.2
http: ^0.13.4 http: ^0.13.4
oauth2: ^2.0.0 oauth2: ^2.0.0
flutter_secure_storage: ^5.0.2
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:

View file

@ -5,6 +5,7 @@ void main() {
validUsernameTest(); validUsernameTest();
usernameToUrlTest(); usernameToUrlTest();
cleanupNameTest(); cleanupNameTest();
userFromUsernameTest();
} }
void validUsernameTest() { void validUsernameTest() {
@ -36,3 +37,10 @@ void cleanupNameTest() {
expect(cleanUpUsername(name: ""), ""); expect(cleanUpUsername(name: ""), "");
}); });
} }
void userFromUsernameTest() {
test("try extracting user from the full valid user id", () {
expect(userFromUsername(name: "@hello@world"), "hello");
expect(userFromUsername(name: "@john@from.garfield"), "john");
});
}

View file

@ -6,6 +6,9 @@
#include "generated_plugin_registrant.h" #include "generated_plugin_registrant.h"
#include <flutter_secure_storage_windows/flutter_secure_storage_windows_plugin.h>
void RegisterPlugins(flutter::PluginRegistry* registry) { void RegisterPlugins(flutter::PluginRegistry* registry) {
FlutterSecureStorageWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FlutterSecureStorageWindowsPlugin"));
} }

View file

@ -3,6 +3,7 @@
# #
list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_PLUGIN_LIST
flutter_secure_storage_windows
) )
list(APPEND FLUTTER_FFI_PLUGIN_LIST list(APPEND FLUTTER_FFI_PLUGIN_LIST