diff --git a/lib/business_logic/auth/oauth.dart b/lib/business_logic/auth/oauth.dart new file mode 100644 index 0000000..ff95415 --- /dev/null +++ b/lib/business_logic/auth/oauth.dart @@ -0,0 +1,53 @@ +import 'package:http/http.dart' as http; +import 'package:url_launcher/url_launcher.dart'; +import '../../global.dart' as global; + +class App { + late String clientSecret; + late String clientId; + late String id; + late String name; + late String website; + late String redirectUri; + App( + {required this.clientSecret, + required this.clientId, + required this.id, + required this.name, + required this.website, + required this.redirectUri}); + factory App.fromJson(Map json) { + return App( + id: json["id"].toString(), + name: json["name"].toString(), + website: json["website"].toString(), + redirectUri: json["redirect_uri"].toString(), + clientId: json["client_id"].toString(), + clientSecret: json["client_secret"].toString()); + } +} + +Future registerApp(String baseurl) async { + //String url = baseurl Uri."api/v1/apps"; + Uri url = Uri.https(baseurl, "/api/v1/apps"); + var response = await http.post(url, headers: global.defaultHeaders, body: { + 'client_name': global.name, + 'redirect_uris': "ietf:wg:oauth:2.0:oob", + 'scopes': "read write", + 'website': global.website + }); + return response; +} + +void openBrowserForAuthCode(String baseurl, App app) { + Uri url = Uri.https( + baseurl, + // ignore: prefer_interpolation_to_compose_strings + "/oauth/authorize" + + "?client_id=" + + app.clientId + + "&scope=read+write" + + "&redirect_uri=urn:ietf:wg:oauth:2.0:oob" + + "&response_type=code"); + launchUrl(url); +} diff --git a/lib/api/auth/secrets.dart b/lib/business_logic/auth/secrets.dart similarity index 100% rename from lib/api/auth/secrets.dart rename to lib/business_logic/auth/secrets.dart diff --git a/lib/api/user.dart b/lib/business_logic/user.dart similarity index 100% rename from lib/api/user.dart rename to lib/business_logic/user.dart diff --git a/lib/api/auth/oauth.dart b/lib/business_logic/webfinger.dart similarity index 100% rename from lib/api/auth/oauth.dart rename to lib/business_logic/webfinger.dart diff --git a/lib/global.dart b/lib/global.dart new file mode 100644 index 0000000..ade3d05 --- /dev/null +++ b/lib/global.dart @@ -0,0 +1,9 @@ +const String name = "slothmu"; +const String version = "v0.1 'not even alpha'"; +const String useragent = "$name/$version"; +const String website = "https://git.kittycat.homes/zoe/slothmu"; +const Map defaultHeaders = { + "User-Agent": useragent, + "accept": "application/json", + "Content-Type": "application/json" +}; diff --git a/lib/main.dart b/lib/main.dart index ea09307..95e54ce 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,10 +1,15 @@ import 'package:flutter/material.dart'; +import 'package:intl/intl.dart'; import 'package:localization/localization.dart'; import 'package:slothmu/partials/main_scaffold.dart'; import 'pages/login.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; -void main() => runApp(const Slothmu()); +void main() { + Intl.defaultLocale = 'en_US'; + + runApp(const Slothmu()); +} class Slothmu extends StatefulWidget { const Slothmu({Key? key}) : super(key: key); @@ -14,15 +19,15 @@ class Slothmu extends StatefulWidget { } class _SlothmuState extends State { + List supported = const [ + Locale("en", "US"), + Locale("de", "DE"), + ]; @override Widget build(BuildContext context) { LocalJsonLocalization.delegate.directories = ['lib/i18n']; return MaterialApp( - supportedLocales: const [ - Locale("en", "US"), - Locale("de", "DE"), - ], - locale: const Locale("de", "DE"), + supportedLocales: supported, localizationsDelegates: [ GlobalCupertinoLocalizations.delegate, GlobalWidgetsLocalizations.delegate, diff --git a/lib/pages/login.dart b/lib/pages/login.dart index 761a17e..44d1dab 100644 --- a/lib/pages/login.dart +++ b/lib/pages/login.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; -import 'package:slothmu/api/user.dart'; +import 'package:slothmu/business_logic/user.dart'; import 'package:localization/localization.dart'; +import '../business_logic/auth/oauth.dart' as oauth; class Login extends StatefulWidget { const Login({Key? key}) : super(key: key); @@ -64,6 +65,13 @@ class _LoginFormState extends State { if (!isValid) { ScaffoldMessenger.of(context).showSnackBar(SnackBar( content: Text("login-failed-snackbar-text".i18n()))); + } else { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => + const AuthPage(baseurl: "kittycat.homes"), + )); } }, icon: const Icon(Icons.login), @@ -73,3 +81,21 @@ class _LoginFormState extends State { ); } } + +class AuthPage extends StatefulWidget { + const AuthPage({Key? key, required String baseurl}) : super(key: key); + + @override + State createState() => _AuthPageState(); +} + +class _AuthPageState extends State { + @override + Widget build(BuildContext context) { + return Scaffold( + body: Center( + child: Text("hello"), + ), + ); + } +} diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index e71a16d..f6f23bf 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -6,6 +6,10 @@ #include "generated_plugin_registrant.h" +#include void fl_register_plugins(FlPluginRegistry* registry) { + g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar = + fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin"); + url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar); } diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake index 2e1de87..f16b4c3 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -3,6 +3,7 @@ # list(APPEND FLUTTER_PLUGIN_LIST + url_launcher_linux ) list(APPEND FLUTTER_FFI_PLUGIN_LIST diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index cccf817..766b5cf 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,6 +5,12 @@ import FlutterMacOS import Foundation +import path_provider_macos +import shared_preferences_macos +import url_launcher_macos func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { + PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) + SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) + UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) } diff --git a/pubspec.lock b/pubspec.lock index 650a78f..84afb8f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -57,6 +57,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.0" + ffi: + dependency: transitive + description: + name: ffi + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" + file: + dependency: transitive + description: + name: file + url: "https://pub.dartlang.org" + source: hosted + version: "6.1.2" flutter: dependency: "direct main" description: flutter @@ -79,6 +93,11 @@ packages: 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: @@ -94,12 +113,19 @@ packages: source: hosted version: "4.0.1" intl: - dependency: transitive + dependency: "direct main" description: name: intl url: "https://pub.dartlang.org" source: hosted version: "0.17.0" + js: + dependency: transitive + description: + name: js + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.4" lints: dependency: transitive description: @@ -114,6 +140,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.0" + localstorage: + dependency: "direct main" + description: + name: localstorage + url: "https://pub.dartlang.org" + source: hosted + version: "4.0.0+1" matcher: dependency: transitive description: @@ -142,6 +175,76 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.1" + path_provider: + dependency: transitive + description: + name: path_provider + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.11" + path_provider_android: + dependency: transitive + description: + name: path_provider_android + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.16" + path_provider_ios: + dependency: transitive + description: + name: path_provider_ios + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.10" + path_provider_linux: + dependency: transitive + description: + name: path_provider_linux + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.7" + path_provider_macos: + dependency: transitive + description: + name: path_provider_macos + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.6" + path_provider_platform_interface: + dependency: transitive + description: + name: path_provider_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.4" + path_provider_windows: + dependency: transitive + description: + name: path_provider_windows + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + platform: + dependency: transitive + description: + name: platform + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.0" + plugin_platform_interface: + dependency: transitive + description: + name: plugin_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.2" + process: + dependency: transitive + description: + name: process + url: "https://pub.dartlang.org" + source: hosted + version: "4.2.4" settings_ui: dependency: "direct main" description: @@ -149,6 +252,62 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.2" + shared_preferences: + dependency: "direct main" + description: + name: shared_preferences + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.15" + shared_preferences_android: + dependency: transitive + description: + name: shared_preferences_android + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.12" + shared_preferences_ios: + dependency: transitive + description: + name: shared_preferences_ios + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.1" + shared_preferences_linux: + dependency: transitive + description: + name: shared_preferences_linux + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.1" + shared_preferences_macos: + dependency: transitive + description: + name: shared_preferences_macos + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.4" + shared_preferences_platform_interface: + dependency: transitive + description: + name: shared_preferences_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" + shared_preferences_web: + dependency: transitive + description: + name: shared_preferences_web + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.4" + shared_preferences_windows: + dependency: transitive + description: + name: shared_preferences_windows + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.1" sky_engine: dependency: transitive description: flutter @@ -203,6 +362,62 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.1" + url_launcher: + dependency: "direct main" + description: + name: url_launcher + url: "https://pub.dartlang.org" + source: hosted + version: "6.1.4" + url_launcher_android: + dependency: transitive + description: + name: url_launcher_android + url: "https://pub.dartlang.org" + source: hosted + version: "6.0.17" + url_launcher_ios: + dependency: transitive + description: + name: url_launcher_ios + url: "https://pub.dartlang.org" + source: hosted + version: "6.0.17" + url_launcher_linux: + dependency: transitive + description: + name: url_launcher_linux + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.1" + url_launcher_macos: + dependency: transitive + description: + name: url_launcher_macos + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.1" + url_launcher_platform_interface: + dependency: transitive + description: + name: url_launcher_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + url_launcher_web: + dependency: transitive + description: + name: url_launcher_web + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.12" + url_launcher_windows: + dependency: transitive + description: + name: url_launcher_windows + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.1" vector_math: dependency: transitive description: @@ -210,5 +425,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.2" + win32: + dependency: transitive + description: + name: win32 + url: "https://pub.dartlang.org" + source: hosted + version: "2.7.0" + xdg_directories: + dependency: transitive + description: + name: xdg_directories + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.0+1" sdks: dart: ">=2.17.3 <3.0.0" + flutter: ">=3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 43f05e7..81bcf58 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -39,6 +39,10 @@ dependencies: settings_ui: ^2.0.2 http: ^0.13.4 localization: ^2.1.0 + shared_preferences: ^2.0.15 + intl: ^0.17.0 + url_launcher: ^6.1.4 + localstorage: ^4.0.0+1 dev_dependencies: flutter_test: diff --git a/test/user/user_test.dart b/test/user/user_test.dart index 464d47b..1c0a0a1 100644 --- a/test/user/user_test.dart +++ b/test/user/user_test.dart @@ -1,5 +1,5 @@ import 'package:flutter_test/flutter_test.dart'; -import 'package:slothmu/api/user.dart'; +import 'package:slothmu/business_logic/user.dart'; void main() { validUsernameTest(); diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 8b6d468..4f78848 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -6,6 +6,9 @@ #include "generated_plugin_registrant.h" +#include void RegisterPlugins(flutter::PluginRegistry* registry) { + UrlLauncherWindowsRegisterWithRegistrar( + registry->GetRegistrarForPlugin("UrlLauncherWindows")); } diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index b93c4c3..88b22e5 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -3,6 +3,7 @@ # list(APPEND FLUTTER_PLUGIN_LIST + url_launcher_windows ) list(APPEND FLUTTER_FFI_PLUGIN_LIST