improve usernames
This commit is contained in:
parent
98798fa14f
commit
40d57fb245
10 changed files with 106 additions and 0 deletions
|
@ -1 +1,8 @@
|
|||
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}) {
|
||||
// }
|
||||
|
|
|
@ -19,3 +19,20 @@ Uri urlFromUsername({required String name}) {
|
|||
name = cleanUpUsername(name: name);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,10 @@
|
|||
|
||||
#include "generated_plugin_registrant.h"
|
||||
|
||||
#include <flutter_secure_storage_linux/flutter_secure_storage_linux_plugin.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#
|
||||
|
||||
list(APPEND FLUTTER_PLUGIN_LIST
|
||||
flutter_secure_storage_linux
|
||||
)
|
||||
|
||||
list(APPEND FLUTTER_FFI_PLUGIN_LIST
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
import FlutterMacOS
|
||||
import Foundation
|
||||
|
||||
import flutter_secure_storage_macos
|
||||
|
||||
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
||||
FlutterSecureStorageMacosPlugin.register(with: registry.registrar(forPlugin: "FlutterSecureStorageMacosPlugin"))
|
||||
}
|
||||
|
|
62
pubspec.lock
62
pubspec.lock
|
@ -76,11 +76,58 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
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:
|
||||
dependency: "direct dev"
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
flutter_web_plugins:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
http:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -95,6 +142,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "4.0.1"
|
||||
js:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: js
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.6.4"
|
||||
lints:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -137,6 +191,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
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:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -207,3 +268,4 @@ packages:
|
|||
version: "2.1.2"
|
||||
sdks:
|
||||
dart: ">=2.17.3 <3.0.0"
|
||||
flutter: ">=2.0.0"
|
||||
|
|
|
@ -37,6 +37,7 @@ dependencies:
|
|||
settings_ui: ^2.0.2
|
||||
http: ^0.13.4
|
||||
oauth2: ^2.0.0
|
||||
flutter_secure_storage: ^5.0.2
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
|
@ -5,6 +5,7 @@ void main() {
|
|||
validUsernameTest();
|
||||
usernameToUrlTest();
|
||||
cleanupNameTest();
|
||||
userFromUsernameTest();
|
||||
}
|
||||
|
||||
void validUsernameTest() {
|
||||
|
@ -36,3 +37,10 @@ void cleanupNameTest() {
|
|||
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");
|
||||
});
|
||||
}
|
||||
|
|
|
@ -6,6 +6,9 @@
|
|||
|
||||
#include "generated_plugin_registrant.h"
|
||||
|
||||
#include <flutter_secure_storage_windows/flutter_secure_storage_windows_plugin.h>
|
||||
|
||||
void RegisterPlugins(flutter::PluginRegistry* registry) {
|
||||
FlutterSecureStorageWindowsPluginRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("FlutterSecureStorageWindowsPlugin"));
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#
|
||||
|
||||
list(APPEND FLUTTER_PLUGIN_LIST
|
||||
flutter_secure_storage_windows
|
||||
)
|
||||
|
||||
list(APPEND FLUTTER_FFI_PLUGIN_LIST
|
||||
|
|
Loading…
Reference in a new issue