From 577c5632eb04885c1705e69df757df3b14e5d946 Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Fri, 18 Aug 2023 12:44:10 +0200 Subject: [PATCH 01/57] feat: get current session information --- kratos-flutter/.gitignore | 46 + kratos-flutter/.metadata | 45 + kratos-flutter/README.md | 16 + kratos-flutter/analysis_options.yaml | 29 + kratos-flutter/android/.gitignore | 13 + kratos-flutter/android/app/build.gradle | 72 ++ .../android/app/src/debug/AndroidManifest.xml | 7 + .../android/app/src/main/AndroidManifest.xml | 33 + .../example/kratos_flutter/MainActivity.kt | 6 + .../res/drawable-v21/launch_background.xml | 12 + .../main/res/drawable/launch_background.xml | 12 + .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 544 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 442 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 721 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 1031 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 1443 bytes .../app/src/main/res/values-night/styles.xml | 18 + .../app/src/main/res/values/styles.xml | 18 + .../app/src/profile/AndroidManifest.xml | 7 + kratos-flutter/android/build.gradle | 31 + kratos-flutter/android/gradle.properties | 3 + .../gradle/wrapper/gradle-wrapper.properties | 5 + kratos-flutter/android/settings.gradle | 11 + kratos-flutter/ios/.gitignore | 34 + .../ios/Flutter/AppFrameworkInfo.plist | 26 + kratos-flutter/ios/Flutter/Debug.xcconfig | 2 + kratos-flutter/ios/Flutter/Release.xcconfig | 2 + kratos-flutter/ios/Podfile | 44 + .../ios/Runner.xcodeproj/project.pbxproj | 613 +++++++++++++ .../contents.xcworkspacedata | 7 + .../xcshareddata/IDEWorkspaceChecks.plist | 8 + .../xcshareddata/WorkspaceSettings.xcsettings | 8 + .../xcshareddata/xcschemes/Runner.xcscheme | 98 +++ .../contents.xcworkspacedata | 7 + .../xcshareddata/IDEWorkspaceChecks.plist | 8 + .../xcshareddata/WorkspaceSettings.xcsettings | 8 + kratos-flutter/ios/Runner/AppDelegate.swift | 13 + .../AppIcon.appiconset/Contents.json | 122 +++ .../Icon-App-1024x1024@1x.png | Bin 0 -> 10932 bytes .../AppIcon.appiconset/Icon-App-20x20@1x.png | Bin 0 -> 295 bytes .../AppIcon.appiconset/Icon-App-20x20@2x.png | Bin 0 -> 406 bytes .../AppIcon.appiconset/Icon-App-20x20@3x.png | Bin 0 -> 450 bytes .../AppIcon.appiconset/Icon-App-29x29@1x.png | Bin 0 -> 282 bytes .../AppIcon.appiconset/Icon-App-29x29@2x.png | Bin 0 -> 462 bytes .../AppIcon.appiconset/Icon-App-29x29@3x.png | Bin 0 -> 704 bytes .../AppIcon.appiconset/Icon-App-40x40@1x.png | Bin 0 -> 406 bytes .../AppIcon.appiconset/Icon-App-40x40@2x.png | Bin 0 -> 586 bytes .../AppIcon.appiconset/Icon-App-40x40@3x.png | Bin 0 -> 862 bytes .../AppIcon.appiconset/Icon-App-60x60@2x.png | Bin 0 -> 862 bytes .../AppIcon.appiconset/Icon-App-60x60@3x.png | Bin 0 -> 1674 bytes .../AppIcon.appiconset/Icon-App-76x76@1x.png | Bin 0 -> 762 bytes .../AppIcon.appiconset/Icon-App-76x76@2x.png | Bin 0 -> 1226 bytes .../Icon-App-83.5x83.5@2x.png | Bin 0 -> 1418 bytes .../LaunchImage.imageset/Contents.json | 23 + .../LaunchImage.imageset/LaunchImage.png | Bin 0 -> 68 bytes .../LaunchImage.imageset/LaunchImage@2x.png | Bin 0 -> 68 bytes .../LaunchImage.imageset/LaunchImage@3x.png | Bin 0 -> 68 bytes .../LaunchImage.imageset/README.md | 5 + .../Runner/Base.lproj/LaunchScreen.storyboard | 37 + .../ios/Runner/Base.lproj/Main.storyboard | 26 + kratos-flutter/ios/Runner/Info.plist | 51 ++ .../ios/Runner/Runner-Bridging-Header.h | 1 + .../ios/RunnerTests/RunnerTests.swift | 12 + kratos-flutter/lib/blocs/auth/auth_bloc.dart | 44 + .../lib/blocs/auth/auth_bloc.freezed.dart | 198 +++++ kratos-flutter/lib/blocs/auth/auth_event.dart | 21 + kratos-flutter/lib/blocs/auth/auth_state.dart | 10 + kratos-flutter/lib/main.dart | 128 +++ kratos-flutter/lib/pages/entry.dart | 12 + kratos-flutter/lib/pages/home.dart | 12 + kratos-flutter/lib/pages/login.dart | 12 + kratos-flutter/lib/repositories/auth.dart | 16 + kratos-flutter/lib/services/auth.dart | 25 + kratos-flutter/lib/services/exceptions.dart | 55 ++ kratos-flutter/lib/services/storage.dart | 34 + kratos-flutter/pubspec.lock | 818 ++++++++++++++++++ kratos-flutter/pubspec.yaml | 106 +++ kratos-flutter/test/widget_test.dart | 30 + 78 files changed, 3060 insertions(+) create mode 100644 kratos-flutter/.gitignore create mode 100644 kratos-flutter/.metadata create mode 100644 kratos-flutter/README.md create mode 100644 kratos-flutter/analysis_options.yaml create mode 100644 kratos-flutter/android/.gitignore create mode 100644 kratos-flutter/android/app/build.gradle create mode 100644 kratos-flutter/android/app/src/debug/AndroidManifest.xml create mode 100644 kratos-flutter/android/app/src/main/AndroidManifest.xml create mode 100644 kratos-flutter/android/app/src/main/kotlin/com/example/kratos_flutter/MainActivity.kt create mode 100644 kratos-flutter/android/app/src/main/res/drawable-v21/launch_background.xml create mode 100644 kratos-flutter/android/app/src/main/res/drawable/launch_background.xml create mode 100644 kratos-flutter/android/app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 kratos-flutter/android/app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 kratos-flutter/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 kratos-flutter/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 kratos-flutter/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 kratos-flutter/android/app/src/main/res/values-night/styles.xml create mode 100644 kratos-flutter/android/app/src/main/res/values/styles.xml create mode 100644 kratos-flutter/android/app/src/profile/AndroidManifest.xml create mode 100644 kratos-flutter/android/build.gradle create mode 100644 kratos-flutter/android/gradle.properties create mode 100644 kratos-flutter/android/gradle/wrapper/gradle-wrapper.properties create mode 100644 kratos-flutter/android/settings.gradle create mode 100644 kratos-flutter/ios/.gitignore create mode 100644 kratos-flutter/ios/Flutter/AppFrameworkInfo.plist create mode 100644 kratos-flutter/ios/Flutter/Debug.xcconfig create mode 100644 kratos-flutter/ios/Flutter/Release.xcconfig create mode 100644 kratos-flutter/ios/Podfile create mode 100644 kratos-flutter/ios/Runner.xcodeproj/project.pbxproj create mode 100644 kratos-flutter/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 kratos-flutter/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 kratos-flutter/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings create mode 100644 kratos-flutter/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme create mode 100644 kratos-flutter/ios/Runner.xcworkspace/contents.xcworkspacedata create mode 100644 kratos-flutter/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 kratos-flutter/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings create mode 100644 kratos-flutter/ios/Runner/AppDelegate.swift create mode 100644 kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png create mode 100644 kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png create mode 100644 kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png create mode 100644 kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png create mode 100644 kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png create mode 100644 kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png create mode 100644 kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png create mode 100644 kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png create mode 100644 kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png create mode 100644 kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png create mode 100644 kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png create mode 100644 kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png create mode 100644 kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png create mode 100644 kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png create mode 100644 kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png create mode 100644 kratos-flutter/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json create mode 100644 kratos-flutter/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png create mode 100644 kratos-flutter/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png create mode 100644 kratos-flutter/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png create mode 100644 kratos-flutter/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md create mode 100644 kratos-flutter/ios/Runner/Base.lproj/LaunchScreen.storyboard create mode 100644 kratos-flutter/ios/Runner/Base.lproj/Main.storyboard create mode 100644 kratos-flutter/ios/Runner/Info.plist create mode 100644 kratos-flutter/ios/Runner/Runner-Bridging-Header.h create mode 100644 kratos-flutter/ios/RunnerTests/RunnerTests.swift create mode 100644 kratos-flutter/lib/blocs/auth/auth_bloc.dart create mode 100644 kratos-flutter/lib/blocs/auth/auth_bloc.freezed.dart create mode 100644 kratos-flutter/lib/blocs/auth/auth_event.dart create mode 100644 kratos-flutter/lib/blocs/auth/auth_state.dart create mode 100644 kratos-flutter/lib/main.dart create mode 100644 kratos-flutter/lib/pages/entry.dart create mode 100644 kratos-flutter/lib/pages/home.dart create mode 100644 kratos-flutter/lib/pages/login.dart create mode 100644 kratos-flutter/lib/repositories/auth.dart create mode 100644 kratos-flutter/lib/services/auth.dart create mode 100644 kratos-flutter/lib/services/exceptions.dart create mode 100644 kratos-flutter/lib/services/storage.dart create mode 100644 kratos-flutter/pubspec.lock create mode 100644 kratos-flutter/pubspec.yaml create mode 100644 kratos-flutter/test/widget_test.dart diff --git a/kratos-flutter/.gitignore b/kratos-flutter/.gitignore new file mode 100644 index 00000000..189b5695 --- /dev/null +++ b/kratos-flutter/.gitignore @@ -0,0 +1,46 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +**/doc/api/ +**/ios/Flutter/.last_build_id +.dart_tool/ +.flutter-plugins +.flutter-plugins-dependencies +.packages +.pub-cache/ +.pub/ +/build/ + +# Symbolication related +app.*.symbols + +# Obfuscation related +app.*.map.json + +# Android Studio will place build artifacts here +/android/app/debug +/android/app/profile +/android/app/release + +.env diff --git a/kratos-flutter/.metadata b/kratos-flutter/.metadata new file mode 100644 index 00000000..de745e4a --- /dev/null +++ b/kratos-flutter/.metadata @@ -0,0 +1,45 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled. + +version: + revision: f468f3366c26a5092eb964a230ce7892fda8f2f8 + channel: stable + +project_type: app + +# Tracks metadata for the flutter migrate command +migration: + platforms: + - platform: root + create_revision: f468f3366c26a5092eb964a230ce7892fda8f2f8 + base_revision: f468f3366c26a5092eb964a230ce7892fda8f2f8 + - platform: android + create_revision: f468f3366c26a5092eb964a230ce7892fda8f2f8 + base_revision: f468f3366c26a5092eb964a230ce7892fda8f2f8 + - platform: ios + create_revision: f468f3366c26a5092eb964a230ce7892fda8f2f8 + base_revision: f468f3366c26a5092eb964a230ce7892fda8f2f8 + - platform: linux + create_revision: f468f3366c26a5092eb964a230ce7892fda8f2f8 + base_revision: f468f3366c26a5092eb964a230ce7892fda8f2f8 + - platform: macos + create_revision: f468f3366c26a5092eb964a230ce7892fda8f2f8 + base_revision: f468f3366c26a5092eb964a230ce7892fda8f2f8 + - platform: web + create_revision: f468f3366c26a5092eb964a230ce7892fda8f2f8 + base_revision: f468f3366c26a5092eb964a230ce7892fda8f2f8 + - platform: windows + create_revision: f468f3366c26a5092eb964a230ce7892fda8f2f8 + base_revision: f468f3366c26a5092eb964a230ce7892fda8f2f8 + + # User provided section + + # List of Local paths (relative to this file) that should be + # ignored by the migrate tool. + # + # Files that are not part of the templates will be ignored by default. + unmanaged_files: + - 'lib/main.dart' + - 'ios/Runner.xcodeproj/project.pbxproj' diff --git a/kratos-flutter/README.md b/kratos-flutter/README.md new file mode 100644 index 00000000..177c296a --- /dev/null +++ b/kratos-flutter/README.md @@ -0,0 +1,16 @@ +# kratos_flutter + +A new Flutter project. + +## Getting Started + +This project is a starting point for a Flutter application. + +A few resources to get you started if this is your first Flutter project: + +- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab) +- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook) + +For help getting started with Flutter development, view the +[online documentation](https://docs.flutter.dev/), which offers tutorials, +samples, guidance on mobile development, and a full API reference. diff --git a/kratos-flutter/analysis_options.yaml b/kratos-flutter/analysis_options.yaml new file mode 100644 index 00000000..61b6c4de --- /dev/null +++ b/kratos-flutter/analysis_options.yaml @@ -0,0 +1,29 @@ +# This file configures the analyzer, which statically analyzes Dart code to +# check for errors, warnings, and lints. +# +# The issues identified by the analyzer are surfaced in the UI of Dart-enabled +# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be +# invoked from the command line by running `flutter analyze`. + +# The following line activates a set of recommended lints for Flutter apps, +# packages, and plugins designed to encourage good coding practices. +include: package:flutter_lints/flutter.yaml + +linter: + # The lint rules applied to this project can be customized in the + # section below to disable rules from the `package:flutter_lints/flutter.yaml` + # included above or to enable additional rules. A list of all available lints + # and their documentation is published at + # https://dart-lang.github.io/linter/lints/index.html. + # + # Instead of disabling a lint rule for the entire project in the + # section below, it can also be suppressed for a single line of code + # or a specific dart file by using the `// ignore: name_of_lint` and + # `// ignore_for_file: name_of_lint` syntax on the line or in the file + # producing the lint. + rules: + # avoid_print: false # Uncomment to disable the `avoid_print` rule + # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/kratos-flutter/android/.gitignore b/kratos-flutter/android/.gitignore new file mode 100644 index 00000000..6f568019 --- /dev/null +++ b/kratos-flutter/android/.gitignore @@ -0,0 +1,13 @@ +gradle-wrapper.jar +/.gradle +/captures/ +/gradlew +/gradlew.bat +/local.properties +GeneratedPluginRegistrant.java + +# Remember to never publicly share your keystore. +# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app +key.properties +**/*.keystore +**/*.jks diff --git a/kratos-flutter/android/app/build.gradle b/kratos-flutter/android/app/build.gradle new file mode 100644 index 00000000..927aafcd --- /dev/null +++ b/kratos-flutter/android/app/build.gradle @@ -0,0 +1,72 @@ +def localProperties = new Properties() +def localPropertiesFile = rootProject.file('local.properties') +if (localPropertiesFile.exists()) { + localPropertiesFile.withReader('UTF-8') { reader -> + localProperties.load(reader) + } +} + +def flutterRoot = localProperties.getProperty('flutter.sdk') +if (flutterRoot == null) { + throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") +} + +def flutterVersionCode = localProperties.getProperty('flutter.versionCode') +if (flutterVersionCode == null) { + flutterVersionCode = '1' +} + +def flutterVersionName = localProperties.getProperty('flutter.versionName') +if (flutterVersionName == null) { + flutterVersionName = '1.0' +} + +apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' +apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" + +android { + namespace "com.example.kratos_flutter" + compileSdkVersion flutter.compileSdkVersion + ndkVersion flutter.ndkVersion + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + kotlinOptions { + jvmTarget = '1.8' + } + + sourceSets { + main.java.srcDirs += 'src/main/kotlin' + } + + defaultConfig { + // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). + applicationId "com.example.kratos_flutter" + // You can update the following values to match your application needs. + // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. + minSdkVersion 18 + targetSdkVersion flutter.targetSdkVersion + versionCode flutterVersionCode.toInteger() + versionName flutterVersionName + } + + buildTypes { + release { + // TODO: Add your own signing config for the release build. + // Signing with the debug keys for now, so `flutter run --release` works. + signingConfig signingConfigs.debug + } + } +} + +flutter { + source '../..' +} + +dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" +} diff --git a/kratos-flutter/android/app/src/debug/AndroidManifest.xml b/kratos-flutter/android/app/src/debug/AndroidManifest.xml new file mode 100644 index 00000000..399f6981 --- /dev/null +++ b/kratos-flutter/android/app/src/debug/AndroidManifest.xml @@ -0,0 +1,7 @@ + + + + diff --git a/kratos-flutter/android/app/src/main/AndroidManifest.xml b/kratos-flutter/android/app/src/main/AndroidManifest.xml new file mode 100644 index 00000000..86e04b93 --- /dev/null +++ b/kratos-flutter/android/app/src/main/AndroidManifest.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + diff --git a/kratos-flutter/android/app/src/main/kotlin/com/example/kratos_flutter/MainActivity.kt b/kratos-flutter/android/app/src/main/kotlin/com/example/kratos_flutter/MainActivity.kt new file mode 100644 index 00000000..617d1a24 --- /dev/null +++ b/kratos-flutter/android/app/src/main/kotlin/com/example/kratos_flutter/MainActivity.kt @@ -0,0 +1,6 @@ +package com.example.kratos_flutter + +import io.flutter.embedding.android.FlutterActivity + +class MainActivity: FlutterActivity() { +} diff --git a/kratos-flutter/android/app/src/main/res/drawable-v21/launch_background.xml b/kratos-flutter/android/app/src/main/res/drawable-v21/launch_background.xml new file mode 100644 index 00000000..f74085f3 --- /dev/null +++ b/kratos-flutter/android/app/src/main/res/drawable-v21/launch_background.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/kratos-flutter/android/app/src/main/res/drawable/launch_background.xml b/kratos-flutter/android/app/src/main/res/drawable/launch_background.xml new file mode 100644 index 00000000..304732f8 --- /dev/null +++ b/kratos-flutter/android/app/src/main/res/drawable/launch_background.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/kratos-flutter/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/kratos-flutter/android/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000000000000000000000000000000000000..db77bb4b7b0906d62b1847e87f15cdcacf6a4f29 GIT binary patch literal 544 zcmeAS@N?(olHy`uVBq!ia0vp^9w5xY3?!3`olAj~WQl7;NpOBzNqJ&XDuZK6ep0G} zXKrG8YEWuoN@d~6R2!h8bpbvhu0Wd6uZuB!w&u2PAxD2eNXD>P5D~Wn-+_Wa#27Xc zC?Zj|6r#X(-D3u$NCt}(Ms06KgJ4FxJVv{GM)!I~&n8Bnc94O7-Hd)cjDZswgC;Qs zO=b+9!WcT8F?0rF7!Uys2bs@gozCP?z~o%U|N3vA*22NaGQG zlg@K`O_XuxvZ&Ks^m&R!`&1=spLvfx7oGDKDwpwW`#iqdw@AL`7MR}m`rwr|mZgU`8P7SBkL78fFf!WnuYWm$5Z0 zNXhDbCv&49sM544K|?c)WrFfiZvCi9h0O)B3Pgg&ebxsLQ05GG~ AQ2+n{ literal 0 HcmV?d00001 diff --git a/kratos-flutter/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/kratos-flutter/android/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000000000000000000000000000000000000..17987b79bb8a35cc66c3c1fd44f5a5526c1b78be GIT binary patch literal 442 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA3?vioaBc-sk|nMYCBgY=CFO}lsSJ)O`AMk? zp1FzXsX?iUDV2pMQ*D5Xx&nMcT!A!W`0S9QKQy;}1Cl^CgaH=;G9cpY;r$Q>i*pfB zP2drbID<_#qf;rPZx^FqH)F_D#*k@@q03KywUtLX8Ua?`H+NMzkczFPK3lFz@i_kW%1NOn0|D2I9n9wzH8m|-tHjsw|9>@K=iMBhxvkv6m8Y-l zytQ?X=U+MF$@3 zt`~i=@j|6y)RWMK--}M|=T`o&^Ni>IoWKHEbBXz7?A@mgWoL>!*SXo`SZH-*HSdS+ yn*9;$7;m`l>wYBC5bq;=U}IMqLzqbYCidGC!)_gkIk_C@Uy!y&wkt5C($~2D>~)O*cj@FGjOCM)M>_ixfudOh)?xMu#Fs z#}Y=@YDTwOM)x{K_j*Q;dPdJ?Mz0n|pLRx{4n|)f>SXlmV)XB04CrSJn#dS5nK2lM zrZ9#~WelCp7&e13Y$jvaEXHskn$2V!!DN-nWS__6T*l;H&Fopn?A6HZ-6WRLFP=R` zqG+CE#d4|IbyAI+rJJ`&x9*T`+a=p|0O(+s{UBcyZdkhj=yS1>AirP+0R;mf2uMgM zC}@~JfByORAh4SyRgi&!(cja>F(l*O+nd+@4m$|6K6KDn_&uvCpV23&>G9HJp{xgg zoq1^2_p9@|WEo z*X_Uko@K)qYYv~>43eQGMdbiGbo>E~Q& zrYBH{QP^@Sti!`2)uG{irBBq@y*$B zi#&(U-*=fp74j)RyIw49+0MRPMRU)+a2r*PJ$L5roHt2$UjExCTZSbq%V!HeS7J$N zdG@vOZB4v_lF7Plrx+hxo7(fCV&}fHq)$ literal 0 HcmV?d00001 diff --git a/kratos-flutter/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/kratos-flutter/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000000000000000000000000000000000000..d5f1c8d34e7a88e3f88bea192c3a370d44689c3c GIT binary patch literal 1031 zcmeAS@N?(olHy`uVBq!ia0vp^6F``Q8Ax83A=Cw=BuiW)N`mv#O3D+9QW+dm@{>{( zJaZG%Q-e|yQz{EjrrIztFa`(sgt!6~Yi|1%a`XoT0ojZ}lNrNjb9xjc(B0U1_% zz5^97Xt*%oq$rQy4?0GKNfJ44uvxI)gC`h-NZ|&0-7(qS@?b!5r36oQ}zyZrNO3 zMO=Or+<~>+A&uN&E!^Sl+>xE!QC-|oJv`ApDhqC^EWD|@=#J`=d#Xzxs4ah}w&Jnc z$|q_opQ^2TrnVZ0o~wh<3t%W&flvYGe#$xqda2bR_R zvPYgMcHgjZ5nSA^lJr%;<&0do;O^tDDh~=pIxA#coaCY>&N%M2^tq^U%3DB@ynvKo}b?yu-bFc-u0JHzced$sg7S3zqI(2 z#Km{dPr7I=pQ5>FuK#)QwK?Y`E`B?nP+}U)I#c1+FM*1kNvWG|a(TpksZQ3B@sD~b zpQ2)*V*TdwjFOtHvV|;OsiDqHi=6%)o4b!)x$)%9pGTsE z-JL={-Ffv+T87W(Xpooq<`r*VzWQcgBN$$`u}f>-ZQI1BB8ykN*=e4rIsJx9>z}*o zo~|9I;xof literal 0 HcmV?d00001 diff --git a/kratos-flutter/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/kratos-flutter/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000000000000000000000000000000000000..4d6372eebdb28e45604e46eeda8dd24651419bc0 GIT binary patch literal 1443 zcmb`G{WsKk6vsdJTdFg%tJav9_E4vzrOaqkWF|A724Nly!y+?N9`YV6wZ}5(X(D_N(?!*n3`|_r0Hc?=PQw&*vnU?QTFY zB_MsH|!j$PP;I}?dppoE_gA(4uc!jV&0!l7_;&p2^pxNo>PEcNJv za5_RT$o2Mf!<+r?&EbHH6nMoTsDOa;mN(wv8RNsHpG)`^ymG-S5By8=l9iVXzN_eG%Xg2@Xeq76tTZ*dGh~Lo9vl;Zfs+W#BydUw zCkZ$o1LqWQO$FC9aKlLl*7x9^0q%0}$OMlp@Kk_jHXOjofdePND+j!A{q!8~Jn+s3 z?~~w@4?egS02}8NuulUA=L~QQfm;MzCGd)XhiftT;+zFO&JVyp2mBww?;QByS_1w! zrQlx%{^cMj0|Bo1FjwY@Q8?Hx0cIPF*@-ZRFpPc#bBw{5@tD(5%sClzIfl8WU~V#u zm5Q;_F!wa$BSpqhN>W@2De?TKWR*!ujY;Yylk_X5#~V!L*Gw~;$%4Q8~Mad z@`-kG?yb$a9cHIApZDVZ^U6Xkp<*4rU82O7%}0jjHlK{id@?-wpN*fCHXyXh(bLt* zPc}H-x0e4E&nQ>y%B-(EL=9}RyC%MyX=upHuFhAk&MLbsF0LP-q`XnH78@fT+pKPW zu72MW`|?8ht^tz$iC}ZwLp4tB;Q49K!QCF3@!iB1qOI=?w z7In!}F~ij(18UYUjnbmC!qKhPo%24?8U1x{7o(+?^Zu0Hx81|FuS?bJ0jgBhEMzf< zCgUq7r2OCB(`XkKcN-TL>u5y#dD6D!)5W?`O5)V^>jb)P)GBdy%t$uUMpf$SNV31$ zb||OojAbvMP?T@$h_ZiFLFVHDmbyMhJF|-_)HX3%m=CDI+ID$0^C>kzxprBW)hw(v zr!Gmda);ICoQyhV_oP5+C%?jcG8v+D@9f?Dk*!BxY}dazmrT@64UrP3hlslANK)bq z$67n83eh}OeW&SV@HG95P|bjfqJ7gw$e+`Hxo!4cx`jdK1bJ>YDSpGKLPZ^1cv$ek zIB?0S<#tX?SJCLWdMd{-ME?$hc7A$zBOdIJ)4!KcAwb=VMov)nK;9z>x~rfT1>dS+ zZ6#`2v@`jgbqq)P22H)Tx2CpmM^o1$B+xT6`(v%5xJ(?j#>Q$+rx_R|7TzDZe{J6q zG1*EcU%tE?!kO%^M;3aM6JN*LAKUVb^xz8-Pxo#jR5(-KBeLJvA@-gxNHx0M-ZJLl z;#JwQoh~9V?`UVo#}{6ka@II>++D@%KqGpMdlQ}?9E*wFcf5(#XQnP$Dk5~%iX^>f z%$y;?M0BLp{O3a(-4A?ewryHrrD%cx#Q^%KY1H zNre$ve+vceSLZcNY4U(RBX&)oZn*Py()h)XkE?PL$!bNb{N5FVI2Y%LKEm%yvpyTP z(1P?z~7YxD~Rf<(a@_y` literal 0 HcmV?d00001 diff --git a/kratos-flutter/android/app/src/main/res/values-night/styles.xml b/kratos-flutter/android/app/src/main/res/values-night/styles.xml new file mode 100644 index 00000000..06952be7 --- /dev/null +++ b/kratos-flutter/android/app/src/main/res/values-night/styles.xml @@ -0,0 +1,18 @@ + + + + + + + diff --git a/kratos-flutter/android/app/src/main/res/values/styles.xml b/kratos-flutter/android/app/src/main/res/values/styles.xml new file mode 100644 index 00000000..cb1ef880 --- /dev/null +++ b/kratos-flutter/android/app/src/main/res/values/styles.xml @@ -0,0 +1,18 @@ + + + + + + + diff --git a/kratos-flutter/android/app/src/profile/AndroidManifest.xml b/kratos-flutter/android/app/src/profile/AndroidManifest.xml new file mode 100644 index 00000000..399f6981 --- /dev/null +++ b/kratos-flutter/android/app/src/profile/AndroidManifest.xml @@ -0,0 +1,7 @@ + + + + diff --git a/kratos-flutter/android/build.gradle b/kratos-flutter/android/build.gradle new file mode 100644 index 00000000..f7eb7f63 --- /dev/null +++ b/kratos-flutter/android/build.gradle @@ -0,0 +1,31 @@ +buildscript { + ext.kotlin_version = '1.7.10' + repositories { + google() + mavenCentral() + } + + dependencies { + classpath 'com.android.tools.build:gradle:7.3.0' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} + +allprojects { + repositories { + google() + mavenCentral() + } +} + +rootProject.buildDir = '../build' +subprojects { + project.buildDir = "${rootProject.buildDir}/${project.name}" +} +subprojects { + project.evaluationDependsOn(':app') +} + +tasks.register("clean", Delete) { + delete rootProject.buildDir +} diff --git a/kratos-flutter/android/gradle.properties b/kratos-flutter/android/gradle.properties new file mode 100644 index 00000000..94adc3a3 --- /dev/null +++ b/kratos-flutter/android/gradle.properties @@ -0,0 +1,3 @@ +org.gradle.jvmargs=-Xmx1536M +android.useAndroidX=true +android.enableJetifier=true diff --git a/kratos-flutter/android/gradle/wrapper/gradle-wrapper.properties b/kratos-flutter/android/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..3c472b99 --- /dev/null +++ b/kratos-flutter/android/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip diff --git a/kratos-flutter/android/settings.gradle b/kratos-flutter/android/settings.gradle new file mode 100644 index 00000000..44e62bcf --- /dev/null +++ b/kratos-flutter/android/settings.gradle @@ -0,0 +1,11 @@ +include ':app' + +def localPropertiesFile = new File(rootProject.projectDir, "local.properties") +def properties = new Properties() + +assert localPropertiesFile.exists() +localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } + +def flutterSdkPath = properties.getProperty("flutter.sdk") +assert flutterSdkPath != null, "flutter.sdk not set in local.properties" +apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" diff --git a/kratos-flutter/ios/.gitignore b/kratos-flutter/ios/.gitignore new file mode 100644 index 00000000..7a7f9873 --- /dev/null +++ b/kratos-flutter/ios/.gitignore @@ -0,0 +1,34 @@ +**/dgph +*.mode1v3 +*.mode2v3 +*.moved-aside +*.pbxuser +*.perspectivev3 +**/*sync/ +.sconsign.dblite +.tags* +**/.vagrant/ +**/DerivedData/ +Icon? +**/Pods/ +**/.symlinks/ +profile +xcuserdata +**/.generated/ +Flutter/App.framework +Flutter/Flutter.framework +Flutter/Flutter.podspec +Flutter/Generated.xcconfig +Flutter/ephemeral/ +Flutter/app.flx +Flutter/app.zip +Flutter/flutter_assets/ +Flutter/flutter_export_environment.sh +ServiceDefinitions.json +Runner/GeneratedPluginRegistrant.* + +# Exceptions to above rules. +!default.mode1v3 +!default.mode2v3 +!default.pbxuser +!default.perspectivev3 diff --git a/kratos-flutter/ios/Flutter/AppFrameworkInfo.plist b/kratos-flutter/ios/Flutter/AppFrameworkInfo.plist new file mode 100644 index 00000000..9625e105 --- /dev/null +++ b/kratos-flutter/ios/Flutter/AppFrameworkInfo.plist @@ -0,0 +1,26 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + App + CFBundleIdentifier + io.flutter.flutter.app + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + App + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1.0 + MinimumOSVersion + 11.0 + + diff --git a/kratos-flutter/ios/Flutter/Debug.xcconfig b/kratos-flutter/ios/Flutter/Debug.xcconfig new file mode 100644 index 00000000..ec97fc6f --- /dev/null +++ b/kratos-flutter/ios/Flutter/Debug.xcconfig @@ -0,0 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" +#include "Generated.xcconfig" diff --git a/kratos-flutter/ios/Flutter/Release.xcconfig b/kratos-flutter/ios/Flutter/Release.xcconfig new file mode 100644 index 00000000..c4855bfe --- /dev/null +++ b/kratos-flutter/ios/Flutter/Release.xcconfig @@ -0,0 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" +#include "Generated.xcconfig" diff --git a/kratos-flutter/ios/Podfile b/kratos-flutter/ios/Podfile new file mode 100644 index 00000000..fdcc671e --- /dev/null +++ b/kratos-flutter/ios/Podfile @@ -0,0 +1,44 @@ +# Uncomment this line to define a global platform for your project +# platform :ios, '11.0' + +# CocoaPods analytics sends network stats synchronously affecting flutter build latency. +ENV['COCOAPODS_DISABLE_STATS'] = 'true' + +project 'Runner', { + 'Debug' => :debug, + 'Profile' => :release, + 'Release' => :release, +} + +def flutter_root + generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) + unless File.exist?(generated_xcode_build_settings_path) + raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" + end + + File.foreach(generated_xcode_build_settings_path) do |line| + matches = line.match(/FLUTTER_ROOT\=(.*)/) + return matches[1].strip if matches + end + raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" +end + +require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) + +flutter_ios_podfile_setup + +target 'Runner' do + use_frameworks! + use_modular_headers! + + flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) + target 'RunnerTests' do + inherit! :search_paths + end +end + +post_install do |installer| + installer.pods_project.targets.each do |target| + flutter_additional_ios_build_settings(target) + end +end diff --git a/kratos-flutter/ios/Runner.xcodeproj/project.pbxproj b/kratos-flutter/ios/Runner.xcodeproj/project.pbxproj new file mode 100644 index 00000000..183f3d10 --- /dev/null +++ b/kratos-flutter/ios/Runner.xcodeproj/project.pbxproj @@ -0,0 +1,613 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 54; + objects = { + +/* Begin PBXBuildFile section */ + 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; + 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; + 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; }; + 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; + 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; + 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; + 331C808B294A63AB00263BE5 /* RunnerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 331C807B294A618700263BE5 /* RunnerTests.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 331C8085294A63A400263BE5 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 97C146E61CF9000F007C117D /* Project object */; + proxyType = 1; + remoteGlobalIDString = 97C146ED1CF9000F007C117D; + remoteInfo = Runner; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 9705A1C41CF9048500538489 /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + ); + name = "Embed Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; + 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; + 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; + 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = ""; }; + 74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; + 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; + 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; + 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 331C807B294A618700263BE5 /* RunnerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RunnerTests.swift; sourceTree = ""; }; + 331C8081294A63A400263BE5 /* RunnerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RunnerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 97C146EB1CF9000F007C117D /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 9740EEB11CF90186004384FC /* Flutter */ = { + isa = PBXGroup; + children = ( + 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, + 9740EEB21CF90195004384FC /* Debug.xcconfig */, + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, + 9740EEB31CF90195004384FC /* Generated.xcconfig */, + ); + name = Flutter; + sourceTree = ""; + }; + 331C8082294A63A400263BE5 /* RunnerTests */ = { + isa = PBXGroup; + children = ( + 331C807B294A618700263BE5 /* RunnerTests.swift */, + ); + path = RunnerTests; + sourceTree = ""; + }; + 97C146E51CF9000F007C117D = { + isa = PBXGroup; + children = ( + 9740EEB11CF90186004384FC /* Flutter */, + 97C146F01CF9000F007C117D /* Runner */, + 97C146EF1CF9000F007C117D /* Products */, + 331C8082294A63A400263BE5 /* RunnerTests */, + ); + sourceTree = ""; + }; + 97C146EF1CF9000F007C117D /* Products */ = { + isa = PBXGroup; + children = ( + 97C146EE1CF9000F007C117D /* Runner.app */, + 331C8081294A63A400263BE5 /* RunnerTests.xctest */, + ); + name = Products; + sourceTree = ""; + }; + 97C146F01CF9000F007C117D /* Runner */ = { + isa = PBXGroup; + children = ( + 97C146FA1CF9000F007C117D /* Main.storyboard */, + 97C146FD1CF9000F007C117D /* Assets.xcassets */, + 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */, + 97C147021CF9000F007C117D /* Info.plist */, + 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */, + 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */, + 74858FAE1ED2DC5600515810 /* AppDelegate.swift */, + 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */, + ); + path = Runner; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 331C8080294A63A400263BE5 /* RunnerTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 331C8087294A63A400263BE5 /* Build configuration list for PBXNativeTarget "RunnerTests" */; + buildPhases = ( + 331C807D294A63A400263BE5 /* Sources */, + 331C807E294A63A400263BE5 /* Frameworks */, + 331C807F294A63A400263BE5 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 331C8086294A63A400263BE5 /* PBXTargetDependency */, + ); + name = RunnerTests; + productName = RunnerTests; + productReference = 331C8081294A63A400263BE5 /* RunnerTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; + 97C146ED1CF9000F007C117D /* Runner */ = { + isa = PBXNativeTarget; + buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; + buildPhases = ( + 9740EEB61CF901F6004384FC /* Run Script */, + 97C146EA1CF9000F007C117D /* Sources */, + 97C146EB1CF9000F007C117D /* Frameworks */, + 97C146EC1CF9000F007C117D /* Resources */, + 9705A1C41CF9048500538489 /* Embed Frameworks */, + 3B06AD1E1E4923F5004D2608 /* Thin Binary */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = Runner; + productName = Runner; + productReference = 97C146EE1CF9000F007C117D /* Runner.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 97C146E61CF9000F007C117D /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 1300; + ORGANIZATIONNAME = ""; + TargetAttributes = { + 331C8080294A63A400263BE5 = { + CreatedOnToolsVersion = 14.0; + TestTargetID = 97C146ED1CF9000F007C117D; + }; + 97C146ED1CF9000F007C117D = { + CreatedOnToolsVersion = 7.3.1; + LastSwiftMigration = 1100; + }; + }; + }; + buildConfigurationList = 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 97C146E51CF9000F007C117D; + productRefGroup = 97C146EF1CF9000F007C117D /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 97C146ED1CF9000F007C117D /* Runner */, + 331C8080294A63A400263BE5 /* RunnerTests */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 331C807F294A63A400263BE5 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 97C146EC1CF9000F007C117D /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */, + 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */, + 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */, + 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { + isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}", + ); + name = "Thin Binary"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin"; + }; + 9740EEB61CF901F6004384FC /* Run Script */ = { + isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Run Script"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 331C807D294A63A400263BE5 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 331C808B294A63AB00263BE5 /* RunnerTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 97C146EA1CF9000F007C117D /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */, + 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 331C8086294A63A400263BE5 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 97C146ED1CF9000F007C117D /* Runner */; + targetProxy = 331C8085294A63A400263BE5 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin PBXVariantGroup section */ + 97C146FA1CF9000F007C117D /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 97C146FB1CF9000F007C117D /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 97C147001CF9000F007C117D /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 249021D3217E4FDB00AE95B9 /* Profile */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + SUPPORTED_PLATFORMS = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Profile; + }; + 249021D4217E4FDB00AE95B9 /* Profile */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + ENABLE_BITCODE = NO; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.example.kratosFlutter; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; + SWIFT_VERSION = 5.0; + VERSIONING_SYSTEM = "apple-generic"; + }; + name = Profile; + }; + 331C8088294A63A400263BE5 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = AE0B7B92F70575B8D7E0D07E /* Pods-RunnerTests.debug.xcconfig */; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.example.kratosFlutter.RunnerTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner"; + }; + name = Debug; + }; + 331C8089294A63A400263BE5 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 89B67EB44CE7B6631473024E /* Pods-RunnerTests.release.xcconfig */; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.example.kratosFlutter.RunnerTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner"; + }; + name = Release; + }; + 331C808A294A63A400263BE5 /* Profile */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 640959BDD8F10B91D80A66BE /* Pods-RunnerTests.profile.xcconfig */; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.example.kratosFlutter.RunnerTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner"; + }; + name = Profile; + }; + 97C147031CF9000F007C117D /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 97C147041CF9000F007C117D /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + SUPPORTED_PLATFORMS = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 97C147061CF9000F007C117D /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + ENABLE_BITCODE = NO; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.example.kratosFlutter; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + VERSIONING_SYSTEM = "apple-generic"; + }; + name = Debug; + }; + 97C147071CF9000F007C117D /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + ENABLE_BITCODE = NO; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.example.kratosFlutter; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; + SWIFT_VERSION = 5.0; + VERSIONING_SYSTEM = "apple-generic"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 331C8087294A63A400263BE5 /* Build configuration list for PBXNativeTarget "RunnerTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 331C8088294A63A400263BE5 /* Debug */, + 331C8089294A63A400263BE5 /* Release */, + 331C808A294A63A400263BE5 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 97C147031CF9000F007C117D /* Debug */, + 97C147041CF9000F007C117D /* Release */, + 249021D3217E4FDB00AE95B9 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 97C147061CF9000F007C117D /* Debug */, + 97C147071CF9000F007C117D /* Release */, + 249021D4217E4FDB00AE95B9 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 97C146E61CF9000F007C117D /* Project object */; +} diff --git a/kratos-flutter/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/kratos-flutter/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..919434a6 --- /dev/null +++ b/kratos-flutter/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/kratos-flutter/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/kratos-flutter/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 00000000..18d98100 --- /dev/null +++ b/kratos-flutter/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/kratos-flutter/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/kratos-flutter/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings new file mode 100644 index 00000000..f9b0d7c5 --- /dev/null +++ b/kratos-flutter/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings @@ -0,0 +1,8 @@ + + + + + PreviewsEnabled + + + diff --git a/kratos-flutter/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/kratos-flutter/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme new file mode 100644 index 00000000..e42adcb3 --- /dev/null +++ b/kratos-flutter/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/kratos-flutter/ios/Runner.xcworkspace/contents.xcworkspacedata b/kratos-flutter/ios/Runner.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..1d526a16 --- /dev/null +++ b/kratos-flutter/ios/Runner.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/kratos-flutter/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/kratos-flutter/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 00000000..18d98100 --- /dev/null +++ b/kratos-flutter/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/kratos-flutter/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/kratos-flutter/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings new file mode 100644 index 00000000..f9b0d7c5 --- /dev/null +++ b/kratos-flutter/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings @@ -0,0 +1,8 @@ + + + + + PreviewsEnabled + + + diff --git a/kratos-flutter/ios/Runner/AppDelegate.swift b/kratos-flutter/ios/Runner/AppDelegate.swift new file mode 100644 index 00000000..70693e4a --- /dev/null +++ b/kratos-flutter/ios/Runner/AppDelegate.swift @@ -0,0 +1,13 @@ +import UIKit +import Flutter + +@UIApplicationMain +@objc class AppDelegate: FlutterAppDelegate { + override func application( + _ application: UIApplication, + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? + ) -> Bool { + GeneratedPluginRegistrant.register(with: self) + return super.application(application, didFinishLaunchingWithOptions: launchOptions) + } +} diff --git a/kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json b/kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 00000000..d36b1fab --- /dev/null +++ b/kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,122 @@ +{ + "images" : [ + { + "size" : "20x20", + "idiom" : "iphone", + "filename" : "Icon-App-20x20@2x.png", + "scale" : "2x" + }, + { + "size" : "20x20", + "idiom" : "iphone", + "filename" : "Icon-App-20x20@3x.png", + "scale" : "3x" + }, + { + "size" : "29x29", + "idiom" : "iphone", + "filename" : "Icon-App-29x29@1x.png", + "scale" : "1x" + }, + { + "size" : "29x29", + "idiom" : "iphone", + "filename" : "Icon-App-29x29@2x.png", + "scale" : "2x" + }, + { + "size" : "29x29", + "idiom" : "iphone", + "filename" : "Icon-App-29x29@3x.png", + "scale" : "3x" + }, + { + "size" : "40x40", + "idiom" : "iphone", + "filename" : "Icon-App-40x40@2x.png", + "scale" : "2x" + }, + { + "size" : "40x40", + "idiom" : "iphone", + "filename" : "Icon-App-40x40@3x.png", + "scale" : "3x" + }, + { + "size" : "60x60", + "idiom" : "iphone", + "filename" : "Icon-App-60x60@2x.png", + "scale" : "2x" + }, + { + "size" : "60x60", + "idiom" : "iphone", + "filename" : "Icon-App-60x60@3x.png", + "scale" : "3x" + }, + { + "size" : "20x20", + "idiom" : "ipad", + "filename" : "Icon-App-20x20@1x.png", + "scale" : "1x" + }, + { + "size" : "20x20", + "idiom" : "ipad", + "filename" : "Icon-App-20x20@2x.png", + "scale" : "2x" + }, + { + "size" : "29x29", + "idiom" : "ipad", + "filename" : "Icon-App-29x29@1x.png", + "scale" : "1x" + }, + { + "size" : "29x29", + "idiom" : "ipad", + "filename" : "Icon-App-29x29@2x.png", + "scale" : "2x" + }, + { + "size" : "40x40", + "idiom" : "ipad", + "filename" : "Icon-App-40x40@1x.png", + "scale" : "1x" + }, + { + "size" : "40x40", + "idiom" : "ipad", + "filename" : "Icon-App-40x40@2x.png", + "scale" : "2x" + }, + { + "size" : "76x76", + "idiom" : "ipad", + "filename" : "Icon-App-76x76@1x.png", + "scale" : "1x" + }, + { + "size" : "76x76", + "idiom" : "ipad", + "filename" : "Icon-App-76x76@2x.png", + "scale" : "2x" + }, + { + "size" : "83.5x83.5", + "idiom" : "ipad", + "filename" : "Icon-App-83.5x83.5@2x.png", + "scale" : "2x" + }, + { + "size" : "1024x1024", + "idiom" : "ios-marketing", + "filename" : "Icon-App-1024x1024@1x.png", + "scale" : "1x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} diff --git a/kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png b/kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png new file mode 100644 index 0000000000000000000000000000000000000000..dc9ada4725e9b0ddb1deab583e5b5102493aa332 GIT binary patch literal 10932 zcmeHN2~<R zh`|8`A_PQ1nSu(UMFx?8j8PC!!VDphaL#`F42fd#7Vlc`zIE4n%Y~eiz4y1j|NDpi z?<@|pSJ-HM`qifhf@m%MamgwK83`XpBA<+azdF#2QsT{X@z0A9Bq>~TVErigKH1~P zRX-!h-f0NJ4Mh++{D}J+K>~~rq}d%o%+4dogzXp7RxX4C>Km5XEI|PAFDmo;DFm6G zzjVoB`@qW98Yl0Kvc-9w09^PrsobmG*Eju^=3f?0o-t$U)TL1B3;sZ^!++3&bGZ!o-*6w?;oOhf z=A+Qb$scV5!RbG+&2S}BQ6YH!FKb0``VVX~T$dzzeSZ$&9=X$3)_7Z{SspSYJ!lGE z7yig_41zpQ)%5dr4ff0rh$@ky3-JLRk&DK)NEIHecf9c*?Z1bUB4%pZjQ7hD!A0r-@NF(^WKdr(LXj|=UE7?gBYGgGQV zidf2`ZT@pzXf7}!NH4q(0IMcxsUGDih(0{kRSez&z?CFA0RVXsVFw3^u=^KMtt95q z43q$b*6#uQDLoiCAF_{RFc{!H^moH_cmll#Fc^KXi{9GDl{>%+3qyfOE5;Zq|6#Hb zp^#1G+z^AXfRKaa9HK;%b3Ux~U@q?xg<2DXP%6k!3E)PA<#4$ui8eDy5|9hA5&{?v z(-;*1%(1~-NTQ`Is1_MGdQ{+i*ccd96ab$R$T3=% zw_KuNF@vI!A>>Y_2pl9L{9h1-C6H8<)J4gKI6{WzGBi<@u3P6hNsXG=bRq5c+z;Gc3VUCe;LIIFDmQAGy+=mRyF++u=drBWV8-^>0yE9N&*05XHZpPlE zxu@?8(ZNy7rm?|<+UNe0Vs6&o?l`Pt>P&WaL~M&#Eh%`rg@Mbb)J&@DA-wheQ>hRV z<(XhigZAT z>=M;URcdCaiO3d^?H<^EiEMDV+7HsTiOhoaMX%P65E<(5xMPJKxf!0u>U~uVqnPN7T!X!o@_gs3Ct1 zlZ_$5QXP4{Aj645wG_SNT&6m|O6~Tsl$q?nK*)(`{J4b=(yb^nOATtF1_aS978$x3 zx>Q@s4i3~IT*+l{@dx~Hst21fR*+5}S1@cf>&8*uLw-0^zK(+OpW?cS-YG1QBZ5q! zgTAgivzoF#`cSz&HL>Ti!!v#?36I1*l^mkrx7Y|K6L#n!-~5=d3;K<;Zqi|gpNUn_ z_^GaQDEQ*jfzh;`j&KXb66fWEk1K7vxQIMQ_#Wu_%3 z4Oeb7FJ`8I>Px;^S?)}2+4D_83gHEq>8qSQY0PVP?o)zAv3K~;R$fnwTmI-=ZLK`= zTm+0h*e+Yfr(IlH3i7gUclNH^!MU>id$Jw>O?2i0Cila#v|twub21@e{S2v}8Z13( zNDrTXZVgris|qYm<0NU(tAPouG!QF4ZNpZPkX~{tVf8xY690JqY1NVdiTtW+NqyRP zZ&;T0ikb8V{wxmFhlLTQ&?OP7 z;(z*<+?J2~z*6asSe7h`$8~Se(@t(#%?BGLVs$p``;CyvcT?7Y!{tIPva$LxCQ&4W z6v#F*);|RXvI%qnoOY&i4S*EL&h%hP3O zLsrFZhv&Hu5tF$Lx!8(hs&?!Kx5&L(fdu}UI5d*wn~A`nPUhG&Rv z2#ixiJdhSF-K2tpVL=)5UkXRuPAFrEW}7mW=uAmtVQ&pGE-&az6@#-(Te^n*lrH^m@X-ftVcwO_#7{WI)5v(?>uC9GG{lcGXYJ~Q8q zbMFl7;t+kV;|;KkBW2!P_o%Czhw&Q(nXlxK9ak&6r5t_KH8#1Mr-*0}2h8R9XNkr zto5-b7P_auqTJb(TJlmJ9xreA=6d=d)CVbYP-r4$hDn5|TIhB>SReMfh&OVLkMk-T zYf%$taLF0OqYF?V{+6Xkn>iX@TuqQ?&cN6UjC9YF&%q{Ut3zv{U2)~$>-3;Dp)*(? zg*$mu8^i=-e#acaj*T$pNowo{xiGEk$%DusaQiS!KjJH96XZ-hXv+jk%ard#fu=@Q z$AM)YWvE^{%tDfK%nD49=PI|wYu}lYVbB#a7wtN^Nml@CE@{Gv7+jo{_V?I*jkdLD zJE|jfdrmVbkfS>rN*+`#l%ZUi5_bMS<>=MBDNlpiSb_tAF|Zy`K7kcp@|d?yaTmB^ zo?(vg;B$vxS|SszusORgDg-*Uitzdi{dUV+glA~R8V(?`3GZIl^egW{a919!j#>f` znL1o_^-b`}xnU0+~KIFLQ)$Q6#ym%)(GYC`^XM*{g zv3AM5$+TtDRs%`2TyR^$(hqE7Y1b&`Jd6dS6B#hDVbJlUXcG3y*439D8MrK!2D~6gn>UD4Imctb z+IvAt0iaW73Iq$K?4}H`7wq6YkTMm`tcktXgK0lKPmh=>h+l}Y+pDtvHnG>uqBA)l zAH6BV4F}v$(o$8Gfo*PB>IuaY1*^*`OTx4|hM8jZ?B6HY;F6p4{`OcZZ(us-RVwDx zUzJrCQlp@mz1ZFiSZ*$yX3c_#h9J;yBE$2g%xjmGF4ca z&yL`nGVs!Zxsh^j6i%$a*I3ZD2SoNT`{D%mU=LKaEwbN(_J5%i-6Va?@*>=3(dQy` zOv%$_9lcy9+(t>qohkuU4r_P=R^6ME+wFu&LA9tw9RA?azGhjrVJKy&8=*qZT5Dr8g--d+S8zAyJ$1HlW3Olryt`yE zFIph~Z6oF&o64rw{>lgZISC6p^CBer9C5G6yq%?8tC+)7*d+ib^?fU!JRFxynRLEZ zj;?PwtS}Ao#9whV@KEmwQgM0TVP{hs>dg(1*DiMUOKHdQGIqa0`yZnHk9mtbPfoLx zo;^V6pKUJ!5#n`w2D&381#5#_t}AlTGEgDz$^;u;-vxDN?^#5!zN9ngytY@oTv!nc zp1Xn8uR$1Z;7vY`-<*?DfPHB;x|GUi_fI9@I9SVRv1)qETbNU_8{5U|(>Du84qP#7 z*l9Y$SgA&wGbj>R1YeT9vYjZuC@|{rajTL0f%N@>3$DFU=`lSPl=Iv;EjuGjBa$Gw zHD-;%YOE@<-!7-Mn`0WuO3oWuL6tB2cpPw~Nvuj|KM@))ixuDK`9;jGMe2d)7gHin zS<>k@!x;!TJEc#HdL#RF(`|4W+H88d4V%zlh(7#{q2d0OQX9*FW^`^_<3r$kabWAB z$9BONo5}*(%kx zOXi-yM_cmB3>inPpI~)duvZykJ@^^aWzQ=eQ&STUa}2uT@lV&WoRzkUoE`rR0)`=l zFT%f|LA9fCw>`enm$p7W^E@U7RNBtsh{_-7vVz3DtB*y#*~(L9+x9*wn8VjWw|Q~q zKFsj1Yl>;}%MG3=PY`$g$_mnyhuV&~O~u~)968$0b2!Jkd;2MtAP#ZDYw9hmK_+M$ zb3pxyYC&|CuAbtiG8HZjj?MZJBFbt`ryf+c1dXFuC z0*ZQhBzNBd*}s6K_G}(|Z_9NDV162#y%WSNe|FTDDhx)K!c(mMJh@h87@8(^YdK$&d*^WQe8Z53 z(|@MRJ$Lk-&ii74MPIs80WsOFZ(NX23oR-?As+*aq6b?~62@fSVmM-_*cb1RzZ)`5$agEiL`-E9s7{GM2?(KNPgK1(+c*|-FKoy}X(D_b#etO|YR z(BGZ)0Ntfv-7R4GHoXp?l5g#*={S1{u-QzxCGng*oWr~@X-5f~RA14b8~B+pLKvr4 zfgL|7I>jlak9>D4=(i(cqYf7#318!OSR=^`xxvI!bBlS??`xxWeg?+|>MxaIdH1U~#1tHu zB{QMR?EGRmQ_l4p6YXJ{o(hh-7Tdm>TAX380TZZZyVkqHNzjUn*_|cb?T? zt;d2s-?B#Mc>T-gvBmQZx(y_cfkXZO~{N zT6rP7SD6g~n9QJ)8F*8uHxTLCAZ{l1Y&?6v)BOJZ)=R-pY=Y=&1}jE7fQ>USS}xP#exo57uND0i*rEk@$;nLvRB@u~s^dwRf?G?_enN@$t* zbL%JO=rV(3Ju8#GqUpeE3l_Wu1lN9Y{D4uaUe`g>zlj$1ER$6S6@{m1!~V|bYkhZA z%CvrDRTkHuajMU8;&RZ&itnC~iYLW4DVkP<$}>#&(`UO>!n)Po;Mt(SY8Yb`AS9lt znbX^i?Oe9r_o=?})IHKHoQGKXsps_SE{hwrg?6dMI|^+$CeC&z@*LuF+P`7LfZ*yr+KN8B4{Nzv<`A(wyR@!|gw{zB6Ha ziwPAYh)oJ(nlqSknu(8g9N&1hu0$vFK$W#mp%>X~AU1ay+EKWcFdif{% z#4!4aoVVJ;ULmkQf!ke2}3hqxLK>eq|-d7Ly7-J9zMpT`?dxo6HdfJA|t)?qPEVBDv z{y_b?4^|YA4%WW0VZd8C(ZgQzRI5(I^)=Ub`Y#MHc@nv0w-DaJAqsbEHDWG8Ia6ju zo-iyr*sq((gEwCC&^TYBWt4_@|81?=B-?#P6NMff(*^re zYqvDuO`K@`mjm_Jd;mW_tP`3$cS?R$jR1ZN09$YO%_iBqh5ftzSpMQQtxKFU=FYmP zeY^jph+g<4>YO;U^O>-NFLn~-RqlHvnZl2yd2A{Yc1G@Ga$d+Q&(f^tnPf+Z7serIU};17+2DU_f4Z z@GaPFut27d?!YiD+QP@)T=77cR9~MK@bd~pY%X(h%L={{OIb8IQmf-!xmZkm8A0Ga zQSWONI17_ru5wpHg3jI@i9D+_Y|pCqVuHJNdHUauTD=R$JcD2K_liQisqG$(sm=k9;L* z!L?*4B~ql7uioSX$zWJ?;q-SWXRFhz2Jt4%fOHA=Bwf|RzhwqdXGr78y$J)LR7&3T zE1WWz*>GPWKZ0%|@%6=fyx)5rzUpI;bCj>3RKzNG_1w$fIFCZ&UR0(7S?g}`&Pg$M zf`SLsz8wK82Vyj7;RyKmY{a8G{2BHG%w!^T|Njr!h9TO2LaP^_f22Q1=l$QiU84ao zHe_#{S6;qrC6w~7{y(hs-?-j?lbOfgH^E=XcSgnwW*eEz{_Z<_xN#0001NP)t-s|Ns9~ z#rXRE|M&d=0au&!`~QyF`q}dRnBDt}*!qXo`c{v z{Djr|@Adh0(D_%#_&mM$D6{kE_x{oE{l@J5@%H*?%=t~i_`ufYOPkAEn!pfkr2$fs z652Tz0001XNklqeeKN4RM4i{jKqmiC$?+xN>3Apn^ z0QfuZLym_5b<*QdmkHjHlj811{If)dl(Z2K0A+ekGtrFJb?g|wt#k#pV-#A~bK=OT ts8>{%cPtyC${m|1#B1A6#u!Q;umknL1chzTM$P~L002ovPDHLkV1lTfnu!1a literal 0 HcmV?d00001 diff --git a/kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png b/kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..797d452e458972bab9d994556c8305db4c827017 GIT binary patch literal 406 zcmV;H0crk;P))>cdjpWt&rLJgVp-t?DREyuq1A%0Z4)6_WsQ7{nzjN zo!X zGXV)2i3kcZIL~_j>uIKPK_zib+3T+Nt3Mb&Br)s)UIaA}@p{wDda>7=Q|mGRp7pqY zkJ!7E{MNz$9nOwoVqpFb)}$IP24Wn2JJ=Cw(!`OXJBr45rP>>AQr$6c7slJWvbpNW z@KTwna6d?PP>hvXCcp=4F;=GR@R4E7{4VU^0p4F>v^#A|>07*qoM6N<$f*5nx ACIA2c literal 0 HcmV?d00001 diff --git a/kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png b/kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png new file mode 100644 index 0000000000000000000000000000000000000000..6ed2d933e1120817fe9182483a228007b18ab6ae GIT binary patch literal 450 zcmV;z0X_bSP)iGWQ_5NJQ_~rNh*z)}eT%KUb z`7gNk0#AwF^#0T0?hIa^`~Ck;!}#m+_uT050aTR(J!bU#|IzRL%^UsMS#KsYnTF*!YeDOytlP4VhV?b} z%rz_<=#CPc)tU1MZTq~*2=8~iZ!lSa<{9b@2Jl;?IEV8)=fG217*|@)CCYgFze-x? zIFODUIA>nWKpE+bn~n7;-89sa>#DR>TSlqWk*!2hSN6D~Qb#VqbP~4Fk&m`@1$JGr zXPIdeRE&b2Thd#{MtDK$px*d3-Wx``>!oimf%|A-&-q*6KAH)e$3|6JV%HX{Hig)k suLT-RhftRq8b9;(V=235Wa|I=027H2wCDra;{X5v07*qoM6N<$f;9x^2LJ#7 literal 0 HcmV?d00001 diff --git a/kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png b/kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png new file mode 100644 index 0000000000000000000000000000000000000000..4cd7b0099ca80c806f8fe495613e8d6c69460d76 GIT binary patch literal 282 zcmV+#0p(^bcu7P-R4C8Q z&e;xxFbF_Vrezo%_kH*OKhshZ6BFpG-Y1e10`QXJKbND7AMQ&cMj60B5TNObaZxYybcN07*qoM6N<$g3m;S%K!iX literal 0 HcmV?d00001 diff --git a/kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png b/kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..fe730945a01f64a61e2235dbe3f45b08f7729182 GIT binary patch literal 462 zcmV;<0WtoGP)-}iV`2<;=$?g5M=KQbZ{F&YRNy7Nn@%_*5{gvDM0aKI4?ESmw z{NnZg)A0R`+4?NF_RZexyVB&^^ZvN!{I28tr{Vje;QNTz`dG&Jz0~Ek&f2;*Z7>B|cg}xYpxEFY+0YrKLF;^Q+-HreN0P{&i zK~zY`?b7ECf-n?@;d<&orQ*Q7KoR%4|C>{W^h6@&01>0SKS`dn{Q}GT%Qj_{PLZ_& zs`MFI#j-(>?bvdZ!8^xTwlY{qA)T4QLbY@j(!YJ7aXJervHy6HaG_2SB`6CC{He}f zHVw(fJWApwPq!6VY7r1w-Fs)@ox~N+q|w~e;JI~C4Vf^@d>Wvj=fl`^u9x9wd9 zR%3*Q+)t%S!MU_`id^@&Y{y7-r98lZX0?YrHlfmwb?#}^1b{8g&KzmkE(L>Z&)179 zp<)v6Y}pRl100G2FL_t(o!|l{-Q-VMg#&MKg7c{O0 z2wJImOS3Gy*Z2Qifdv~JYOp;v+U)a|nLoc7hNH;I$;lzDt$}rkaFw1mYK5_0Q(Sut zvbEloxON7$+HSOgC9Z8ltuC&0OSF!-mXv5caV>#bc3@hBPX@I$58-z}(ZZE!t-aOG zpjNkbau@>yEzH(5Yj4kZiMH32XI!4~gVXNnjAvRx;Sdg^`>2DpUEwoMhTs_st8pKG z(%SHyHdU&v%f36~uERh!bd`!T2dw;z6PrOTQ7Vt*#9F2uHlUVnb#ev_o^fh}Dzmq} zWtlk35}k=?xj28uO|5>>$yXadTUE@@IPpgH`gJ~Ro4>jd1IF|(+IX>8M4Ps{PNvmI zNj4D+XgN83gPt_Gm}`Ybv{;+&yu-C(Grdiahmo~BjG-l&mWM+{e5M1sm&=xduwgM9 z`8OEh`=F3r`^E{n_;%9weN{cf2%7=VzC@cYj+lg>+3|D|_1C@{hcU(DyQG_BvBWe? zvTv``=%b1zrol#=R`JB)>cdjpWt&rLJgVp-t?DREyuq1A%0Z4)6_WsQ7{nzjN zo!X zGXV)2i3kcZIL~_j>uIKPK_zib+3T+Nt3Mb&Br)s)UIaA}@p{wDda>7=Q|mGRp7pqY zkJ!7E{MNz$9nOwoVqpFb)}$IP24Wn2JJ=Cw(!`OXJBr45rP>>AQr$6c7slJWvbpNW z@KTwna6d?PP>hvXCcp=4F;=GR@R4E7{4VU^0p4F>v^#A|>07*qoM6N<$f*5nx ACIA2c literal 0 HcmV?d00001 diff --git a/kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png b/kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..502f463a9bc882b461c96aadf492d1729e49e725 GIT binary patch literal 586 zcmV-Q0=4~#P)+}#`wDE{8-2Mebf5<{{PqV{TgVcv*r8?UZ3{-|G?_}T*&y;@cqf{ z{Q*~+qr%%p!1pS*_Uicl#q9lc(D`!D`LN62sNwq{oYw(Wmhk)k<@f$!$@ng~_5)Ru z0Z)trIA5^j{DIW^c+vT2%lW+2<(RtE2wR;4O@)Tm`Xr*?A(qYoM}7i5Yxw>D(&6ou zxz!_Xr~yNF+waPe00049Nkl*;a!v6h%{rlvIH#gW3s8p;bFr=l}mRqpW2h zw=OA%hdyL~z+UHOzl0eKhEr$YYOL-c-%Y<)=j?(bzDweB7{b+%_ypvm_cG{SvM=DK zhv{K@m>#Bw>2W$eUI#iU)Wdgs8Y3U+A$Gd&{+j)d)BmGKx+43U_!tik_YlN)>$7G! zhkE!s;%oku3;IwG3U^2kw?z+HM)jB{@zFhK8P#KMSytSthr+4!c(5c%+^UBn`0X*2 zy3(k600_CSZj?O$Qu%&$;|TGUJrptR(HzyIx>5E(2r{eA(<6t3e3I0B)7d6s7?Z5J zZ!rtKvA{MiEBm&KFtoifx>5P^Z=vl)95XJn()aS5%ad(s?4-=Tkis9IGu{`Fy8r+H07*qoM6N<$f20Z)wqMt%V?S?~D#06};F zA3KcL`Wb+>5ObvgQIG&ig8(;V04hz?@cqy3{mSh8o!|U|)cI!1_+!fWH@o*8vh^CU z^ws0;(c$gI+2~q^tO#GDHf@=;DncUw00J^eL_t(&-tE|HQ`%4vfZ;WsBqu-$0nu1R zq^Vj;p$clf^?twn|KHO+IGt^q#a3X?w9dXC@*yxhv&l}F322(8Y1&=P&I}~G@#h6; z1CV9ecD9ZEe87{{NtI*)_aJ<`kJa z?5=RBtFF50s;jQLFil-`)m2wrb=6h(&brpj%nG_U&ut~$?8Rokzxi8zJoWr#2dto5 zOX_URcc<1`Iky+jc;A%Vzx}1QU{2$|cKPom2Vf1{8m`vja4{F>HS?^Nc^rp}xo+Nh zxd}eOm`fm3@MQC1< zIk&aCjb~Yh%5+Yq0`)D;q{#-Uqlv*o+Oor zE!I71Z@ASH3grl8&P^L0WpavHoP|UX4e?!igT`4?AZk$hu*@%6WJ;zDOGlw7kj@ zY5!B-0ft0f?Lgb>C;$Ke07*qoM6N<$f~t1N9smFU literal 0 HcmV?d00001 diff --git a/kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png b/kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..0ec303439225b78712f49115768196d8d76f6790 GIT binary patch literal 862 zcmV-k1EKthP)20Z)wqMt%V?S?~D#06};F zA3KcL`Wb+>5ObvgQIG&ig8(;V04hz?@cqy3{mSh8o!|U|)cI!1_+!fWH@o*8vh^CU z^ws0;(c$gI+2~q^tO#GDHf@=;DncUw00J^eL_t(&-tE|HQ`%4vfZ;WsBqu-$0nu1R zq^Vj;p$clf^?twn|KHO+IGt^q#a3X?w9dXC@*yxhv&l}F322(8Y1&=P&I}~G@#h6; z1CV9ecD9ZEe87{{NtI*)_aJ<`kJa z?5=RBtFF50s;jQLFil-`)m2wrb=6h(&brpj%nG_U&ut~$?8Rokzxi8zJoWr#2dto5 zOX_URcc<1`Iky+jc;A%Vzx}1QU{2$|cKPom2Vf1{8m`vja4{F>HS?^Nc^rp}xo+Nh zxd}eOm`fm3@MQC1< zIk&aCjb~Yh%5+Yq0`)D;q{#-Uqlv*o+Oor zE!I71Z@ASH3grl8&P^L0WpavHoP|UX4e?!igT`4?AZk$hu*@%6WJ;zDOGlw7kj@ zY5!B-0ft0f?Lgb>C;$Ke07*qoM6N<$f~t1N9smFU literal 0 HcmV?d00001 diff --git a/kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png b/kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png new file mode 100644 index 0000000000000000000000000000000000000000..e9f5fea27c705180eb716271f41b582e76dcbd90 GIT binary patch literal 1674 zcmV;526g#~P){YQnis^a@{&-nmRmq)<&%Mztj67_#M}W?l>kYSliK<%xAp;0j{!}J0!o7b zE>q9${Lb$D&h7k=+4=!ek^n+`0zq>LL1O?lVyea53S5x`Nqqo2YyeuIrQrJj9XjOp z{;T5qbj3}&1vg1VK~#9!?b~^C5-}JC@Pyrv-6dSEqJqT}#j9#dJ@GzT@B8}x zU&J@bBI>f6w6en+CeI)3^kC*U?}X%OD8$Fd$H&LV$H&LV$H&LV#|K5~mLYf|VqzOc zkc7qL~0sOYuM{tG`rYEDV{DWY`Z8&)kW*hc2VkBuY+^Yx&92j&StN}Wp=LD zxoGxXw6f&8sB^u})h@b@z0RBeD`K7RMR9deyL(ZJu#39Z>rT)^>v}Khq8U-IbIvT> z?4pV9qGj=2)TNH3d)=De<+^w;>S7m_eFKTvzeaBeir45xY!^m!FmxnljbSS_3o=g( z->^wC9%qkR{kbGnW8MfFew_o9h3(r55Is`L$8KI@d+*%{=Nx+FXJ98L0PjFIu;rGnnfY zn1R5Qnp<{Jq0M1vX=X&F8gtLmcWv$1*M@4ZfF^9``()#hGTeKeP`1!iED ztNE(TN}M5}3Bbc*d=FIv`DNv&@|C6yYj{sSqUj5oo$#*0$7pu|Dd2TLI>t5%I zIa4Dvr(iayb+5x=j*Vum9&irk)xV1`t509lnPO0%skL8_1c#Xbamh(2@f?4yUI zhhuT5<#8RJhGz4%b$`PJwKPAudsm|at?u;*hGgnA zU1;9gnxVBC)wA(BsB`AW54N{|qmikJR*%x0c`{LGsSfa|NK61pYH(r-UQ4_JXd!Rsz)=k zL{GMc5{h138)fF5CzHEDM>+FqY)$pdN3}Ml+riTgJOLN0F*Vh?{9ESR{SVVg>*>=# zix;VJHPtvFFCRY$Ks*F;VX~%*r9F)W`PmPE9F!(&s#x07n2<}?S{(ygpXgX-&B&OM zONY&BRQ(#%0%jeQs?oJ4P!p*R98>qCy5p8w>_gpuh39NcOlp)(wOoz0sY-Qz55eB~ z7OC-fKBaD1sE3$l-6QgBJO!n?QOTza`!S_YK z_v-lm^7{VO^8Q@M_^8F)09Ki6%=s?2_5eupee(w1FB%aqSweusQ-T+CH0Xt{` zFjMvW{@C&TB)k25()nh~_yJ9coBRL(0oO@HK~z}7?bm5j;y@69;bvlHb2tf!$ReA~x{22wTq550 z?f?Hnw(;m3ip30;QzdV~7pi!wyMYhDtXW#cO7T>|f=bdFhu+F!zMZ2UFj;GUKX7tI z;hv3{q~!*pMj75WP_c}>6)IWvg5_yyg<9Op()eD1hWC19M@?_9_MHec{Z8n3FaF{8 z;u`Mw0ly(uE>*CgQYv{be6ab2LWhlaH1^iLIM{olnag$78^Fd}%dR7;JECQ+hmk|o z!u2&!3MqPfP5ChDSkFSH8F2WVOEf0(E_M(JL17G}Y+fg0_IuW%WQ zG(mG&u?|->YSdk0;8rc{yw2@2Z&GA}z{Wb91Ooz9VhA{b2DYE7RmG zjL}?eq#iX%3#k;JWMx_{^2nNax`xPhByFiDX+a7uTGU|otOvIAUy|dEKkXOm-`aWS z27pUzD{a)Ct<6p{{3)+lq@i`t@%>-wT4r?*S}k)58e09WZYP0{{R3FC5Sl00039P)t-s|Ns9~ z#rP?<_5oL$Q^olD{r_0T`27C={r>*`|Nj71npVa5OTzc(_WfbW_({R{p56NV{r*M2 z_xt?)2V0#0NsfV0u>{42ctGP(8vQj-Btk1n|O0ZD=YLwd&R{Ko41Gr9H= zY@z@@bOAMB5Ltl$E>bJJ{>JP30ZxkmI%?eW{k`b?Wy<&gOo;dS`~CR$Vwb@XWtR|N zi~t=w02?-0&j0TD{>bb6sNwsK*!p?V`RMQUl(*DVjk-9Cx+-z1KXab|Ka2oXhX5f% z`$|e!000AhNklrxs)5QTeTVRiEmz~MKK1WAjCw(c-JK6eox;2O)?`? zTG`AHia671e^vgmp!llKp|=5sVHk#C7=~epA~VAf-~%aPC=%Qw01h8mnSZ|p?hz91 z7p83F3%LVu9;S$tSI$C^%^yud1dfTM_6p2|+5Ejp$bd`GDvbR|xit>i!ZD&F>@CJrPmu*UjD&?DfZs=$@e3FQA(vNiU+$A*%a} z?`XcG2jDxJ_ZQ#Md`H{4Lpf6QBDp81_KWZ6Tk#yCy1)32zO#3<7>b`eT7UyYH1eGz z;O(rH$=QR*L%%ZcBpc=eGua?N55nD^K(8<#gl2+pN_j~b2MHs4#mcLmv%DkspS-3< zpI1F=^9siI0s-;IN_IrA;5xm~3?3!StX}pUv0vkxMaqm+zxrg7X7(I&*N~&dEd0kD z-FRV|g=|QuUsuh>-xCI}vD2imzYIOIdcCVV=$Bz@*u0+Bs<|L^)32nN*=wu3n%Ynw z@1|eLG>!8ruU1pFXUfb`j>(=Gy~?Rn4QJ-c3%3T|(Frd!bI`9u&zAnyFYTqlG#&J7 zAkD(jpw|oZLNiA>;>hgp1KX7-wxC~31II47gc zHcehD6Uxlf%+M^^uN5Wc*G%^;>D5qT{>=uxUhX%WJu^Z*(_Wq9y}npFO{Hhb>s6<9 zNi0pHXWFaVZnb)1+RS&F)xOv6&aeILcI)`k#0YE+?e)5&#r7J#c`3Z7x!LpTc01dx zrdC3{Z;joZ^KN&))zB_i)I9fWedoN>Zl-6_Iz+^G&*ak2jpF07*qoM6N<$f;w%0(f|Me literal 0 HcmV?d00001 diff --git a/kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png b/kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..0467bf12aa4d28f374bb26596605a46dcbb3e7c8 GIT binary patch literal 1418 zcmV;51$Fv~P)q zKfU)WzW*n(@|xWGCA9ScMt*e9`2kdxPQ&&>|-UCa7_51w+ zLUsW@ZzZSW0y$)Hp~e9%PvP|a03ks1`~K?q{u;6NC8*{AOqIUq{CL&;p56Lf$oQGq z^={4hPQv)y=I|4n+?>7Fim=dxt1 z2H+Dm+1+fh+IF>G0SjJMkQQre1x4|G*Z==(Ot&kCnUrL4I(rf(ucITwmuHf^hXiJT zkdTm&kdTm&kdTm&kdP`esgWG0BcWCVkVZ&2dUwN`cgM8QJb`Z7Z~e<&Yj2(}>Tmf` zm1{eLgw!b{bXkjWbF%dTkTZEJWyWOb##Lfw4EK2}<0d6%>AGS{po>WCOy&f$Tay_> z?NBlkpo@s-O;0V%Y_Xa-G#_O08q5LR*~F%&)}{}r&L%Sbs8AS4t7Y0NEx*{soY=0MZExqA5XHQkqi#4gW3 zqODM^iyZl;dvf)-bOXtOru(s)Uc7~BFx{w-FK;2{`VA?(g&@3z&bfLFyctOH!cVsF z7IL=fo-qBndRUm;kAdXR4e6>k-z|21AaN%ubeVrHl*<|s&Ax@W-t?LR(P-24A5=>a z*R9#QvjzF8n%@1Nw@?CG@6(%>+-0ASK~jEmCV|&a*7-GKT72W<(TbSjf)&Eme6nGE z>Gkj4Sq&2e+-G%|+NM8OOm5zVl9{Z8Dd8A5z3y8mZ=4Bv4%>as_{9cN#bm~;h>62( zdqY93Zy}v&c4n($Vv!UybR8ocs7#zbfX1IY-*w~)p}XyZ-SFC~4w>BvMVr`dFbelV{lLL0bx7@*ZZdebr3`sP;? zVImji)kG)(6Juv0lz@q`F!k1FE;CQ(D0iG$wchPbKZQELlsZ#~rt8#90Y_Xh&3U-< z{s<&cCV_1`^TD^ia9!*mQDq& zn2{r`j};V|uV%_wsP!zB?m%;FeaRe+X47K0e+KE!8C{gAWF8)lCd1u1%~|M!XNRvw zvtqy3iz0WSpWdhn6$hP8PaRBmp)q`#PCA`Vd#Tc$@f1tAcM>f_I@bC)hkI9|o(Iqv zo}Piadq!j76}004RBio<`)70k^`K1NK)q>w?p^C6J2ZC!+UppiK6&y3Kmbv&O!oYF z34$0Z;QO!JOY#!`qyGH<3Pd}Pt@q*A0V=3SVtWKRR8d8Z&@)3qLPA19LPA19LPEUC YUoZo%k(ykuW&i*H07*qoM6N<$f+CH{y8r+H literal 0 HcmV?d00001 diff --git a/kratos-flutter/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json b/kratos-flutter/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json new file mode 100644 index 00000000..0bedcf2f --- /dev/null +++ b/kratos-flutter/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "LaunchImage.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "LaunchImage@2x.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "filename" : "LaunchImage@3x.png", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} diff --git a/kratos-flutter/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png b/kratos-flutter/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png new file mode 100644 index 0000000000000000000000000000000000000000..9da19eacad3b03bb08bbddbbf4ac48dd78b3d838 GIT binary patch literal 68 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx0wlM}@Gt=>Zci7-kcv6Uzs@r-FtIZ-&5|)J Q1PU{Fy85}Sb4q9e0B4a5jsO4v literal 0 HcmV?d00001 diff --git a/kratos-flutter/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png b/kratos-flutter/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..9da19eacad3b03bb08bbddbbf4ac48dd78b3d838 GIT binary patch literal 68 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx0wlM}@Gt=>Zci7-kcv6Uzs@r-FtIZ-&5|)J Q1PU{Fy85}Sb4q9e0B4a5jsO4v literal 0 HcmV?d00001 diff --git a/kratos-flutter/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png b/kratos-flutter/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png new file mode 100644 index 0000000000000000000000000000000000000000..9da19eacad3b03bb08bbddbbf4ac48dd78b3d838 GIT binary patch literal 68 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx0wlM}@Gt=>Zci7-kcv6Uzs@r-FtIZ-&5|)J Q1PU{Fy85}Sb4q9e0B4a5jsO4v literal 0 HcmV?d00001 diff --git a/kratos-flutter/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md b/kratos-flutter/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md new file mode 100644 index 00000000..89c2725b --- /dev/null +++ b/kratos-flutter/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md @@ -0,0 +1,5 @@ +# Launch Screen Assets + +You can customize the launch screen with your own desired assets by replacing the image files in this directory. + +You can also do it by opening your Flutter project's Xcode project with `open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project Navigator and dropping in the desired images. \ No newline at end of file diff --git a/kratos-flutter/ios/Runner/Base.lproj/LaunchScreen.storyboard b/kratos-flutter/ios/Runner/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 00000000..f2e259c7 --- /dev/null +++ b/kratos-flutter/ios/Runner/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/kratos-flutter/ios/Runner/Base.lproj/Main.storyboard b/kratos-flutter/ios/Runner/Base.lproj/Main.storyboard new file mode 100644 index 00000000..f3c28516 --- /dev/null +++ b/kratos-flutter/ios/Runner/Base.lproj/Main.storyboard @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/kratos-flutter/ios/Runner/Info.plist b/kratos-flutter/ios/Runner/Info.plist new file mode 100644 index 00000000..70201f08 --- /dev/null +++ b/kratos-flutter/ios/Runner/Info.plist @@ -0,0 +1,51 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleDisplayName + Kratos Flutter + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + kratos_flutter + CFBundlePackageType + APPL + CFBundleShortVersionString + $(FLUTTER_BUILD_NAME) + CFBundleSignature + ???? + CFBundleVersion + $(FLUTTER_BUILD_NUMBER) + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UIViewControllerBasedStatusBarAppearance + + CADisableMinimumFrameDurationOnPhone + + UIApplicationSupportsIndirectInputEvents + + + diff --git a/kratos-flutter/ios/Runner/Runner-Bridging-Header.h b/kratos-flutter/ios/Runner/Runner-Bridging-Header.h new file mode 100644 index 00000000..308a2a56 --- /dev/null +++ b/kratos-flutter/ios/Runner/Runner-Bridging-Header.h @@ -0,0 +1 @@ +#import "GeneratedPluginRegistrant.h" diff --git a/kratos-flutter/ios/RunnerTests/RunnerTests.swift b/kratos-flutter/ios/RunnerTests/RunnerTests.swift new file mode 100644 index 00000000..86a7c3b1 --- /dev/null +++ b/kratos-flutter/ios/RunnerTests/RunnerTests.swift @@ -0,0 +1,12 @@ +import Flutter +import UIKit +import XCTest + +class RunnerTests: XCTestCase { + + func testExample() { + // If you add code to the Runner application, consider adding tests here. + // See https://developer.apple.com/documentation/xctest for more information about using XCTest. + } + +} diff --git a/kratos-flutter/lib/blocs/auth/auth_bloc.dart b/kratos-flutter/lib/blocs/auth/auth_bloc.dart new file mode 100644 index 00000000..bfbb4982 --- /dev/null +++ b/kratos-flutter/lib/blocs/auth/auth_bloc.dart @@ -0,0 +1,44 @@ +import 'package:bloc/bloc.dart'; +import 'package:equatable/equatable.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:ory_client/ory_client.dart'; + +import '../../repositories/auth.dart'; +import '../../services/exceptions.dart'; + +part 'auth_event.dart'; +part 'auth_state.dart'; +part 'auth_bloc.freezed.dart'; + +class AuthBloc extends Bloc { + final AuthRepository repository; + AuthBloc({required this.repository}) + : super(const AuthState(status: AuthStatus.uninitialized)) { + on(_onGetCurrentSessionInformation); + on(_changeAuthStatus); + } + + _changeAuthStatus(ChangeAuthStatus event, Emitter emit) { + emit(state.copyWith(status: event.status)); + } + + Future _onGetCurrentSessionInformation( + GetCurrentSessionInformation event, Emitter emit) async { + try { + emit(state.copyWith(isLoading: true, errorMessage: null)); + final session = await repository.getCurrentSessionInformation(); + emit(state.copyWith( + isLoading: false, + status: AuthStatus.authenticated, + session: session)); + } on CustomException catch (e) { + if (e.exceptionType == OryExceptionType.unauthorizedException) { + emit(state.copyWith( + status: AuthStatus.unauthenticated, + isLoading: false, + errorMessage: e.message)); + } + emit(state.copyWith(isLoading: false, errorMessage: e.message)); + } + } +} diff --git a/kratos-flutter/lib/blocs/auth/auth_bloc.freezed.dart b/kratos-flutter/lib/blocs/auth/auth_bloc.freezed.dart new file mode 100644 index 00000000..02acfd8b --- /dev/null +++ b/kratos-flutter/lib/blocs/auth/auth_bloc.freezed.dart @@ -0,0 +1,198 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'auth_bloc.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +mixin _$AuthState { + AuthStatus get status => throw _privateConstructorUsedError; + Session? get session => throw _privateConstructorUsedError; + bool get isLoading => throw _privateConstructorUsedError; + String? get errorMessage => throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $AuthStateCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $AuthStateCopyWith<$Res> { + factory $AuthStateCopyWith(AuthState value, $Res Function(AuthState) then) = + _$AuthStateCopyWithImpl<$Res, AuthState>; + @useResult + $Res call( + {AuthStatus status, + Session? session, + bool isLoading, + String? errorMessage}); +} + +/// @nodoc +class _$AuthStateCopyWithImpl<$Res, $Val extends AuthState> + implements $AuthStateCopyWith<$Res> { + _$AuthStateCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? status = null, + Object? session = freezed, + Object? isLoading = null, + Object? errorMessage = freezed, + }) { + return _then(_value.copyWith( + status: null == status + ? _value.status + : status // ignore: cast_nullable_to_non_nullable + as AuthStatus, + session: freezed == session + ? _value.session + : session // ignore: cast_nullable_to_non_nullable + as Session?, + isLoading: null == isLoading + ? _value.isLoading + : isLoading // ignore: cast_nullable_to_non_nullable + as bool, + errorMessage: freezed == errorMessage + ? _value.errorMessage + : errorMessage // ignore: cast_nullable_to_non_nullable + as String?, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$_AuthStateCopyWith<$Res> implements $AuthStateCopyWith<$Res> { + factory _$$_AuthStateCopyWith( + _$_AuthState value, $Res Function(_$_AuthState) then) = + __$$_AuthStateCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {AuthStatus status, + Session? session, + bool isLoading, + String? errorMessage}); +} + +/// @nodoc +class __$$_AuthStateCopyWithImpl<$Res> + extends _$AuthStateCopyWithImpl<$Res, _$_AuthState> + implements _$$_AuthStateCopyWith<$Res> { + __$$_AuthStateCopyWithImpl( + _$_AuthState _value, $Res Function(_$_AuthState) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? status = null, + Object? session = freezed, + Object? isLoading = null, + Object? errorMessage = freezed, + }) { + return _then(_$_AuthState( + status: null == status + ? _value.status + : status // ignore: cast_nullable_to_non_nullable + as AuthStatus, + session: freezed == session + ? _value.session + : session // ignore: cast_nullable_to_non_nullable + as Session?, + isLoading: null == isLoading + ? _value.isLoading + : isLoading // ignore: cast_nullable_to_non_nullable + as bool, + errorMessage: freezed == errorMessage + ? _value.errorMessage + : errorMessage // ignore: cast_nullable_to_non_nullable + as String?, + )); + } +} + +/// @nodoc + +class _$_AuthState implements _AuthState { + const _$_AuthState( + {required this.status, + this.session, + this.isLoading = false, + this.errorMessage}); + + @override + final AuthStatus status; + @override + final Session? session; + @override + @JsonKey() + final bool isLoading; + @override + final String? errorMessage; + + @override + String toString() { + return 'AuthState(status: $status, session: $session, isLoading: $isLoading, errorMessage: $errorMessage)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$_AuthState && + (identical(other.status, status) || other.status == status) && + (identical(other.session, session) || other.session == session) && + (identical(other.isLoading, isLoading) || + other.isLoading == isLoading) && + (identical(other.errorMessage, errorMessage) || + other.errorMessage == errorMessage)); + } + + @override + int get hashCode => + Object.hash(runtimeType, status, session, isLoading, errorMessage); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$_AuthStateCopyWith<_$_AuthState> get copyWith => + __$$_AuthStateCopyWithImpl<_$_AuthState>(this, _$identity); +} + +abstract class _AuthState implements AuthState { + const factory _AuthState( + {required final AuthStatus status, + final Session? session, + final bool isLoading, + final String? errorMessage}) = _$_AuthState; + + @override + AuthStatus get status; + @override + Session? get session; + @override + bool get isLoading; + @override + String? get errorMessage; + @override + @JsonKey(ignore: true) + _$$_AuthStateCopyWith<_$_AuthState> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/kratos-flutter/lib/blocs/auth/auth_event.dart b/kratos-flutter/lib/blocs/auth/auth_event.dart new file mode 100644 index 00000000..8a138130 --- /dev/null +++ b/kratos-flutter/lib/blocs/auth/auth_event.dart @@ -0,0 +1,21 @@ +part of 'auth_bloc.dart'; + +@immutable +sealed class AuthEvent extends Equatable { + @override + List get props => []; +} + +final class ChangeAuthStatus extends AuthEvent { + final AuthStatus status; + + ChangeAuthStatus({required this.status}); + @override + List get props => [status]; +} + +//get current session information +final class GetCurrentSessionInformation extends AuthEvent {} + +//log out +final class LogOut extends AuthEvent {} diff --git a/kratos-flutter/lib/blocs/auth/auth_state.dart b/kratos-flutter/lib/blocs/auth/auth_state.dart new file mode 100644 index 00000000..afc06e01 --- /dev/null +++ b/kratos-flutter/lib/blocs/auth/auth_state.dart @@ -0,0 +1,10 @@ +part of 'auth_bloc.dart'; + +@freezed +sealed class AuthState with _$AuthState { + const factory AuthState( + {required AuthStatus status, + Session? session, + @Default(false) bool isLoading, + String? errorMessage}) = _AuthState; +} diff --git a/kratos-flutter/lib/main.dart b/kratos-flutter/lib/main.dart new file mode 100644 index 00000000..5457e10b --- /dev/null +++ b/kratos-flutter/lib/main.dart @@ -0,0 +1,128 @@ +import 'package:dio/dio.dart'; +import 'package:dio/io.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:flutter_dotenv/flutter_dotenv.dart'; + +import 'blocs/auth/auth_bloc.dart'; +import 'pages/home.dart'; +import 'pages/login.dart'; +import 'pages/entry.dart'; +import 'repositories/auth.dart'; +import 'services/auth.dart'; + +Future main() async { + await dotenv.load(fileName: '.env'); + final baseUrl = dotenv.get('ORY_BASE_URL'); + + // create the dio client for http requests + final options = BaseOptions( + baseUrl: baseUrl, + connectTimeout: const Duration(seconds: 10000), + receiveTimeout: const Duration(seconds: 5000), + headers: { + 'Accept': 'application/json', + }, + validateStatus: (status) { + // here we prevent the request from throwing an error when the status code is less than 500 (internal server error) + return status! < 500; + }, + ); + final dio = DioForNative(options); + + final authService = AuthService(dio); + final authRepository = AuthRepository(service: authService); + runApp(RepositoryProvider.value( + value: authRepository, + child: BlocProvider( + create: (context) => AuthBloc(repository: authRepository) + ..add(GetCurrentSessionInformation()), + child: const MyApp(), + ))); +} + +class MyApp extends StatelessWidget { + const MyApp({super.key}); + + // This widget is the root of your application. + @override + Widget build(BuildContext context) { + return MaterialApp( + title: 'Flutter Demo', + theme: ThemeData( + // This is the theme of your application. + // + // TRY THIS: Try running your application with "flutter run". You'll see + // the application has a blue toolbar. Then, without quitting the app, + // try changing the seedColor in the colorScheme below to Colors.green + // and then invoke "hot reload" (save your changes or press the "hot + // reload" button in a Flutter-supported IDE, or press "r" if you used + // the command line to start the app). + // + // Notice that the counter didn't reset back to zero; the application + // state is not lost during the reload. To reset the state, use hot + // restart instead. + // + // This works for code too, not just values: Most code changes can be + // tested with just a hot reload. + colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), + useMaterial3: true, + ), + home: const MyAppView(title: 'Flutter Demo Home Page'), + ); + } +} + +class MyAppView extends StatefulWidget { + const MyAppView({super.key, required this.title}); + + // This widget is the home page of your application. It is stateful, meaning + // that it has a State object (defined below) that contains fields that affect + // how it looks. + + // This class is the configuration for the state. It holds the values (in this + // case the title) provided by the parent (in this case the App widget) and + // used by the build method of the State. Fields in a Widget subclass are + // always marked "final". + + final String title; + + @override + State createState() => _MyAppViewState(); +} + +class _MyAppViewState extends State { + final _navigatorKey = GlobalKey(); + + NavigatorState get _navigator => _navigatorKey.currentState!; + + @override + Widget build(BuildContext context) { + return MaterialApp( + navigatorKey: _navigatorKey, + builder: (context, child) { + return BlocListener( + listener: (context, state) { + switch (state.status) { + case AuthStatus.authenticated: + _navigator.pushAndRemoveUntil( + MaterialPageRoute( + builder: (BuildContext context) => const HomePage()), + (Route route) => false); + case AuthStatus.unauthenticated: + _navigator.pushAndRemoveUntil( + MaterialPageRoute( + builder: (BuildContext context) => const LoginPage()), + (Route route) => false); + case AuthStatus.uninitialized: + break; + } + }, + child: child, + ); + }, + onGenerateRoute: (_) => MaterialPageRoute( + builder: (BuildContext context) => const EntryPage()), + ); + } +} diff --git a/kratos-flutter/lib/pages/entry.dart b/kratos-flutter/lib/pages/entry.dart new file mode 100644 index 00000000..888aab1c --- /dev/null +++ b/kratos-flutter/lib/pages/entry.dart @@ -0,0 +1,12 @@ +import 'package:flutter/material.dart'; + +class EntryPage extends StatelessWidget { + const EntryPage({super.key}); + + @override + Widget build(BuildContext context) { + return const Scaffold( + body: Center(child: CircularProgressIndicator()), + ); + } +} diff --git a/kratos-flutter/lib/pages/home.dart b/kratos-flutter/lib/pages/home.dart new file mode 100644 index 00000000..c47a819f --- /dev/null +++ b/kratos-flutter/lib/pages/home.dart @@ -0,0 +1,12 @@ +import 'package:flutter/material.dart'; + +class HomePage extends StatelessWidget { + const HomePage({super.key}); + + @override + Widget build(BuildContext context) { + return const Scaffold( + body: Center(child: Text('logged in')), + ); + } +} diff --git a/kratos-flutter/lib/pages/login.dart b/kratos-flutter/lib/pages/login.dart new file mode 100644 index 00000000..04996e77 --- /dev/null +++ b/kratos-flutter/lib/pages/login.dart @@ -0,0 +1,12 @@ +import 'package:flutter/material.dart'; + +class LoginPage extends StatelessWidget { + const LoginPage({super.key}); + + @override + Widget build(BuildContext context) { + return const Scaffold( + body: Center(child: Text('log in')), + ); + } +} diff --git a/kratos-flutter/lib/repositories/auth.dart b/kratos-flutter/lib/repositories/auth.dart new file mode 100644 index 00000000..b6093b0b --- /dev/null +++ b/kratos-flutter/lib/repositories/auth.dart @@ -0,0 +1,16 @@ +import 'package:ory_client/ory_client.dart'; + +import '../services/auth.dart'; + +enum AuthStatus { uninitialized, authenticated, unauthenticated } + +class AuthRepository { + final AuthService service; + + AuthRepository({required this.service}); + + Future getCurrentSessionInformation() async { + final session = await service.getCurrentSessionInformation(); + return session; + } +} diff --git a/kratos-flutter/lib/services/auth.dart b/kratos-flutter/lib/services/auth.dart new file mode 100644 index 00000000..1cc109c4 --- /dev/null +++ b/kratos-flutter/lib/services/auth.dart @@ -0,0 +1,25 @@ +import 'package:dio/dio.dart'; +import 'package:ory_client/ory_client.dart'; + +import 'exceptions.dart'; +import 'storage.dart'; + +class AuthService { + final storage = SecureStorage(); + final FrontendApi _ory; + AuthService(Dio dio) : _ory = OryClient(dio: dio).getFrontendApi(); + + Future getCurrentSessionInformation() async { + try { + final token = await storage.getToken(); + final response = await _ory.toSession(xSessionToken: token); + if (response.data != null) { + return response.data!; + } else { + throw DioException(requestOptions: response.requestOptions); + } + } on DioException catch (e) { + throw CustomException.fromDioException(e); + } + } +} diff --git a/kratos-flutter/lib/services/exceptions.dart b/kratos-flutter/lib/services/exceptions.dart new file mode 100644 index 00000000..bb4b7f03 --- /dev/null +++ b/kratos-flutter/lib/services/exceptions.dart @@ -0,0 +1,55 @@ +import 'package:dio/dio.dart'; + +enum OryExceptionType { + //exception for an expired session token. + unauthorizedException, + + //exception for an incorrect parameter in a request/response. + badRequestException, + + //The exception for an unknown type of failure. + unknownException, + + //The exception for an expired flow + flowExpiredException +} + +class CustomException implements Exception { + final String? message; + + final int? statusCode; + final OryExceptionType exceptionType; + + CustomException({ + statusCode, + this.message = 'An error occured. Please try again later', + this.exceptionType = OryExceptionType.unknownException, + }) : statusCode = statusCode ?? 500; + + factory CustomException.fromDioException(DioException error) { + try { + switch (error.type) { + case DioExceptionType.unknown: + if (error.response?.statusCode == 401) { + return CustomException( + exceptionType: OryExceptionType.unauthorizedException, + statusCode: error.response?.statusCode, + message: error.response?.data?['error']['message'], + ); + } else if (error.response?.statusCode == 410) { + return CustomException( + exceptionType: OryExceptionType.flowExpiredException, + statusCode: error.response?.statusCode, + message: error.response?.data?['error']['message'], + ); + } else { + return CustomException(statusCode: error.response?.statusCode); + } + default: + return CustomException(statusCode: error.response?.statusCode); + } + } on Exception catch (_) { + return CustomException(); + } + } +} diff --git a/kratos-flutter/lib/services/storage.dart b/kratos-flutter/lib/services/storage.dart new file mode 100644 index 00000000..cad86b14 --- /dev/null +++ b/kratos-flutter/lib/services/storage.dart @@ -0,0 +1,34 @@ +import 'package:flutter_secure_storage/flutter_secure_storage.dart'; + +class SecureStorage { + static SecureStorage? _instance; + + factory SecureStorage() => + _instance ?? SecureStorage._(const FlutterSecureStorage()); + + SecureStorage._(this._storage); + + final FlutterSecureStorage _storage; + static const _tokenKey = 'TOKEN'; + + Future persistToken(String token) async { + await _storage.write(key: _tokenKey, value: token); + } + + Future hasToken() async { + var value = await _storage.read(key: _tokenKey); + return value != null; + } + + Future deleteToken() async { + return _storage.delete(key: _tokenKey); + } + + Future getToken() async { + return _storage.read(key: _tokenKey); + } + + Future deleteAll() async { + return _storage.deleteAll(); + } +} diff --git a/kratos-flutter/pubspec.lock b/kratos-flutter/pubspec.lock new file mode 100644 index 00000000..638b75e0 --- /dev/null +++ b/kratos-flutter/pubspec.lock @@ -0,0 +1,818 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + _fe_analyzer_shared: + dependency: transitive + description: + name: _fe_analyzer_shared + sha256: eb376e9acf6938204f90eb3b1f00b578640d3188b4c8a8ec054f9f479af8d051 + url: "https://pub.dev" + source: hosted + version: "64.0.0" + analyzer: + dependency: transitive + description: + name: analyzer + sha256: "69f54f967773f6c26c7dcb13e93d7ccee8b17a641689da39e878d5cf13b06893" + url: "https://pub.dev" + source: hosted + version: "6.2.0" + args: + dependency: transitive + description: + name: args + sha256: eef6c46b622e0494a36c5a12d10d77fb4e855501a91c1b9ef9339326e58f0596 + url: "https://pub.dev" + source: hosted + version: "2.4.2" + async: + dependency: transitive + description: + name: async + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" + source: hosted + version: "2.11.0" + bloc: + dependency: "direct main" + description: + name: bloc + sha256: "3820f15f502372d979121de1f6b97bfcf1630ebff8fe1d52fb2b0bfa49be5b49" + url: "https://pub.dev" + source: hosted + version: "8.1.2" + boolean_selector: + dependency: transitive + description: + name: boolean_selector + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + build: + dependency: transitive + description: + name: build + sha256: "80184af8b6cb3e5c1c4ec6d8544d27711700bc3e6d2efad04238c7b5290889f0" + url: "https://pub.dev" + source: hosted + version: "2.4.1" + build_config: + dependency: transitive + description: + name: build_config + sha256: bf80fcfb46a29945b423bd9aad884590fb1dc69b330a4d4700cac476af1708d1 + url: "https://pub.dev" + source: hosted + version: "1.1.1" + build_daemon: + dependency: transitive + description: + name: build_daemon + sha256: "5f02d73eb2ba16483e693f80bee4f088563a820e47d1027d4cdfe62b5bb43e65" + url: "https://pub.dev" + source: hosted + version: "4.0.0" + build_resolvers: + dependency: transitive + description: + name: build_resolvers + sha256: "6c4dd11d05d056e76320b828a1db0fc01ccd376922526f8e9d6c796a5adbac20" + url: "https://pub.dev" + source: hosted + version: "2.2.1" + build_runner: + dependency: "direct dev" + description: + name: build_runner + sha256: "10c6bcdbf9d049a0b666702cf1cee4ddfdc38f02a19d35ae392863b47519848b" + url: "https://pub.dev" + source: hosted + version: "2.4.6" + build_runner_core: + dependency: transitive + description: + name: build_runner_core + sha256: "6d6ee4276b1c5f34f21fdf39425202712d2be82019983d52f351c94aafbc2c41" + url: "https://pub.dev" + source: hosted + version: "7.2.10" + built_collection: + dependency: transitive + description: + name: built_collection + sha256: "376e3dd27b51ea877c28d525560790aee2e6fbb5f20e2f85d5081027d94e2100" + url: "https://pub.dev" + source: hosted + version: "5.1.1" + built_value: + dependency: transitive + description: + name: built_value + sha256: "598a2a682e2a7a90f08ba39c0aaa9374c5112340f0a2e275f61b59389543d166" + url: "https://pub.dev" + source: hosted + version: "8.6.1" + characters: + dependency: transitive + description: + name: characters + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" + source: hosted + version: "1.3.0" + checked_yaml: + dependency: transitive + description: + name: checked_yaml + sha256: feb6bed21949061731a7a75fc5d2aa727cf160b91af9a3e464c5e3a32e28b5ff + url: "https://pub.dev" + source: hosted + version: "2.0.3" + clock: + dependency: transitive + description: + name: clock + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" + source: hosted + version: "1.1.1" + code_builder: + dependency: transitive + description: + name: code_builder + sha256: "4ad01d6e56db961d29661561effde45e519939fdaeb46c351275b182eac70189" + url: "https://pub.dev" + source: hosted + version: "4.5.0" + collection: + dependency: transitive + description: + name: collection + sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c" + url: "https://pub.dev" + source: hosted + version: "1.17.1" + convert: + dependency: transitive + description: + name: convert + sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592" + url: "https://pub.dev" + source: hosted + version: "3.1.1" + crypto: + dependency: transitive + description: + name: crypto + sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab + url: "https://pub.dev" + source: hosted + version: "3.0.3" + cupertino_icons: + dependency: "direct main" + description: + name: cupertino_icons + sha256: e35129dc44c9118cee2a5603506d823bab99c68393879edb440e0090d07586be + url: "https://pub.dev" + source: hosted + version: "1.0.5" + dart_style: + dependency: transitive + description: + name: dart_style + sha256: "1efa911ca7086affd35f463ca2fc1799584fb6aa89883cf0af8e3664d6a02d55" + url: "https://pub.dev" + source: hosted + version: "2.3.2" + dio: + dependency: "direct main" + description: + name: dio + sha256: ce75a1b40947fea0a0e16ce73337122a86762e38b982e1ccb909daa3b9bc4197 + url: "https://pub.dev" + source: hosted + version: "5.3.2" + dotenv: + dependency: "direct main" + description: + name: dotenv + sha256: e169b516bc7b88801919e1c508772bcb8e3d0d1776a43f74ab692c57e741cd8a + url: "https://pub.dev" + source: hosted + version: "4.1.0" + equatable: + dependency: "direct main" + description: + name: equatable + sha256: c2b87cb7756efdf69892005af546c56c0b5037f54d2a88269b4f347a505e3ca2 + url: "https://pub.dev" + source: hosted + version: "2.0.5" + fake_async: + dependency: transitive + description: + name: fake_async + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" + source: hosted + version: "1.3.1" + ffi: + dependency: transitive + description: + name: ffi + sha256: "7bf0adc28a23d395f19f3f1eb21dd7cfd1dd9f8e1c50051c069122e6853bc878" + url: "https://pub.dev" + source: hosted + version: "2.1.0" + file: + dependency: transitive + description: + name: file + sha256: "1b92bec4fc2a72f59a8e15af5f52cd441e4a7860b49499d69dfa817af20e925d" + url: "https://pub.dev" + source: hosted + version: "6.1.4" + fixnum: + dependency: transitive + description: + name: fixnum + sha256: "25517a4deb0c03aa0f32fd12db525856438902d9c16536311e76cdc57b31d7d1" + url: "https://pub.dev" + source: hosted + version: "1.1.0" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + flutter_bloc: + dependency: "direct main" + description: + name: flutter_bloc + sha256: e74efb89ee6945bcbce74a5b3a5a3376b088e5f21f55c263fc38cbdc6237faae + url: "https://pub.dev" + source: hosted + version: "8.1.3" + flutter_dotenv: + dependency: "direct main" + description: + name: flutter_dotenv + sha256: "9357883bdd153ab78cbf9ffa07656e336b8bbb2b5a3ca596b0b27e119f7c7d77" + url: "https://pub.dev" + source: hosted + version: "5.1.0" + flutter_lints: + dependency: "direct dev" + description: + name: flutter_lints + sha256: "2118df84ef0c3ca93f96123a616ae8540879991b8b57af2f81b76a7ada49b2a4" + url: "https://pub.dev" + source: hosted + version: "2.0.2" + flutter_secure_storage: + dependency: "direct main" + description: + name: flutter_secure_storage + sha256: "98352186ee7ad3639ccc77ad7924b773ff6883076ab952437d20f18a61f0a7c5" + url: "https://pub.dev" + source: hosted + version: "8.0.0" + flutter_secure_storage_linux: + dependency: transitive + description: + name: flutter_secure_storage_linux + sha256: "0912ae29a572230ad52d8a4697e5518d7f0f429052fd51df7e5a7952c7efe2a3" + url: "https://pub.dev" + source: hosted + version: "1.1.3" + flutter_secure_storage_macos: + dependency: transitive + description: + name: flutter_secure_storage_macos + sha256: "083add01847fc1c80a07a08e1ed6927e9acd9618a35e330239d4422cd2a58c50" + url: "https://pub.dev" + source: hosted + version: "3.0.0" + flutter_secure_storage_platform_interface: + dependency: transitive + description: + name: flutter_secure_storage_platform_interface + sha256: b3773190e385a3c8a382007893d678ae95462b3c2279e987b55d140d3b0cb81b + url: "https://pub.dev" + source: hosted + version: "1.0.1" + flutter_secure_storage_web: + dependency: transitive + description: + name: flutter_secure_storage_web + sha256: "42938e70d4b872e856e678c423cc0e9065d7d294f45bc41fc1981a4eb4beaffe" + url: "https://pub.dev" + source: hosted + version: "1.1.1" + flutter_secure_storage_windows: + dependency: transitive + description: + name: flutter_secure_storage_windows + sha256: fc2910ec9b28d60598216c29ea763b3a96c401f0ce1d13cdf69ccb0e5c93c3ee + url: "https://pub.dev" + source: hosted + version: "2.0.0" + 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" + formz: + dependency: "direct main" + description: + name: formz + sha256: b2b4cb99b228020d2c7185500eed1c02ca290dd4cc19edaf42df17f5dc546d5a + url: "https://pub.dev" + source: hosted + version: "0.6.0" + freezed: + dependency: "direct dev" + description: + name: freezed + sha256: "83462cfc33dc9680533a7f3a4a6ab60aa94f287db5f4ee6511248c22833c497f" + url: "https://pub.dev" + source: hosted + version: "2.4.2" + freezed_annotation: + dependency: "direct main" + description: + name: freezed_annotation + sha256: c3fd9336eb55a38cc1bbd79ab17573113a8deccd0ecbbf926cca3c62803b5c2d + url: "https://pub.dev" + source: hosted + version: "2.4.1" + frontend_server_client: + dependency: transitive + description: + name: frontend_server_client + sha256: "408e3ca148b31c20282ad6f37ebfa6f4bdc8fede5b74bc2f08d9d92b55db3612" + url: "https://pub.dev" + source: hosted + version: "3.2.0" + glob: + dependency: transitive + description: + name: glob + sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63" + url: "https://pub.dev" + source: hosted + version: "2.1.2" + graphs: + dependency: transitive + description: + name: graphs + sha256: aedc5a15e78fc65a6e23bcd927f24c64dd995062bcd1ca6eda65a3cff92a4d19 + url: "https://pub.dev" + source: hosted + version: "2.3.1" + http_multi_server: + dependency: transitive + description: + name: http_multi_server + sha256: "97486f20f9c2f7be8f514851703d0119c3596d14ea63227af6f7a481ef2b2f8b" + url: "https://pub.dev" + source: hosted + version: "3.2.1" + http_parser: + dependency: transitive + description: + name: http_parser + sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b" + url: "https://pub.dev" + source: hosted + version: "4.0.2" + io: + dependency: transitive + description: + name: io + sha256: "2ec25704aba361659e10e3e5f5d672068d332fc8ac516421d483a11e5cbd061e" + url: "https://pub.dev" + source: hosted + version: "1.0.4" + js: + dependency: transitive + description: + name: js + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + url: "https://pub.dev" + source: hosted + version: "0.6.7" + json_annotation: + dependency: "direct main" + description: + name: json_annotation + sha256: b10a7b2ff83d83c777edba3c6a0f97045ddadd56c944e1a23a3fdf43a1bf4467 + url: "https://pub.dev" + source: hosted + version: "4.8.1" + json_serializable: + dependency: "direct dev" + description: + name: json_serializable + sha256: aa1f5a8912615733e0fdc7a02af03308933c93235bdc8d50d0b0c8a8ccb0b969 + url: "https://pub.dev" + source: hosted + version: "6.7.1" + lints: + dependency: transitive + description: + name: lints + sha256: "0a217c6c989d21039f1498c3ed9f3ed71b354e69873f13a8dfc3c9fe76f1b452" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + logging: + dependency: transitive + description: + name: logging + sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340" + url: "https://pub.dev" + source: hosted + version: "1.2.0" + matcher: + dependency: transitive + description: + name: matcher + sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb" + url: "https://pub.dev" + source: hosted + version: "0.12.15" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724 + url: "https://pub.dev" + source: hosted + version: "0.2.0" + meta: + dependency: transitive + description: + name: meta + sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" + url: "https://pub.dev" + source: hosted + version: "1.9.1" + mime: + dependency: transitive + description: + name: mime + sha256: e4ff8e8564c03f255408decd16e7899da1733852a9110a58fe6d1b817684a63e + url: "https://pub.dev" + source: hosted + version: "1.0.4" + nested: + dependency: transitive + description: + name: nested + sha256: "03bac4c528c64c95c722ec99280375a6f2fc708eec17c7b3f07253b626cd2a20" + url: "https://pub.dev" + source: hosted + version: "1.0.0" + one_of: + dependency: "direct main" + description: + name: one_of + sha256: "25fe0fcf181e761c6fcd604caf9d5fdf952321be17584ba81c72c06bdaa511f0" + url: "https://pub.dev" + source: hosted + version: "1.5.0" + one_of_serializer: + dependency: transitive + description: + name: one_of_serializer + sha256: "3f3dfb5c1578ba3afef1cb47fcc49e585e797af3f2b6c2cc7ed90aad0c5e7b83" + url: "https://pub.dev" + source: hosted + version: "1.5.0" + ory_client: + dependency: "direct main" + description: + name: ory_client + sha256: a7cdf22fb8f057e773cd6764831aaf4dab7dc8b6cfefc643b5b545b574b214c9 + url: "https://pub.dev" + source: hosted + version: "1.1.49" + package_config: + dependency: transitive + description: + name: package_config + sha256: "1c5b77ccc91e4823a5af61ee74e6b972db1ef98c2ff5a18d3161c982a55448bd" + url: "https://pub.dev" + source: hosted + version: "2.1.0" + path: + dependency: transitive + description: + name: path + sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + url: "https://pub.dev" + source: hosted + version: "1.8.3" + path_provider_linux: + dependency: transitive + description: + name: path_provider_linux + sha256: ba2b77f0c52a33db09fc8caf85b12df691bf28d983e84cf87ff6d693cfa007b3 + url: "https://pub.dev" + source: hosted + version: "2.2.0" + path_provider_platform_interface: + dependency: transitive + description: + name: path_provider_platform_interface + sha256: bced5679c7df11190e1ddc35f3222c858f328fff85c3942e46e7f5589bf9eb84 + url: "https://pub.dev" + source: hosted + version: "2.1.0" + path_provider_windows: + dependency: transitive + description: + name: path_provider_windows + sha256: ee0e0d164516b90ae1f970bdf29f726f1aa730d7cfc449ecc74c495378b705da + url: "https://pub.dev" + source: hosted + version: "2.2.0" + platform: + dependency: transitive + description: + name: platform + sha256: "57c07bf82207aee366dfaa3867b3164e4f03a238a461a11b0e8a3a510d51203d" + url: "https://pub.dev" + source: hosted + version: "3.1.1" + plugin_platform_interface: + dependency: transitive + description: + name: plugin_platform_interface + sha256: "43798d895c929056255600343db8f049921cbec94d31ec87f1dc5c16c01935dd" + url: "https://pub.dev" + source: hosted + version: "2.1.5" + pool: + dependency: transitive + description: + name: pool + sha256: "20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a" + url: "https://pub.dev" + source: hosted + version: "1.5.1" + provider: + dependency: transitive + description: + name: provider + sha256: cdbe7530b12ecd9eb455bdaa2fcb8d4dad22e80b8afb4798b41479d5ce26847f + url: "https://pub.dev" + source: hosted + version: "6.0.5" + pub_semver: + dependency: transitive + description: + name: pub_semver + sha256: "40d3ab1bbd474c4c2328c91e3a7df8c6dd629b79ece4c4bd04bee496a224fb0c" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + pubspec_parse: + dependency: transitive + description: + name: pubspec_parse + sha256: c63b2876e58e194e4b0828fcb080ad0e06d051cb607a6be51a9e084f47cb9367 + url: "https://pub.dev" + source: hosted + version: "1.2.3" + quiver: + dependency: transitive + description: + name: quiver + sha256: b1c1ac5ce6688d77f65f3375a9abb9319b3cb32486bdc7a1e0fdf004d7ba4e47 + url: "https://pub.dev" + source: hosted + version: "3.2.1" + shared_preferences: + dependency: "direct main" + description: + name: shared_preferences + sha256: "0344316c947ffeb3a529eac929e1978fcd37c26be4e8468628bac399365a3ca1" + url: "https://pub.dev" + source: hosted + version: "2.2.0" + shared_preferences_android: + dependency: transitive + description: + name: shared_preferences_android + sha256: fe8401ec5b6dcd739a0fe9588802069e608c3fdbfd3c3c93e546cf2f90438076 + url: "https://pub.dev" + source: hosted + version: "2.2.0" + shared_preferences_foundation: + dependency: transitive + description: + name: shared_preferences_foundation + sha256: d29753996d8eb8f7619a1f13df6ce65e34bc107bef6330739ed76f18b22310ef + url: "https://pub.dev" + source: hosted + version: "2.3.3" + shared_preferences_linux: + dependency: transitive + description: + name: shared_preferences_linux + sha256: "71d6806d1449b0a9d4e85e0c7a917771e672a3d5dc61149cc9fac871115018e1" + url: "https://pub.dev" + source: hosted + version: "2.3.0" + shared_preferences_platform_interface: + dependency: transitive + description: + name: shared_preferences_platform_interface + sha256: "23b052f17a25b90ff2b61aad4cc962154da76fb62848a9ce088efe30d7c50ab1" + url: "https://pub.dev" + source: hosted + version: "2.3.0" + shared_preferences_web: + dependency: transitive + description: + name: shared_preferences_web + sha256: "7347b194fb0bbeb4058e6a4e87ee70350b6b2b90f8ac5f8bd5b3a01548f6d33a" + url: "https://pub.dev" + source: hosted + version: "2.2.0" + shared_preferences_windows: + dependency: transitive + description: + name: shared_preferences_windows + sha256: f95e6a43162bce43c9c3405f3eb6f39e5b5d11f65fab19196cf8225e2777624d + url: "https://pub.dev" + source: hosted + version: "2.3.0" + shelf: + dependency: transitive + description: + name: shelf + sha256: ad29c505aee705f41a4d8963641f91ac4cee3c8fad5947e033390a7bd8180fa4 + url: "https://pub.dev" + source: hosted + version: "1.4.1" + shelf_web_socket: + dependency: transitive + description: + name: shelf_web_socket + sha256: "9ca081be41c60190ebcb4766b2486a7d50261db7bd0f5d9615f2d653637a84c1" + url: "https://pub.dev" + source: hosted + version: "1.0.4" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.99" + source_gen: + dependency: transitive + description: + name: source_gen + sha256: fc0da689e5302edb6177fdd964efcb7f58912f43c28c2047a808f5bfff643d16 + url: "https://pub.dev" + source: hosted + version: "1.4.0" + source_helper: + dependency: transitive + description: + name: source_helper + sha256: "6adebc0006c37dd63fe05bca0a929b99f06402fc95aa35bf36d67f5c06de01fd" + url: "https://pub.dev" + source: hosted + version: "1.3.4" + source_span: + dependency: transitive + description: + name: source_span + sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250 + url: "https://pub.dev" + source: hosted + version: "1.9.1" + stack_trace: + dependency: transitive + description: + name: stack_trace + sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 + url: "https://pub.dev" + source: hosted + version: "1.11.0" + stream_channel: + dependency: transitive + description: + name: stream_channel + sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + stream_transform: + dependency: transitive + description: + name: stream_transform + sha256: "14a00e794c7c11aa145a170587321aedce29769c08d7f58b1d141da75e3b1c6f" + url: "https://pub.dev" + source: hosted + version: "2.1.0" + string_scanner: + dependency: transitive + description: + name: string_scanner + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" + source: hosted + version: "1.2.0" + term_glyph: + dependency: transitive + description: + name: term_glyph + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" + source: hosted + version: "1.2.1" + test_api: + dependency: transitive + description: + name: test_api + sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb + url: "https://pub.dev" + source: hosted + version: "0.5.1" + timing: + dependency: transitive + description: + name: timing + sha256: "70a3b636575d4163c477e6de42f247a23b315ae20e86442bebe32d3cabf61c32" + url: "https://pub.dev" + source: hosted + version: "1.0.1" + typed_data: + dependency: transitive + description: + name: typed_data + sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c + url: "https://pub.dev" + source: hosted + version: "1.3.2" + vector_math: + dependency: transitive + description: + name: vector_math + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + watcher: + dependency: transitive + description: + name: watcher + sha256: "3d2ad6751b3c16cf07c7fca317a1413b3f26530319181b37e3b9039b84fc01d8" + url: "https://pub.dev" + source: hosted + version: "1.1.0" + web_socket_channel: + dependency: transitive + description: + name: web_socket_channel + sha256: d88238e5eac9a42bb43ca4e721edba3c08c6354d4a53063afaa568516217621b + url: "https://pub.dev" + source: hosted + version: "2.4.0" + win32: + dependency: transitive + description: + name: win32 + sha256: f2add6fa510d3ae152903412227bda57d0d5a8da61d2c39c1fb022c9429a41c0 + url: "https://pub.dev" + source: hosted + version: "5.0.6" + xdg_directories: + dependency: transitive + description: + name: xdg_directories + sha256: f0c26453a2d47aa4c2570c6a033246a3fc62da2fe23c7ffdd0a7495086dc0247 + url: "https://pub.dev" + source: hosted + version: "1.0.2" + yaml: + dependency: transitive + description: + name: yaml + sha256: "75769501ea3489fca56601ff33454fe45507ea3bfb014161abc3b43ae25989d5" + url: "https://pub.dev" + source: hosted + version: "3.1.2" +sdks: + dart: ">=3.0.6 <4.0.0" + flutter: ">=3.3.0" diff --git a/kratos-flutter/pubspec.yaml b/kratos-flutter/pubspec.yaml new file mode 100644 index 00000000..1fb27622 --- /dev/null +++ b/kratos-flutter/pubspec.yaml @@ -0,0 +1,106 @@ +name: kratos_flutter +description: A new Flutter project. +# The following line prevents the package from being accidentally published to +# pub.dev using `flutter pub publish`. This is preferred for private packages. +publish_to: 'none' # Remove this line if you wish to publish to pub.dev + +# The following defines the version and build number for your application. +# A version number is three numbers separated by dots, like 1.2.43 +# followed by an optional build number separated by a +. +# Both the version and the builder number may be overridden in flutter +# build by specifying --build-name and --build-number, respectively. +# In Android, build-name is used as versionName while build-number used as versionCode. +# Read more about Android versioning at https://developer.android.com/studio/publish/versioning +# In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion. +# Read more about iOS versioning at +# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html +# In Windows, build-name is used as the major, minor, and patch parts +# of the product and file versions while build-number is used as the build suffix. +version: 1.0.0+1 + +environment: + sdk: '>=3.0.6 <4.0.0' + +# Dependencies specify other packages that your package needs in order to work. +# To automatically upgrade your package dependencies to the latest versions +# consider running `flutter pub upgrade --major-versions`. Alternatively, +# dependencies can be manually updated by changing the version numbers below to +# the latest version available on pub.dev. To see which dependencies have newer +# versions available, run `flutter pub outdated`. +dependencies: + flutter: + sdk: flutter + + + # The following adds the Cupertino Icons font to your application. + # Use with the CupertinoIcons class for iOS style icons. + cupertino_icons: ^1.0.2 + bloc: ^8.1.2 + flutter_bloc: ^8.1.3 + shared_preferences: ^2.2.0 + dio: ^5.3.2 + ory_client: ^1.1.44 + flutter_dotenv: ^5.1.0 + freezed_annotation: ^2.4.1 + json_annotation: ^4.8.1 + formz: ^0.6.0 + equatable: ^2.0.5 + one_of: ^1.5.0 + flutter_secure_storage: ^8.0.0 + dotenv: ^4.1.0 + +dev_dependencies: + flutter_test: + sdk: flutter + + # The "flutter_lints" package below contains a set of recommended lints to + # encourage good coding practices. The lint set provided by the package is + # activated in the `analysis_options.yaml` file located at the root of your + # package. See that file for information about deactivating specific lint + # rules and activating additional ones. + flutter_lints: ^2.0.0 + build_runner: ^2.4.6 + freezed: ^2.4.2 + json_serializable: ^6.7.1 + +# For information on the generic Dart part of this file, see the +# following page: https://dart.dev/tools/pub/pubspec + +# The following section is specific to Flutter packages. +flutter: + + # The following line ensures that the Material Icons font is + # included with your application, so that you can use the icons in + # the material Icons class. + uses-material-design: true + + # To add assets to your application, add an assets section, like this: + assets: + - .env + + + # An image asset can refer to one or more resolution-specific "variants", see + # https://flutter.dev/assets-and-images/#resolution-aware + + # For details regarding adding assets from package dependencies, see + # https://flutter.dev/assets-and-images/#from-packages + + # To add custom fonts to your application, add a fonts section here, + # in this "flutter" section. Each entry in this list should have a + # "family" key with the font family name, and a "fonts" key with a + # list giving the asset and other descriptors for the font. For + # example: + # fonts: + # - family: Schyler + # fonts: + # - asset: fonts/Schyler-Regular.ttf + # - asset: fonts/Schyler-Italic.ttf + # style: italic + # - family: Trajan Pro + # fonts: + # - asset: fonts/TrajanPro.ttf + # - asset: fonts/TrajanPro_Bold.ttf + # weight: 700 + # + # For details regarding fonts from package dependencies, + # see https://flutter.dev/custom-fonts/#from-packages diff --git a/kratos-flutter/test/widget_test.dart b/kratos-flutter/test/widget_test.dart new file mode 100644 index 00000000..80f9a1a4 --- /dev/null +++ b/kratos-flutter/test/widget_test.dart @@ -0,0 +1,30 @@ +// This is a basic Flutter widget test. +// +// To perform an interaction with a widget in your test, use the WidgetTester +// utility in the flutter_test package. For example, you can send tap and scroll +// gestures. You can also use WidgetTester to find child widgets in the widget +// tree, read text, and verify that the values of widget properties are correct. + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'package:kratos_flutter/main.dart'; + +void main() { + testWidgets('Counter increments smoke test', (WidgetTester tester) async { + // Build our app and trigger a frame. + await tester.pumpWidget(const MyApp()); + + // Verify that our counter starts at 0. + expect(find.text('0'), findsOneWidget); + expect(find.text('1'), findsNothing); + + // Tap the '+' icon and trigger a frame. + await tester.tap(find.byIcon(Icons.add)); + await tester.pump(); + + // Verify that our counter has incremented. + expect(find.text('0'), findsNothing); + expect(find.text('1'), findsOneWidget); + }); +} From 6b5239c52eee68318e6039397125a21a017044d2 Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Fri, 18 Aug 2023 12:59:09 +0200 Subject: [PATCH 02/57] feat: create login flow --- .../lib/blocs/login/login_bloc.dart | 31 +++ .../lib/blocs/login/login_bloc.freezed.dart | 223 ++++++++++++++++++ .../lib/blocs/login/login_event.dart | 46 ++++ .../lib/blocs/login/login_state.dart | 11 + kratos-flutter/lib/pages/login.dart | 83 ++++++- kratos-flutter/lib/repositories/auth.dart | 5 + kratos-flutter/lib/services/auth.dart | 13 + 7 files changed, 410 insertions(+), 2 deletions(-) create mode 100644 kratos-flutter/lib/blocs/login/login_bloc.dart create mode 100644 kratos-flutter/lib/blocs/login/login_bloc.freezed.dart create mode 100644 kratos-flutter/lib/blocs/login/login_event.dart create mode 100644 kratos-flutter/lib/blocs/login/login_state.dart diff --git a/kratos-flutter/lib/blocs/login/login_bloc.dart b/kratos-flutter/lib/blocs/login/login_bloc.dart new file mode 100644 index 00000000..fffa0883 --- /dev/null +++ b/kratos-flutter/lib/blocs/login/login_bloc.dart @@ -0,0 +1,31 @@ +import 'package:bloc/bloc.dart'; +import 'package:equatable/equatable.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; + +import '../../repositories/auth.dart'; +import '../../services/exceptions.dart'; +import '../auth/auth_bloc.dart'; + +part 'login_event.dart'; +part 'login_state.dart'; +part 'login_bloc.freezed.dart'; + +class LoginBloc extends Bloc { + final AuthBloc authBloc; + final AuthRepository repository; + LoginBloc({required this.authBloc, required this.repository}) + : super(const LoginState()) { + on(_onCreateLoginFlow); + } + + Future _onCreateLoginFlow( + CreateLoginFlow event, Emitter emit) async { + try { + emit(state.copyWith(isLoading: true, errorMessage: null)); + final flowId = await repository.createLoginFlow(); + emit(state.copyWith(flowId: flowId, isLoading: false)); + } on CustomException catch (e) { + emit(state.copyWith(isLoading: false, errorMessage: e.message)); + } + } +} diff --git a/kratos-flutter/lib/blocs/login/login_bloc.freezed.dart b/kratos-flutter/lib/blocs/login/login_bloc.freezed.dart new file mode 100644 index 00000000..fd543d96 --- /dev/null +++ b/kratos-flutter/lib/blocs/login/login_bloc.freezed.dart @@ -0,0 +1,223 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'login_bloc.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +mixin _$LoginState { + String? get flowId => throw _privateConstructorUsedError; + String get email => throw _privateConstructorUsedError; + String get password => throw _privateConstructorUsedError; + bool get isLoading => throw _privateConstructorUsedError; + String? get errorMessage => throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $LoginStateCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $LoginStateCopyWith<$Res> { + factory $LoginStateCopyWith( + LoginState value, $Res Function(LoginState) then) = + _$LoginStateCopyWithImpl<$Res, LoginState>; + @useResult + $Res call( + {String? flowId, + String email, + String password, + bool isLoading, + String? errorMessage}); +} + +/// @nodoc +class _$LoginStateCopyWithImpl<$Res, $Val extends LoginState> + implements $LoginStateCopyWith<$Res> { + _$LoginStateCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? flowId = freezed, + Object? email = null, + Object? password = null, + Object? isLoading = null, + Object? errorMessage = freezed, + }) { + return _then(_value.copyWith( + flowId: freezed == flowId + ? _value.flowId + : flowId // ignore: cast_nullable_to_non_nullable + as String?, + email: null == email + ? _value.email + : email // ignore: cast_nullable_to_non_nullable + as String, + password: null == password + ? _value.password + : password // ignore: cast_nullable_to_non_nullable + as String, + isLoading: null == isLoading + ? _value.isLoading + : isLoading // ignore: cast_nullable_to_non_nullable + as bool, + errorMessage: freezed == errorMessage + ? _value.errorMessage + : errorMessage // ignore: cast_nullable_to_non_nullable + as String?, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$_LoginStateCopyWith<$Res> + implements $LoginStateCopyWith<$Res> { + factory _$$_LoginStateCopyWith( + _$_LoginState value, $Res Function(_$_LoginState) then) = + __$$_LoginStateCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {String? flowId, + String email, + String password, + bool isLoading, + String? errorMessage}); +} + +/// @nodoc +class __$$_LoginStateCopyWithImpl<$Res> + extends _$LoginStateCopyWithImpl<$Res, _$_LoginState> + implements _$$_LoginStateCopyWith<$Res> { + __$$_LoginStateCopyWithImpl( + _$_LoginState _value, $Res Function(_$_LoginState) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? flowId = freezed, + Object? email = null, + Object? password = null, + Object? isLoading = null, + Object? errorMessage = freezed, + }) { + return _then(_$_LoginState( + flowId: freezed == flowId + ? _value.flowId + : flowId // ignore: cast_nullable_to_non_nullable + as String?, + email: null == email + ? _value.email + : email // ignore: cast_nullable_to_non_nullable + as String, + password: null == password + ? _value.password + : password // ignore: cast_nullable_to_non_nullable + as String, + isLoading: null == isLoading + ? _value.isLoading + : isLoading // ignore: cast_nullable_to_non_nullable + as bool, + errorMessage: freezed == errorMessage + ? _value.errorMessage + : errorMessage // ignore: cast_nullable_to_non_nullable + as String?, + )); + } +} + +/// @nodoc + +class _$_LoginState implements _LoginState { + const _$_LoginState( + {this.flowId, + this.email = '', + this.password = '', + this.isLoading = false, + this.errorMessage}); + + @override + final String? flowId; + @override + @JsonKey() + final String email; + @override + @JsonKey() + final String password; + @override + @JsonKey() + final bool isLoading; + @override + final String? errorMessage; + + @override + String toString() { + return 'LoginState(flowId: $flowId, email: $email, password: $password, isLoading: $isLoading, errorMessage: $errorMessage)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$_LoginState && + (identical(other.flowId, flowId) || other.flowId == flowId) && + (identical(other.email, email) || other.email == email) && + (identical(other.password, password) || + other.password == password) && + (identical(other.isLoading, isLoading) || + other.isLoading == isLoading) && + (identical(other.errorMessage, errorMessage) || + other.errorMessage == errorMessage)); + } + + @override + int get hashCode => Object.hash( + runtimeType, flowId, email, password, isLoading, errorMessage); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$_LoginStateCopyWith<_$_LoginState> get copyWith => + __$$_LoginStateCopyWithImpl<_$_LoginState>(this, _$identity); +} + +abstract class _LoginState implements LoginState { + const factory _LoginState( + {final String? flowId, + final String email, + final String password, + final bool isLoading, + final String? errorMessage}) = _$_LoginState; + + @override + String? get flowId; + @override + String get email; + @override + String get password; + @override + bool get isLoading; + @override + String? get errorMessage; + @override + @JsonKey(ignore: true) + _$$_LoginStateCopyWith<_$_LoginState> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/kratos-flutter/lib/blocs/login/login_event.dart b/kratos-flutter/lib/blocs/login/login_event.dart new file mode 100644 index 00000000..ae96f71f --- /dev/null +++ b/kratos-flutter/lib/blocs/login/login_event.dart @@ -0,0 +1,46 @@ +part of 'login_bloc.dart'; + +@immutable +sealed class LoginEvent extends Equatable { + @override + List get props => []; +} + +//create login flow +final class CreateLoginFlow extends LoginEvent {} + +final class ChangeEmail extends LoginEvent { + final String value; + + ChangeEmail({required this.value}); + + @override + List get props => [value]; +} + +final class ChangePassword extends LoginEvent { + final String value; + + ChangePassword({required this.value}); + + @override + List get props => [value]; +} + +final class ChangePasswordVisibility extends LoginEvent { + final bool isVisible; + ChangePasswordVisibility({required this.isVisible}); +} + +//log in +final class LoginWithEmailAndPassword extends LoginEvent { + final String flowId; + final String email; + final String password; + + LoginWithEmailAndPassword( + {required this.flowId, required this.email, required this.password}); + + @override + List get props => [flowId, email, password]; +} diff --git a/kratos-flutter/lib/blocs/login/login_state.dart b/kratos-flutter/lib/blocs/login/login_state.dart new file mode 100644 index 00000000..3c1a8815 --- /dev/null +++ b/kratos-flutter/lib/blocs/login/login_state.dart @@ -0,0 +1,11 @@ +part of 'login_bloc.dart'; + +@freezed +sealed class LoginState with _$LoginState { + const factory LoginState( + {String? flowId, + @Default('') String email, + @Default('') String password, + @Default(false) bool isLoading, + String? errorMessage}) = _LoginState; +} diff --git a/kratos-flutter/lib/pages/login.dart b/kratos-flutter/lib/pages/login.dart index 04996e77..b3ea7046 100644 --- a/kratos-flutter/lib/pages/login.dart +++ b/kratos-flutter/lib/pages/login.dart @@ -1,12 +1,91 @@ import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; + +import '../blocs/auth/auth_bloc.dart'; +import '../blocs/login/login_bloc.dart'; +import '../repositories/auth.dart'; class LoginPage extends StatelessWidget { const LoginPage({super.key}); @override Widget build(BuildContext context) { - return const Scaffold( - body: Center(child: Text('log in')), + return Scaffold( + body: BlocProvider( + create: (context) => LoginBloc( + authBloc: context.read(), + repository: RepositoryProvider.of(context)) + ..add(CreateLoginFlow()), + child: const LoginForm()), + ); + } +} + +class LoginForm extends StatelessWidget { + const LoginForm({super.key}); + + @override + Widget build(BuildContext context) { + final loginBloc = BlocProvider.of(context); + return BlocBuilder( + bloc: loginBloc, + builder: (context, state) { + // creating login flow is in process, show loading indicator + if (state.flowId != null) { + return _buildLoginForm(context, state); + } else { + return _buildLoginFlowNotCreated(context, state); + } + }); + } + + _buildLoginFlowNotCreated(BuildContext context, LoginState state) { + if (state.errorMessage != null) { + return Center(child: Text(state.errorMessage!)); + } else { + return const Center(child: CircularProgressIndicator()); + } + } + + _buildLoginForm(BuildContext context, LoginState state) { + return Padding( + padding: const EdgeInsets.all(10.0), + child: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + TextFormField( + enabled: !state.isLoading, + initialValue: state.email, + onChanged: (String value) => + context.read().add(ChangeEmail(value: value)), + decoration: const InputDecoration( + border: OutlineInputBorder(), + label: Text('Email'), + hintText: 'Enter your email', + ), + ), + const SizedBox( + height: 20, + ), + TextFormField( + enabled: !state.isLoading, + initialValue: state.email, + onChanged: (String value) => + context.read().add(ChangePassword(value: value)), + decoration: const InputDecoration( + border: OutlineInputBorder(), + label: Text('Password'), + hintText: 'Enter your password', + ), + ), + if (state.errorMessage != null) + Text(state.errorMessage!, + style: const TextStyle(color: Colors.red)), + OutlinedButton(onPressed: null, child: const Text('Submit')) + ], + )), ); } } diff --git a/kratos-flutter/lib/repositories/auth.dart b/kratos-flutter/lib/repositories/auth.dart index b6093b0b..0c0c108b 100644 --- a/kratos-flutter/lib/repositories/auth.dart +++ b/kratos-flutter/lib/repositories/auth.dart @@ -13,4 +13,9 @@ class AuthRepository { final session = await service.getCurrentSessionInformation(); return session; } + + Future createLoginFlow() async { + final flowId = await service.createLoginFlow(); + return flowId; + } } diff --git a/kratos-flutter/lib/services/auth.dart b/kratos-flutter/lib/services/auth.dart index 1cc109c4..3954f17c 100644 --- a/kratos-flutter/lib/services/auth.dart +++ b/kratos-flutter/lib/services/auth.dart @@ -22,4 +22,17 @@ class AuthService { throw CustomException.fromDioException(e); } } + + Future createLoginFlow() async { + try { + final response = await _ory.createNativeLoginFlow(); + if (response.statusCode == 200) { + return response.data!.id; + } else { + throw CustomException(statusCode: response.statusCode); + } + } on DioException catch (e) { + throw CustomException.fromDioException(e); + } + } } From 8ec28062cd0f6c23af53b58a835c2d1095810d20 Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Wed, 23 Aug 2023 11:29:25 +0200 Subject: [PATCH 03/57] feat: login with email and password --- kratos-flutter/lib/blocs/auth/auth_bloc.dart | 13 +- .../lib/blocs/login/login_bloc.dart | 66 +- .../lib/blocs/login/login_bloc.freezed.dart | 60 +- .../lib/blocs/login/login_state.dart | 4 +- kratos-flutter/lib/entities/formfield.dart | 8 + .../lib/entities/formfield.freezed.dart | 151 ++++ kratos-flutter/lib/pages/login.dart | 46 +- kratos-flutter/lib/repositories/auth.dart | 8 + kratos-flutter/lib/services/auth.dart | 84 +- kratos-flutter/lib/services/exceptions.dart | 76 +- .../lib/services/exceptions.freezed.dart | 815 ++++++++++++++++++ kratos-flutter/lib/services/message.dart | 31 + .../lib/services/message.freezed.dart | 353 ++++++++ kratos-flutter/lib/services/message.g.dart | 45 + kratos-flutter/pubspec.lock | 2 +- kratos-flutter/pubspec.yaml | 1 + 16 files changed, 1664 insertions(+), 99 deletions(-) create mode 100644 kratos-flutter/lib/entities/formfield.dart create mode 100644 kratos-flutter/lib/entities/formfield.freezed.dart create mode 100644 kratos-flutter/lib/services/exceptions.freezed.dart create mode 100644 kratos-flutter/lib/services/message.dart create mode 100644 kratos-flutter/lib/services/message.freezed.dart create mode 100644 kratos-flutter/lib/services/message.g.dart diff --git a/kratos-flutter/lib/blocs/auth/auth_bloc.dart b/kratos-flutter/lib/blocs/auth/auth_bloc.dart index bfbb4982..be41698a 100644 --- a/kratos-flutter/lib/blocs/auth/auth_bloc.dart +++ b/kratos-flutter/lib/blocs/auth/auth_bloc.dart @@ -26,19 +26,22 @@ class AuthBloc extends Bloc { GetCurrentSessionInformation event, Emitter emit) async { try { emit(state.copyWith(isLoading: true, errorMessage: null)); + final session = await repository.getCurrentSessionInformation(); + emit(state.copyWith( isLoading: false, status: AuthStatus.authenticated, session: session)); } on CustomException catch (e) { - if (e.exceptionType == OryExceptionType.unauthorizedException) { + if (e case UnauthorizedException _) { emit(state.copyWith( - status: AuthStatus.unauthenticated, - isLoading: false, - errorMessage: e.message)); + status: AuthStatus.unauthenticated, isLoading: false)); + } else if (e case UnknownException _) { + emit(state.copyWith(isLoading: false, errorMessage: e.message)); + } else { + emit(state.copyWith(isLoading: false)); } - emit(state.copyWith(isLoading: false, errorMessage: e.message)); } } } diff --git a/kratos-flutter/lib/blocs/login/login_bloc.dart b/kratos-flutter/lib/blocs/login/login_bloc.dart index fffa0883..f981a93a 100644 --- a/kratos-flutter/lib/blocs/login/login_bloc.dart +++ b/kratos-flutter/lib/blocs/login/login_bloc.dart @@ -1,9 +1,12 @@ import 'package:bloc/bloc.dart'; import 'package:equatable/equatable.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:collection/collection.dart'; +import '../../entities/formfield.dart'; import '../../repositories/auth.dart'; import '../../services/exceptions.dart'; +import '../../services/message.dart'; import '../auth/auth_bloc.dart'; part 'login_event.dart'; @@ -16,6 +19,9 @@ class LoginBloc extends Bloc { LoginBloc({required this.authBloc, required this.repository}) : super(const LoginState()) { on(_onCreateLoginFlow); + on(_onChangeEmail); + on(_onChangePassword); + on(_onLoginWithEmailAndPassword); } Future _onCreateLoginFlow( @@ -25,7 +31,65 @@ class LoginBloc extends Bloc { final flowId = await repository.createLoginFlow(); emit(state.copyWith(flowId: flowId, isLoading: false)); } on CustomException catch (e) { - emit(state.copyWith(isLoading: false, errorMessage: e.message)); + if (e case UnknownException _) { + emit(state.copyWith(isLoading: false, errorMessage: e.message)); + } else { + emit(state.copyWith(isLoading: false)); + } + } + } + + _onChangeEmail(ChangeEmail event, Emitter emit) { + // remove email and general error when changing email + emit(state.copyWith + .email(value: event.value, errorMessage: null) + .copyWith(errorMessage: null)); + } + + _onChangePassword(ChangePassword event, Emitter emit) { + // remove password and general error when changing email + emit(state.copyWith + .password(value: event.value, errorMessage: null) + .copyWith(errorMessage: null)); + } + + Future _onLoginWithEmailAndPassword( + LoginWithEmailAndPassword event, Emitter emit) async { + try { + emit(state.copyWith(isLoading: true, errorMessage: null)); + + await repository.loginWithEmailAndPassword( + flowId: event.flowId, email: event.email, password: event.password); + + authBloc.add(ChangeAuthStatus(status: AuthStatus.authenticated)); + } on CustomException catch (e) { + if (e case BadRequestException _) { + // get credential errors + final emailMessage = e.messages?.firstWhereOrNull( + (element) => element.context.property == Property.identifier); + final passwordMessage = e.messages?.firstWhereOrNull( + (element) => element.context.property == Property.password); + final generalMessage = e.messages?.firstWhereOrNull( + (element) => element.context.property == Property.general); + + // update state to new one with errors + emit(state + .copyWith(isLoading: false, errorMessage: generalMessage?.text) + .copyWith + .email(errorMessage: emailMessage?.text) + .copyWith + .password(errorMessage: passwordMessage?.text)); + } else if (e case FlowExpiredException _) { + // use new flow id to log in user + add(LoginWithEmailAndPassword( + flowId: e.flowId, + email: state.email.value, + password: state.password.value)); + } else if (e case UnknownException _) { + emit(state.copyWith(isLoading: false, errorMessage: e.message)); + } else { + emit(state.copyWith(isLoading: false)); + } } } } diff --git a/kratos-flutter/lib/blocs/login/login_bloc.freezed.dart b/kratos-flutter/lib/blocs/login/login_bloc.freezed.dart index fd543d96..635ea0de 100644 --- a/kratos-flutter/lib/blocs/login/login_bloc.freezed.dart +++ b/kratos-flutter/lib/blocs/login/login_bloc.freezed.dart @@ -17,8 +17,8 @@ final _privateConstructorUsedError = UnsupportedError( /// @nodoc mixin _$LoginState { String? get flowId => throw _privateConstructorUsedError; - String get email => throw _privateConstructorUsedError; - String get password => throw _privateConstructorUsedError; + FormField get email => throw _privateConstructorUsedError; + FormField get password => throw _privateConstructorUsedError; bool get isLoading => throw _privateConstructorUsedError; String? get errorMessage => throw _privateConstructorUsedError; @@ -35,10 +35,13 @@ abstract class $LoginStateCopyWith<$Res> { @useResult $Res call( {String? flowId, - String email, - String password, + FormField email, + FormField password, bool isLoading, String? errorMessage}); + + $FormFieldCopyWith get email; + $FormFieldCopyWith get password; } /// @nodoc @@ -68,11 +71,11 @@ class _$LoginStateCopyWithImpl<$Res, $Val extends LoginState> email: null == email ? _value.email : email // ignore: cast_nullable_to_non_nullable - as String, + as FormField, password: null == password ? _value.password : password // ignore: cast_nullable_to_non_nullable - as String, + as FormField, isLoading: null == isLoading ? _value.isLoading : isLoading // ignore: cast_nullable_to_non_nullable @@ -83,6 +86,22 @@ class _$LoginStateCopyWithImpl<$Res, $Val extends LoginState> as String?, ) as $Val); } + + @override + @pragma('vm:prefer-inline') + $FormFieldCopyWith get email { + return $FormFieldCopyWith(_value.email, (value) { + return _then(_value.copyWith(email: value) as $Val); + }); + } + + @override + @pragma('vm:prefer-inline') + $FormFieldCopyWith get password { + return $FormFieldCopyWith(_value.password, (value) { + return _then(_value.copyWith(password: value) as $Val); + }); + } } /// @nodoc @@ -95,10 +114,15 @@ abstract class _$$_LoginStateCopyWith<$Res> @useResult $Res call( {String? flowId, - String email, - String password, + FormField email, + FormField password, bool isLoading, String? errorMessage}); + + @override + $FormFieldCopyWith get email; + @override + $FormFieldCopyWith get password; } /// @nodoc @@ -126,11 +150,11 @@ class __$$_LoginStateCopyWithImpl<$Res> email: null == email ? _value.email : email // ignore: cast_nullable_to_non_nullable - as String, + as FormField, password: null == password ? _value.password : password // ignore: cast_nullable_to_non_nullable - as String, + as FormField, isLoading: null == isLoading ? _value.isLoading : isLoading // ignore: cast_nullable_to_non_nullable @@ -148,8 +172,8 @@ class __$$_LoginStateCopyWithImpl<$Res> class _$_LoginState implements _LoginState { const _$_LoginState( {this.flowId, - this.email = '', - this.password = '', + this.email = const FormField(value: ''), + this.password = const FormField(value: ''), this.isLoading = false, this.errorMessage}); @@ -157,10 +181,10 @@ class _$_LoginState implements _LoginState { final String? flowId; @override @JsonKey() - final String email; + final FormField email; @override @JsonKey() - final String password; + final FormField password; @override @JsonKey() final bool isLoading; @@ -201,17 +225,17 @@ class _$_LoginState implements _LoginState { abstract class _LoginState implements LoginState { const factory _LoginState( {final String? flowId, - final String email, - final String password, + final FormField email, + final FormField password, final bool isLoading, final String? errorMessage}) = _$_LoginState; @override String? get flowId; @override - String get email; + FormField get email; @override - String get password; + FormField get password; @override bool get isLoading; @override diff --git a/kratos-flutter/lib/blocs/login/login_state.dart b/kratos-flutter/lib/blocs/login/login_state.dart index 3c1a8815..89f5054b 100644 --- a/kratos-flutter/lib/blocs/login/login_state.dart +++ b/kratos-flutter/lib/blocs/login/login_state.dart @@ -4,8 +4,8 @@ part of 'login_bloc.dart'; sealed class LoginState with _$LoginState { const factory LoginState( {String? flowId, - @Default('') String email, - @Default('') String password, + @Default(FormField(value: '')) FormField email, + @Default(FormField(value: '')) FormField password, @Default(false) bool isLoading, String? errorMessage}) = _LoginState; } diff --git a/kratos-flutter/lib/entities/formfield.dart b/kratos-flutter/lib/entities/formfield.dart new file mode 100644 index 00000000..caeafe57 --- /dev/null +++ b/kratos-flutter/lib/entities/formfield.dart @@ -0,0 +1,8 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'formfield.freezed.dart'; + +@freezed +sealed class FormField with _$FormField { + const factory FormField({T? value, String? errorMessage}) = _FormField; +} diff --git a/kratos-flutter/lib/entities/formfield.freezed.dart b/kratos-flutter/lib/entities/formfield.freezed.dart new file mode 100644 index 00000000..67e05f8d --- /dev/null +++ b/kratos-flutter/lib/entities/formfield.freezed.dart @@ -0,0 +1,151 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'formfield.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +mixin _$FormField { + T? get value => throw _privateConstructorUsedError; + String? get errorMessage => throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $FormFieldCopyWith> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $FormFieldCopyWith { + factory $FormFieldCopyWith( + FormField value, $Res Function(FormField) then) = + _$FormFieldCopyWithImpl>; + @useResult + $Res call({T? value, String? errorMessage}); +} + +/// @nodoc +class _$FormFieldCopyWithImpl> + implements $FormFieldCopyWith { + _$FormFieldCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? value = freezed, + Object? errorMessage = freezed, + }) { + return _then(_value.copyWith( + value: freezed == value + ? _value.value + : value // ignore: cast_nullable_to_non_nullable + as T?, + errorMessage: freezed == errorMessage + ? _value.errorMessage + : errorMessage // ignore: cast_nullable_to_non_nullable + as String?, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$_FormFieldCopyWith + implements $FormFieldCopyWith { + factory _$$_FormFieldCopyWith( + _$_FormField value, $Res Function(_$_FormField) then) = + __$$_FormFieldCopyWithImpl; + @override + @useResult + $Res call({T? value, String? errorMessage}); +} + +/// @nodoc +class __$$_FormFieldCopyWithImpl + extends _$FormFieldCopyWithImpl> + implements _$$_FormFieldCopyWith { + __$$_FormFieldCopyWithImpl( + _$_FormField _value, $Res Function(_$_FormField) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? value = freezed, + Object? errorMessage = freezed, + }) { + return _then(_$_FormField( + value: freezed == value + ? _value.value + : value // ignore: cast_nullable_to_non_nullable + as T?, + errorMessage: freezed == errorMessage + ? _value.errorMessage + : errorMessage // ignore: cast_nullable_to_non_nullable + as String?, + )); + } +} + +/// @nodoc + +class _$_FormField implements _FormField { + const _$_FormField({this.value, this.errorMessage}); + + @override + final T? value; + @override + final String? errorMessage; + + @override + String toString() { + return 'FormField<$T>(value: $value, errorMessage: $errorMessage)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$_FormField && + const DeepCollectionEquality().equals(other.value, value) && + (identical(other.errorMessage, errorMessage) || + other.errorMessage == errorMessage)); + } + + @override + int get hashCode => Object.hash( + runtimeType, const DeepCollectionEquality().hash(value), errorMessage); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$_FormFieldCopyWith> get copyWith => + __$$_FormFieldCopyWithImpl>(this, _$identity); +} + +abstract class _FormField implements FormField { + const factory _FormField({final T? value, final String? errorMessage}) = + _$_FormField; + + @override + T? get value; + @override + String? get errorMessage; + @override + @JsonKey(ignore: true) + _$$_FormFieldCopyWith> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/kratos-flutter/lib/pages/login.dart b/kratos-flutter/lib/pages/login.dart index b3ea7046..094e7eda 100644 --- a/kratos-flutter/lib/pages/login.dart +++ b/kratos-flutter/lib/pages/login.dart @@ -41,7 +41,11 @@ class LoginForm extends StatelessWidget { _buildLoginFlowNotCreated(BuildContext context, LoginState state) { if (state.errorMessage != null) { - return Center(child: Text(state.errorMessage!)); + return Center( + child: Text( + state.errorMessage!, + style: const TextStyle(color: Colors.red), + )); } else { return const Center(child: CircularProgressIndicator()); } @@ -49,7 +53,7 @@ class LoginForm extends StatelessWidget { _buildLoginForm(BuildContext context, LoginState state) { return Padding( - padding: const EdgeInsets.all(10.0), + padding: const EdgeInsets.all(20.0), child: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, @@ -57,33 +61,45 @@ class LoginForm extends StatelessWidget { children: [ TextFormField( enabled: !state.isLoading, - initialValue: state.email, + initialValue: state.email.value, onChanged: (String value) => context.read().add(ChangeEmail(value: value)), - decoration: const InputDecoration( - border: OutlineInputBorder(), - label: Text('Email'), - hintText: 'Enter your email', - ), + decoration: InputDecoration( + border: const OutlineInputBorder(), + label: const Text('Email'), + hintText: 'Enter your email', + errorText: state.email.errorMessage), ), const SizedBox( height: 20, ), TextFormField( enabled: !state.isLoading, - initialValue: state.email, + initialValue: state.email.value, onChanged: (String value) => context.read().add(ChangePassword(value: value)), - decoration: const InputDecoration( - border: OutlineInputBorder(), - label: Text('Password'), - hintText: 'Enter your password', - ), + decoration: InputDecoration( + border: const OutlineInputBorder(), + label: const Text('Password'), + hintText: 'Enter your password', + errorText: state.password.errorMessage), + ), + const SizedBox( + height: 20, ), if (state.errorMessage != null) Text(state.errorMessage!, style: const TextStyle(color: Colors.red)), - OutlinedButton(onPressed: null, child: const Text('Submit')) + OutlinedButton( + onPressed: state.isLoading + ? null + : () { + context.read().add(LoginWithEmailAndPassword( + flowId: state.flowId!, + email: state.email.value, + password: state.password.value)); + }, + child: const Text('Submit')) ], )), ); diff --git a/kratos-flutter/lib/repositories/auth.dart b/kratos-flutter/lib/repositories/auth.dart index 0c0c108b..32ab8c16 100644 --- a/kratos-flutter/lib/repositories/auth.dart +++ b/kratos-flutter/lib/repositories/auth.dart @@ -18,4 +18,12 @@ class AuthRepository { final flowId = await service.createLoginFlow(); return flowId; } + + Future loginWithEmailAndPassword( + {required String flowId, + required String email, + required String password}) async { + await service.loginWithEmailAndPassword( + flowId: flowId, email: email, password: password); + } } diff --git a/kratos-flutter/lib/services/auth.dart b/kratos-flutter/lib/services/auth.dart index 3954f17c..3037bb7f 100644 --- a/kratos-flutter/lib/services/auth.dart +++ b/kratos-flutter/lib/services/auth.dart @@ -1,7 +1,9 @@ import 'package:dio/dio.dart'; +import 'package:one_of/one_of.dart'; import 'package:ory_client/ory_client.dart'; import 'exceptions.dart'; +import 'message.dart'; import 'storage.dart'; class AuthService { @@ -14,12 +16,21 @@ class AuthService { final token = await storage.getToken(); final response = await _ory.toSession(xSessionToken: token); if (response.data != null) { + // return session return response.data!; } else { throw DioException(requestOptions: response.requestOptions); } } on DioException catch (e) { - throw CustomException.fromDioException(e); + if (e.response?.statusCode == 401) { + throw const CustomException.unauthorized(); + } else { + throw CustomException.unknown( + statusCode: e.response?.statusCode, + message: e.response?.data['error'] != null + ? e.response?.data['error']['message'] + : null); + } } } @@ -27,12 +38,79 @@ class AuthService { try { final response = await _ory.createNativeLoginFlow(); if (response.statusCode == 200) { + // return flow id return response.data!.id; } else { - throw CustomException(statusCode: response.statusCode); + throw const CustomException.unknown(); } } on DioException catch (e) { - throw CustomException.fromDioException(e); + throw CustomException.unknown( + statusCode: e.response?.statusCode, + message: e.response?.data['error'] != null + ? e.response?.data['error']['message'] + : null); } } + + Future loginWithEmailAndPassword( + {required String flowId, + required String email, + required String password}) async { + try { + final UpdateLoginFlowWithPasswordMethod loginFLowBilder = + UpdateLoginFlowWithPasswordMethod((b) => b + ..identifier = email + ..password = password + ..method = 'password'); + + final response = await _ory.updateLoginFlow( + flow: flowId, + updateLoginFlowBody: UpdateLoginFlowBody( + (b) => b..oneOf = OneOf.fromValue1(value: loginFLowBilder))); + if (response.statusCode == 200 && response.data?.sessionToken != null) { + // save session token after successful login + await storage.persistToken(response.data!.sessionToken!); + return; + } else { + throw const CustomException.unknown(); + } + } on DioException catch (e) { + if (e.response?.statusCode == 401) { + throw const CustomException.unauthorized(); + } else if (e.response?.statusCode == 400) { + final messages = checkFormForErrors(e.response?.data); + throw CustomException.badRequest(messages: messages); + } else if (e.response?.statusCode == 410) { + throw CustomException.flowExpired( + flowId: e.response?.data['use_flow_id']); + } else { + throw CustomException.unknown( + statusCode: e.response?.statusCode, + message: e.response?.data['error'] != null + ? e.response?.data['error']['message'] + : null); + } + } + } + + List checkFormForErrors(Map response) { + final ui = Map.from(response['ui']); + final nodeList = ui['nodes'] as List; + final nodeMessages = + nodeList.map((element) => element['messages'] as List).toList(); + + if (ui['messages'] != null) { + final messageList = ui['messages'] as List; + nodeMessages.add(messageList); + } + + final flattedNodeMessages = + nodeMessages.expand((element) => element).toList(); + + final parsedMessages = flattedNodeMessages + .map((e) => UiNodeMessage.fromJson(e)) + .toList(); + + return parsedMessages; + } } diff --git a/kratos-flutter/lib/services/exceptions.dart b/kratos-flutter/lib/services/exceptions.dart index bb4b7f03..0066efeb 100644 --- a/kratos-flutter/lib/services/exceptions.dart +++ b/kratos-flutter/lib/services/exceptions.dart @@ -1,55 +1,23 @@ -import 'package:dio/dio.dart'; - -enum OryExceptionType { - //exception for an expired session token. - unauthorizedException, - - //exception for an incorrect parameter in a request/response. - badRequestException, - - //The exception for an unknown type of failure. - unknownException, - - //The exception for an expired flow - flowExpiredException -} - -class CustomException implements Exception { - final String? message; - - final int? statusCode; - final OryExceptionType exceptionType; - - CustomException({ - statusCode, - this.message = 'An error occured. Please try again later', - this.exceptionType = OryExceptionType.unknownException, - }) : statusCode = statusCode ?? 500; - - factory CustomException.fromDioException(DioException error) { - try { - switch (error.type) { - case DioExceptionType.unknown: - if (error.response?.statusCode == 401) { - return CustomException( - exceptionType: OryExceptionType.unauthorizedException, - statusCode: error.response?.statusCode, - message: error.response?.data?['error']['message'], - ); - } else if (error.response?.statusCode == 410) { - return CustomException( - exceptionType: OryExceptionType.flowExpiredException, - statusCode: error.response?.statusCode, - message: error.response?.data?['error']['message'], - ); - } else { - return CustomException(statusCode: error.response?.statusCode); - } - default: - return CustomException(statusCode: error.response?.statusCode); - } - } on Exception catch (_) { - return CustomException(); - } - } +import 'package:flutter/foundation.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; + +import 'message.dart'; + +part 'exceptions.freezed.dart'; + +@freezed +sealed class CustomException with _$CustomException { + const CustomException._(); + const factory CustomException.badRequest( + {List? messages, + @Default(400) int statusCode}) = BadRequestException; + const factory CustomException.unauthorized({@Default(401) int statusCode}) = + UnauthorizedException; + const factory CustomException.flowExpired( + {@Default(410) int statusCode, + required String flowId}) = FlowExpiredException; + const factory CustomException.unknown( + {int? statusCode, + @Default('An error occured. Please try again later.') + String message}) = UnknownException; } diff --git a/kratos-flutter/lib/services/exceptions.freezed.dart b/kratos-flutter/lib/services/exceptions.freezed.dart new file mode 100644 index 00000000..7ec831f9 --- /dev/null +++ b/kratos-flutter/lib/services/exceptions.freezed.dart @@ -0,0 +1,815 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'exceptions.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +mixin _$CustomException { + int? get statusCode => throw _privateConstructorUsedError; + @optionalTypeArgs + TResult when({ + required TResult Function(List? messages, int statusCode) + badRequest, + required TResult Function(int statusCode) unauthorized, + required TResult Function(int statusCode, String flowId) flowExpired, + required TResult Function(int? statusCode, String message) unknown, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(List? messages, int statusCode)? + badRequest, + TResult? Function(int statusCode)? unauthorized, + TResult? Function(int statusCode, String flowId)? flowExpired, + TResult? Function(int? statusCode, String message)? unknown, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(List? messages, int statusCode)? badRequest, + TResult Function(int statusCode)? unauthorized, + TResult Function(int statusCode, String flowId)? flowExpired, + TResult Function(int? statusCode, String message)? unknown, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(BadRequestException value) badRequest, + required TResult Function(UnauthorizedException value) unauthorized, + required TResult Function(FlowExpiredException value) flowExpired, + required TResult Function(UnknownException value) unknown, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(BadRequestException value)? badRequest, + TResult? Function(UnauthorizedException value)? unauthorized, + TResult? Function(FlowExpiredException value)? flowExpired, + TResult? Function(UnknownException value)? unknown, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(BadRequestException value)? badRequest, + TResult Function(UnauthorizedException value)? unauthorized, + TResult Function(FlowExpiredException value)? flowExpired, + TResult Function(UnknownException value)? unknown, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $CustomExceptionCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $CustomExceptionCopyWith<$Res> { + factory $CustomExceptionCopyWith( + CustomException value, $Res Function(CustomException) then) = + _$CustomExceptionCopyWithImpl<$Res, CustomException>; + @useResult + $Res call({int statusCode}); +} + +/// @nodoc +class _$CustomExceptionCopyWithImpl<$Res, $Val extends CustomException> + implements $CustomExceptionCopyWith<$Res> { + _$CustomExceptionCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? statusCode = null, + }) { + return _then(_value.copyWith( + statusCode: null == statusCode + ? _value.statusCode! + : statusCode // ignore: cast_nullable_to_non_nullable + as int, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$BadRequestExceptionCopyWith<$Res> + implements $CustomExceptionCopyWith<$Res> { + factory _$$BadRequestExceptionCopyWith(_$BadRequestException value, + $Res Function(_$BadRequestException) then) = + __$$BadRequestExceptionCopyWithImpl<$Res>; + @override + @useResult + $Res call({List? messages, int statusCode}); +} + +/// @nodoc +class __$$BadRequestExceptionCopyWithImpl<$Res> + extends _$CustomExceptionCopyWithImpl<$Res, _$BadRequestException> + implements _$$BadRequestExceptionCopyWith<$Res> { + __$$BadRequestExceptionCopyWithImpl( + _$BadRequestException _value, $Res Function(_$BadRequestException) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? messages = freezed, + Object? statusCode = null, + }) { + return _then(_$BadRequestException( + messages: freezed == messages + ? _value._messages + : messages // ignore: cast_nullable_to_non_nullable + as List?, + statusCode: null == statusCode + ? _value.statusCode + : statusCode // ignore: cast_nullable_to_non_nullable + as int, + )); + } +} + +/// @nodoc + +class _$BadRequestException extends BadRequestException + with DiagnosticableTreeMixin { + const _$BadRequestException( + {final List? messages, this.statusCode = 400}) + : _messages = messages, + super._(); + + final List? _messages; + @override + List? get messages { + final value = _messages; + if (value == null) return null; + if (_messages is EqualUnmodifiableListView) return _messages; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(value); + } + + @override + @JsonKey() + final int statusCode; + + @override + String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { + return 'CustomException.badRequest(messages: $messages, statusCode: $statusCode)'; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties + ..add(DiagnosticsProperty('type', 'CustomException.badRequest')) + ..add(DiagnosticsProperty('messages', messages)) + ..add(DiagnosticsProperty('statusCode', statusCode)); + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$BadRequestException && + const DeepCollectionEquality().equals(other._messages, _messages) && + (identical(other.statusCode, statusCode) || + other.statusCode == statusCode)); + } + + @override + int get hashCode => Object.hash( + runtimeType, const DeepCollectionEquality().hash(_messages), statusCode); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$BadRequestExceptionCopyWith<_$BadRequestException> get copyWith => + __$$BadRequestExceptionCopyWithImpl<_$BadRequestException>( + this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(List? messages, int statusCode) + badRequest, + required TResult Function(int statusCode) unauthorized, + required TResult Function(int statusCode, String flowId) flowExpired, + required TResult Function(int? statusCode, String message) unknown, + }) { + return badRequest(messages, statusCode); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(List? messages, int statusCode)? + badRequest, + TResult? Function(int statusCode)? unauthorized, + TResult? Function(int statusCode, String flowId)? flowExpired, + TResult? Function(int? statusCode, String message)? unknown, + }) { + return badRequest?.call(messages, statusCode); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(List? messages, int statusCode)? badRequest, + TResult Function(int statusCode)? unauthorized, + TResult Function(int statusCode, String flowId)? flowExpired, + TResult Function(int? statusCode, String message)? unknown, + required TResult orElse(), + }) { + if (badRequest != null) { + return badRequest(messages, statusCode); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(BadRequestException value) badRequest, + required TResult Function(UnauthorizedException value) unauthorized, + required TResult Function(FlowExpiredException value) flowExpired, + required TResult Function(UnknownException value) unknown, + }) { + return badRequest(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(BadRequestException value)? badRequest, + TResult? Function(UnauthorizedException value)? unauthorized, + TResult? Function(FlowExpiredException value)? flowExpired, + TResult? Function(UnknownException value)? unknown, + }) { + return badRequest?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(BadRequestException value)? badRequest, + TResult Function(UnauthorizedException value)? unauthorized, + TResult Function(FlowExpiredException value)? flowExpired, + TResult Function(UnknownException value)? unknown, + required TResult orElse(), + }) { + if (badRequest != null) { + return badRequest(this); + } + return orElse(); + } +} + +abstract class BadRequestException extends CustomException { + const factory BadRequestException( + {final List? messages, + final int statusCode}) = _$BadRequestException; + const BadRequestException._() : super._(); + + List? get messages; + @override + int get statusCode; + @override + @JsonKey(ignore: true) + _$$BadRequestExceptionCopyWith<_$BadRequestException> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$$UnauthorizedExceptionCopyWith<$Res> + implements $CustomExceptionCopyWith<$Res> { + factory _$$UnauthorizedExceptionCopyWith(_$UnauthorizedException value, + $Res Function(_$UnauthorizedException) then) = + __$$UnauthorizedExceptionCopyWithImpl<$Res>; + @override + @useResult + $Res call({int statusCode}); +} + +/// @nodoc +class __$$UnauthorizedExceptionCopyWithImpl<$Res> + extends _$CustomExceptionCopyWithImpl<$Res, _$UnauthorizedException> + implements _$$UnauthorizedExceptionCopyWith<$Res> { + __$$UnauthorizedExceptionCopyWithImpl(_$UnauthorizedException _value, + $Res Function(_$UnauthorizedException) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? statusCode = null, + }) { + return _then(_$UnauthorizedException( + statusCode: null == statusCode + ? _value.statusCode + : statusCode // ignore: cast_nullable_to_non_nullable + as int, + )); + } +} + +/// @nodoc + +class _$UnauthorizedException extends UnauthorizedException + with DiagnosticableTreeMixin { + const _$UnauthorizedException({this.statusCode = 401}) : super._(); + + @override + @JsonKey() + final int statusCode; + + @override + String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { + return 'CustomException.unauthorized(statusCode: $statusCode)'; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties + ..add(DiagnosticsProperty('type', 'CustomException.unauthorized')) + ..add(DiagnosticsProperty('statusCode', statusCode)); + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$UnauthorizedException && + (identical(other.statusCode, statusCode) || + other.statusCode == statusCode)); + } + + @override + int get hashCode => Object.hash(runtimeType, statusCode); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$UnauthorizedExceptionCopyWith<_$UnauthorizedException> get copyWith => + __$$UnauthorizedExceptionCopyWithImpl<_$UnauthorizedException>( + this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(List? messages, int statusCode) + badRequest, + required TResult Function(int statusCode) unauthorized, + required TResult Function(int statusCode, String flowId) flowExpired, + required TResult Function(int? statusCode, String message) unknown, + }) { + return unauthorized(statusCode); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(List? messages, int statusCode)? + badRequest, + TResult? Function(int statusCode)? unauthorized, + TResult? Function(int statusCode, String flowId)? flowExpired, + TResult? Function(int? statusCode, String message)? unknown, + }) { + return unauthorized?.call(statusCode); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(List? messages, int statusCode)? badRequest, + TResult Function(int statusCode)? unauthorized, + TResult Function(int statusCode, String flowId)? flowExpired, + TResult Function(int? statusCode, String message)? unknown, + required TResult orElse(), + }) { + if (unauthorized != null) { + return unauthorized(statusCode); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(BadRequestException value) badRequest, + required TResult Function(UnauthorizedException value) unauthorized, + required TResult Function(FlowExpiredException value) flowExpired, + required TResult Function(UnknownException value) unknown, + }) { + return unauthorized(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(BadRequestException value)? badRequest, + TResult? Function(UnauthorizedException value)? unauthorized, + TResult? Function(FlowExpiredException value)? flowExpired, + TResult? Function(UnknownException value)? unknown, + }) { + return unauthorized?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(BadRequestException value)? badRequest, + TResult Function(UnauthorizedException value)? unauthorized, + TResult Function(FlowExpiredException value)? flowExpired, + TResult Function(UnknownException value)? unknown, + required TResult orElse(), + }) { + if (unauthorized != null) { + return unauthorized(this); + } + return orElse(); + } +} + +abstract class UnauthorizedException extends CustomException { + const factory UnauthorizedException({final int statusCode}) = + _$UnauthorizedException; + const UnauthorizedException._() : super._(); + + @override + int get statusCode; + @override + @JsonKey(ignore: true) + _$$UnauthorizedExceptionCopyWith<_$UnauthorizedException> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$$FlowExpiredExceptionCopyWith<$Res> + implements $CustomExceptionCopyWith<$Res> { + factory _$$FlowExpiredExceptionCopyWith(_$FlowExpiredException value, + $Res Function(_$FlowExpiredException) then) = + __$$FlowExpiredExceptionCopyWithImpl<$Res>; + @override + @useResult + $Res call({int statusCode, String flowId}); +} + +/// @nodoc +class __$$FlowExpiredExceptionCopyWithImpl<$Res> + extends _$CustomExceptionCopyWithImpl<$Res, _$FlowExpiredException> + implements _$$FlowExpiredExceptionCopyWith<$Res> { + __$$FlowExpiredExceptionCopyWithImpl(_$FlowExpiredException _value, + $Res Function(_$FlowExpiredException) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? statusCode = null, + Object? flowId = null, + }) { + return _then(_$FlowExpiredException( + statusCode: null == statusCode + ? _value.statusCode + : statusCode // ignore: cast_nullable_to_non_nullable + as int, + flowId: null == flowId + ? _value.flowId + : flowId // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc + +class _$FlowExpiredException extends FlowExpiredException + with DiagnosticableTreeMixin { + const _$FlowExpiredException({this.statusCode = 410, required this.flowId}) + : super._(); + + @override + @JsonKey() + final int statusCode; + @override + final String flowId; + + @override + String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { + return 'CustomException.flowExpired(statusCode: $statusCode, flowId: $flowId)'; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties + ..add(DiagnosticsProperty('type', 'CustomException.flowExpired')) + ..add(DiagnosticsProperty('statusCode', statusCode)) + ..add(DiagnosticsProperty('flowId', flowId)); + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$FlowExpiredException && + (identical(other.statusCode, statusCode) || + other.statusCode == statusCode) && + (identical(other.flowId, flowId) || other.flowId == flowId)); + } + + @override + int get hashCode => Object.hash(runtimeType, statusCode, flowId); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$FlowExpiredExceptionCopyWith<_$FlowExpiredException> get copyWith => + __$$FlowExpiredExceptionCopyWithImpl<_$FlowExpiredException>( + this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(List? messages, int statusCode) + badRequest, + required TResult Function(int statusCode) unauthorized, + required TResult Function(int statusCode, String flowId) flowExpired, + required TResult Function(int? statusCode, String message) unknown, + }) { + return flowExpired(statusCode, flowId); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(List? messages, int statusCode)? + badRequest, + TResult? Function(int statusCode)? unauthorized, + TResult? Function(int statusCode, String flowId)? flowExpired, + TResult? Function(int? statusCode, String message)? unknown, + }) { + return flowExpired?.call(statusCode, flowId); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(List? messages, int statusCode)? badRequest, + TResult Function(int statusCode)? unauthorized, + TResult Function(int statusCode, String flowId)? flowExpired, + TResult Function(int? statusCode, String message)? unknown, + required TResult orElse(), + }) { + if (flowExpired != null) { + return flowExpired(statusCode, flowId); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(BadRequestException value) badRequest, + required TResult Function(UnauthorizedException value) unauthorized, + required TResult Function(FlowExpiredException value) flowExpired, + required TResult Function(UnknownException value) unknown, + }) { + return flowExpired(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(BadRequestException value)? badRequest, + TResult? Function(UnauthorizedException value)? unauthorized, + TResult? Function(FlowExpiredException value)? flowExpired, + TResult? Function(UnknownException value)? unknown, + }) { + return flowExpired?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(BadRequestException value)? badRequest, + TResult Function(UnauthorizedException value)? unauthorized, + TResult Function(FlowExpiredException value)? flowExpired, + TResult Function(UnknownException value)? unknown, + required TResult orElse(), + }) { + if (flowExpired != null) { + return flowExpired(this); + } + return orElse(); + } +} + +abstract class FlowExpiredException extends CustomException { + const factory FlowExpiredException( + {final int statusCode, + required final String flowId}) = _$FlowExpiredException; + const FlowExpiredException._() : super._(); + + @override + int get statusCode; + String get flowId; + @override + @JsonKey(ignore: true) + _$$FlowExpiredExceptionCopyWith<_$FlowExpiredException> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$$UnknownExceptionCopyWith<$Res> + implements $CustomExceptionCopyWith<$Res> { + factory _$$UnknownExceptionCopyWith( + _$UnknownException value, $Res Function(_$UnknownException) then) = + __$$UnknownExceptionCopyWithImpl<$Res>; + @override + @useResult + $Res call({int? statusCode, String message}); +} + +/// @nodoc +class __$$UnknownExceptionCopyWithImpl<$Res> + extends _$CustomExceptionCopyWithImpl<$Res, _$UnknownException> + implements _$$UnknownExceptionCopyWith<$Res> { + __$$UnknownExceptionCopyWithImpl( + _$UnknownException _value, $Res Function(_$UnknownException) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? statusCode = freezed, + Object? message = null, + }) { + return _then(_$UnknownException( + statusCode: freezed == statusCode + ? _value.statusCode + : statusCode // ignore: cast_nullable_to_non_nullable + as int?, + message: null == message + ? _value.message + : message // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc + +class _$UnknownException extends UnknownException with DiagnosticableTreeMixin { + const _$UnknownException( + {this.statusCode, + this.message = 'An error occured. Please try again later.'}) + : super._(); + + @override + final int? statusCode; + @override + @JsonKey() + final String message; + + @override + String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { + return 'CustomException.unknown(statusCode: $statusCode, message: $message)'; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties + ..add(DiagnosticsProperty('type', 'CustomException.unknown')) + ..add(DiagnosticsProperty('statusCode', statusCode)) + ..add(DiagnosticsProperty('message', message)); + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$UnknownException && + (identical(other.statusCode, statusCode) || + other.statusCode == statusCode) && + (identical(other.message, message) || other.message == message)); + } + + @override + int get hashCode => Object.hash(runtimeType, statusCode, message); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$UnknownExceptionCopyWith<_$UnknownException> get copyWith => + __$$UnknownExceptionCopyWithImpl<_$UnknownException>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(List? messages, int statusCode) + badRequest, + required TResult Function(int statusCode) unauthorized, + required TResult Function(int statusCode, String flowId) flowExpired, + required TResult Function(int? statusCode, String message) unknown, + }) { + return unknown(statusCode, message); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(List? messages, int statusCode)? + badRequest, + TResult? Function(int statusCode)? unauthorized, + TResult? Function(int statusCode, String flowId)? flowExpired, + TResult? Function(int? statusCode, String message)? unknown, + }) { + return unknown?.call(statusCode, message); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(List? messages, int statusCode)? badRequest, + TResult Function(int statusCode)? unauthorized, + TResult Function(int statusCode, String flowId)? flowExpired, + TResult Function(int? statusCode, String message)? unknown, + required TResult orElse(), + }) { + if (unknown != null) { + return unknown(statusCode, message); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(BadRequestException value) badRequest, + required TResult Function(UnauthorizedException value) unauthorized, + required TResult Function(FlowExpiredException value) flowExpired, + required TResult Function(UnknownException value) unknown, + }) { + return unknown(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(BadRequestException value)? badRequest, + TResult? Function(UnauthorizedException value)? unauthorized, + TResult? Function(FlowExpiredException value)? flowExpired, + TResult? Function(UnknownException value)? unknown, + }) { + return unknown?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(BadRequestException value)? badRequest, + TResult Function(UnauthorizedException value)? unauthorized, + TResult Function(FlowExpiredException value)? flowExpired, + TResult Function(UnknownException value)? unknown, + required TResult orElse(), + }) { + if (unknown != null) { + return unknown(this); + } + return orElse(); + } +} + +abstract class UnknownException extends CustomException { + const factory UnknownException( + {final int? statusCode, final String message}) = _$UnknownException; + const UnknownException._() : super._(); + + @override + int? get statusCode; + String get message; + @override + @JsonKey(ignore: true) + _$$UnknownExceptionCopyWith<_$UnknownException> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/kratos-flutter/lib/services/message.dart b/kratos-flutter/lib/services/message.dart new file mode 100644 index 00000000..20225596 --- /dev/null +++ b/kratos-flutter/lib/services/message.dart @@ -0,0 +1,31 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'message.freezed.dart'; +part 'message.g.dart'; + +@freezed +class UiNodeMessage with _$UiNodeMessage { + const factory UiNodeMessage( + {required int id, + required String text, + required MessageType type, + required Context context}) = _UiNodeMessage; + + factory UiNodeMessage.fromJson(Map json) => + _$UiNodeMessageFromJson(json); +} + +@freezed +class Context with _$Context { + const factory Context({@Default(Property.general) Property property}) = + _Context; + + factory Context.fromJson(Map json) => + _$ContextFromJson(json); +} + +// speicifies which group the node belongs to +enum Property { identifier, password, general } + +// specifies message type +enum MessageType { info, error, success } diff --git a/kratos-flutter/lib/services/message.freezed.dart b/kratos-flutter/lib/services/message.freezed.dart new file mode 100644 index 00000000..0a19c507 --- /dev/null +++ b/kratos-flutter/lib/services/message.freezed.dart @@ -0,0 +1,353 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'message.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +UiNodeMessage _$UiNodeMessageFromJson(Map json) { + return _UiNodeMessage.fromJson(json); +} + +/// @nodoc +mixin _$UiNodeMessage { + int get id => throw _privateConstructorUsedError; + String get text => throw _privateConstructorUsedError; + MessageType get type => throw _privateConstructorUsedError; + Context get context => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $UiNodeMessageCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $UiNodeMessageCopyWith<$Res> { + factory $UiNodeMessageCopyWith( + UiNodeMessage value, $Res Function(UiNodeMessage) then) = + _$UiNodeMessageCopyWithImpl<$Res, UiNodeMessage>; + @useResult + $Res call({int id, String text, MessageType type, Context context}); + + $ContextCopyWith<$Res> get context; +} + +/// @nodoc +class _$UiNodeMessageCopyWithImpl<$Res, $Val extends UiNodeMessage> + implements $UiNodeMessageCopyWith<$Res> { + _$UiNodeMessageCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? text = null, + Object? type = null, + Object? context = null, + }) { + return _then(_value.copyWith( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as int, + text: null == text + ? _value.text + : text // ignore: cast_nullable_to_non_nullable + as String, + type: null == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as MessageType, + context: null == context + ? _value.context + : context // ignore: cast_nullable_to_non_nullable + as Context, + ) as $Val); + } + + @override + @pragma('vm:prefer-inline') + $ContextCopyWith<$Res> get context { + return $ContextCopyWith<$Res>(_value.context, (value) { + return _then(_value.copyWith(context: value) as $Val); + }); + } +} + +/// @nodoc +abstract class _$$_UiNodeMessageCopyWith<$Res> + implements $UiNodeMessageCopyWith<$Res> { + factory _$$_UiNodeMessageCopyWith( + _$_UiNodeMessage value, $Res Function(_$_UiNodeMessage) then) = + __$$_UiNodeMessageCopyWithImpl<$Res>; + @override + @useResult + $Res call({int id, String text, MessageType type, Context context}); + + @override + $ContextCopyWith<$Res> get context; +} + +/// @nodoc +class __$$_UiNodeMessageCopyWithImpl<$Res> + extends _$UiNodeMessageCopyWithImpl<$Res, _$_UiNodeMessage> + implements _$$_UiNodeMessageCopyWith<$Res> { + __$$_UiNodeMessageCopyWithImpl( + _$_UiNodeMessage _value, $Res Function(_$_UiNodeMessage) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? text = null, + Object? type = null, + Object? context = null, + }) { + return _then(_$_UiNodeMessage( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as int, + text: null == text + ? _value.text + : text // ignore: cast_nullable_to_non_nullable + as String, + type: null == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as MessageType, + context: null == context + ? _value.context + : context // ignore: cast_nullable_to_non_nullable + as Context, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$_UiNodeMessage implements _UiNodeMessage { + const _$_UiNodeMessage( + {required this.id, + required this.text, + required this.type, + required this.context}); + + factory _$_UiNodeMessage.fromJson(Map json) => + _$$_UiNodeMessageFromJson(json); + + @override + final int id; + @override + final String text; + @override + final MessageType type; + @override + final Context context; + + @override + String toString() { + return 'UiNodeMessage(id: $id, text: $text, type: $type, context: $context)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$_UiNodeMessage && + (identical(other.id, id) || other.id == id) && + (identical(other.text, text) || other.text == text) && + (identical(other.type, type) || other.type == type) && + (identical(other.context, context) || other.context == context)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash(runtimeType, id, text, type, context); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$_UiNodeMessageCopyWith<_$_UiNodeMessage> get copyWith => + __$$_UiNodeMessageCopyWithImpl<_$_UiNodeMessage>(this, _$identity); + + @override + Map toJson() { + return _$$_UiNodeMessageToJson( + this, + ); + } +} + +abstract class _UiNodeMessage implements UiNodeMessage { + const factory _UiNodeMessage( + {required final int id, + required final String text, + required final MessageType type, + required final Context context}) = _$_UiNodeMessage; + + factory _UiNodeMessage.fromJson(Map json) = + _$_UiNodeMessage.fromJson; + + @override + int get id; + @override + String get text; + @override + MessageType get type; + @override + Context get context; + @override + @JsonKey(ignore: true) + _$$_UiNodeMessageCopyWith<_$_UiNodeMessage> get copyWith => + throw _privateConstructorUsedError; +} + +Context _$ContextFromJson(Map json) { + return _Context.fromJson(json); +} + +/// @nodoc +mixin _$Context { + Property get property => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $ContextCopyWith get copyWith => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $ContextCopyWith<$Res> { + factory $ContextCopyWith(Context value, $Res Function(Context) then) = + _$ContextCopyWithImpl<$Res, Context>; + @useResult + $Res call({Property property}); +} + +/// @nodoc +class _$ContextCopyWithImpl<$Res, $Val extends Context> + implements $ContextCopyWith<$Res> { + _$ContextCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? property = null, + }) { + return _then(_value.copyWith( + property: null == property + ? _value.property + : property // ignore: cast_nullable_to_non_nullable + as Property, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$_ContextCopyWith<$Res> implements $ContextCopyWith<$Res> { + factory _$$_ContextCopyWith( + _$_Context value, $Res Function(_$_Context) then) = + __$$_ContextCopyWithImpl<$Res>; + @override + @useResult + $Res call({Property property}); +} + +/// @nodoc +class __$$_ContextCopyWithImpl<$Res> + extends _$ContextCopyWithImpl<$Res, _$_Context> + implements _$$_ContextCopyWith<$Res> { + __$$_ContextCopyWithImpl(_$_Context _value, $Res Function(_$_Context) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? property = null, + }) { + return _then(_$_Context( + property: null == property + ? _value.property + : property // ignore: cast_nullable_to_non_nullable + as Property, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$_Context implements _Context { + const _$_Context({this.property = Property.general}); + + factory _$_Context.fromJson(Map json) => + _$$_ContextFromJson(json); + + @override + @JsonKey() + final Property property; + + @override + String toString() { + return 'Context(property: $property)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$_Context && + (identical(other.property, property) || + other.property == property)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash(runtimeType, property); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$_ContextCopyWith<_$_Context> get copyWith => + __$$_ContextCopyWithImpl<_$_Context>(this, _$identity); + + @override + Map toJson() { + return _$$_ContextToJson( + this, + ); + } +} + +abstract class _Context implements Context { + const factory _Context({final Property property}) = _$_Context; + + factory _Context.fromJson(Map json) = _$_Context.fromJson; + + @override + Property get property; + @override + @JsonKey(ignore: true) + _$$_ContextCopyWith<_$_Context> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/kratos-flutter/lib/services/message.g.dart b/kratos-flutter/lib/services/message.g.dart new file mode 100644 index 00000000..aa1a9afd --- /dev/null +++ b/kratos-flutter/lib/services/message.g.dart @@ -0,0 +1,45 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'message.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$_UiNodeMessage _$$_UiNodeMessageFromJson(Map json) => + _$_UiNodeMessage( + id: json['id'] as int, + text: json['text'] as String, + type: $enumDecode(_$MessageTypeEnumMap, json['type']), + context: Context.fromJson(json['context'] as Map), + ); + +Map _$$_UiNodeMessageToJson(_$_UiNodeMessage instance) => + { + 'id': instance.id, + 'text': instance.text, + 'type': _$MessageTypeEnumMap[instance.type]!, + 'context': instance.context, + }; + +const _$MessageTypeEnumMap = { + MessageType.info: 'info', + MessageType.error: 'error', + MessageType.success: 'success', +}; + +_$_Context _$$_ContextFromJson(Map json) => _$_Context( + property: $enumDecodeNullable(_$PropertyEnumMap, json['property']) ?? + Property.general, + ); + +Map _$$_ContextToJson(_$_Context instance) => + { + 'property': _$PropertyEnumMap[instance.property]!, + }; + +const _$PropertyEnumMap = { + Property.identifier: 'identifier', + Property.password: 'password', + Property.general: 'general', +}; diff --git a/kratos-flutter/pubspec.lock b/kratos-flutter/pubspec.lock index 638b75e0..54816061 100644 --- a/kratos-flutter/pubspec.lock +++ b/kratos-flutter/pubspec.lock @@ -146,7 +146,7 @@ packages: source: hosted version: "4.5.0" collection: - dependency: transitive + dependency: "direct main" description: name: collection sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c" diff --git a/kratos-flutter/pubspec.yaml b/kratos-flutter/pubspec.yaml index 1fb27622..c8760c50 100644 --- a/kratos-flutter/pubspec.yaml +++ b/kratos-flutter/pubspec.yaml @@ -48,6 +48,7 @@ dependencies: one_of: ^1.5.0 flutter_secure_storage: ^8.0.0 dotenv: ^4.1.0 + collection: ^1.17.1 dev_dependencies: flutter_test: From b89a99dfd3ad350f2ea720e9754f1daadfe68578 Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Wed, 23 Aug 2023 16:09:41 +0200 Subject: [PATCH 04/57] feat: register with email and password --- .../lib/blocs/login/login_bloc.dart | 16 +- .../lib/blocs/login/login_event.dart | 5 - .../blocs/registration/registration_bloc.dart | 95 +++++ .../registration_bloc.freezed.dart | 248 ++++++++++++ .../registration/registration_event.dart | 41 ++ .../registration/registration_state.dart | 11 + kratos-flutter/lib/entities/form_node.dart | 17 + .../lib/entities/form_node.freezed.dart | 188 ++++++++++ kratos-flutter/lib/entities/form_node.g.dart | 21 ++ kratos-flutter/lib/entities/message.dart | 19 + .../lib/entities/message.freezed.dart | 208 +++++++++++ kratos-flutter/lib/entities/message.g.dart | 29 ++ .../lib/entities/node_attribute.dart | 11 + .../lib/entities/node_attribute.freezed.dart | 151 ++++++++ .../lib/entities/node_attribute.g.dart | 17 + kratos-flutter/lib/pages/login.dart | 30 +- kratos-flutter/lib/pages/registration.dart | 129 +++++++ kratos-flutter/lib/repositories/auth.dart | 13 + kratos-flutter/lib/services/auth.dart | 99 ++++- kratos-flutter/lib/services/exceptions.dart | 4 +- .../lib/services/exceptions.freezed.dart | 49 ++- kratos-flutter/lib/services/message.dart | 31 -- .../lib/services/message.freezed.dart | 353 ------------------ kratos-flutter/lib/services/message.g.dart | 45 --- kratos-flutter/pubspec.lock | 2 +- kratos-flutter/pubspec.yaml | 1 + 26 files changed, 1344 insertions(+), 489 deletions(-) create mode 100644 kratos-flutter/lib/blocs/registration/registration_bloc.dart create mode 100644 kratos-flutter/lib/blocs/registration/registration_bloc.freezed.dart create mode 100644 kratos-flutter/lib/blocs/registration/registration_event.dart create mode 100644 kratos-flutter/lib/blocs/registration/registration_state.dart create mode 100644 kratos-flutter/lib/entities/form_node.dart create mode 100644 kratos-flutter/lib/entities/form_node.freezed.dart create mode 100644 kratos-flutter/lib/entities/form_node.g.dart create mode 100644 kratos-flutter/lib/entities/message.dart create mode 100644 kratos-flutter/lib/entities/message.freezed.dart create mode 100644 kratos-flutter/lib/entities/message.g.dart create mode 100644 kratos-flutter/lib/entities/node_attribute.dart create mode 100644 kratos-flutter/lib/entities/node_attribute.freezed.dart create mode 100644 kratos-flutter/lib/entities/node_attribute.g.dart create mode 100644 kratos-flutter/lib/pages/registration.dart delete mode 100644 kratos-flutter/lib/services/message.dart delete mode 100644 kratos-flutter/lib/services/message.freezed.dart delete mode 100644 kratos-flutter/lib/services/message.g.dart diff --git a/kratos-flutter/lib/blocs/login/login_bloc.dart b/kratos-flutter/lib/blocs/login/login_bloc.dart index f981a93a..1300eb88 100644 --- a/kratos-flutter/lib/blocs/login/login_bloc.dart +++ b/kratos-flutter/lib/blocs/login/login_bloc.dart @@ -6,7 +6,6 @@ import 'package:collection/collection.dart'; import '../../entities/formfield.dart'; import '../../repositories/auth.dart'; import '../../services/exceptions.dart'; -import '../../services/message.dart'; import '../auth/auth_bloc.dart'; part 'login_event.dart'; @@ -17,7 +16,7 @@ class LoginBloc extends Bloc { final AuthBloc authBloc; final AuthRepository repository; LoginBloc({required this.authBloc, required this.repository}) - : super(const LoginState()) { + : super(LoginState()) { on(_onCreateLoginFlow); on(_onChangeEmail); on(_onChangePassword); @@ -64,13 +63,12 @@ class LoginBloc extends Bloc { authBloc.add(ChangeAuthStatus(status: AuthStatus.authenticated)); } on CustomException catch (e) { if (e case BadRequestException _) { - // get credential errors - final emailMessage = e.messages?.firstWhereOrNull( - (element) => element.context.property == Property.identifier); - final passwordMessage = e.messages?.firstWhereOrNull( - (element) => element.context.property == Property.password); - final generalMessage = e.messages?.firstWhereOrNull( - (element) => element.context.property == Property.general); + final emailMessage = e.messages + ?.firstWhereOrNull((element) => element.attr == 'identifier'); + final passwordMessage = e.messages + ?.firstWhereOrNull((element) => element.attr == 'password'); + final generalMessage = e.messages + ?.firstWhereOrNull((element) => element.attr == 'general'); // update state to new one with errors emit(state diff --git a/kratos-flutter/lib/blocs/login/login_event.dart b/kratos-flutter/lib/blocs/login/login_event.dart index ae96f71f..eecc4056 100644 --- a/kratos-flutter/lib/blocs/login/login_event.dart +++ b/kratos-flutter/lib/blocs/login/login_event.dart @@ -27,11 +27,6 @@ final class ChangePassword extends LoginEvent { List get props => [value]; } -final class ChangePasswordVisibility extends LoginEvent { - final bool isVisible; - ChangePasswordVisibility({required this.isVisible}); -} - //log in final class LoginWithEmailAndPassword extends LoginEvent { final String flowId; diff --git a/kratos-flutter/lib/blocs/registration/registration_bloc.dart b/kratos-flutter/lib/blocs/registration/registration_bloc.dart new file mode 100644 index 00000000..ea5f5713 --- /dev/null +++ b/kratos-flutter/lib/blocs/registration/registration_bloc.dart @@ -0,0 +1,95 @@ +import 'package:bloc/bloc.dart'; +import 'package:equatable/equatable.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:collection/collection.dart'; + +import '../../entities/formfield.dart'; +import '../../repositories/auth.dart'; +import '../../services/exceptions.dart'; +import '../auth/auth_bloc.dart'; + +part 'registration_event.dart'; +part 'registration_state.dart'; +part 'registration_bloc.freezed.dart'; + +class RegistrationBloc extends Bloc { + final AuthBloc authBloc; + final AuthRepository repository; + RegistrationBloc({required this.authBloc, required this.repository}) + : super(RegistrationState()) { + on(_onCreateRegistrationFlow); + on(_onChangeEmail); + on(_onChangePassword); + on(_onRegisterWithEmailAndPassword); + } + + Future _onCreateRegistrationFlow( + CreateRegistrationFlow event, Emitter emit) async { + try { + emit(state.copyWith(isLoading: true, errorMessage: null)); + final flowId = await repository.createRegistrationFlow(); + emit(state.copyWith(flowId: flowId, isLoading: false)); + } on CustomException catch (e) { + if (e case UnknownException _) { + emit(state.copyWith(isLoading: false, errorMessage: e.message)); + } else { + emit(state.copyWith(isLoading: false)); + } + } + } + + _onChangeEmail(ChangeEmail event, Emitter emit) { + // remove email and general error when changing email + emit(state.copyWith + .email(value: event.value, errorMessage: null) + .copyWith(errorMessage: null)); + } + + _onChangePassword(ChangePassword event, Emitter emit) { + // remove password and general error when changing email + emit(state.copyWith + .password(value: event.value, errorMessage: null) + .copyWith(errorMessage: null)); + } + + Future _onRegisterWithEmailAndPassword( + RegisterWithEmailAndPassword event, + Emitter emit) async { + try { + emit(state.copyWith(isLoading: true, errorMessage: null)); + + await repository.registerWithEmailAndPassword( + flowId: event.flowId, email: event.email, password: event.password); + + authBloc.add(ChangeAuthStatus(status: AuthStatus.authenticated)); + } on CustomException catch (e) { + if (e case BadRequestException _) { + // get credential errors + final emailMessage = e.messages + ?.firstWhereOrNull((element) => element.attr == 'traits.email'); + final passwordMessage = e.messages + ?.firstWhereOrNull((element) => element.attr == 'password'); + final generalMessage = e.messages + ?.firstWhereOrNull((element) => element.attr == 'general'); + + // update state to new one with errors + emit(state + .copyWith(isLoading: false, errorMessage: generalMessage?.text) + .copyWith + .email(errorMessage: emailMessage?.text) + .copyWith + .password(errorMessage: passwordMessage?.text)); + } else if (e case FlowExpiredException _) { + // use new flow id to log in user + add(RegisterWithEmailAndPassword( + flowId: e.flowId, + email: state.email.value, + password: state.password.value)); + } else if (e case UnknownException _) { + emit(state.copyWith(isLoading: false, errorMessage: e.message)); + } else { + emit(state.copyWith(isLoading: false)); + } + } + } +} diff --git a/kratos-flutter/lib/blocs/registration/registration_bloc.freezed.dart b/kratos-flutter/lib/blocs/registration/registration_bloc.freezed.dart new file mode 100644 index 00000000..94367224 --- /dev/null +++ b/kratos-flutter/lib/blocs/registration/registration_bloc.freezed.dart @@ -0,0 +1,248 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'registration_bloc.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +mixin _$RegistrationState { + String? get flowId => throw _privateConstructorUsedError; + FormField get email => throw _privateConstructorUsedError; + FormField get password => throw _privateConstructorUsedError; + bool get isLoading => throw _privateConstructorUsedError; + String? get errorMessage => throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $RegistrationStateCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $RegistrationStateCopyWith<$Res> { + factory $RegistrationStateCopyWith( + RegistrationState value, $Res Function(RegistrationState) then) = + _$RegistrationStateCopyWithImpl<$Res, RegistrationState>; + @useResult + $Res call( + {String? flowId, + FormField email, + FormField password, + bool isLoading, + String? errorMessage}); + + $FormFieldCopyWith get email; + $FormFieldCopyWith get password; +} + +/// @nodoc +class _$RegistrationStateCopyWithImpl<$Res, $Val extends RegistrationState> + implements $RegistrationStateCopyWith<$Res> { + _$RegistrationStateCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? flowId = freezed, + Object? email = null, + Object? password = null, + Object? isLoading = null, + Object? errorMessage = freezed, + }) { + return _then(_value.copyWith( + flowId: freezed == flowId + ? _value.flowId + : flowId // ignore: cast_nullable_to_non_nullable + as String?, + email: null == email + ? _value.email + : email // ignore: cast_nullable_to_non_nullable + as FormField, + password: null == password + ? _value.password + : password // ignore: cast_nullable_to_non_nullable + as FormField, + isLoading: null == isLoading + ? _value.isLoading + : isLoading // ignore: cast_nullable_to_non_nullable + as bool, + errorMessage: freezed == errorMessage + ? _value.errorMessage + : errorMessage // ignore: cast_nullable_to_non_nullable + as String?, + ) as $Val); + } + + @override + @pragma('vm:prefer-inline') + $FormFieldCopyWith get email { + return $FormFieldCopyWith(_value.email, (value) { + return _then(_value.copyWith(email: value) as $Val); + }); + } + + @override + @pragma('vm:prefer-inline') + $FormFieldCopyWith get password { + return $FormFieldCopyWith(_value.password, (value) { + return _then(_value.copyWith(password: value) as $Val); + }); + } +} + +/// @nodoc +abstract class _$$_RegistrationStateCopyWith<$Res> + implements $RegistrationStateCopyWith<$Res> { + factory _$$_RegistrationStateCopyWith(_$_RegistrationState value, + $Res Function(_$_RegistrationState) then) = + __$$_RegistrationStateCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {String? flowId, + FormField email, + FormField password, + bool isLoading, + String? errorMessage}); + + @override + $FormFieldCopyWith get email; + @override + $FormFieldCopyWith get password; +} + +/// @nodoc +class __$$_RegistrationStateCopyWithImpl<$Res> + extends _$RegistrationStateCopyWithImpl<$Res, _$_RegistrationState> + implements _$$_RegistrationStateCopyWith<$Res> { + __$$_RegistrationStateCopyWithImpl( + _$_RegistrationState _value, $Res Function(_$_RegistrationState) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? flowId = freezed, + Object? email = null, + Object? password = null, + Object? isLoading = null, + Object? errorMessage = freezed, + }) { + return _then(_$_RegistrationState( + flowId: freezed == flowId + ? _value.flowId + : flowId // ignore: cast_nullable_to_non_nullable + as String?, + email: null == email + ? _value.email + : email // ignore: cast_nullable_to_non_nullable + as FormField, + password: null == password + ? _value.password + : password // ignore: cast_nullable_to_non_nullable + as FormField, + isLoading: null == isLoading + ? _value.isLoading + : isLoading // ignore: cast_nullable_to_non_nullable + as bool, + errorMessage: freezed == errorMessage + ? _value.errorMessage + : errorMessage // ignore: cast_nullable_to_non_nullable + as String?, + )); + } +} + +/// @nodoc + +class _$_RegistrationState implements _RegistrationState { + const _$_RegistrationState( + {this.flowId, + this.email = const FormField(value: ''), + this.password = const FormField(value: ''), + this.isLoading = false, + this.errorMessage}); + + @override + final String? flowId; + @override + @JsonKey() + final FormField email; + @override + @JsonKey() + final FormField password; + @override + @JsonKey() + final bool isLoading; + @override + final String? errorMessage; + + @override + String toString() { + return 'RegistrationState(flowId: $flowId, email: $email, password: $password, isLoading: $isLoading, errorMessage: $errorMessage)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$_RegistrationState && + (identical(other.flowId, flowId) || other.flowId == flowId) && + (identical(other.email, email) || other.email == email) && + (identical(other.password, password) || + other.password == password) && + (identical(other.isLoading, isLoading) || + other.isLoading == isLoading) && + (identical(other.errorMessage, errorMessage) || + other.errorMessage == errorMessage)); + } + + @override + int get hashCode => Object.hash( + runtimeType, flowId, email, password, isLoading, errorMessage); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$_RegistrationStateCopyWith<_$_RegistrationState> get copyWith => + __$$_RegistrationStateCopyWithImpl<_$_RegistrationState>( + this, _$identity); +} + +abstract class _RegistrationState implements RegistrationState { + const factory _RegistrationState( + {final String? flowId, + final FormField email, + final FormField password, + final bool isLoading, + final String? errorMessage}) = _$_RegistrationState; + + @override + String? get flowId; + @override + FormField get email; + @override + FormField get password; + @override + bool get isLoading; + @override + String? get errorMessage; + @override + @JsonKey(ignore: true) + _$$_RegistrationStateCopyWith<_$_RegistrationState> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/kratos-flutter/lib/blocs/registration/registration_event.dart b/kratos-flutter/lib/blocs/registration/registration_event.dart new file mode 100644 index 00000000..69e40aaf --- /dev/null +++ b/kratos-flutter/lib/blocs/registration/registration_event.dart @@ -0,0 +1,41 @@ +part of 'registration_bloc.dart'; + +@immutable +sealed class RegistrationEvent extends Equatable { + @override + List get props => []; +} + +//create registration flow +final class CreateRegistrationFlow extends RegistrationEvent {} + +final class ChangeEmail extends RegistrationEvent { + final String value; + + ChangeEmail({required this.value}); + + @override + List get props => [value]; +} + +final class ChangePassword extends RegistrationEvent { + final String value; + + ChangePassword({required this.value}); + + @override + List get props => [value]; +} + +//log in +final class RegisterWithEmailAndPassword extends RegistrationEvent { + final String flowId; + final String email; + final String password; + + RegisterWithEmailAndPassword( + {required this.flowId, required this.email, required this.password}); + + @override + List get props => [flowId, email, password]; +} diff --git a/kratos-flutter/lib/blocs/registration/registration_state.dart b/kratos-flutter/lib/blocs/registration/registration_state.dart new file mode 100644 index 00000000..1f757884 --- /dev/null +++ b/kratos-flutter/lib/blocs/registration/registration_state.dart @@ -0,0 +1,11 @@ +part of 'registration_bloc.dart'; + +@freezed +sealed class RegistrationState with _$RegistrationState { + const factory RegistrationState( + {String? flowId, + @Default(FormField(value: '')) FormField email, + @Default(FormField(value: '')) FormField password, + @Default(false) bool isLoading, + String? errorMessage}) = _RegistrationState; +} diff --git a/kratos-flutter/lib/entities/form_node.dart b/kratos-flutter/lib/entities/form_node.dart new file mode 100644 index 00000000..f6679a67 --- /dev/null +++ b/kratos-flutter/lib/entities/form_node.dart @@ -0,0 +1,17 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; + +import 'message.dart'; +import 'node_attribute.dart'; + +part 'form_node.freezed.dart'; +part 'form_node.g.dart'; + +@freezed +sealed class FormNode with _$FormNode { + const factory FormNode( + {required NodeAttribute attributes, + required List messages}) = _FormNode; + + factory FormNode.fromJson(Map json) => + _$FormNodeFromJson(json); +} diff --git a/kratos-flutter/lib/entities/form_node.freezed.dart b/kratos-flutter/lib/entities/form_node.freezed.dart new file mode 100644 index 00000000..b66dacb6 --- /dev/null +++ b/kratos-flutter/lib/entities/form_node.freezed.dart @@ -0,0 +1,188 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'form_node.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +FormNode _$FormNodeFromJson(Map json) { + return _FormNode.fromJson(json); +} + +/// @nodoc +mixin _$FormNode { + NodeAttribute get attributes => throw _privateConstructorUsedError; + List get messages => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $FormNodeCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $FormNodeCopyWith<$Res> { + factory $FormNodeCopyWith(FormNode value, $Res Function(FormNode) then) = + _$FormNodeCopyWithImpl<$Res, FormNode>; + @useResult + $Res call({NodeAttribute attributes, List messages}); + + $NodeAttributeCopyWith<$Res> get attributes; +} + +/// @nodoc +class _$FormNodeCopyWithImpl<$Res, $Val extends FormNode> + implements $FormNodeCopyWith<$Res> { + _$FormNodeCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? attributes = null, + Object? messages = null, + }) { + return _then(_value.copyWith( + attributes: null == attributes + ? _value.attributes + : attributes // ignore: cast_nullable_to_non_nullable + as NodeAttribute, + messages: null == messages + ? _value.messages + : messages // ignore: cast_nullable_to_non_nullable + as List, + ) as $Val); + } + + @override + @pragma('vm:prefer-inline') + $NodeAttributeCopyWith<$Res> get attributes { + return $NodeAttributeCopyWith<$Res>(_value.attributes, (value) { + return _then(_value.copyWith(attributes: value) as $Val); + }); + } +} + +/// @nodoc +abstract class _$$_FormNodeCopyWith<$Res> implements $FormNodeCopyWith<$Res> { + factory _$$_FormNodeCopyWith( + _$_FormNode value, $Res Function(_$_FormNode) then) = + __$$_FormNodeCopyWithImpl<$Res>; + @override + @useResult + $Res call({NodeAttribute attributes, List messages}); + + @override + $NodeAttributeCopyWith<$Res> get attributes; +} + +/// @nodoc +class __$$_FormNodeCopyWithImpl<$Res> + extends _$FormNodeCopyWithImpl<$Res, _$_FormNode> + implements _$$_FormNodeCopyWith<$Res> { + __$$_FormNodeCopyWithImpl( + _$_FormNode _value, $Res Function(_$_FormNode) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? attributes = null, + Object? messages = null, + }) { + return _then(_$_FormNode( + attributes: null == attributes + ? _value.attributes + : attributes // ignore: cast_nullable_to_non_nullable + as NodeAttribute, + messages: null == messages + ? _value._messages + : messages // ignore: cast_nullable_to_non_nullable + as List, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$_FormNode implements _FormNode { + const _$_FormNode( + {required this.attributes, required final List messages}) + : _messages = messages; + + factory _$_FormNode.fromJson(Map json) => + _$$_FormNodeFromJson(json); + + @override + final NodeAttribute attributes; + final List _messages; + @override + List get messages { + if (_messages is EqualUnmodifiableListView) return _messages; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_messages); + } + + @override + String toString() { + return 'FormNode(attributes: $attributes, messages: $messages)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$_FormNode && + (identical(other.attributes, attributes) || + other.attributes == attributes) && + const DeepCollectionEquality().equals(other._messages, _messages)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash( + runtimeType, attributes, const DeepCollectionEquality().hash(_messages)); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$_FormNodeCopyWith<_$_FormNode> get copyWith => + __$$_FormNodeCopyWithImpl<_$_FormNode>(this, _$identity); + + @override + Map toJson() { + return _$$_FormNodeToJson( + this, + ); + } +} + +abstract class _FormNode implements FormNode { + const factory _FormNode( + {required final NodeAttribute attributes, + required final List messages}) = _$_FormNode; + + factory _FormNode.fromJson(Map json) = _$_FormNode.fromJson; + + @override + NodeAttribute get attributes; + @override + List get messages; + @override + @JsonKey(ignore: true) + _$$_FormNodeCopyWith<_$_FormNode> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/kratos-flutter/lib/entities/form_node.g.dart b/kratos-flutter/lib/entities/form_node.g.dart new file mode 100644 index 00000000..98e6de11 --- /dev/null +++ b/kratos-flutter/lib/entities/form_node.g.dart @@ -0,0 +1,21 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'form_node.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$_FormNode _$$_FormNodeFromJson(Map json) => _$_FormNode( + attributes: + NodeAttribute.fromJson(json['attributes'] as Map), + messages: (json['messages'] as List) + .map((e) => NodeMessage.fromJson(e as Map)) + .toList(), + ); + +Map _$$_FormNodeToJson(_$_FormNode instance) => + { + 'attributes': instance.attributes, + 'messages': instance.messages, + }; diff --git a/kratos-flutter/lib/entities/message.dart b/kratos-flutter/lib/entities/message.dart new file mode 100644 index 00000000..25eea025 --- /dev/null +++ b/kratos-flutter/lib/entities/message.dart @@ -0,0 +1,19 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'message.freezed.dart'; +part 'message.g.dart'; + +@freezed +class NodeMessage with _$NodeMessage { + const factory NodeMessage( + {required int id, + required String text, + required MessageType type, + @Default('general') String attr}) = _NodeMessage; + + factory NodeMessage.fromJson(Map json) => + _$NodeMessageFromJson(json); +} + +// specifies message type +enum MessageType { info, error, success } diff --git a/kratos-flutter/lib/entities/message.freezed.dart b/kratos-flutter/lib/entities/message.freezed.dart new file mode 100644 index 00000000..c3637139 --- /dev/null +++ b/kratos-flutter/lib/entities/message.freezed.dart @@ -0,0 +1,208 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'message.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +NodeMessage _$NodeMessageFromJson(Map json) { + return _NodeMessage.fromJson(json); +} + +/// @nodoc +mixin _$NodeMessage { + int get id => throw _privateConstructorUsedError; + String get text => throw _privateConstructorUsedError; + MessageType get type => throw _privateConstructorUsedError; + String get attr => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $NodeMessageCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $NodeMessageCopyWith<$Res> { + factory $NodeMessageCopyWith( + NodeMessage value, $Res Function(NodeMessage) then) = + _$NodeMessageCopyWithImpl<$Res, NodeMessage>; + @useResult + $Res call({int id, String text, MessageType type, String attr}); +} + +/// @nodoc +class _$NodeMessageCopyWithImpl<$Res, $Val extends NodeMessage> + implements $NodeMessageCopyWith<$Res> { + _$NodeMessageCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? text = null, + Object? type = null, + Object? attr = null, + }) { + return _then(_value.copyWith( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as int, + text: null == text + ? _value.text + : text // ignore: cast_nullable_to_non_nullable + as String, + type: null == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as MessageType, + attr: null == attr + ? _value.attr + : attr // ignore: cast_nullable_to_non_nullable + as String, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$_NodeMessageCopyWith<$Res> + implements $NodeMessageCopyWith<$Res> { + factory _$$_NodeMessageCopyWith( + _$_NodeMessage value, $Res Function(_$_NodeMessage) then) = + __$$_NodeMessageCopyWithImpl<$Res>; + @override + @useResult + $Res call({int id, String text, MessageType type, String attr}); +} + +/// @nodoc +class __$$_NodeMessageCopyWithImpl<$Res> + extends _$NodeMessageCopyWithImpl<$Res, _$_NodeMessage> + implements _$$_NodeMessageCopyWith<$Res> { + __$$_NodeMessageCopyWithImpl( + _$_NodeMessage _value, $Res Function(_$_NodeMessage) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? text = null, + Object? type = null, + Object? attr = null, + }) { + return _then(_$_NodeMessage( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as int, + text: null == text + ? _value.text + : text // ignore: cast_nullable_to_non_nullable + as String, + type: null == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as MessageType, + attr: null == attr + ? _value.attr + : attr // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$_NodeMessage implements _NodeMessage { + const _$_NodeMessage( + {required this.id, + required this.text, + required this.type, + this.attr = 'general'}); + + factory _$_NodeMessage.fromJson(Map json) => + _$$_NodeMessageFromJson(json); + + @override + final int id; + @override + final String text; + @override + final MessageType type; + @override + @JsonKey() + final String attr; + + @override + String toString() { + return 'NodeMessage(id: $id, text: $text, type: $type, attr: $attr)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$_NodeMessage && + (identical(other.id, id) || other.id == id) && + (identical(other.text, text) || other.text == text) && + (identical(other.type, type) || other.type == type) && + (identical(other.attr, attr) || other.attr == attr)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash(runtimeType, id, text, type, attr); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$_NodeMessageCopyWith<_$_NodeMessage> get copyWith => + __$$_NodeMessageCopyWithImpl<_$_NodeMessage>(this, _$identity); + + @override + Map toJson() { + return _$$_NodeMessageToJson( + this, + ); + } +} + +abstract class _NodeMessage implements NodeMessage { + const factory _NodeMessage( + {required final int id, + required final String text, + required final MessageType type, + final String attr}) = _$_NodeMessage; + + factory _NodeMessage.fromJson(Map json) = + _$_NodeMessage.fromJson; + + @override + int get id; + @override + String get text; + @override + MessageType get type; + @override + String get attr; + @override + @JsonKey(ignore: true) + _$$_NodeMessageCopyWith<_$_NodeMessage> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/kratos-flutter/lib/entities/message.g.dart b/kratos-flutter/lib/entities/message.g.dart new file mode 100644 index 00000000..d63f9eb2 --- /dev/null +++ b/kratos-flutter/lib/entities/message.g.dart @@ -0,0 +1,29 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'message.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$_NodeMessage _$$_NodeMessageFromJson(Map json) => + _$_NodeMessage( + id: json['id'] as int, + text: json['text'] as String, + type: $enumDecode(_$MessageTypeEnumMap, json['type']), + attr: json['attr'] as String? ?? 'general', + ); + +Map _$$_NodeMessageToJson(_$_NodeMessage instance) => + { + 'id': instance.id, + 'text': instance.text, + 'type': _$MessageTypeEnumMap[instance.type]!, + 'attr': instance.attr, + }; + +const _$MessageTypeEnumMap = { + MessageType.info: 'info', + MessageType.error: 'error', + MessageType.success: 'success', +}; diff --git a/kratos-flutter/lib/entities/node_attribute.dart b/kratos-flutter/lib/entities/node_attribute.dart new file mode 100644 index 00000000..e2e8b408 --- /dev/null +++ b/kratos-flutter/lib/entities/node_attribute.dart @@ -0,0 +1,11 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; +part 'node_attribute.freezed.dart'; +part 'node_attribute.g.dart'; + +@freezed +sealed class NodeAttribute with _$NodeAttribute { + const factory NodeAttribute({required String name}) = _NodeAttribute; + + factory NodeAttribute.fromJson(Map json) => + _$NodeAttributeFromJson(json); +} diff --git a/kratos-flutter/lib/entities/node_attribute.freezed.dart b/kratos-flutter/lib/entities/node_attribute.freezed.dart new file mode 100644 index 00000000..72ddae2d --- /dev/null +++ b/kratos-flutter/lib/entities/node_attribute.freezed.dart @@ -0,0 +1,151 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'node_attribute.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +NodeAttribute _$NodeAttributeFromJson(Map json) { + return _NodeAttribute.fromJson(json); +} + +/// @nodoc +mixin _$NodeAttribute { + String get name => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $NodeAttributeCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $NodeAttributeCopyWith<$Res> { + factory $NodeAttributeCopyWith( + NodeAttribute value, $Res Function(NodeAttribute) then) = + _$NodeAttributeCopyWithImpl<$Res, NodeAttribute>; + @useResult + $Res call({String name}); +} + +/// @nodoc +class _$NodeAttributeCopyWithImpl<$Res, $Val extends NodeAttribute> + implements $NodeAttributeCopyWith<$Res> { + _$NodeAttributeCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? name = null, + }) { + return _then(_value.copyWith( + name: null == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$_NodeAttributeCopyWith<$Res> + implements $NodeAttributeCopyWith<$Res> { + factory _$$_NodeAttributeCopyWith( + _$_NodeAttribute value, $Res Function(_$_NodeAttribute) then) = + __$$_NodeAttributeCopyWithImpl<$Res>; + @override + @useResult + $Res call({String name}); +} + +/// @nodoc +class __$$_NodeAttributeCopyWithImpl<$Res> + extends _$NodeAttributeCopyWithImpl<$Res, _$_NodeAttribute> + implements _$$_NodeAttributeCopyWith<$Res> { + __$$_NodeAttributeCopyWithImpl( + _$_NodeAttribute _value, $Res Function(_$_NodeAttribute) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? name = null, + }) { + return _then(_$_NodeAttribute( + name: null == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$_NodeAttribute implements _NodeAttribute { + const _$_NodeAttribute({required this.name}); + + factory _$_NodeAttribute.fromJson(Map json) => + _$$_NodeAttributeFromJson(json); + + @override + final String name; + + @override + String toString() { + return 'NodeAttribute(name: $name)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$_NodeAttribute && + (identical(other.name, name) || other.name == name)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash(runtimeType, name); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$_NodeAttributeCopyWith<_$_NodeAttribute> get copyWith => + __$$_NodeAttributeCopyWithImpl<_$_NodeAttribute>(this, _$identity); + + @override + Map toJson() { + return _$$_NodeAttributeToJson( + this, + ); + } +} + +abstract class _NodeAttribute implements NodeAttribute { + const factory _NodeAttribute({required final String name}) = _$_NodeAttribute; + + factory _NodeAttribute.fromJson(Map json) = + _$_NodeAttribute.fromJson; + + @override + String get name; + @override + @JsonKey(ignore: true) + _$$_NodeAttributeCopyWith<_$_NodeAttribute> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/kratos-flutter/lib/entities/node_attribute.g.dart b/kratos-flutter/lib/entities/node_attribute.g.dart new file mode 100644 index 00000000..92cd7317 --- /dev/null +++ b/kratos-flutter/lib/entities/node_attribute.g.dart @@ -0,0 +1,17 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'node_attribute.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$_NodeAttribute _$$_NodeAttributeFromJson(Map json) => + _$_NodeAttribute( + name: json['name'] as String, + ); + +Map _$$_NodeAttributeToJson(_$_NodeAttribute instance) => + { + 'name': instance.name, + }; diff --git a/kratos-flutter/lib/pages/login.dart b/kratos-flutter/lib/pages/login.dart index 094e7eda..2f160b7a 100644 --- a/kratos-flutter/lib/pages/login.dart +++ b/kratos-flutter/lib/pages/login.dart @@ -4,6 +4,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import '../blocs/auth/auth_bloc.dart'; import '../blocs/login/login_bloc.dart'; import '../repositories/auth.dart'; +import 'registration.dart'; class LoginPage extends StatelessWidget { const LoginPage({super.key}); @@ -68,7 +69,8 @@ class LoginForm extends StatelessWidget { border: const OutlineInputBorder(), label: const Text('Email'), hintText: 'Enter your email', - errorText: state.email.errorMessage), + errorText: state.email.errorMessage, + errorMaxLines: 3), ), const SizedBox( height: 20, @@ -82,14 +84,18 @@ class LoginForm extends StatelessWidget { border: const OutlineInputBorder(), label: const Text('Password'), hintText: 'Enter your password', - errorText: state.password.errorMessage), + errorText: state.password.errorMessage, + errorMaxLines: 3), ), const SizedBox( height: 20, ), if (state.errorMessage != null) - Text(state.errorMessage!, - style: const TextStyle(color: Colors.red)), + Text( + state.errorMessage!, + style: const TextStyle(color: Colors.red), + maxLines: 3, + ), OutlinedButton( onPressed: state.isLoading ? null @@ -99,7 +105,21 @@ class LoginForm extends StatelessWidget { email: state.email.value, password: state.password.value)); }, - child: const Text('Submit')) + child: const Text('Submit')), + const SizedBox( + height: 20, + ), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Text('Don\'t have an account yet?'), + TextButton( + onPressed: () => Navigator.of(context).pushReplacement( + MaterialPageRoute( + builder: (context) => const RegistrationPage())), + child: const Text('Get started')) + ], + ) ], )), ); diff --git a/kratos-flutter/lib/pages/registration.dart b/kratos-flutter/lib/pages/registration.dart new file mode 100644 index 00000000..0de1e078 --- /dev/null +++ b/kratos-flutter/lib/pages/registration.dart @@ -0,0 +1,129 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; + +import '../blocs/auth/auth_bloc.dart'; +import '../blocs/registration/registration_bloc.dart'; +import '../repositories/auth.dart'; +import 'login.dart'; + +class RegistrationPage extends StatelessWidget { + const RegistrationPage({super.key}); + + @override + Widget build(BuildContext context) { + return Scaffold( + body: BlocProvider( + create: (context) => RegistrationBloc( + authBloc: context.read(), + repository: RepositoryProvider.of(context)) + ..add(CreateRegistrationFlow()), + child: const LoginForm()), + ); + } +} + +class LoginForm extends StatelessWidget { + const LoginForm({super.key}); + + @override + Widget build(BuildContext context) { + final registrationBloc = BlocProvider.of(context); + return BlocBuilder( + bloc: registrationBloc, + builder: (context, state) { + // creating registration flow is in process, show loading indicator + if (state.flowId != null) { + return _buildRegistrationForm(context, state); + } else { + return _buildRegistrationFlowNotCreated(context, state); + } + }); + } + + _buildRegistrationFlowNotCreated( + BuildContext context, RegistrationState state) { + if (state.errorMessage != null) { + return Center( + child: Text( + state.errorMessage!, + style: const TextStyle(color: Colors.red), + )); + } else { + return const Center(child: CircularProgressIndicator()); + } + } + + _buildRegistrationForm(BuildContext context, RegistrationState state) { + return Padding( + padding: const EdgeInsets.all(20.0), + child: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + TextFormField( + enabled: !state.isLoading, + initialValue: state.email.value, + onChanged: (String value) => + context.read().add(ChangeEmail(value: value)), + decoration: InputDecoration( + border: const OutlineInputBorder(), + label: const Text('Email'), + hintText: 'Enter your email', + errorText: state.email.errorMessage, + errorMaxLines: 3), + ), + const SizedBox( + height: 20, + ), + TextFormField( + enabled: !state.isLoading, + initialValue: state.email.value, + onChanged: (String value) => context + .read() + .add(ChangePassword(value: value)), + decoration: InputDecoration( + border: const OutlineInputBorder(), + label: const Text('Password'), + hintText: 'Enter your password', + errorText: state.password.errorMessage, + errorMaxLines: 3), + ), + const SizedBox( + height: 20, + ), + if (state.errorMessage != null) + Text( + state.errorMessage!, + style: const TextStyle(color: Colors.red), + ), + OutlinedButton( + onPressed: state.isLoading + ? null + : () { + context.read().add( + RegisterWithEmailAndPassword( + flowId: state.flowId!, + email: state.email.value, + password: state.password.value)); + }, + child: const Text('Submit')), + const SizedBox( + height: 20, + ), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text('Already have an account?'), + TextButton( + onPressed: () => Navigator.of(context).pushReplacement( + MaterialPageRoute( + builder: (context) => const LoginPage())), + child: Text('Log in')) + ], + ) + ], + )), + ); + } +} diff --git a/kratos-flutter/lib/repositories/auth.dart b/kratos-flutter/lib/repositories/auth.dart index 32ab8c16..841b98f2 100644 --- a/kratos-flutter/lib/repositories/auth.dart +++ b/kratos-flutter/lib/repositories/auth.dart @@ -19,6 +19,11 @@ class AuthRepository { return flowId; } + Future createRegistrationFlow() async { + final flowId = await service.createRegistrationFlow(); + return flowId; + } + Future loginWithEmailAndPassword( {required String flowId, required String email, @@ -26,4 +31,12 @@ class AuthRepository { await service.loginWithEmailAndPassword( flowId: flowId, email: email, password: password); } + + Future registerWithEmailAndPassword( + {required String flowId, + required String email, + required String password}) async { + await service.registerWithEmailAndPassword( + flowId: flowId, email: email, password: password); + } } diff --git a/kratos-flutter/lib/services/auth.dart b/kratos-flutter/lib/services/auth.dart index 3037bb7f..eeff1284 100644 --- a/kratos-flutter/lib/services/auth.dart +++ b/kratos-flutter/lib/services/auth.dart @@ -1,9 +1,11 @@ +import 'package:built_value/json_object.dart'; import 'package:dio/dio.dart'; import 'package:one_of/one_of.dart'; import 'package:ory_client/ory_client.dart'; +import '../entities/form_node.dart'; import 'exceptions.dart'; -import 'message.dart'; +import '../entities/message.dart'; import 'storage.dart'; class AuthService { @@ -11,6 +13,7 @@ class AuthService { final FrontendApi _ory; AuthService(Dio dio) : _ory = OryClient(dio: dio).getFrontendApi(); + /// Get current session information Future getCurrentSessionInformation() async { try { final token = await storage.getToken(); @@ -34,6 +37,7 @@ class AuthService { } } + /// Create login flow Future createLoginFlow() async { try { final response = await _ory.createNativeLoginFlow(); @@ -52,6 +56,26 @@ class AuthService { } } + /// Create registration flow + Future createRegistrationFlow() async { + try { + final response = await _ory.createNativeRegistrationFlow(); + if (response.statusCode == 200) { + // return flow id + return response.data!.id; + } else { + throw const CustomException.unknown(); + } + } on DioException catch (e) { + throw CustomException.unknown( + statusCode: e.response?.statusCode, + message: e.response?.data['error'] != null + ? e.response?.data['error']['message'] + : null); + } + } + + /// Log in with [email] and [password] using login flow with [flowId] Future loginWithEmailAndPassword( {required String flowId, required String email, @@ -93,24 +117,77 @@ class AuthService { } } - List checkFormForErrors(Map response) { + /// Register with [email] and [password] using registration flow with [flowId] + Future registerWithEmailAndPassword( + {required String flowId, + required String email, + required String password}) async { + try { + final UpdateRegistrationFlowWithPasswordMethod registrationFLowBuilder = + UpdateRegistrationFlowWithPasswordMethod((b) => b + ..traits = JsonObject({'email': email}) + ..password = password + ..method = 'password'); + + final response = await _ory.updateRegistrationFlow( + flow: flowId, + updateRegistrationFlowBody: UpdateRegistrationFlowBody((b) => + b..oneOf = OneOf.fromValue1(value: registrationFLowBuilder))); + if (response.statusCode == 200 && response.data?.sessionToken != null) { + // save session token after successful login + await storage.persistToken(response.data!.sessionToken!); + return; + } else { + throw const CustomException.unknown(); + } + } on DioException catch (e) { + if (e.response?.statusCode == 401) { + throw const CustomException.unauthorized(); + } else if (e.response?.statusCode == 400) { + final messages = checkFormForErrors(e.response?.data); + throw CustomException.badRequest(messages: messages); + } else if (e.response?.statusCode == 410) { + throw CustomException.flowExpired( + flowId: e.response?.data['use_flow_id']); + } else { + throw CustomException.unknown( + statusCode: e.response?.statusCode, + message: e.response?.data['error'] != null + ? e.response?.data['error']['message'] + : null); + } + } + } + + List checkFormForErrors(Map response) { final ui = Map.from(response['ui']); final nodeList = ui['nodes'] as List; - final nodeMessages = - nodeList.map((element) => element['messages'] as List).toList(); + // parse ui nodes + final nodes = nodeList.map((e) => FormNode.fromJson(e)).toList(); + + // get only nodes that have messages + final nonEmptyNodes = + nodes.where((element) => element.messages.isNotEmpty).toList(); + + // get node messages + final nodeMessages = nonEmptyNodes + .map((node) => node.messages + .map((msg) => msg.copyWith(attr: node.attributes.name)) + .toList()) + .toList(); + + // get general message if it exists if (ui['messages'] != null) { final messageList = ui['messages'] as List; - nodeMessages.add(messageList); + final messages = + messageList.map((e) => NodeMessage.fromJson(e)).toList(); + nodeMessages.add(messages); } - + // flatten message lists final flattedNodeMessages = nodeMessages.expand((element) => element).toList(); - final parsedMessages = flattedNodeMessages - .map((e) => UiNodeMessage.fromJson(e)) - .toList(); - - return parsedMessages; + return flattedNodeMessages; } } diff --git a/kratos-flutter/lib/services/exceptions.dart b/kratos-flutter/lib/services/exceptions.dart index 0066efeb..39b3bc94 100644 --- a/kratos-flutter/lib/services/exceptions.dart +++ b/kratos-flutter/lib/services/exceptions.dart @@ -1,7 +1,7 @@ import 'package:flutter/foundation.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; -import 'message.dart'; +import '../entities/message.dart'; part 'exceptions.freezed.dart'; @@ -9,7 +9,7 @@ part 'exceptions.freezed.dart'; sealed class CustomException with _$CustomException { const CustomException._(); const factory CustomException.badRequest( - {List? messages, + {List? messages, @Default(400) int statusCode}) = BadRequestException; const factory CustomException.unauthorized({@Default(401) int statusCode}) = UnauthorizedException; diff --git a/kratos-flutter/lib/services/exceptions.freezed.dart b/kratos-flutter/lib/services/exceptions.freezed.dart index 7ec831f9..62bc580a 100644 --- a/kratos-flutter/lib/services/exceptions.freezed.dart +++ b/kratos-flutter/lib/services/exceptions.freezed.dart @@ -19,7 +19,7 @@ mixin _$CustomException { int? get statusCode => throw _privateConstructorUsedError; @optionalTypeArgs TResult when({ - required TResult Function(List? messages, int statusCode) + required TResult Function(List? messages, int statusCode) badRequest, required TResult Function(int statusCode) unauthorized, required TResult Function(int statusCode, String flowId) flowExpired, @@ -28,8 +28,7 @@ mixin _$CustomException { throw _privateConstructorUsedError; @optionalTypeArgs TResult? whenOrNull({ - TResult? Function(List? messages, int statusCode)? - badRequest, + TResult? Function(List? messages, int statusCode)? badRequest, TResult? Function(int statusCode)? unauthorized, TResult? Function(int statusCode, String flowId)? flowExpired, TResult? Function(int? statusCode, String message)? unknown, @@ -37,7 +36,7 @@ mixin _$CustomException { throw _privateConstructorUsedError; @optionalTypeArgs TResult maybeWhen({ - TResult Function(List? messages, int statusCode)? badRequest, + TResult Function(List? messages, int statusCode)? badRequest, TResult Function(int statusCode)? unauthorized, TResult Function(int statusCode, String flowId)? flowExpired, TResult Function(int? statusCode, String message)? unknown, @@ -116,7 +115,7 @@ abstract class _$$BadRequestExceptionCopyWith<$Res> __$$BadRequestExceptionCopyWithImpl<$Res>; @override @useResult - $Res call({List? messages, int statusCode}); + $Res call({List? messages, int statusCode}); } /// @nodoc @@ -137,7 +136,7 @@ class __$$BadRequestExceptionCopyWithImpl<$Res> messages: freezed == messages ? _value._messages : messages // ignore: cast_nullable_to_non_nullable - as List?, + as List?, statusCode: null == statusCode ? _value.statusCode : statusCode // ignore: cast_nullable_to_non_nullable @@ -151,13 +150,13 @@ class __$$BadRequestExceptionCopyWithImpl<$Res> class _$BadRequestException extends BadRequestException with DiagnosticableTreeMixin { const _$BadRequestException( - {final List? messages, this.statusCode = 400}) + {final List? messages, this.statusCode = 400}) : _messages = messages, super._(); - final List? _messages; + final List? _messages; @override - List? get messages { + List? get messages { final value = _messages; if (value == null) return null; if (_messages is EqualUnmodifiableListView) return _messages; @@ -207,7 +206,7 @@ class _$BadRequestException extends BadRequestException @override @optionalTypeArgs TResult when({ - required TResult Function(List? messages, int statusCode) + required TResult Function(List? messages, int statusCode) badRequest, required TResult Function(int statusCode) unauthorized, required TResult Function(int statusCode, String flowId) flowExpired, @@ -219,8 +218,7 @@ class _$BadRequestException extends BadRequestException @override @optionalTypeArgs TResult? whenOrNull({ - TResult? Function(List? messages, int statusCode)? - badRequest, + TResult? Function(List? messages, int statusCode)? badRequest, TResult? Function(int statusCode)? unauthorized, TResult? Function(int statusCode, String flowId)? flowExpired, TResult? Function(int? statusCode, String message)? unknown, @@ -231,7 +229,7 @@ class _$BadRequestException extends BadRequestException @override @optionalTypeArgs TResult maybeWhen({ - TResult Function(List? messages, int statusCode)? badRequest, + TResult Function(List? messages, int statusCode)? badRequest, TResult Function(int statusCode)? unauthorized, TResult Function(int statusCode, String flowId)? flowExpired, TResult Function(int? statusCode, String message)? unknown, @@ -283,11 +281,11 @@ class _$BadRequestException extends BadRequestException abstract class BadRequestException extends CustomException { const factory BadRequestException( - {final List? messages, + {final List? messages, final int statusCode}) = _$BadRequestException; const BadRequestException._() : super._(); - List? get messages; + List? get messages; @override int get statusCode; @override @@ -374,7 +372,7 @@ class _$UnauthorizedException extends UnauthorizedException @override @optionalTypeArgs TResult when({ - required TResult Function(List? messages, int statusCode) + required TResult Function(List? messages, int statusCode) badRequest, required TResult Function(int statusCode) unauthorized, required TResult Function(int statusCode, String flowId) flowExpired, @@ -386,8 +384,7 @@ class _$UnauthorizedException extends UnauthorizedException @override @optionalTypeArgs TResult? whenOrNull({ - TResult? Function(List? messages, int statusCode)? - badRequest, + TResult? Function(List? messages, int statusCode)? badRequest, TResult? Function(int statusCode)? unauthorized, TResult? Function(int statusCode, String flowId)? flowExpired, TResult? Function(int? statusCode, String message)? unknown, @@ -398,7 +395,7 @@ class _$UnauthorizedException extends UnauthorizedException @override @optionalTypeArgs TResult maybeWhen({ - TResult Function(List? messages, int statusCode)? badRequest, + TResult Function(List? messages, int statusCode)? badRequest, TResult Function(int statusCode)? unauthorized, TResult Function(int statusCode, String flowId)? flowExpired, TResult Function(int? statusCode, String message)? unknown, @@ -549,7 +546,7 @@ class _$FlowExpiredException extends FlowExpiredException @override @optionalTypeArgs TResult when({ - required TResult Function(List? messages, int statusCode) + required TResult Function(List? messages, int statusCode) badRequest, required TResult Function(int statusCode) unauthorized, required TResult Function(int statusCode, String flowId) flowExpired, @@ -561,8 +558,7 @@ class _$FlowExpiredException extends FlowExpiredException @override @optionalTypeArgs TResult? whenOrNull({ - TResult? Function(List? messages, int statusCode)? - badRequest, + TResult? Function(List? messages, int statusCode)? badRequest, TResult? Function(int statusCode)? unauthorized, TResult? Function(int statusCode, String flowId)? flowExpired, TResult? Function(int? statusCode, String message)? unknown, @@ -573,7 +569,7 @@ class _$FlowExpiredException extends FlowExpiredException @override @optionalTypeArgs TResult maybeWhen({ - TResult Function(List? messages, int statusCode)? badRequest, + TResult Function(List? messages, int statusCode)? badRequest, TResult Function(int statusCode)? unauthorized, TResult Function(int statusCode, String flowId)? flowExpired, TResult Function(int? statusCode, String message)? unknown, @@ -726,7 +722,7 @@ class _$UnknownException extends UnknownException with DiagnosticableTreeMixin { @override @optionalTypeArgs TResult when({ - required TResult Function(List? messages, int statusCode) + required TResult Function(List? messages, int statusCode) badRequest, required TResult Function(int statusCode) unauthorized, required TResult Function(int statusCode, String flowId) flowExpired, @@ -738,8 +734,7 @@ class _$UnknownException extends UnknownException with DiagnosticableTreeMixin { @override @optionalTypeArgs TResult? whenOrNull({ - TResult? Function(List? messages, int statusCode)? - badRequest, + TResult? Function(List? messages, int statusCode)? badRequest, TResult? Function(int statusCode)? unauthorized, TResult? Function(int statusCode, String flowId)? flowExpired, TResult? Function(int? statusCode, String message)? unknown, @@ -750,7 +745,7 @@ class _$UnknownException extends UnknownException with DiagnosticableTreeMixin { @override @optionalTypeArgs TResult maybeWhen({ - TResult Function(List? messages, int statusCode)? badRequest, + TResult Function(List? messages, int statusCode)? badRequest, TResult Function(int statusCode)? unauthorized, TResult Function(int statusCode, String flowId)? flowExpired, TResult Function(int? statusCode, String message)? unknown, diff --git a/kratos-flutter/lib/services/message.dart b/kratos-flutter/lib/services/message.dart deleted file mode 100644 index 20225596..00000000 --- a/kratos-flutter/lib/services/message.dart +++ /dev/null @@ -1,31 +0,0 @@ -import 'package:freezed_annotation/freezed_annotation.dart'; - -part 'message.freezed.dart'; -part 'message.g.dart'; - -@freezed -class UiNodeMessage with _$UiNodeMessage { - const factory UiNodeMessage( - {required int id, - required String text, - required MessageType type, - required Context context}) = _UiNodeMessage; - - factory UiNodeMessage.fromJson(Map json) => - _$UiNodeMessageFromJson(json); -} - -@freezed -class Context with _$Context { - const factory Context({@Default(Property.general) Property property}) = - _Context; - - factory Context.fromJson(Map json) => - _$ContextFromJson(json); -} - -// speicifies which group the node belongs to -enum Property { identifier, password, general } - -// specifies message type -enum MessageType { info, error, success } diff --git a/kratos-flutter/lib/services/message.freezed.dart b/kratos-flutter/lib/services/message.freezed.dart deleted file mode 100644 index 0a19c507..00000000 --- a/kratos-flutter/lib/services/message.freezed.dart +++ /dev/null @@ -1,353 +0,0 @@ -// coverage:ignore-file -// GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: type=lint -// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark - -part of 'message.dart'; - -// ************************************************************************** -// FreezedGenerator -// ************************************************************************** - -T _$identity(T value) => value; - -final _privateConstructorUsedError = UnsupportedError( - 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); - -UiNodeMessage _$UiNodeMessageFromJson(Map json) { - return _UiNodeMessage.fromJson(json); -} - -/// @nodoc -mixin _$UiNodeMessage { - int get id => throw _privateConstructorUsedError; - String get text => throw _privateConstructorUsedError; - MessageType get type => throw _privateConstructorUsedError; - Context get context => throw _privateConstructorUsedError; - - Map toJson() => throw _privateConstructorUsedError; - @JsonKey(ignore: true) - $UiNodeMessageCopyWith get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $UiNodeMessageCopyWith<$Res> { - factory $UiNodeMessageCopyWith( - UiNodeMessage value, $Res Function(UiNodeMessage) then) = - _$UiNodeMessageCopyWithImpl<$Res, UiNodeMessage>; - @useResult - $Res call({int id, String text, MessageType type, Context context}); - - $ContextCopyWith<$Res> get context; -} - -/// @nodoc -class _$UiNodeMessageCopyWithImpl<$Res, $Val extends UiNodeMessage> - implements $UiNodeMessageCopyWith<$Res> { - _$UiNodeMessageCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? id = null, - Object? text = null, - Object? type = null, - Object? context = null, - }) { - return _then(_value.copyWith( - id: null == id - ? _value.id - : id // ignore: cast_nullable_to_non_nullable - as int, - text: null == text - ? _value.text - : text // ignore: cast_nullable_to_non_nullable - as String, - type: null == type - ? _value.type - : type // ignore: cast_nullable_to_non_nullable - as MessageType, - context: null == context - ? _value.context - : context // ignore: cast_nullable_to_non_nullable - as Context, - ) as $Val); - } - - @override - @pragma('vm:prefer-inline') - $ContextCopyWith<$Res> get context { - return $ContextCopyWith<$Res>(_value.context, (value) { - return _then(_value.copyWith(context: value) as $Val); - }); - } -} - -/// @nodoc -abstract class _$$_UiNodeMessageCopyWith<$Res> - implements $UiNodeMessageCopyWith<$Res> { - factory _$$_UiNodeMessageCopyWith( - _$_UiNodeMessage value, $Res Function(_$_UiNodeMessage) then) = - __$$_UiNodeMessageCopyWithImpl<$Res>; - @override - @useResult - $Res call({int id, String text, MessageType type, Context context}); - - @override - $ContextCopyWith<$Res> get context; -} - -/// @nodoc -class __$$_UiNodeMessageCopyWithImpl<$Res> - extends _$UiNodeMessageCopyWithImpl<$Res, _$_UiNodeMessage> - implements _$$_UiNodeMessageCopyWith<$Res> { - __$$_UiNodeMessageCopyWithImpl( - _$_UiNodeMessage _value, $Res Function(_$_UiNodeMessage) _then) - : super(_value, _then); - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? id = null, - Object? text = null, - Object? type = null, - Object? context = null, - }) { - return _then(_$_UiNodeMessage( - id: null == id - ? _value.id - : id // ignore: cast_nullable_to_non_nullable - as int, - text: null == text - ? _value.text - : text // ignore: cast_nullable_to_non_nullable - as String, - type: null == type - ? _value.type - : type // ignore: cast_nullable_to_non_nullable - as MessageType, - context: null == context - ? _value.context - : context // ignore: cast_nullable_to_non_nullable - as Context, - )); - } -} - -/// @nodoc -@JsonSerializable() -class _$_UiNodeMessage implements _UiNodeMessage { - const _$_UiNodeMessage( - {required this.id, - required this.text, - required this.type, - required this.context}); - - factory _$_UiNodeMessage.fromJson(Map json) => - _$$_UiNodeMessageFromJson(json); - - @override - final int id; - @override - final String text; - @override - final MessageType type; - @override - final Context context; - - @override - String toString() { - return 'UiNodeMessage(id: $id, text: $text, type: $type, context: $context)'; - } - - @override - bool operator ==(dynamic other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$_UiNodeMessage && - (identical(other.id, id) || other.id == id) && - (identical(other.text, text) || other.text == text) && - (identical(other.type, type) || other.type == type) && - (identical(other.context, context) || other.context == context)); - } - - @JsonKey(ignore: true) - @override - int get hashCode => Object.hash(runtimeType, id, text, type, context); - - @JsonKey(ignore: true) - @override - @pragma('vm:prefer-inline') - _$$_UiNodeMessageCopyWith<_$_UiNodeMessage> get copyWith => - __$$_UiNodeMessageCopyWithImpl<_$_UiNodeMessage>(this, _$identity); - - @override - Map toJson() { - return _$$_UiNodeMessageToJson( - this, - ); - } -} - -abstract class _UiNodeMessage implements UiNodeMessage { - const factory _UiNodeMessage( - {required final int id, - required final String text, - required final MessageType type, - required final Context context}) = _$_UiNodeMessage; - - factory _UiNodeMessage.fromJson(Map json) = - _$_UiNodeMessage.fromJson; - - @override - int get id; - @override - String get text; - @override - MessageType get type; - @override - Context get context; - @override - @JsonKey(ignore: true) - _$$_UiNodeMessageCopyWith<_$_UiNodeMessage> get copyWith => - throw _privateConstructorUsedError; -} - -Context _$ContextFromJson(Map json) { - return _Context.fromJson(json); -} - -/// @nodoc -mixin _$Context { - Property get property => throw _privateConstructorUsedError; - - Map toJson() => throw _privateConstructorUsedError; - @JsonKey(ignore: true) - $ContextCopyWith get copyWith => throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $ContextCopyWith<$Res> { - factory $ContextCopyWith(Context value, $Res Function(Context) then) = - _$ContextCopyWithImpl<$Res, Context>; - @useResult - $Res call({Property property}); -} - -/// @nodoc -class _$ContextCopyWithImpl<$Res, $Val extends Context> - implements $ContextCopyWith<$Res> { - _$ContextCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? property = null, - }) { - return _then(_value.copyWith( - property: null == property - ? _value.property - : property // ignore: cast_nullable_to_non_nullable - as Property, - ) as $Val); - } -} - -/// @nodoc -abstract class _$$_ContextCopyWith<$Res> implements $ContextCopyWith<$Res> { - factory _$$_ContextCopyWith( - _$_Context value, $Res Function(_$_Context) then) = - __$$_ContextCopyWithImpl<$Res>; - @override - @useResult - $Res call({Property property}); -} - -/// @nodoc -class __$$_ContextCopyWithImpl<$Res> - extends _$ContextCopyWithImpl<$Res, _$_Context> - implements _$$_ContextCopyWith<$Res> { - __$$_ContextCopyWithImpl(_$_Context _value, $Res Function(_$_Context) _then) - : super(_value, _then); - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? property = null, - }) { - return _then(_$_Context( - property: null == property - ? _value.property - : property // ignore: cast_nullable_to_non_nullable - as Property, - )); - } -} - -/// @nodoc -@JsonSerializable() -class _$_Context implements _Context { - const _$_Context({this.property = Property.general}); - - factory _$_Context.fromJson(Map json) => - _$$_ContextFromJson(json); - - @override - @JsonKey() - final Property property; - - @override - String toString() { - return 'Context(property: $property)'; - } - - @override - bool operator ==(dynamic other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$_Context && - (identical(other.property, property) || - other.property == property)); - } - - @JsonKey(ignore: true) - @override - int get hashCode => Object.hash(runtimeType, property); - - @JsonKey(ignore: true) - @override - @pragma('vm:prefer-inline') - _$$_ContextCopyWith<_$_Context> get copyWith => - __$$_ContextCopyWithImpl<_$_Context>(this, _$identity); - - @override - Map toJson() { - return _$$_ContextToJson( - this, - ); - } -} - -abstract class _Context implements Context { - const factory _Context({final Property property}) = _$_Context; - - factory _Context.fromJson(Map json) = _$_Context.fromJson; - - @override - Property get property; - @override - @JsonKey(ignore: true) - _$$_ContextCopyWith<_$_Context> get copyWith => - throw _privateConstructorUsedError; -} diff --git a/kratos-flutter/lib/services/message.g.dart b/kratos-flutter/lib/services/message.g.dart deleted file mode 100644 index aa1a9afd..00000000 --- a/kratos-flutter/lib/services/message.g.dart +++ /dev/null @@ -1,45 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'message.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -_$_UiNodeMessage _$$_UiNodeMessageFromJson(Map json) => - _$_UiNodeMessage( - id: json['id'] as int, - text: json['text'] as String, - type: $enumDecode(_$MessageTypeEnumMap, json['type']), - context: Context.fromJson(json['context'] as Map), - ); - -Map _$$_UiNodeMessageToJson(_$_UiNodeMessage instance) => - { - 'id': instance.id, - 'text': instance.text, - 'type': _$MessageTypeEnumMap[instance.type]!, - 'context': instance.context, - }; - -const _$MessageTypeEnumMap = { - MessageType.info: 'info', - MessageType.error: 'error', - MessageType.success: 'success', -}; - -_$_Context _$$_ContextFromJson(Map json) => _$_Context( - property: $enumDecodeNullable(_$PropertyEnumMap, json['property']) ?? - Property.general, - ); - -Map _$$_ContextToJson(_$_Context instance) => - { - 'property': _$PropertyEnumMap[instance.property]!, - }; - -const _$PropertyEnumMap = { - Property.identifier: 'identifier', - Property.password: 'password', - Property.general: 'general', -}; diff --git a/kratos-flutter/pubspec.lock b/kratos-flutter/pubspec.lock index 54816061..5d053942 100644 --- a/kratos-flutter/pubspec.lock +++ b/kratos-flutter/pubspec.lock @@ -106,7 +106,7 @@ packages: source: hosted version: "5.1.1" built_value: - dependency: transitive + dependency: "direct main" description: name: built_value sha256: "598a2a682e2a7a90f08ba39c0aaa9374c5112340f0a2e275f61b59389543d166" diff --git a/kratos-flutter/pubspec.yaml b/kratos-flutter/pubspec.yaml index c8760c50..c13e514c 100644 --- a/kratos-flutter/pubspec.yaml +++ b/kratos-flutter/pubspec.yaml @@ -49,6 +49,7 @@ dependencies: flutter_secure_storage: ^8.0.0 dotenv: ^4.1.0 collection: ^1.17.1 + built_value: ^8.6.1 dev_dependencies: flutter_test: From 81290a0c4c941c75e6c9ada8e4c5aecd92049946 Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Thu, 24 Aug 2023 13:16:51 +0200 Subject: [PATCH 05/57] fix: handle all errors incl deserialization error --- kratos-flutter/lib/services/auth.dart | 54 ++++----- kratos-flutter/lib/services/exceptions.dart | 5 +- .../lib/services/exceptions.freezed.dart | 113 +++++------------- 3 files changed, 56 insertions(+), 116 deletions(-) diff --git a/kratos-flutter/lib/services/auth.dart b/kratos-flutter/lib/services/auth.dart index eeff1284..ce554678 100644 --- a/kratos-flutter/lib/services/auth.dart +++ b/kratos-flutter/lib/services/auth.dart @@ -22,17 +22,13 @@ class AuthService { // return session return response.data!; } else { - throw DioException(requestOptions: response.requestOptions); + throw const CustomException.unknown(); } } on DioException catch (e) { if (e.response?.statusCode == 401) { throw const CustomException.unauthorized(); } else { - throw CustomException.unknown( - statusCode: e.response?.statusCode, - message: e.response?.data['error'] != null - ? e.response?.data['error']['message'] - : null); + throw _handleUnknownException(e.response?.data); } } } @@ -48,11 +44,7 @@ class AuthService { throw const CustomException.unknown(); } } on DioException catch (e) { - throw CustomException.unknown( - statusCode: e.response?.statusCode, - message: e.response?.data['error'] != null - ? e.response?.data['error']['message'] - : null); + throw _handleUnknownException(e.response?.data); } } @@ -67,11 +59,7 @@ class AuthService { throw const CustomException.unknown(); } } on DioException catch (e) { - throw CustomException.unknown( - statusCode: e.response?.statusCode, - message: e.response?.data['error'] != null - ? e.response?.data['error']['message'] - : null); + throw _handleUnknownException(e.response?.data); } } @@ -81,7 +69,7 @@ class AuthService { required String email, required String password}) async { try { - final UpdateLoginFlowWithPasswordMethod loginFLowBilder = + final UpdateLoginFlowWithPasswordMethod loginFLowBuilder = UpdateLoginFlowWithPasswordMethod((b) => b ..identifier = email ..password = password @@ -90,8 +78,9 @@ class AuthService { final response = await _ory.updateLoginFlow( flow: flowId, updateLoginFlowBody: UpdateLoginFlowBody( - (b) => b..oneOf = OneOf.fromValue1(value: loginFLowBilder))); - if (response.statusCode == 200 && response.data?.sessionToken != null) { + (b) => b..oneOf = OneOf.fromValue1(value: loginFLowBuilder))); + + if (response.statusCode == 200) { // save session token after successful login await storage.persistToken(response.data!.sessionToken!); return; @@ -102,17 +91,13 @@ class AuthService { if (e.response?.statusCode == 401) { throw const CustomException.unauthorized(); } else if (e.response?.statusCode == 400) { - final messages = checkFormForErrors(e.response?.data); + final messages = _checkFormForErrors(e.response?.data); throw CustomException.badRequest(messages: messages); } else if (e.response?.statusCode == 410) { throw CustomException.flowExpired( flowId: e.response?.data['use_flow_id']); } else { - throw CustomException.unknown( - statusCode: e.response?.statusCode, - message: e.response?.data['error'] != null - ? e.response?.data['error']['message'] - : null); + throw _handleUnknownException(e.response?.data); } } } @@ -144,22 +129,18 @@ class AuthService { if (e.response?.statusCode == 401) { throw const CustomException.unauthorized(); } else if (e.response?.statusCode == 400) { - final messages = checkFormForErrors(e.response?.data); + final messages = _checkFormForErrors(e.response?.data); throw CustomException.badRequest(messages: messages); } else if (e.response?.statusCode == 410) { throw CustomException.flowExpired( flowId: e.response?.data['use_flow_id']); } else { - throw CustomException.unknown( - statusCode: e.response?.statusCode, - message: e.response?.data['error'] != null - ? e.response?.data['error']['message'] - : null); + throw _handleUnknownException(e.response?.data); } } } - List checkFormForErrors(Map response) { + List _checkFormForErrors(Map response) { final ui = Map.from(response['ui']); final nodeList = ui['nodes'] as List; @@ -190,4 +171,13 @@ class AuthService { return flattedNodeMessages; } + + CustomException _handleUnknownException(Map? response) { + // use error message if response contains it, otherwise use default value + if (response != null && response.containsKey('error')) { + return CustomException.unknown(message: response['error']['message']); + } else { + return const CustomException.unknown(); + } + } } diff --git a/kratos-flutter/lib/services/exceptions.dart b/kratos-flutter/lib/services/exceptions.dart index 39b3bc94..cc8b2181 100644 --- a/kratos-flutter/lib/services/exceptions.dart +++ b/kratos-flutter/lib/services/exceptions.dart @@ -17,7 +17,6 @@ sealed class CustomException with _$CustomException { {@Default(410) int statusCode, required String flowId}) = FlowExpiredException; const factory CustomException.unknown( - {int? statusCode, - @Default('An error occured. Please try again later.') - String message}) = UnknownException; + {@Default('An error occured. Please try again later.') + String? message}) = UnknownException; } diff --git a/kratos-flutter/lib/services/exceptions.freezed.dart b/kratos-flutter/lib/services/exceptions.freezed.dart index 62bc580a..87924c68 100644 --- a/kratos-flutter/lib/services/exceptions.freezed.dart +++ b/kratos-flutter/lib/services/exceptions.freezed.dart @@ -16,14 +16,13 @@ final _privateConstructorUsedError = UnsupportedError( /// @nodoc mixin _$CustomException { - int? get statusCode => throw _privateConstructorUsedError; @optionalTypeArgs TResult when({ required TResult Function(List? messages, int statusCode) badRequest, required TResult Function(int statusCode) unauthorized, required TResult Function(int statusCode, String flowId) flowExpired, - required TResult Function(int? statusCode, String message) unknown, + required TResult Function(String? message) unknown, }) => throw _privateConstructorUsedError; @optionalTypeArgs @@ -31,7 +30,7 @@ mixin _$CustomException { TResult? Function(List? messages, int statusCode)? badRequest, TResult? Function(int statusCode)? unauthorized, TResult? Function(int statusCode, String flowId)? flowExpired, - TResult? Function(int? statusCode, String message)? unknown, + TResult? Function(String? message)? unknown, }) => throw _privateConstructorUsedError; @optionalTypeArgs @@ -39,7 +38,7 @@ mixin _$CustomException { TResult Function(List? messages, int statusCode)? badRequest, TResult Function(int statusCode)? unauthorized, TResult Function(int statusCode, String flowId)? flowExpired, - TResult Function(int? statusCode, String message)? unknown, + TResult Function(String? message)? unknown, required TResult orElse(), }) => throw _privateConstructorUsedError; @@ -68,10 +67,6 @@ mixin _$CustomException { required TResult orElse(), }) => throw _privateConstructorUsedError; - - @JsonKey(ignore: true) - $CustomExceptionCopyWith get copyWith => - throw _privateConstructorUsedError; } /// @nodoc @@ -79,8 +74,6 @@ abstract class $CustomExceptionCopyWith<$Res> { factory $CustomExceptionCopyWith( CustomException value, $Res Function(CustomException) then) = _$CustomExceptionCopyWithImpl<$Res, CustomException>; - @useResult - $Res call({int statusCode}); } /// @nodoc @@ -92,28 +85,13 @@ class _$CustomExceptionCopyWithImpl<$Res, $Val extends CustomException> final $Val _value; // ignore: unused_field final $Res Function($Val) _then; - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? statusCode = null, - }) { - return _then(_value.copyWith( - statusCode: null == statusCode - ? _value.statusCode! - : statusCode // ignore: cast_nullable_to_non_nullable - as int, - ) as $Val); - } } /// @nodoc -abstract class _$$BadRequestExceptionCopyWith<$Res> - implements $CustomExceptionCopyWith<$Res> { +abstract class _$$BadRequestExceptionCopyWith<$Res> { factory _$$BadRequestExceptionCopyWith(_$BadRequestException value, $Res Function(_$BadRequestException) then) = __$$BadRequestExceptionCopyWithImpl<$Res>; - @override @useResult $Res call({List? messages, int statusCode}); } @@ -210,7 +188,7 @@ class _$BadRequestException extends BadRequestException badRequest, required TResult Function(int statusCode) unauthorized, required TResult Function(int statusCode, String flowId) flowExpired, - required TResult Function(int? statusCode, String message) unknown, + required TResult Function(String? message) unknown, }) { return badRequest(messages, statusCode); } @@ -221,7 +199,7 @@ class _$BadRequestException extends BadRequestException TResult? Function(List? messages, int statusCode)? badRequest, TResult? Function(int statusCode)? unauthorized, TResult? Function(int statusCode, String flowId)? flowExpired, - TResult? Function(int? statusCode, String message)? unknown, + TResult? Function(String? message)? unknown, }) { return badRequest?.call(messages, statusCode); } @@ -232,7 +210,7 @@ class _$BadRequestException extends BadRequestException TResult Function(List? messages, int statusCode)? badRequest, TResult Function(int statusCode)? unauthorized, TResult Function(int statusCode, String flowId)? flowExpired, - TResult Function(int? statusCode, String message)? unknown, + TResult Function(String? message)? unknown, required TResult orElse(), }) { if (badRequest != null) { @@ -286,21 +264,17 @@ abstract class BadRequestException extends CustomException { const BadRequestException._() : super._(); List? get messages; - @override int get statusCode; - @override @JsonKey(ignore: true) _$$BadRequestExceptionCopyWith<_$BadRequestException> get copyWith => throw _privateConstructorUsedError; } /// @nodoc -abstract class _$$UnauthorizedExceptionCopyWith<$Res> - implements $CustomExceptionCopyWith<$Res> { +abstract class _$$UnauthorizedExceptionCopyWith<$Res> { factory _$$UnauthorizedExceptionCopyWith(_$UnauthorizedException value, $Res Function(_$UnauthorizedException) then) = __$$UnauthorizedExceptionCopyWithImpl<$Res>; - @override @useResult $Res call({int statusCode}); } @@ -376,7 +350,7 @@ class _$UnauthorizedException extends UnauthorizedException badRequest, required TResult Function(int statusCode) unauthorized, required TResult Function(int statusCode, String flowId) flowExpired, - required TResult Function(int? statusCode, String message) unknown, + required TResult Function(String? message) unknown, }) { return unauthorized(statusCode); } @@ -387,7 +361,7 @@ class _$UnauthorizedException extends UnauthorizedException TResult? Function(List? messages, int statusCode)? badRequest, TResult? Function(int statusCode)? unauthorized, TResult? Function(int statusCode, String flowId)? flowExpired, - TResult? Function(int? statusCode, String message)? unknown, + TResult? Function(String? message)? unknown, }) { return unauthorized?.call(statusCode); } @@ -398,7 +372,7 @@ class _$UnauthorizedException extends UnauthorizedException TResult Function(List? messages, int statusCode)? badRequest, TResult Function(int statusCode)? unauthorized, TResult Function(int statusCode, String flowId)? flowExpired, - TResult Function(int? statusCode, String message)? unknown, + TResult Function(String? message)? unknown, required TResult orElse(), }) { if (unauthorized != null) { @@ -450,21 +424,17 @@ abstract class UnauthorizedException extends CustomException { _$UnauthorizedException; const UnauthorizedException._() : super._(); - @override int get statusCode; - @override @JsonKey(ignore: true) _$$UnauthorizedExceptionCopyWith<_$UnauthorizedException> get copyWith => throw _privateConstructorUsedError; } /// @nodoc -abstract class _$$FlowExpiredExceptionCopyWith<$Res> - implements $CustomExceptionCopyWith<$Res> { +abstract class _$$FlowExpiredExceptionCopyWith<$Res> { factory _$$FlowExpiredExceptionCopyWith(_$FlowExpiredException value, $Res Function(_$FlowExpiredException) then) = __$$FlowExpiredExceptionCopyWithImpl<$Res>; - @override @useResult $Res call({int statusCode, String flowId}); } @@ -550,7 +520,7 @@ class _$FlowExpiredException extends FlowExpiredException badRequest, required TResult Function(int statusCode) unauthorized, required TResult Function(int statusCode, String flowId) flowExpired, - required TResult Function(int? statusCode, String message) unknown, + required TResult Function(String? message) unknown, }) { return flowExpired(statusCode, flowId); } @@ -561,7 +531,7 @@ class _$FlowExpiredException extends FlowExpiredException TResult? Function(List? messages, int statusCode)? badRequest, TResult? Function(int statusCode)? unauthorized, TResult? Function(int statusCode, String flowId)? flowExpired, - TResult? Function(int? statusCode, String message)? unknown, + TResult? Function(String? message)? unknown, }) { return flowExpired?.call(statusCode, flowId); } @@ -572,7 +542,7 @@ class _$FlowExpiredException extends FlowExpiredException TResult Function(List? messages, int statusCode)? badRequest, TResult Function(int statusCode)? unauthorized, TResult Function(int statusCode, String flowId)? flowExpired, - TResult Function(int? statusCode, String message)? unknown, + TResult Function(String? message)? unknown, required TResult orElse(), }) { if (flowExpired != null) { @@ -625,24 +595,20 @@ abstract class FlowExpiredException extends CustomException { required final String flowId}) = _$FlowExpiredException; const FlowExpiredException._() : super._(); - @override int get statusCode; String get flowId; - @override @JsonKey(ignore: true) _$$FlowExpiredExceptionCopyWith<_$FlowExpiredException> get copyWith => throw _privateConstructorUsedError; } /// @nodoc -abstract class _$$UnknownExceptionCopyWith<$Res> - implements $CustomExceptionCopyWith<$Res> { +abstract class _$$UnknownExceptionCopyWith<$Res> { factory _$$UnknownExceptionCopyWith( _$UnknownException value, $Res Function(_$UnknownException) then) = __$$UnknownExceptionCopyWithImpl<$Res>; - @override @useResult - $Res call({int? statusCode, String message}); + $Res call({String? message}); } /// @nodoc @@ -656,18 +622,13 @@ class __$$UnknownExceptionCopyWithImpl<$Res> @pragma('vm:prefer-inline') @override $Res call({ - Object? statusCode = freezed, - Object? message = null, + Object? message = freezed, }) { return _then(_$UnknownException( - statusCode: freezed == statusCode - ? _value.statusCode - : statusCode // ignore: cast_nullable_to_non_nullable - as int?, - message: null == message + message: freezed == message ? _value.message : message // ignore: cast_nullable_to_non_nullable - as String, + as String?, )); } } @@ -676,19 +637,16 @@ class __$$UnknownExceptionCopyWithImpl<$Res> class _$UnknownException extends UnknownException with DiagnosticableTreeMixin { const _$UnknownException( - {this.statusCode, - this.message = 'An error occured. Please try again later.'}) + {this.message = 'An error occured. Please try again later.'}) : super._(); - @override - final int? statusCode; @override @JsonKey() - final String message; + final String? message; @override String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { - return 'CustomException.unknown(statusCode: $statusCode, message: $message)'; + return 'CustomException.unknown(message: $message)'; } @override @@ -696,7 +654,6 @@ class _$UnknownException extends UnknownException with DiagnosticableTreeMixin { super.debugFillProperties(properties); properties ..add(DiagnosticsProperty('type', 'CustomException.unknown')) - ..add(DiagnosticsProperty('statusCode', statusCode)) ..add(DiagnosticsProperty('message', message)); } @@ -705,13 +662,11 @@ class _$UnknownException extends UnknownException with DiagnosticableTreeMixin { return identical(this, other) || (other.runtimeType == runtimeType && other is _$UnknownException && - (identical(other.statusCode, statusCode) || - other.statusCode == statusCode) && (identical(other.message, message) || other.message == message)); } @override - int get hashCode => Object.hash(runtimeType, statusCode, message); + int get hashCode => Object.hash(runtimeType, message); @JsonKey(ignore: true) @override @@ -726,9 +681,9 @@ class _$UnknownException extends UnknownException with DiagnosticableTreeMixin { badRequest, required TResult Function(int statusCode) unauthorized, required TResult Function(int statusCode, String flowId) flowExpired, - required TResult Function(int? statusCode, String message) unknown, + required TResult Function(String? message) unknown, }) { - return unknown(statusCode, message); + return unknown(message); } @override @@ -737,9 +692,9 @@ class _$UnknownException extends UnknownException with DiagnosticableTreeMixin { TResult? Function(List? messages, int statusCode)? badRequest, TResult? Function(int statusCode)? unauthorized, TResult? Function(int statusCode, String flowId)? flowExpired, - TResult? Function(int? statusCode, String message)? unknown, + TResult? Function(String? message)? unknown, }) { - return unknown?.call(statusCode, message); + return unknown?.call(message); } @override @@ -748,11 +703,11 @@ class _$UnknownException extends UnknownException with DiagnosticableTreeMixin { TResult Function(List? messages, int statusCode)? badRequest, TResult Function(int statusCode)? unauthorized, TResult Function(int statusCode, String flowId)? flowExpired, - TResult Function(int? statusCode, String message)? unknown, + TResult Function(String? message)? unknown, required TResult orElse(), }) { if (unknown != null) { - return unknown(statusCode, message); + return unknown(message); } return orElse(); } @@ -796,14 +751,10 @@ class _$UnknownException extends UnknownException with DiagnosticableTreeMixin { } abstract class UnknownException extends CustomException { - const factory UnknownException( - {final int? statusCode, final String message}) = _$UnknownException; + const factory UnknownException({final String? message}) = _$UnknownException; const UnknownException._() : super._(); - @override - int? get statusCode; - String get message; - @override + String? get message; @JsonKey(ignore: true) _$$UnknownExceptionCopyWith<_$UnknownException> get copyWith => throw _privateConstructorUsedError; From e00383dd6adef298d123c0ee5e7022f34852d80b Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Thu, 24 Aug 2023 16:08:18 +0200 Subject: [PATCH 06/57] feat: logout & get session on home page init --- kratos-flutter/lib/blocs/auth/auth_bloc.dart | 29 +++++++- kratos-flutter/lib/main.dart | 2 + kratos-flutter/lib/pages/home.dart | 76 +++++++++++++++++++- kratos-flutter/lib/pages/login.dart | 9 ++- kratos-flutter/lib/pages/registration.dart | 9 ++- kratos-flutter/lib/repositories/auth.dart | 4 ++ kratos-flutter/lib/services/auth.dart | 33 +++++++-- 7 files changed, 147 insertions(+), 15 deletions(-) diff --git a/kratos-flutter/lib/blocs/auth/auth_bloc.dart b/kratos-flutter/lib/blocs/auth/auth_bloc.dart index be41698a..2a0fb55d 100644 --- a/kratos-flutter/lib/blocs/auth/auth_bloc.dart +++ b/kratos-flutter/lib/blocs/auth/auth_bloc.dart @@ -16,10 +16,11 @@ class AuthBloc extends Bloc { : super(const AuthState(status: AuthStatus.uninitialized)) { on(_onGetCurrentSessionInformation); on(_changeAuthStatus); + on(_logOut); } _changeAuthStatus(ChangeAuthStatus event, Emitter emit) { - emit(state.copyWith(status: event.status)); + emit(state.copyWith(status: event.status, isLoading: false)); } Future _onGetCurrentSessionInformation( @@ -36,7 +37,31 @@ class AuthBloc extends Bloc { } on CustomException catch (e) { if (e case UnauthorizedException _) { emit(state.copyWith( - status: AuthStatus.unauthenticated, isLoading: false)); + status: AuthStatus.unauthenticated, + session: null, + isLoading: false)); + } else if (e case UnknownException _) { + emit(state.copyWith(isLoading: false, errorMessage: e.message)); + } else { + emit(state.copyWith(isLoading: false)); + } + } + } + + Future _logOut(LogOut event, Emitter emit) async { + try { + emit(state.copyWith(isLoading: true, errorMessage: null)); + + await repository.logout(); + + emit(state.copyWith( + isLoading: false, status: AuthStatus.unauthenticated, session: null)); + } on CustomException catch (e) { + if (e case UnauthorizedException _) { + emit(state.copyWith( + isLoading: false, + status: AuthStatus.unauthenticated, + session: null)); } else if (e case UnknownException _) { emit(state.copyWith(isLoading: false, errorMessage: e.message)); } else { diff --git a/kratos-flutter/lib/main.dart b/kratos-flutter/lib/main.dart index 5457e10b..406d06d4 100644 --- a/kratos-flutter/lib/main.dart +++ b/kratos-flutter/lib/main.dart @@ -102,6 +102,8 @@ class _MyAppViewState extends State { navigatorKey: _navigatorKey, builder: (context, child) { return BlocListener( + // navigate to pages only when auth status has changed + listenWhen: (previous, current) => previous.status != current.status, listener: (context, state) { switch (state.status) { case AuthStatus.authenticated: diff --git a/kratos-flutter/lib/pages/home.dart b/kratos-flutter/lib/pages/home.dart index c47a819f..f1f98561 100644 --- a/kratos-flutter/lib/pages/home.dart +++ b/kratos-flutter/lib/pages/home.dart @@ -1,12 +1,82 @@ import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:ory_client/ory_client.dart'; -class HomePage extends StatelessWidget { +import '../blocs/auth/auth_bloc.dart'; + +class HomePage extends StatefulWidget { const HomePage({super.key}); + @override + State createState() => _HomePageState(); +} + +class _HomePageState extends State { + @override + void initState() { + super.initState(); + // get current session information when the page opens + context.read().add(GetCurrentSessionInformation()); + } + @override Widget build(BuildContext context) { - return const Scaffold( - body: Center(child: Text('logged in')), + // get loading state + final isLoading = + context.select((AuthBloc authBloc) => authBloc.state.isLoading); + + return Scaffold( + appBar: AppBar( + actions: [ + // if auth is loading, show progress indicator, otherwise a logout icon + isLoading + ? const Padding( + padding: EdgeInsets.only(right: 20.0), + child: Center( + widthFactor: 1, + heightFactor: 1, + child: SizedBox( + height: 24, + width: 24, + child: CircularProgressIndicator( + backgroundColor: Colors.white, + ), + ), + ), + ) + : IconButton( + onPressed: () => context.read()..add(LogOut()), + icon: const Icon(Icons.logout), + ), + ], + ), + body: BlocBuilder( + bloc: context.read(), + builder: (BuildContext context, AuthState state) { + if (state.session != null) { + return _buildSessionInformation(context, state.session!); + } else { + return _buildSessionNotFetched(context, state); + } + }, + )); + } + + _buildSessionInformation(BuildContext context, Session session) { + return Column( + children: [Text("Session Information")], ); } + + _buildSessionNotFetched(BuildContext context, AuthState state) { + if (state.errorMessage != null) { + return Center( + child: Text( + state.errorMessage!, + style: const TextStyle(color: Colors.red), + )); + } else { + return const Center(child: CircularProgressIndicator()); + } + } } diff --git a/kratos-flutter/lib/pages/login.dart b/kratos-flutter/lib/pages/login.dart index 2f160b7a..e71ee7e9 100644 --- a/kratos-flutter/lib/pages/login.dart +++ b/kratos-flutter/lib/pages/login.dart @@ -96,6 +96,7 @@ class LoginForm extends StatelessWidget { style: const TextStyle(color: Colors.red), maxLines: 3, ), + if (state.isLoading) const CircularProgressIndicator(), OutlinedButton( onPressed: state.isLoading ? null @@ -114,9 +115,11 @@ class LoginForm extends StatelessWidget { children: [ const Text('Don\'t have an account yet?'), TextButton( - onPressed: () => Navigator.of(context).pushReplacement( - MaterialPageRoute( - builder: (context) => const RegistrationPage())), + onPressed: state.isLoading + ? null + : () => Navigator.of(context).pushReplacement( + MaterialPageRoute( + builder: (context) => const RegistrationPage())), child: const Text('Get started')) ], ) diff --git a/kratos-flutter/lib/pages/registration.dart b/kratos-flutter/lib/pages/registration.dart index 0de1e078..3498e6f2 100644 --- a/kratos-flutter/lib/pages/registration.dart +++ b/kratos-flutter/lib/pages/registration.dart @@ -97,6 +97,7 @@ class LoginForm extends StatelessWidget { state.errorMessage!, style: const TextStyle(color: Colors.red), ), + if (state.isLoading) const CircularProgressIndicator(), OutlinedButton( onPressed: state.isLoading ? null @@ -116,9 +117,11 @@ class LoginForm extends StatelessWidget { children: [ Text('Already have an account?'), TextButton( - onPressed: () => Navigator.of(context).pushReplacement( - MaterialPageRoute( - builder: (context) => const LoginPage())), + onPressed: state.isLoading + ? null + : () => Navigator.of(context).pushReplacement( + MaterialPageRoute( + builder: (context) => const LoginPage())), child: Text('Log in')) ], ) diff --git a/kratos-flutter/lib/repositories/auth.dart b/kratos-flutter/lib/repositories/auth.dart index 841b98f2..ce368489 100644 --- a/kratos-flutter/lib/repositories/auth.dart +++ b/kratos-flutter/lib/repositories/auth.dart @@ -39,4 +39,8 @@ class AuthRepository { await service.registerWithEmailAndPassword( flowId: flowId, email: email, password: password); } + + Future logout() async { + await service.logout(); + } } diff --git a/kratos-flutter/lib/services/auth.dart b/kratos-flutter/lib/services/auth.dart index ce554678..b09e1feb 100644 --- a/kratos-flutter/lib/services/auth.dart +++ b/kratos-flutter/lib/services/auth.dart @@ -26,6 +26,7 @@ class AuthService { } } on DioException catch (e) { if (e.response?.statusCode == 401) { + await storage.deleteToken(); throw const CustomException.unauthorized(); } else { throw _handleUnknownException(e.response?.data); @@ -80,7 +81,7 @@ class AuthService { updateLoginFlowBody: UpdateLoginFlowBody( (b) => b..oneOf = OneOf.fromValue1(value: loginFLowBuilder))); - if (response.statusCode == 200) { + if (response.statusCode == 200 && response.data?.session != null) { // save session token after successful login await storage.persistToken(response.data!.sessionToken!); return; @@ -89,6 +90,7 @@ class AuthService { } } on DioException catch (e) { if (e.response?.statusCode == 401) { + await storage.deleteToken(); throw const CustomException.unauthorized(); } else if (e.response?.statusCode == 400) { final messages = _checkFormForErrors(e.response?.data); @@ -108,7 +110,7 @@ class AuthService { required String email, required String password}) async { try { - final UpdateRegistrationFlowWithPasswordMethod registrationFLowBuilder = + final UpdateRegistrationFlowWithPasswordMethod registrationFLow = UpdateRegistrationFlowWithPasswordMethod((b) => b ..traits = JsonObject({'email': email}) ..password = password @@ -116,8 +118,8 @@ class AuthService { final response = await _ory.updateRegistrationFlow( flow: flowId, - updateRegistrationFlowBody: UpdateRegistrationFlowBody((b) => - b..oneOf = OneOf.fromValue1(value: registrationFLowBuilder))); + updateRegistrationFlowBody: UpdateRegistrationFlowBody( + (b) => b..oneOf = OneOf.fromValue1(value: registrationFLow))); if (response.statusCode == 200 && response.data?.sessionToken != null) { // save session token after successful login await storage.persistToken(response.data!.sessionToken!); @@ -127,6 +129,7 @@ class AuthService { } } on DioException catch (e) { if (e.response?.statusCode == 401) { + await storage.deleteToken(); throw const CustomException.unauthorized(); } else if (e.response?.statusCode == 400) { final messages = _checkFormForErrors(e.response?.data); @@ -140,6 +143,28 @@ class AuthService { } } + Future logout() async { + try { + final token = await storage.getToken(); + + final PerformNativeLogoutBody logoutBody = + PerformNativeLogoutBody((b) => b..sessionToken = token); + final response = + await _ory.performNativeLogout(performNativeLogoutBody: logoutBody); + if (response.statusCode == 204) { + await storage.deleteToken(); + return; + } + } on DioException catch (e) { + if (e.response?.statusCode == 401) { + await storage.deleteToken(); + throw const CustomException.unauthorized(); + } else { + throw _handleUnknownException(e.response?.data); + } + } + } + List _checkFormForErrors(Map response) { final ui = Map.from(response['ui']); final nodeList = ui['nodes'] as List; From a6459a06d46938287f66d68a4f23afbd64a10d36 Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Tue, 29 Aug 2023 16:42:08 +0200 Subject: [PATCH 07/57] feat: show session information --- kratos-flutter/lib/pages/home.dart | 62 +++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/kratos-flutter/lib/pages/home.dart b/kratos-flutter/lib/pages/home.dart index f1f98561..df55a0a4 100644 --- a/kratos-flutter/lib/pages/home.dart +++ b/kratos-flutter/lib/pages/home.dart @@ -63,8 +63,66 @@ class _HomePageState extends State { } _buildSessionInformation(BuildContext context, Session session) { - return Column( - children: [Text("Session Information")], + return Padding( + padding: const EdgeInsets.all(30.0), + child: SingleChildScrollView( + physics: const BouncingScrollPhysics(), + child: Column( + children: [ + Text( + "Welcome back,\n${session.identity.id}!", + style: const TextStyle(fontWeight: FontWeight.w900, fontSize: 35), + ), + const Padding( + padding: EdgeInsets.only(top: 15.0), + child: Text( + "Hello, nice to have you! you signed up with this data:"), + ), + Padding( + padding: const EdgeInsets.only(top: 15.0), + child: Container( + padding: const EdgeInsets.all(35), + width: double.infinity, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(8), + color: Colors.grey[400]), + child: Text(session.identity.traits.toString()), + ), + ), + const Padding( + padding: EdgeInsets.only(top: 15.0), + child: + Text("You are signed in using an ORY Kratos Session Token:"), + ), + Padding( + padding: const EdgeInsets.only(top: 15.0), + child: Container( + padding: const EdgeInsets.all(35), + width: double.infinity, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(8), + color: Colors.grey[400]), + child: Text(session.id), + ), + ), + const Padding( + padding: EdgeInsets.only(top: 15.0), + child: Text( + "This app mackes REST requests to ORY Kratos' Public API to validate and decode the ORY Kratos Session payload:")), + Padding( + padding: const EdgeInsets.only(top: 15.0), + child: Container( + padding: const EdgeInsets.all(35), + width: double.infinity, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(8), + color: Colors.grey[400]), + child: Text(session.toString()), + ), + ), + ], + ), + ), ); } From bd77e992e8564c7aa013aad6d2cee1aeb3d0c86c Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Fri, 1 Sep 2023 11:24:50 +0200 Subject: [PATCH 08/57] feat: add design and refactor blocs --- .../flows-auth-buttons-social-linkedin.svg | 10 + kratos-flutter/assets/icons/eye-off.png | Bin 0 -> 384 bytes kratos-flutter/assets/icons/eye.png | Bin 0 -> 356 bytes .../flows-auth-buttons-social-apple.png | Bin 0 -> 476 bytes .../flows-auth-buttons-social-github.png | Bin 0 -> 635 bytes .../flows-auth-buttons-social-google.png | Bin 0 -> 674 bytes .../flows-auth-buttons-social-linkedin.png | Bin 0 -> 610 bytes kratos-flutter/assets/images/ory_logo.png | Bin 0 -> 18190 bytes .../lib/blocs/login/login_bloc.dart | 27 +- .../lib/blocs/login/login_bloc.freezed.dart | 28 +- .../lib/blocs/login/login_event.dart | 9 + .../lib/blocs/login/login_state.dart | 1 + .../blocs/registration/registration_bloc.dart | 27 +- .../registration_bloc.freezed.dart | 28 +- .../registration/registration_event.dart | 10 +- .../registration/registration_state.dart | 1 + kratos-flutter/lib/main.dart | 2 + kratos-flutter/lib/pages/entry.dart | 9 +- kratos-flutter/lib/pages/home.dart | 33 +- kratos-flutter/lib/pages/login.dart | 286 +++++++++++++----- kratos-flutter/lib/pages/registration.dart | 267 +++++++++++----- kratos-flutter/lib/services/auth.dart | 18 +- kratos-flutter/lib/services/exceptions.dart | 3 +- .../lib/services/exceptions.freezed.dart | 77 +++-- kratos-flutter/lib/widgets/ory_theme.dart | 80 +++++ .../lib/widgets/social_provider_box.dart | 25 ++ kratos-flutter/pubspec.lock | 70 ++++- kratos-flutter/pubspec.yaml | 3 + 28 files changed, 790 insertions(+), 224 deletions(-) create mode 100644 assets/images/images/flows-auth-buttons-social-linkedin.svg create mode 100644 kratos-flutter/assets/icons/eye-off.png create mode 100644 kratos-flutter/assets/icons/eye.png create mode 100644 kratos-flutter/assets/images/flows-auth-buttons-social-apple.png create mode 100644 kratos-flutter/assets/images/flows-auth-buttons-social-github.png create mode 100644 kratos-flutter/assets/images/flows-auth-buttons-social-google.png create mode 100644 kratos-flutter/assets/images/flows-auth-buttons-social-linkedin.png create mode 100644 kratos-flutter/assets/images/ory_logo.png create mode 100644 kratos-flutter/lib/widgets/ory_theme.dart create mode 100644 kratos-flutter/lib/widgets/social_provider_box.dart diff --git a/assets/images/images/flows-auth-buttons-social-linkedin.svg b/assets/images/images/flows-auth-buttons-social-linkedin.svg new file mode 100644 index 00000000..100dc8ed --- /dev/null +++ b/assets/images/images/flows-auth-buttons-social-linkedin.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/kratos-flutter/assets/icons/eye-off.png b/kratos-flutter/assets/icons/eye-off.png new file mode 100644 index 0000000000000000000000000000000000000000..65924f7d338aed1651c4992fd31a07030c328bcc GIT binary patch literal 384 zcmV-`0e}99P)X1^@s6D=Y3@00009a7bBm000XU z000XU0RWnu7ytkO0drDELIAGL9O(c600d`2O+f$vv5yPM3#7gFw|57? zFUb>TQ^4d5VMeJXO*|PROpr>|G1)VvjOFtFWFmZV+XVgT@|jp-LX4C?nLgnK!!;p^ zi7;~WI?u|%#6y#^UY%vLZV{EENpHFcRq@C$7oaIJ!7l2?tXq>urVvaEuR;R5Nx@{O zy3Qz_N7EJcf>NG0*l$v&*ea3$-!P|dm&Uo$q&mLw2F`368!8 zY&#g0AFx?8Neie4s5kHyuvCANx)3va(Z}wG)Awvy_F8iz+QT%=Ylx4UeR)QQajvwcA$mSzb!Jy}#uCzDS84{jF)G(-qDhBv10LgBHu?UOxM>B{54(tnLJJcDJqT1hp5+z(8Q|boFyt=akR{0LC7Q AcmMzZ literal 0 HcmV?d00001 diff --git a/kratos-flutter/assets/images/flows-auth-buttons-social-apple.png b/kratos-flutter/assets/images/flows-auth-buttons-social-apple.png new file mode 100644 index 0000000000000000000000000000000000000000..2a259447ee732eed31dfda701d9ae5ca4aab459a GIT binary patch literal 476 zcmV<20VDp2P)200009a7bBm000XU z000XU0RWnu7ytkO0drDELIAGL9O(c600d`2O+f$vv5yPl5H2ZAN0}TUH{b>+Cx9COCkRxuK7tD((yj*^X=5jeW1k$ASs4zT4u_=OZ(p7x`6C7T9nd=4lUL z5cs;tw|t~LJxv}&;jMt{=2uu?8ZAm|R$ET8H<3DQE)Y zQFIB!t&}++kk5epguRqqQH9$2xgVq%YguTux^*WTPcr6)tRq=YHU?(YCd0Se+(?rn zGR=A@sd;|G{&Cj6SSXr#FcNitvo1iTSq@<&DcUM1QTzlWRh*Sj!73O?ChM#O)be2@ z_BMC+ddalqLcg1t0+>nqIdXELiHNN(3?w~ylbx)k<{y8&4r&|QGC62sHBw7)+vDN8 zMp2}5*U5S(odzN(CS1vjzX0U8qr-t(+K&SLTq5b?*^Q<%Z>8EW&`N3imA(LW!+`mD SP9Dbq00000)+jEP)200009a7bBm000XU z000XU0RWnu7ytkO0drDELIAGL9O(c600d`2O+f$vv5yPHiC`2gH92{2?!@(dV)?*0Gyz30?G-JoPgdS=?OX&3Sx&@fYO}> zi$-n7ug~+BnQ4ybSBMnAuOw!vQoCC7-?w%-`?Fsr%il04i}r-3T-9I_rz_qS(H7 zV+tkmOGovxQmKnEk>OB%U1(BH0wus#g^d7bu#VVPxtyenvw#PX1d3>X=L!ON1M3LJ z{qoW!H;XA$UD$llq?^)a0eDyXLR44^R!mA8h7bp`=Y=bQPduNS#nq-NZUUX8VZ2d-*L~!3RRxXSL=e9{)R^eq30$+b6PLcxh` literal 0 HcmV?d00001 diff --git a/kratos-flutter/assets/images/flows-auth-buttons-social-google.png b/kratos-flutter/assets/images/flows-auth-buttons-social-google.png new file mode 100644 index 0000000000000000000000000000000000000000..9a9c46c24ce2120b48e1ad703ceb8f7f09430fea GIT binary patch literal 674 zcmV;T0$u%yP)200009a7bBm000XU z000XU0RWnu7ytkO0drDELIAGL9O(c600d`2O+f$vv5yP;bQQZpn{)CC81U|=wafo{%P24F%6p_TzL7XE@}3rI*!H-NeDEyAJ2B{*p6dRtA5kz?!DiA_wL;RoPscEv8yVQ`E#fd;xY%y zhbcWG+7%a4`qKNB@!wDn_Ui$n{g419nD3~XIyZT=RB!i!^XVDj&5~>mM?0L6r{seG z0chqxlzCX53w0b?gHaRwqxy~v8$d@O2@qwb9ck9&o^!^%2w;bw{hb#1YDHklKv&Zw`|&4rr3e=>t8^~9Wa%i z9|st6I%$YbEfv@0@3gUSYkVadeB;GvI}v8X?uTdDx?fX5kdY1-7fmBRjWkFQ39iSw z5VvR(_TdEbog!hI_mZ9Q2*m3E2QlGTot>MyN3i=LD3HC+J*a*)bMSajlnS-1vbXk5 z52k;7nho{j>dS#*+o(o}9aR$lq&`#3 zGv)4Rb9eN3&3U5kGtK-^A=AC>3=LaIm1ChtE-Xwnqu_ZGhbu;=v+e_9p+_pz?rw5R zY(Sz=PgAg>?M%F<9&wJqp(xeU!x=5u?ee65&!@I07*qo IM6N<$f}<`dXaE2J literal 0 HcmV?d00001 diff --git a/kratos-flutter/assets/images/flows-auth-buttons-social-linkedin.png b/kratos-flutter/assets/images/flows-auth-buttons-social-linkedin.png new file mode 100644 index 0000000000000000000000000000000000000000..1bac417e150462538473dec9f00c4ec0e68101d3 GIT binary patch literal 610 zcmV-o0-gPdP)200009a7bBm000XU z000XU0RWnu7ytkO0drDELIAGL9O(c600d`2O+f$vv5yPP4`@-rdn5EL-CKKVyce27Z7n@Co?5CdRPYis;6*_N zy$MFl#e=das0X9FC@RsN=e*Ud*%;$S@dNwbydU#r-Y`4BJs_?-h@~=-{bT)&Ahb(f zLL$PqEuP03b!TS#r(xD5+R~T(2vCa6$aRjI5W~$OXTVGu){UakFXJPUWCFo3n{?`~ zj9M#Sw0s`_U5B6|R&=y!m8z6JHKW7go~sl zcuIMqL=-Q-pq@XQjANZeI)6+d$Ei>(Z`yeI{9N?^!a6>T<~$!M(SeHR#}I(|)dGG^ zuDJHQt~O3lgLlSd)QQoxs`$B9M{p}ddUvp=*B7ax zFleNOq<^Rv0h4rRz`s>N^iw7+h4vmn1vTonYBdx^VaP}bP_J^RA!qTOKNO-)t4d!L wH5^NM?%;B93!9s@$-@#gJ87#*AH7%30F++55#!XMfB*mh07*qoM6N<$g1cxB3jhEB literal 0 HcmV?d00001 diff --git a/kratos-flutter/assets/images/ory_logo.png b/kratos-flutter/assets/images/ory_logo.png new file mode 100644 index 0000000000000000000000000000000000000000..41915eb95e33632e1d8175f00b04756301280427 GIT binary patch literal 18190 zcmbuncOcc@|2Y1<*H%VF%5Eq#m08B6UQzbQirgz9vWjf(jii)R_7+)@OG1Q8ik2>} ztz2cV%xhfkeg4i>y+6PIzx|VQpO1YWXFbm2aqgQK>2h%jazYTqb>aMfW)Q>-{zO9T ztl&T4Hqjag(&@hNpZ3K7#N3azr*_>nD(fxACaYu~~Nxh3uN!dTT=a{q0_?6Yw zk4yaGrI6yx{$HHTxsOB-+|_vX1{rNbwBxpYr%=E)!NqYpXOCC}C&$=y{Yja~i)I%n zPsD=pl+AOH!~x!mPMVcjaD`@SwqElC!jO?vXfnz(bv*Y|24R*V)Cafl7h7HH1#?GX zql!c9;1|gxD0_F53Z0Du30iuGA<6F@LU05#0<^TnKS<48&`Q_1;9n}C;?QKuZ^geHY7Lq%!AV2?QwJyKl zf)wdr89jnKeNh0qwiT$n4OHcZgkn&-+a34$VhEJIIB|6w!zP-6AsfYDE_wC_0@sq& z&C3v&W@!MRTr{?!P!vt5eZ68oL*s08kPsj|#mXSu&Qrew;QPjjgT`dl5Hlo*rD`+e z^);UWa-nG3{ZpG)!JvGSVHcd|q#dAKV89@TsW`m{5G#sc;P*X@VFUQn+bBKP9RUiq zVqn~-fVQl=F~T?3dtl?V`&|a4b!;Vogxf9w=MehV-+PX?Y}?f^l|6d_IhC0*hJQ8Y zZyTc9IuP(9m*grlJW1J*A)RdRXJ8Q6Ipa0MOUhigWjU27%0Rwu!*EBO;U0z=3MyVh zS|bFTVmF54xu-I?tEQO$;chj8eJqY4F-+9Bn63&;ta080?%Kyk&NPI#dY!J|3uhfZduKmk;tPhp&Rs(g%a$46#p|)&Q59L7|_$E3@>)!*W*HN>m7TAF~Vj{F7b+kuehLCaJ~xj?{GshQ2WX3BRu%mf#o88#5+z{k z{};MModLc0Qs%GTmW(0wbH!5Ruc-PwK-993V$Q#c=P|5kUGMZ)w$>sB^Ahr_zp9M9 zXRuSAfBn~PH)erb^ZfAX{L5bTCWHNNHP657>y88VXJKKbzwEgg6I44^{vW#nhU)PX zWq;8F_<(fJLfHN&ckyb#Vy8fj6nnPdh6a3TbBKr0SO0JSUi2{6D+_yYjWk7=swY3X za(ti8bJOSJm9Bct`K~(4=mecu+M!&5EtytSXx~>&BdHiRLxuZCLe=1!)mR1B-SPzW z%!mF*5oL&JvCy@F$ZGmt`LN5c0!KE`qQyHR)`M-m1_s(^$5W4Q;BDV(o8A?`)@O9C zJdiXYz1NLXtH!esEw03PX2tq3LmCT{2i6?i&qb5Jig^yk=I*Z~-@RLII;TQ7Ke8He zW0Sm6kevTxUwX>>V)?lsRaPT?TJBXO?$>O7*DUu+y}O9uQiRS_vW>j#}7@g_&%_J zD3YO6)aH#cMPs8{^_62upZ58tP^Vi_>kD!>sr?qJ^ zI0)wmfN=o$g%hAyGi<#|BCHMa$g^dfNQ>r5B?7|Trf}^A+KfB`I_h2F`puqy%j51p zgpJ|zvOaSUHtcOUPRYhndj+P^WOhikDE`;LF#22A74j+-m?JYaAMO_qDBTMGNY0*c z&59!b)~_+$P{g(^^&Z3RF^8!-w1`Wu9mtiw^K`NL-d=gH5BE-TInLABOrLE$&XrxB zf-9_8FCo0|(GE)z_UUM6^((NoKBx1arOl|yK-PEp+FB!gL^6ve8!r62S zKye?SSQVn&h-zrK?B+8dWrESu-C7! zKr>e*8mFyU+Qll3;ffq9=xe_HGU=2qqSaAQ2VaCu52v!RyxNVqRf3#kBf&JZ7|Un$ z_tl?cJabXDhyoWu9WS65aQritP#K3MvIMx>4;6Ln6shaEjA`K<^m6317+;GXuDgsgd(fHb>A^I3#1O7fFufPj-rZjT)3H_O z=HP4Cb+^WwmH47@Y{L?MLU+O*9!m<2Qwv6jJfoLinI=cqQ7d|v&)(|r_aGV0tv#5t zqEjgAKi_&a>`c5epM{P^)A~2&Bz-K1mbNgA*X)I@;4v~@*L(=~JcCY1LI<~QxI_b6 z>ihow0Xv#wUYxD|`n$~&eSJeopdHNIGdXl^nfgv%n(i~ZM< z>K-9`92*X=f+-Xs^qgJ};Q0=p^U)yh+avp-ZvS<^94)C2n}Hu3RytO+pV`_Q?Nz0m zhCXg4u|_n-tV+0U2+t@RNQJubh@|Dv%e5KUc~fE~vo@l|Q0<2mct7mEVq%olSuck2 z7)k$vNb|2a<-c10^!NF^w_T{yIy5zwYN-9d$ZGvo)!Nd{H@mXc(zoE(LoXrgS%1oc zew1C6eBvz=cv2jAaC;awa3KmK1$vW}1iQ>wK*vKuugm0ZdgL6DEAUxr=#y7xu8^J< z6UnD*@9L~Ni%7~{sep3iXKC1cu*2WLJyi@C{+VhC5PT|2xym0%UpK#G7g@9{K^XP{I_wB zAJ5welc?j{@p z)VQk%8?QwRF1Nz21`Qo^C{hwhs3O+WzYtfC_^*cVQCnNyf%QTqS>>oV`=C(pT0J(b zLP+Ff8ojky$TV}Y+TV*Hpx^$99}*3dx_@C`>odCPZVFFOn2$GdrlnME?_y7htPG9(1Q(I?0ky=vI$Uls8V@T1x-cPEM?R1UAA)#I#xFlMq8M0 zKQ~n5RXRe1O`d4$so3EosJb!0jCn@n%^`u}YvZS{c0w1*4ag1qQis+u!BDOv2Pata@AHs_k~OySH_@-rCxgj_ z-N$Lk^vC2K+7?|X6F57n1Zj;dh7!N5!0XDpp`E(6%^S^L50TT#*O`}t4;F%XC$yyFd1PNiRA+AN}9$0oK)e3!}1%@T}q% z@=!fZr=)!ViQ9N)#Y3NL;>;}excIF>qozWQJNg;@3jX$Dj5+S1rJo_xUEpw9;vDj5v%+GD%f7?qxotd-g4+nSKDm4 zTBmkDQ}B^abKj=TCOylu;9A&Ve&nEOdDZRpt2ftH*_w*@wuaDwdp5VXr7WIBcDezt z5+RJ=WOx1MTr-}T{}JZ9reyt(2{wta9J-t>sX@NeXirs09(G!P+w;0c#fT zllgE#MJ6=7m1k@oSIX>tc&_<<3^pWmrapVEi$F>>UK{-Vb2+)?+i05Y+YasKUU`oX z;#KB*2*sf%11?qe5Pp8BF0H(6))8E+e_2`6_C!3Z*z;>-m_M@K@Og3ETXd*!db9=9 z>O#eSCLgt&6%ZH-A!Kw(a(f#zl&@w{{mnc`VkBbDDIW!U+QjeLqg!7V`mQciJ5XB7 zyRG57%`Y8-@>aUfw0#4^y?#$*s+WkMos`DMjSKx~;;nMd;Q#~J*eef#3&nd&e`A_F zL79JZla%F`vp>Xa;7-|+)4QVycM;cx6n zp=S;0;SmN?bOF(@pYQL^1sATwJ$sNx7copbGq2oX=kYCct!4E0969NYdcYDT%gg9@ z$gMore6LZjg`We}xrMLj2_Z^-XQIcOLzMOSWW_X7kB%7b$s3~38x1=2R7h(T2Wfl@B#vlWmL99F%C4YYiP#5An%TPLmxy(`F*PmztJuDRDN z67`4S8xyO+sc_a;D;C)*w&%p~f-Y-#X;hVyEd7*FYI=W5(~CS3*iBT`^M!x zluqtAm)1uwUx6Ast*q~x&i;VKClx94uE6HYEiis$I3<%E>CUBE_?g<<;H5|4ym67V zH#X-iE((crl3J6+z0R;web3RqNwCxZfy7M7lvpmCEw7FeY6E$K=DG+44}F*%2e2nM z^+j0pVvEY@T=ETpxeId#x__*iO#0y}SsjuD%jT z9~eRr`cJJbW8spvnd*0Lxan!~&`?JGD!dW3`h$YXwafKE5f;V(n5eGA5nIf=99@6e16Xg8GWB)rO00|pr4>!ySY{jPF?%$1C}HB4Cjh*FG{fZ%Wqa% z{er6a#{{dW)QdTR&p*QMu@pDm}fW5+@+4|*@DGS`*50Fx6WEaU0W%|fi(z~vU>9ymx{b5ZX45blxIa!{(Kp|e z#)VXvk=|EI5?grM)G3^})t|l3u9hLVnZMTs&7d_Wy{MVvSf3@0#f_C=$xYmwvlcdR zm};;bCmhu4Cq8UfyVoh?auhext~AvOF^bS1+(O?+-un5t)tm*|WJ6!(#xNQA7f2VF z-=GN*6Sv44GclOlrKu(l-etdwH4@nkRF#xjqtx?}WX_JT%kp(L7G>xzwZ+qt7ZY2OgHSD+%ezORc_Z zM-Ev2B?QIkPO{E_pcK#f3>{e%t0ccJWzI+>Uj2wJEPI5DAa#n|O>c(pQHU_6S+k{{V+1HVw^EqmoX z5oP81A2E+z2C{sf3eLdxFTbZuVf}KT#`n8wKLpcuwLe7KGCFy~FUc97b@g|Q|h9?h6^xXPRK0UpJ`II7_uz5OHDG~ z+q;$IvKRS$yh75hlHxT#+u8xwj}W_!*ibL8xNbxwwRZUP2r-D%ac2K_nall=F!Ytw z`&vXRN@LT=!l>XWwK@&|WJk2(#%c73b>q^ni5C_0Hg0Bj);uqkeIJHszh+2uZQOz# z3mz$Hc(efS@34Xl;-*k5T53{(DC^Rt8S)#~d;(8&&(^|{nkoJHo6l6M=8MPk0tio; z5Um|9OrWFW2;{UQ{Dc?9^R>cV!cvgr#wAwCcBg`cW5yd4ylX)e$$!cISN65#3yX?T zkc9F6;+NP>He}*frAYqDFe!U5-<&9R{Yfdy<(_`f*YEkEH9T{>7{6?SUDm4^H0ixX z8&+dHszu2v_i929fyRVD-OtIJV{C)jE_%|#syVZZYa0wl&LeQma5j3$>=Q;xuN1qy z2Y#DoQX#l;J(DNo;hAnbc$H^SShvZHWLN!}>tr!>`UQyu&qg8|7q+mY&%x$2Yo`cn zKu}~ap?nWKql8*0?>mbqF2yPdv#ZvxWseGp1&MkpjxfR+llhv$odI|FArhITU9FVa z?(WSQGTq)=x<`>`xheMC@BR21dK(Y(!!*+}aJ*?o+e=f1yo-fYSpnPpWx%#(TUcUe zmDAIsRyS$a#WLqMT{JbKFHYVvyVXk=kE+NMW8XK``bIQze}lbyVN*0X?#qSN@0n-4trm8$vx+94&~Mq-2Z)g>UrsNS z?|+yx|Lu8BM1kik&g?@$Cuqb>AxL$Lhbs4>ac|}x>1w)$Y$*14>&0oxjmlmE&AXt> zN7UI&QEYEzr{h8y447*2K_w|5P|%(Pdg&VUIEgUstArD+;2J)x_Y%8o4$ILdE{xfW z70~&yV~)0^`lor1=Z#l)_%yV-gI%3aPa42m=ftf<1Y161P8hl$D(%#RDxmwksjmpM z{iv#E9!UEF{32w`QCW?*EZJ7fjBEuZ)4lFlKxy3t+e|T2$K#*fx&N*W>Anb30&C{E~WhVftju@M4R0-rwMe%*`fLcv3 zwCnkK^GwbcqV1$|=n0{N%?gk`(#($)RIoENyn>Z{Ag7^g zb%~~L_}yD_kFL_7f_)$J1zK7$MyUOG9$S_U50|`s?e2OsJuB}h` z-!WhUh`o1RDS1?^V4X{X24QTOhX;m_F{`6Yg#97~@k z0k@jshg`%w*-TO$W@&x!W~9~2GO7!ec!5t<+YH`2t;)MV(qz%xB*CWf!`(^DkO+pq zF=!>wqFbQ~GLTD%*qv8Ytbr~pVIX~CEGDL~^LVv}VqO-<$!QWL_JaYutms=eBiQ&2 zoSHubsR2LYga+ON+MoY3o_#0u#c#jvU2=z}}$0 z{Js^N1I?|aqgXN=_#53QG=qerNE~ej&kUL5KM5_1k}0JtMZ_{0Ju5pq(nV-hY-?W2 zanC^U9>)@0Q{U|Ua9&Nj6`Y9=)@RaPj7yD9Xl@3Afd zXX)k@!_?%&<%L4JhU>h$y@cYU@Vxj^{~KeiD?<@i66x~n8E-#J<0NKipqmduWw6-i z#GDO}1p}vULX;Zf%R;k^O3q{Rk#53KF#d)42>cjA|L=!&^Mw0dX=gcObGS16!;Qci zSfjVUOq~;2ohR&tv^u^=(PSmMQC4udLB)|1SB^$!(?u>0IK&d4rp^8QfcDa5`p ztkUN7NyG^53Qo+0=w!MJ>LnD=EmC8`vgUw#nN3yMm%b?8a#Jb7IEQbVY`)6FEK8+U z9kZ*na$nA>SL_4f9B|B*bPXOeMrhrH#4k1l(_F_wj9TJg%0wDM|23hy`XQ?+E%-D2 zHg4>WIx)T~N?_=F->c1>GJws9N>*<33TOIUh%J(G zDpI~o`j78~h8fIl3jDMqr``h%t97v&s;a8&<$w3njidLR2CgPgj-#-O)%fpK0<4cirY znX%B)+hKtAW6znY+R2 zs}Ai`F0 zO}`ha^wNfvZlVkxxz9dixgtK*KjLh{X&TWP(YVDt%cmuh+Ler(lX*t3BtAp4mS}HY z8gwPgCFQo(UWCmQLJ1M@eg6T(DLXM>#r@0uKAsphUYz0qv;IxPS4>V<8`F=wNG&}`n!-TO|5|Wk? zt;)XqJ-;{`cTZ>0;F1eLuEO8~sYz<*l}l9ZCkftr8xKT-IU^#V|CXwWgq6cNaQyF1 zDuFN>zq9)9?=Hl8ADml(buvZS>cL6BB0-ZzWWCYCk2A?r+;?scc=#Uu6E;bouC891 zfoBY95qnP1sxx(M65LQc`m#c}Xo;9DzCz97I(Q1=eKA^({x~5X!_*_i?>%#e z%GP>?iau5hjk~1)@vlAg3O9KMdi30!ULn>cS~Vd<)0MRz#iT`xaNM6pPb#HaK;0mO zudNpW@6x(8u;Rs+Ad^EkjAMdq@KH20BAedSp=221Ohs1>SRuL;f%pimSeh!gb%6p; zq>)Li-^rlOOC}BVR+{&Adj_6rcmZyE&O*=3qyp!YOke{i>+0S1KGR~thNPWCJ6=4- z2YRHgAC@*BTtQVJp=^S|m3}_FhUE9HVFJiSqV%b4-srL*7lSP>62j3t@03f~2b(Cf z!4`#87LXDM4GTjLk%b+S`&dkJO`#|^vs$+YHhI(FUTf?R#e#v+AmOrIG5nB8p&xRq zV{``Z$!hV!iC^m_2{r(i#llGt^m()k>jv(o=2lR9z)xC~RKF#)(4&R+Q^k-Q=yxRe zvCwXCp?{6&82!W9n(`O!gYza`#w$9&OmC`L(!_jY`{$L5dM9>5su^jkwBTK zd>u45<&yV|F@V1$GU0AON`h=7keebm=DQ+^Y~12l z9klS#HwgZ5oF)%qz!1%e1xou>$wo^|gZ+i6ts_e-1jbd;#})YK{~4zpor=x;v_jyH z2*(FNnYo5%T21TeSZ;99ti)-ZyKQ`a($=y;K1?YC7AJm7KXKow&0dhDT{jiW?L8?f%W1euH=PduX|aTB1zBosHS^@2EuVcP zm|CZZVwPbs5sJbjn82xB50O2R=eRSd^zYep(}p9z;{2!^+KoP=Q&=JBVUBt}9JTMg zuQ*GTbRcvrmoDJ~l{rh)jd!6w_xx9Tx+d864|7*u*VEkDnl4Wl@DHgf!jG!bnHn$c zjH>9p1f#vC#l{3xNaJ&iiIF=15e&~L-eZ%GWhx|o8QT2NMcCx2X6pIbE%wFwMh@LH zKdpjBCx0K{3P6zHAg&{EKhneX-#t4P_bH&7x)us10teXGsX#t|umd|S7U_B<@DmI| zh;Z0R(O?gs!@$gfU*RkA!d)N0gd_nbq&eKJ^QMh2_W&`HGnUBeuSc^SPtfp#ve32E zsVronj+)eZ@Nx4qH2qx!F6)TZ$|@0!0=ntljV?llZ^KA5iZSRt!TM8FZpZG{d53m; z2bi9JE+i#=XKmEuLTA;tP_a-pRhKw6Lre7`*E>uTFC^2KJ7VSTd;H!UL}ed{@!vrI(!Fs7#E~tDhe(eQt?p0=?e`@QSTuK0WW{ z&uhi-mx`&f*CG<&T8bkE^~HG})h`S65jd|4Yq6wWw!+Y!gFVQ@`ZK?;75LnpfJbif zY148y73n46Q>Y#Ca+=ptSDf_PByl;X5Sy-`j}+Ss2aFm!4Ifz3@$`<%8yDdzmyYzB zqA3^tS(=N(!es8KFjRPUfFtwbd0@zS))Fl@P8$a7i3(S&qScx)1=d<7N&~yR(UpM) z-ruOs5M?oW)56hbELA|~iUN5VbBL!-pTEH7>cZzZz{MNJFBKb29Qp3Aa%7}jPO2n* z3KhF41@#5Hs@T_vY5f$&QC^2nqxDE@&B{>Xi-%*d!n9bLf~yc*yg2QzqC_h(&!mG( z=Is%CRn!BKEOw`Ry@map57bk^X9-vRU~PQ$Ra7|5R|0I|%1xWklb(%d-SSyNv2lsQ z+IyzHK+)ZrA9rkUo0`ysTI$70nPopj%t_v%w&v$u)8uP^Wwc6PmX+67%+1fhQ`5oCKO}IM>~TNziA-Pz=&9IcFL@aC4t{K?3@$l%cLEC&gZc^F@$&YEv5&?Fi580v63Dt#~$G;8Q+j z22&;EW4)OAjdL*IZnoya4r>+?HgjYO!g%@Vmdfa5E4mP8nTb}`w6u983hvV)-zf&t z1eh^$W+yrv^myD^FjEF_;FAI*?%nTZ)+?6B{l8;rS0s7}t~KV6WnNkDLu#*ajc7Ic zZLz7MZKXAWgtf;klw`SIaVrvzAFCKXuUCxSJZj{{CanD|?hplEFwV0%CdLlJZwWzj z2d+C)iKglb&^`T^4>zI{y9o3zXhQz|oTFH&4^iK)|9ou# zpL)^cfX#L7Oah4$ukt3|=#^j-QcyxY=h)c$FU=v)OE4(DDrI)nlSkIphdgHSds zi`7Umo5>0;2u$2cy#~%-k$}U=n&qU7Up&n2f-;q=`vD7wg*w8NGBl}CfCeiHg;-Bg z&l~Q&L$yi<(Hi}R&Ks)r6VsNDT3510f;^#N0I3Ebt;;F$9z61Ot}>9qb^^wR(ynu6 zuwDgLeE8^g;Dp;_%o+%jKfwxBA+)f0M?9_RK{q9O34Aeo3R2{0vH2gD!@3CJ7B|GR zi)~K{lCVZs7IM(TaXd7|ed*k)mtDUk0o~gI ztkCjVtLPyw770OPdT&-nSg0O||GeDJDJe87FQ9|PFme#zb`BfkB2y{M{?R9y?qepu z6MEITW~=QwuvXHHPkcT~O|s{b9xLk}hdW35QkM z@plnIL>mPXQxm<0wkAU1qCR{j)hg*z#$fM&pMwf#VrQ47TqbZlDPa#5t)89kOgPbf z?;DqTon#2~n9ll}Ja-&D;o(+OJ_A~@v6@_+pwr+@aq(CM+Qe%{ypYH4hJ?7UjjgKx zDv$1!`_e^NTSfv6Df|2;o2KWvrY^$iF?=8igpS0ls+X97g{LNEpfl1;8W?KjL8UIj z>H+F!`qTp7VXWb@{V&NZs#S5l)zZw{NpR|~^^yU>SJ@Bc;DmoQR9H*kf{|5WA_#3p z2_WMgd$t5Ze!-4igy=S++l4$8o+J_WdsC<{-X)ND+&3+iK(A7Jxh%&6TKlEl=-sF* zjLQdo@{5Gd6?3+#o-Zp|PN)2!vaD|pnI?CCniA}~2;Tu&(B{ix(_)*_*AD8G`;%|u zDo@f}E<6%}u9^u>?w$WcDVp+;W1cMdoQkEy>N>L_b@)QB>+3BxFd=3fsl<~Rl292Z zbo$)QTAj*n)B!C*SI<@ywN)FHUcdK)82fr-j9ldjn#+A7KIm$v;JXCtBB>`@|Q@Q;kARFdPXV*zo;s1XK^TQMvTe5i-?B1--4^qHdsWuvvl6WSCULjq;4Y{4Ses=?M5;89jdk8*C)p4QigMC8@`0z%TRYUthR(53=DiKoI(V7Y<&3u`Vqh8} z;WXux93|H2#V@VKc`-YlATVj)vY~V0l8=@ozI%7mnmQmqOC;?VTsA6cbxID(v5~IsxP)&q#EdByoE$tP2ffJ8xwx=RvKdwdbzVc%Ic_hntLcv!5u0e=%gb24 zX|ZC9Ccl>*3%_i8!^1#8A;wY=`kH8S?iJr&qwM=dd3cR{x(L}lSc|lEz<8W0%sP4j zcK3oK^?L_7=HY5=4(!ysA(BCDebH8ZJ&(A(3HfF>r5Oy{R3~^MtoLOSd~-t`2ttid zRswA#jLqQ0XZ@}On@~~t58p-!o^v{ET-ZQYnXrd*e2Z^aqij=Yam7XSeq@1!DYMN=k1A5EARWYW zt{hIcBJRu5a{XywB{Diisk{)J!o0fF`5SX1B6oCOJM z^_n4roxQILvBf>35T=@TH_?i1OQX|QI6`5LNK@6E3YNmQ{rZ~XpzdCASDl+_(+Khi`Lh*X2$%K$`i~voH9@}4sLn^ zy9gF(N~6mbNSjR^FoAt+{ay#=%49ZXSGcKqzt|FSUWL+j99FG_U#*|epz^oL9y4y5 zF2uU)WnQeJ1gd>jimu-jdyTE%>w9+!m3H$;&$an1@@(ej#>~bEH#OYRuk&vkXg5p_ zQ@nERV*(?x;C&h+u@7QtG^>cp;!1iwwPM*Shd3CK+DH4DMGg_wsAlABO@ysd36)}W zm-y>5--*}_>^yDxkp(2OI8E5vq^xRO{Pps9Aa!22nA>(r4kC7jMG$)EW6mIpsRka( z#!QQ;$5C6yY2K@s;zMuEfcU@Vvs-uK;Qr^JFve!Nxj&sVhUsGqI8#gHfiv_l$Fx|+ zV-UcFr+Z%i=$)~6pb)y?5bvs9<1?ev?kdCqIiIUa8JD@xg199#vG(q&deve4ZomZO z>q#*ZY0~j+55n{EYc$_}x)TGYNfJocy1J2_-LTbIT}i3JnB zDOD*xcdGtM0g;BG67PaEu#ZQ;f!QOqX`V^C>-ki$XxL01-Bf`RTbkNEeh=)y4WIMe zCDdK~_0uQAg=#F|t_U#v>90r)m{~YidQOF09ET^|+-Eli63w2|I|9KrdHX)ABx?#K zQnm<*f00iPVKLESaqhj`wz@x@s(ZN$MaB48>VwrmHH{H^-V(PKB4KND_8_zp@z4^l z!PM$}ZNuJ$eUwg#UmT zxNL)jj{i&|fg>|8-P2JSTM_n;;2=*rm%$Ca>ObrKycnU;sYqH=-@17TR2w{}o92Km z^HI}MhgyG_gsB1IWPbx5(xC9>f=if~lYo76`)FSHJV-60=rn?$^o}!fw-7Sf^bUt9*+s+G?!af+#sok3|{DUPo=i97Gimqg)R*o zFPZd_7iJF#$%j|8LGrJAxqOvtrwc-+YcGK~>z}9Jh3Yv+i#S?2f4|sNnGGqLG=;UH=Gu{s%I>`cnbo(QN?;kuqc>HIg1%-90&pVZW>yF14r)#^ zggGGp>DA#xiNOrHzzn&y2(YkQBS5C(_6c-hxcfFv_bS!cm`?z@8W{MCk&*f{-reXr z9DiNkeu@jMxu)>&hb7LE)4&&fB~;_5P@!g5p|ayBiD0Tu^4%LDBl-L5M&hqi^=Kn} zT`1MNz*GEz40$u$%pu$)Y|!&bNL+zyJG`ImVppCo%kSUz`&zr&MPWx_t zf>z)a%>(TI!S#L%`b-Du|rD?`983Xf62U7*@|v7PetAhm!qO)iI%=>jiO zA@NOD!Jaw+(K~^o9UQ&$1`Rb9D;W)4`m~Y$E)>Wi0{)=NBH+$b!qsqP~3>0E-nZuY{(5NpTUg&1?vILA{2V1ERj z^ztXiG)SH{ zUN;YTs{*3&fI9nHCL3Dy00qC+h3YHYxQ&bGtOhx0@(s7-q``nBb3pdP_t}2t&z`-k zSJpQ&-6UXSOq&5YzO_ybWBJ?nqo}$!O3~m_kK_-kOH+X=H58+;H#b8q*GA*MiivnS z#mdMgPV&~mn365R0G7H94JR)(cjwMjjI-4}jNo!TvT?mVeUnaJ zx-c#p;!xQ|IA#iG^ZcD9Y7&_chOm_Op7a5b`C#{`DK^R6ZHUXVG)3;5r{+@Qj$ z%Ot8*V(&3KY7UX~z6&IIey_Pq)m$?d;;z0sm9U9*M+u*+0jpJomvPJ652bz|59sQV zCSO^xoCdCOT*|FXj_!|<)FPvkcf*wUC55mx+XYJtT$ zovFrBC6M(Ku(ysmm{IdRe}r&drp3?OeffeF^`t$GKJqERZi#+MGMefi1di1uP~n&B z0z=fZn@L|xOO+>8H&;i${Z{1!mcGCYT|XYY?~%eF*i`Z~6BPzYwL(&wu|DJ<3++1? z^+X9&t3wE_%QrO)Tpw2>cjj9EOBS8l45plFF;oa`{fWJ`3o7aNRupVmLy^A)J0Ic- zi#zCX?!y4v(2YU95Ye`jw8d$ZzsAa$nl8f8A}l*Jtx&h#QyHJrl{czjs7Kf?bCSF> zh05Cnx%auBRt^m;PGtLaB=yI=sicmbek0xUo0G`|#DwWmAUh znWrX&#|&UeV<_hfQ|@P~)+%25Nx$ya+zD5OVuUG_XR5~4`McC2y0(gFO{E+H3#t^J zLQ|5WmAT$IqxiL${58>03vR32iPZvl5Nw$@yIfM?(>929rdZMFg0|zVJk@55aIPJCC`KiJFt1}L>Erc+Y)v_JwiB#QBz}CGBztU9n2%43FMS;Of z=xV>*R^W3__#urlSiGhJZa%ttu}$<5VYAmX-Bs+-p%`cEbH#M!w(A=QPQj_ptIIxf z&C8R4gkE>!>0iA%3YoA{%mhz0NI&kNfA>9pUr_|Lc3>?HQdOexNOlg%h`pCt!wRr~ z6(Q{5%p5u>SUh_Q_5W582$>`>ocT(?V(%d0;vvGsaxkEXbK5Smox{E%DYk*aJ#0Tm z_W7DcW2w-6PpXz<3H8BmLB(t~XDka88wTpQBTx0M%l|1vC9*@JG&yZ(<-0=+9L^AK zdNCau?vUTbtVOIVTtxq=Kz#)6GpTvu(BvCX%e-Uz2CDT05~mB_6NgTZzxjuHBOIWj zq}g#?YOW&$aX<|hlztEjSi$o$H>PG({UeviAZNva#C%BX{wIn4P9TX43!?1m7tbw$ zKb5VZ_&t{19S*7HSt$Ku%gKb(B}9rtk6gR|u`Ry~*m_B@;{>d&{;@4N0odAdB8PFe zRQ{o|0*MKg;<#y#7yl$t-UlQx=4Cd?F#HFm%Z9|UXhUN&djDwoN5N7#PS*wd^3>U}!p0fQ%cjY*P zZdo8GwEnBGC>yjR9O}W(|5MFWi$NDd(R2L=622|n7pqJEsPOHBWZ99b^=3l<7!5-h zZQjPkg#XC`>tec~IWH?MzY7@Ox&&%@D`% zE7FS(faZ3oxDIdGPC>YPH)wB{iXUZH<%oen75AS~@ycDy!jUc5`hV;PIFOm=MhN@= zvd1_wBfw({72BUSC z5Y!!@NJ}%klAH1VNL!zCSNXxl_t=V5n?9E@Fy^`@i^d2*5g7$`P(7d6A_i*sePKK( z-T%yv1jXrji);|I*FFGB20u~vGlNF}^hZGDu(0pwo<0n)zz;INY zq1q*0@W6p=448zM%XVup zV0-AWGL*!agI5^R{dQnstqgFPcNq9lUBV6yni_Gl{JW@TeX3UVhqmH z+tl48AXP11lOx;Y)WBwo8R68<=!maiQ>De*Zp^^P9p!)?o#$=m*>1S(frR74v(p%C zAmUL-^?53X*Z3av&|wGTg}fG!nEfcki~8`HOOz(5wVybd}U zsBJ9|-a6^p4Lk!#0N!k9Kat0Z*v4<$4f$S_0zL@XWD9|8yxv~m13-XwIV3J~QvVPB zC ShXIVB3+IgfD?Nh=|Nj7c9+!9k literal 0 HcmV?d00001 diff --git a/kratos-flutter/lib/blocs/login/login_bloc.dart b/kratos-flutter/lib/blocs/login/login_bloc.dart index 1300eb88..0e7d559c 100644 --- a/kratos-flutter/lib/blocs/login/login_bloc.dart +++ b/kratos-flutter/lib/blocs/login/login_bloc.dart @@ -20,6 +20,7 @@ class LoginBloc extends Bloc { on(_onCreateLoginFlow); on(_onChangeEmail); on(_onChangePassword); + on(_onChangePasswordVisibility); on(_onLoginWithEmailAndPassword); } @@ -52,10 +53,21 @@ class LoginBloc extends Bloc { .copyWith(errorMessage: null)); } + _onChangePasswordVisibility( + ChangePasswordVisibility event, Emitter emit) { + emit(state.copyWith(isPasswordHidden: event.value)); + } + Future _onLoginWithEmailAndPassword( LoginWithEmailAndPassword event, Emitter emit) async { try { - emit(state.copyWith(isLoading: true, errorMessage: null)); + // remove error messages when performing login + emit(state + .copyWith(isLoading: true, errorMessage: null) + .copyWith + .email(errorMessage: null) + .copyWith + .password(errorMessage: null)); await repository.loginWithEmailAndPassword( flowId: event.flowId, email: event.email, password: event.password); @@ -78,11 +90,14 @@ class LoginBloc extends Bloc { .copyWith .password(errorMessage: passwordMessage?.text)); } else if (e case FlowExpiredException _) { - // use new flow id to log in user - add(LoginWithEmailAndPassword( - flowId: e.flowId, - email: state.email.value, - password: state.password.value)); + // use new flow id, reset fields and show error + emit(state + .copyWith( + flowId: e.flowId, errorMessage: e.message, isLoading: false) + .copyWith + .email(value: '') + .copyWith + .password(value: '')); } else if (e case UnknownException _) { emit(state.copyWith(isLoading: false, errorMessage: e.message)); } else { diff --git a/kratos-flutter/lib/blocs/login/login_bloc.freezed.dart b/kratos-flutter/lib/blocs/login/login_bloc.freezed.dart index 635ea0de..17960491 100644 --- a/kratos-flutter/lib/blocs/login/login_bloc.freezed.dart +++ b/kratos-flutter/lib/blocs/login/login_bloc.freezed.dart @@ -19,6 +19,7 @@ mixin _$LoginState { String? get flowId => throw _privateConstructorUsedError; FormField get email => throw _privateConstructorUsedError; FormField get password => throw _privateConstructorUsedError; + bool get isPasswordHidden => throw _privateConstructorUsedError; bool get isLoading => throw _privateConstructorUsedError; String? get errorMessage => throw _privateConstructorUsedError; @@ -37,6 +38,7 @@ abstract class $LoginStateCopyWith<$Res> { {String? flowId, FormField email, FormField password, + bool isPasswordHidden, bool isLoading, String? errorMessage}); @@ -60,6 +62,7 @@ class _$LoginStateCopyWithImpl<$Res, $Val extends LoginState> Object? flowId = freezed, Object? email = null, Object? password = null, + Object? isPasswordHidden = null, Object? isLoading = null, Object? errorMessage = freezed, }) { @@ -76,6 +79,10 @@ class _$LoginStateCopyWithImpl<$Res, $Val extends LoginState> ? _value.password : password // ignore: cast_nullable_to_non_nullable as FormField, + isPasswordHidden: null == isPasswordHidden + ? _value.isPasswordHidden + : isPasswordHidden // ignore: cast_nullable_to_non_nullable + as bool, isLoading: null == isLoading ? _value.isLoading : isLoading // ignore: cast_nullable_to_non_nullable @@ -116,6 +123,7 @@ abstract class _$$_LoginStateCopyWith<$Res> {String? flowId, FormField email, FormField password, + bool isPasswordHidden, bool isLoading, String? errorMessage}); @@ -139,6 +147,7 @@ class __$$_LoginStateCopyWithImpl<$Res> Object? flowId = freezed, Object? email = null, Object? password = null, + Object? isPasswordHidden = null, Object? isLoading = null, Object? errorMessage = freezed, }) { @@ -155,6 +164,10 @@ class __$$_LoginStateCopyWithImpl<$Res> ? _value.password : password // ignore: cast_nullable_to_non_nullable as FormField, + isPasswordHidden: null == isPasswordHidden + ? _value.isPasswordHidden + : isPasswordHidden // ignore: cast_nullable_to_non_nullable + as bool, isLoading: null == isLoading ? _value.isLoading : isLoading // ignore: cast_nullable_to_non_nullable @@ -174,6 +187,7 @@ class _$_LoginState implements _LoginState { {this.flowId, this.email = const FormField(value: ''), this.password = const FormField(value: ''), + this.isPasswordHidden = true, this.isLoading = false, this.errorMessage}); @@ -187,13 +201,16 @@ class _$_LoginState implements _LoginState { final FormField password; @override @JsonKey() + final bool isPasswordHidden; + @override + @JsonKey() final bool isLoading; @override final String? errorMessage; @override String toString() { - return 'LoginState(flowId: $flowId, email: $email, password: $password, isLoading: $isLoading, errorMessage: $errorMessage)'; + return 'LoginState(flowId: $flowId, email: $email, password: $password, isPasswordHidden: $isPasswordHidden, isLoading: $isLoading, errorMessage: $errorMessage)'; } @override @@ -205,6 +222,8 @@ class _$_LoginState implements _LoginState { (identical(other.email, email) || other.email == email) && (identical(other.password, password) || other.password == password) && + (identical(other.isPasswordHidden, isPasswordHidden) || + other.isPasswordHidden == isPasswordHidden) && (identical(other.isLoading, isLoading) || other.isLoading == isLoading) && (identical(other.errorMessage, errorMessage) || @@ -212,8 +231,8 @@ class _$_LoginState implements _LoginState { } @override - int get hashCode => Object.hash( - runtimeType, flowId, email, password, isLoading, errorMessage); + int get hashCode => Object.hash(runtimeType, flowId, email, password, + isPasswordHidden, isLoading, errorMessage); @JsonKey(ignore: true) @override @@ -227,6 +246,7 @@ abstract class _LoginState implements LoginState { {final String? flowId, final FormField email, final FormField password, + final bool isPasswordHidden, final bool isLoading, final String? errorMessage}) = _$_LoginState; @@ -237,6 +257,8 @@ abstract class _LoginState implements LoginState { @override FormField get password; @override + bool get isPasswordHidden; + @override bool get isLoading; @override String? get errorMessage; diff --git a/kratos-flutter/lib/blocs/login/login_event.dart b/kratos-flutter/lib/blocs/login/login_event.dart index eecc4056..ee140712 100644 --- a/kratos-flutter/lib/blocs/login/login_event.dart +++ b/kratos-flutter/lib/blocs/login/login_event.dart @@ -27,6 +27,15 @@ final class ChangePassword extends LoginEvent { List get props => [value]; } +final class ChangePasswordVisibility extends LoginEvent { + final bool value; + + ChangePasswordVisibility({required this.value}); + + @override + List get props => [value]; +} + //log in final class LoginWithEmailAndPassword extends LoginEvent { final String flowId; diff --git a/kratos-flutter/lib/blocs/login/login_state.dart b/kratos-flutter/lib/blocs/login/login_state.dart index 89f5054b..df977895 100644 --- a/kratos-flutter/lib/blocs/login/login_state.dart +++ b/kratos-flutter/lib/blocs/login/login_state.dart @@ -6,6 +6,7 @@ sealed class LoginState with _$LoginState { {String? flowId, @Default(FormField(value: '')) FormField email, @Default(FormField(value: '')) FormField password, + @Default(true) bool isPasswordHidden, @Default(false) bool isLoading, String? errorMessage}) = _LoginState; } diff --git a/kratos-flutter/lib/blocs/registration/registration_bloc.dart b/kratos-flutter/lib/blocs/registration/registration_bloc.dart index ea5f5713..89eb5c02 100644 --- a/kratos-flutter/lib/blocs/registration/registration_bloc.dart +++ b/kratos-flutter/lib/blocs/registration/registration_bloc.dart @@ -20,6 +20,7 @@ class RegistrationBloc extends Bloc { on(_onCreateRegistrationFlow); on(_onChangeEmail); on(_onChangePassword); + on(_onChangePasswordVisibility); on(_onRegisterWithEmailAndPassword); } @@ -52,11 +53,22 @@ class RegistrationBloc extends Bloc { .copyWith(errorMessage: null)); } + _onChangePasswordVisibility( + ChangePasswordVisibility event, Emitter emit) { + emit(state.copyWith(isPasswordHidden: event.value)); + } + Future _onRegisterWithEmailAndPassword( RegisterWithEmailAndPassword event, Emitter emit) async { try { - emit(state.copyWith(isLoading: true, errorMessage: null)); + // remove error messages when performing registration + emit(state + .copyWith(isLoading: true, errorMessage: null) + .copyWith + .email(errorMessage: null) + .copyWith + .password(errorMessage: null)); await repository.registerWithEmailAndPassword( flowId: event.flowId, email: event.email, password: event.password); @@ -80,11 +92,14 @@ class RegistrationBloc extends Bloc { .copyWith .password(errorMessage: passwordMessage?.text)); } else if (e case FlowExpiredException _) { - // use new flow id to log in user - add(RegisterWithEmailAndPassword( - flowId: e.flowId, - email: state.email.value, - password: state.password.value)); + // use new flow id, reset fields and show error + emit(state + .copyWith( + flowId: e.flowId, errorMessage: e.message, isLoading: false) + .copyWith + .email(value: '') + .copyWith + .password(value: '')); } else if (e case UnknownException _) { emit(state.copyWith(isLoading: false, errorMessage: e.message)); } else { diff --git a/kratos-flutter/lib/blocs/registration/registration_bloc.freezed.dart b/kratos-flutter/lib/blocs/registration/registration_bloc.freezed.dart index 94367224..edbeef53 100644 --- a/kratos-flutter/lib/blocs/registration/registration_bloc.freezed.dart +++ b/kratos-flutter/lib/blocs/registration/registration_bloc.freezed.dart @@ -19,6 +19,7 @@ mixin _$RegistrationState { String? get flowId => throw _privateConstructorUsedError; FormField get email => throw _privateConstructorUsedError; FormField get password => throw _privateConstructorUsedError; + bool get isPasswordHidden => throw _privateConstructorUsedError; bool get isLoading => throw _privateConstructorUsedError; String? get errorMessage => throw _privateConstructorUsedError; @@ -37,6 +38,7 @@ abstract class $RegistrationStateCopyWith<$Res> { {String? flowId, FormField email, FormField password, + bool isPasswordHidden, bool isLoading, String? errorMessage}); @@ -60,6 +62,7 @@ class _$RegistrationStateCopyWithImpl<$Res, $Val extends RegistrationState> Object? flowId = freezed, Object? email = null, Object? password = null, + Object? isPasswordHidden = null, Object? isLoading = null, Object? errorMessage = freezed, }) { @@ -76,6 +79,10 @@ class _$RegistrationStateCopyWithImpl<$Res, $Val extends RegistrationState> ? _value.password : password // ignore: cast_nullable_to_non_nullable as FormField, + isPasswordHidden: null == isPasswordHidden + ? _value.isPasswordHidden + : isPasswordHidden // ignore: cast_nullable_to_non_nullable + as bool, isLoading: null == isLoading ? _value.isLoading : isLoading // ignore: cast_nullable_to_non_nullable @@ -116,6 +123,7 @@ abstract class _$$_RegistrationStateCopyWith<$Res> {String? flowId, FormField email, FormField password, + bool isPasswordHidden, bool isLoading, String? errorMessage}); @@ -139,6 +147,7 @@ class __$$_RegistrationStateCopyWithImpl<$Res> Object? flowId = freezed, Object? email = null, Object? password = null, + Object? isPasswordHidden = null, Object? isLoading = null, Object? errorMessage = freezed, }) { @@ -155,6 +164,10 @@ class __$$_RegistrationStateCopyWithImpl<$Res> ? _value.password : password // ignore: cast_nullable_to_non_nullable as FormField, + isPasswordHidden: null == isPasswordHidden + ? _value.isPasswordHidden + : isPasswordHidden // ignore: cast_nullable_to_non_nullable + as bool, isLoading: null == isLoading ? _value.isLoading : isLoading // ignore: cast_nullable_to_non_nullable @@ -174,6 +187,7 @@ class _$_RegistrationState implements _RegistrationState { {this.flowId, this.email = const FormField(value: ''), this.password = const FormField(value: ''), + this.isPasswordHidden = true, this.isLoading = false, this.errorMessage}); @@ -187,13 +201,16 @@ class _$_RegistrationState implements _RegistrationState { final FormField password; @override @JsonKey() + final bool isPasswordHidden; + @override + @JsonKey() final bool isLoading; @override final String? errorMessage; @override String toString() { - return 'RegistrationState(flowId: $flowId, email: $email, password: $password, isLoading: $isLoading, errorMessage: $errorMessage)'; + return 'RegistrationState(flowId: $flowId, email: $email, password: $password, isPasswordHidden: $isPasswordHidden, isLoading: $isLoading, errorMessage: $errorMessage)'; } @override @@ -205,6 +222,8 @@ class _$_RegistrationState implements _RegistrationState { (identical(other.email, email) || other.email == email) && (identical(other.password, password) || other.password == password) && + (identical(other.isPasswordHidden, isPasswordHidden) || + other.isPasswordHidden == isPasswordHidden) && (identical(other.isLoading, isLoading) || other.isLoading == isLoading) && (identical(other.errorMessage, errorMessage) || @@ -212,8 +231,8 @@ class _$_RegistrationState implements _RegistrationState { } @override - int get hashCode => Object.hash( - runtimeType, flowId, email, password, isLoading, errorMessage); + int get hashCode => Object.hash(runtimeType, flowId, email, password, + isPasswordHidden, isLoading, errorMessage); @JsonKey(ignore: true) @override @@ -228,6 +247,7 @@ abstract class _RegistrationState implements RegistrationState { {final String? flowId, final FormField email, final FormField password, + final bool isPasswordHidden, final bool isLoading, final String? errorMessage}) = _$_RegistrationState; @@ -238,6 +258,8 @@ abstract class _RegistrationState implements RegistrationState { @override FormField get password; @override + bool get isPasswordHidden; + @override bool get isLoading; @override String? get errorMessage; diff --git a/kratos-flutter/lib/blocs/registration/registration_event.dart b/kratos-flutter/lib/blocs/registration/registration_event.dart index 69e40aaf..ea65684d 100644 --- a/kratos-flutter/lib/blocs/registration/registration_event.dart +++ b/kratos-flutter/lib/blocs/registration/registration_event.dart @@ -27,7 +27,15 @@ final class ChangePassword extends RegistrationEvent { List get props => [value]; } -//log in +final class ChangePasswordVisibility extends RegistrationEvent { + final bool value; + + ChangePasswordVisibility({required this.value}); + + @override + List get props => [value]; +} //log in + final class RegisterWithEmailAndPassword extends RegistrationEvent { final String flowId; final String email; diff --git a/kratos-flutter/lib/blocs/registration/registration_state.dart b/kratos-flutter/lib/blocs/registration/registration_state.dart index 1f757884..cf258ee3 100644 --- a/kratos-flutter/lib/blocs/registration/registration_state.dart +++ b/kratos-flutter/lib/blocs/registration/registration_state.dart @@ -6,6 +6,7 @@ sealed class RegistrationState with _$RegistrationState { {String? flowId, @Default(FormField(value: '')) FormField email, @Default(FormField(value: '')) FormField password, + @Default(true) bool isPasswordHidden, @Default(false) bool isLoading, String? errorMessage}) = _RegistrationState; } diff --git a/kratos-flutter/lib/main.dart b/kratos-flutter/lib/main.dart index 406d06d4..8da89d31 100644 --- a/kratos-flutter/lib/main.dart +++ b/kratos-flutter/lib/main.dart @@ -3,6 +3,7 @@ import 'package:dio/io.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; +import 'package:kratos_flutter/widgets/ory_theme.dart'; import 'blocs/auth/auth_bloc.dart'; import 'pages/home.dart'; @@ -99,6 +100,7 @@ class _MyAppViewState extends State { @override Widget build(BuildContext context) { return MaterialApp( + theme: OryTheme.defaultTheme, navigatorKey: _navigatorKey, builder: (context, child) { return BlocListener( diff --git a/kratos-flutter/lib/pages/entry.dart b/kratos-flutter/lib/pages/entry.dart index 888aab1c..7c3c3a92 100644 --- a/kratos-flutter/lib/pages/entry.dart +++ b/kratos-flutter/lib/pages/entry.dart @@ -5,8 +5,13 @@ class EntryPage extends StatelessWidget { @override Widget build(BuildContext context) { - return const Scaffold( - body: Center(child: CircularProgressIndicator()), + return Scaffold( + body: Center( + child: Image.asset( + 'assets/images/ory_logo.png', + width: 100, + ), + ), ); } } diff --git a/kratos-flutter/lib/pages/home.dart b/kratos-flutter/lib/pages/home.dart index df55a0a4..c654c2cf 100644 --- a/kratos-flutter/lib/pages/home.dart +++ b/kratos-flutter/lib/pages/home.dart @@ -27,6 +27,13 @@ class _HomePageState extends State { return Scaffold( appBar: AppBar( + backgroundColor: Colors.transparent, + title: Image.asset( + 'assets/images/ory_logo.png', + width: 40, + ), + elevation: 0, + //shape: Border(bottom: BorderSide(color: Colors.green, width: 1)), actions: [ // if auth is loading, show progress indicator, otherwise a logout icon isLoading @@ -38,9 +45,7 @@ class _HomePageState extends State { child: SizedBox( height: 24, width: 24, - child: CircularProgressIndicator( - backgroundColor: Colors.white, - ), + child: CircularProgressIndicator(), ), ), ) @@ -64,7 +69,7 @@ class _HomePageState extends State { _buildSessionInformation(BuildContext context, Session session) { return Padding( - padding: const EdgeInsets.all(30.0), + padding: const EdgeInsets.symmetric(vertical: 15, horizontal: 32), child: SingleChildScrollView( physics: const BouncingScrollPhysics(), child: Column( @@ -76,7 +81,7 @@ class _HomePageState extends State { const Padding( padding: EdgeInsets.only(top: 15.0), child: Text( - "Hello, nice to have you! you signed up with this data:"), + "Hello, nice to have you! You signed up with this data:"), ), Padding( padding: const EdgeInsets.only(top: 15.0), @@ -85,8 +90,10 @@ class _HomePageState extends State { width: double.infinity, decoration: BoxDecoration( borderRadius: BorderRadius.circular(8), - color: Colors.grey[400]), - child: Text(session.identity.traits.toString()), + color: Colors.grey[600]), + child: Text(session.identity.traits.toString(), + style: const TextStyle( + fontWeight: FontWeight.w500, color: Colors.white)), ), ), const Padding( @@ -101,8 +108,10 @@ class _HomePageState extends State { width: double.infinity, decoration: BoxDecoration( borderRadius: BorderRadius.circular(8), - color: Colors.grey[400]), - child: Text(session.id), + color: Colors.grey[600]), + child: Text(session.id, + style: const TextStyle( + fontWeight: FontWeight.w500, color: Colors.white)), ), ), const Padding( @@ -116,8 +125,10 @@ class _HomePageState extends State { width: double.infinity, decoration: BoxDecoration( borderRadius: BorderRadius.circular(8), - color: Colors.grey[400]), - child: Text(session.toString()), + color: Colors.grey[600]), + child: Text(session.toString(), + style: const TextStyle( + fontWeight: FontWeight.w500, color: Colors.white)), ), ), ], diff --git a/kratos-flutter/lib/pages/login.dart b/kratos-flutter/lib/pages/login.dart index e71ee7e9..6880d493 100644 --- a/kratos-flutter/lib/pages/login.dart +++ b/kratos-flutter/lib/pages/login.dart @@ -4,6 +4,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import '../blocs/auth/auth_bloc.dart'; import '../blocs/login/login_bloc.dart'; import '../repositories/auth.dart'; +import '../widgets/social_provider_box.dart'; import 'registration.dart'; class LoginPage extends StatelessWidget { @@ -12,6 +13,7 @@ class LoginPage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( + extendBodyBehindAppBar: true, body: BlocProvider( create: (context) => LoginBloc( authBloc: context.read(), @@ -22,19 +24,39 @@ class LoginPage extends StatelessWidget { } } -class LoginForm extends StatelessWidget { +class LoginForm extends StatefulWidget { const LoginForm({super.key}); + @override + State createState() => LoginFormState(); +} + +class LoginFormState extends State { + final emailController = TextEditingController(); + final passwordController = TextEditingController(); @override Widget build(BuildContext context) { final loginBloc = BlocProvider.of(context); - return BlocBuilder( + return BlocConsumer( bloc: loginBloc, + // listen to email and password changes + listenWhen: (previous, current) { + return (previous.email.value != current.email.value && + emailController.text != current.email.value) || + (previous.password.value != current.password.value && + passwordController.text != current.password.value); + }, + // if email or password value have changed, update text controller values + listener: (BuildContext context, LoginState state) { + emailController.text = state.email.value; + passwordController.text = state.password.value; + }, builder: (context, state) { - // creating login flow is in process, show loading indicator + // login flow was created if (state.flowId != null) { return _buildLoginForm(context, state); - } else { + } // otherwise, show loading or error + else { return _buildLoginFlowNotCreated(context, state); } }); @@ -54,77 +76,193 @@ class LoginForm extends StatelessWidget { _buildLoginForm(BuildContext context, LoginState state) { return Padding( - padding: const EdgeInsets.all(20.0), - child: Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - TextFormField( - enabled: !state.isLoading, - initialValue: state.email.value, - onChanged: (String value) => - context.read().add(ChangeEmail(value: value)), - decoration: InputDecoration( - border: const OutlineInputBorder(), - label: const Text('Email'), - hintText: 'Enter your email', - errorText: state.email.errorMessage, - errorMaxLines: 3), - ), - const SizedBox( - height: 20, - ), - TextFormField( - enabled: !state.isLoading, - initialValue: state.email.value, - onChanged: (String value) => - context.read().add(ChangePassword(value: value)), - decoration: InputDecoration( - border: const OutlineInputBorder(), - label: const Text('Password'), - hintText: 'Enter your password', - errorText: state.password.errorMessage, - errorMaxLines: 3), - ), - const SizedBox( - height: 20, - ), - if (state.errorMessage != null) - Text( - state.errorMessage!, - style: const TextStyle(color: Colors.red), - maxLines: 3, + padding: const EdgeInsets.symmetric(horizontal: 32), + child: SingleChildScrollView( + // do not show scrolling indicator + physics: const BouncingScrollPhysics(), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Padding( + padding: EdgeInsets.only( + //status bar height + padding + top: MediaQuery.of(context).viewPadding.top + 48), + child: Image.asset( + 'assets/images/ory_logo.png', + width: 70, + ), + ), + const SizedBox( + height: 32, + ), + const Text("Sign in", + style: TextStyle( + fontWeight: FontWeight.w600, height: 1.5, fontSize: 18)), + const Text( + "Sign in with a social provider or with your email and password"), + const SizedBox( + height: 32, + ), + const Row( + children: [ + SocialProviderBox(provider: SocialProvider.google), + SizedBox( + width: 12, + ), + SocialProviderBox(provider: SocialProvider.github), + SizedBox( + width: 12, + ), + SocialProviderBox(provider: SocialProvider.apple), + SizedBox( + width: 12, + ), + SocialProviderBox(provider: SocialProvider.linkedin) + ], + ), + const SizedBox( + height: 32, + ), + const Divider( + color: Color.fromRGBO(226, 232, 240, 1), thickness: 1), + const SizedBox( + height: 32, + ), + + const SizedBox( + height: 20, + ), + + const SizedBox( + height: 32, + ), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text('Email'), + const SizedBox( + height: 4, + ), + TextFormField( + enabled: !state.isLoading, + controller: emailController, + onChanged: (String value) => + context.read().add(ChangeEmail(value: value)), + decoration: InputDecoration( + border: const OutlineInputBorder(), + hintText: 'Enter your email', + errorText: state.email.errorMessage, + errorMaxLines: 3), + ), + ], + ), + const SizedBox( + height: 20, + ), + Container( + padding: EdgeInsets.zero, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text('Password'), + TextButton( + onPressed: null, child: Text("Forgot password?")) + ], + ), + const SizedBox( + height: 4, + ), + TextFormField( + enabled: !state.isLoading, + controller: passwordController, + onChanged: (String value) => context + .read() + .add(ChangePassword(value: value)), + obscureText: state.isPasswordHidden, + decoration: InputDecoration( + border: const OutlineInputBorder(), + hintText: 'Enter your password', + // change password visibility + suffixIcon: GestureDetector( + onTap: () => context.read().add( + ChangePasswordVisibility( + value: !state.isPasswordHidden)), + child: ImageIcon( + state.isPasswordHidden + ? const AssetImage('assets/icons/eye.png') + : const AssetImage('assets/icons/eye-off.png'), + size: 16, + ), + ), + errorText: state.password.errorMessage, + errorMaxLines: 3), + ), + ], + ), + ), + const SizedBox( + height: 32, + ), + // show general error message if it exists + if (state.errorMessage != null) + Padding( + padding: const EdgeInsets.only(bottom: 15.0), + child: Text( + state.errorMessage!, + style: const TextStyle(color: Colors.red), + maxLines: 3, + ), + ), + // show loading indicator when state is in a loading mode + if (state.isLoading) + const Padding( + padding: EdgeInsets.all(15.0), + child: Center( + child: SizedBox( + width: 30, + height: 30, + child: CircularProgressIndicator())), + ), + SizedBox( + width: double.infinity, + child: FilledButton( + // disable button when state is loading + onPressed: state.isLoading + ? null + : () { + context.read().add(LoginWithEmailAndPassword( + flowId: state.flowId!, + email: state.email.value, + password: state.password.value)); + }, + child: const Text('Sign in'), + ), + ), + const SizedBox( + height: 32, ), - if (state.isLoading) const CircularProgressIndicator(), - OutlinedButton( - onPressed: state.isLoading - ? null - : () { - context.read().add(LoginWithEmailAndPassword( - flowId: state.flowId!, - email: state.email.value, - password: state.password.value)); - }, - child: const Text('Submit')), - const SizedBox( - height: 20, - ), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const Text('Don\'t have an account yet?'), - TextButton( - onPressed: state.isLoading - ? null - : () => Navigator.of(context).pushReplacement( - MaterialPageRoute( - builder: (context) => const RegistrationPage())), - child: const Text('Get started')) - ], - ) - ], - )), + Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + const Text('No account?'), + TextButton( + // disable button when state is loading + onPressed: state.isLoading + ? null + : () => Navigator.of(context).pushReplacement( + MaterialPageRoute( + builder: (context) => + const RegistrationPage())), + child: const Text('Sign up')) + ], + ) + ], + ), + ), ); } } diff --git a/kratos-flutter/lib/pages/registration.dart b/kratos-flutter/lib/pages/registration.dart index 3498e6f2..326d77a0 100644 --- a/kratos-flutter/lib/pages/registration.dart +++ b/kratos-flutter/lib/pages/registration.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:kratos_flutter/widgets/social_provider_box.dart'; import '../blocs/auth/auth_bloc.dart'; import '../blocs/registration/registration_bloc.dart'; @@ -17,24 +18,45 @@ class RegistrationPage extends StatelessWidget { authBloc: context.read(), repository: RepositoryProvider.of(context)) ..add(CreateRegistrationFlow()), - child: const LoginForm()), + child: const RegistrationForm()), ); } } -class LoginForm extends StatelessWidget { - const LoginForm({super.key}); +class RegistrationForm extends StatefulWidget { + const RegistrationForm({super.key}); + + @override + State createState() => RegistrationFormState(); +} + +class RegistrationFormState extends State { + final emailController = TextEditingController(); + final passwordController = TextEditingController(); @override Widget build(BuildContext context) { final registrationBloc = BlocProvider.of(context); - return BlocBuilder( + return BlocConsumer( bloc: registrationBloc, + // listen to email and password changes + listenWhen: (previous, current) { + return (previous.email.value != current.email.value && + emailController.text != current.email.value) || + (previous.password.value != current.password.value && + passwordController.text != current.password.value); + }, + // if email or password value have changed, update text controller values + listener: (BuildContext context, RegistrationState state) { + emailController.text = state.email.value; + passwordController.text = state.password.value; + }, builder: (context, state) { - // creating registration flow is in process, show loading indicator + // registration flow was created if (state.flowId != null) { return _buildRegistrationForm(context, state); - } else { + } // otherwise, show loading or error + else { return _buildRegistrationFlowNotCreated(context, state); } }); @@ -55,78 +77,173 @@ class LoginForm extends StatelessWidget { _buildRegistrationForm(BuildContext context, RegistrationState state) { return Padding( - padding: const EdgeInsets.all(20.0), - child: Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - TextFormField( - enabled: !state.isLoading, - initialValue: state.email.value, - onChanged: (String value) => - context.read().add(ChangeEmail(value: value)), - decoration: InputDecoration( - border: const OutlineInputBorder(), - label: const Text('Email'), - hintText: 'Enter your email', - errorText: state.email.errorMessage, - errorMaxLines: 3), - ), - const SizedBox( - height: 20, - ), - TextFormField( - enabled: !state.isLoading, - initialValue: state.email.value, - onChanged: (String value) => context - .read() - .add(ChangePassword(value: value)), - decoration: InputDecoration( - border: const OutlineInputBorder(), - label: const Text('Password'), - hintText: 'Enter your password', - errorText: state.password.errorMessage, - errorMaxLines: 3), - ), - const SizedBox( - height: 20, - ), - if (state.errorMessage != null) - Text( - state.errorMessage!, - style: const TextStyle(color: Colors.red), + padding: const EdgeInsets.symmetric(horizontal: 32), + child: SingleChildScrollView( + // do not show scrolling indicator + physics: const BouncingScrollPhysics(), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Padding( + padding: EdgeInsets.only( + //status bar height + padding + top: MediaQuery.of(context).viewPadding.top + 48), + child: Image.asset( + 'assets/images/ory_logo.png', + width: 70, + ), + ), + const SizedBox( + height: 32, + ), + const Text("Sign up", + style: TextStyle( + fontWeight: FontWeight.w600, height: 1.5, fontSize: 18)), + const Text("Sign up with a social provider or with your email"), + const SizedBox( + height: 32, + ), + const Row( + children: [ + SocialProviderBox(provider: SocialProvider.google), + SizedBox( + width: 12, + ), + SocialProviderBox(provider: SocialProvider.github), + SizedBox( + width: 12, + ), + SocialProviderBox(provider: SocialProvider.apple), + SizedBox( + width: 12, + ), + SocialProviderBox(provider: SocialProvider.linkedin) + ], + ), + const SizedBox( + height: 32, ), - if (state.isLoading) const CircularProgressIndicator(), - OutlinedButton( - onPressed: state.isLoading - ? null - : () { - context.read().add( - RegisterWithEmailAndPassword( - flowId: state.flowId!, - email: state.email.value, - password: state.password.value)); - }, - child: const Text('Submit')), - const SizedBox( - height: 20, - ), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text('Already have an account?'), - TextButton( + const Divider( + color: Color.fromRGBO(226, 232, 240, 1), thickness: 1), + const SizedBox( + height: 32, + ), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text('Email'), + const SizedBox( + height: 4, + ), + TextFormField( + enabled: !state.isLoading, + controller: emailController, + onChanged: (String value) => context + .read() + .add(ChangeEmail(value: value)), + decoration: InputDecoration( + border: const OutlineInputBorder(), + hintText: 'Enter your email', + errorText: state.email.errorMessage, + errorMaxLines: 3), + ), + ], + ), + const SizedBox( + height: 20, + ), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text('Password'), + const SizedBox( + height: 4, + ), + TextFormField( + enabled: !state.isLoading, + controller: passwordController, + onChanged: (String value) => context + .read() + .add(ChangePassword(value: value)), + obscureText: state.isPasswordHidden, + decoration: InputDecoration( + border: const OutlineInputBorder(), + hintText: 'Enter a password', + // change password visibility + suffixIcon: GestureDetector( + onTap: () => context.read().add( + ChangePasswordVisibility( + value: !state.isPasswordHidden)), + child: ImageIcon( + state.isPasswordHidden + ? const AssetImage('assets/icons/eye.png') + : const AssetImage('assets/icons/eye-off.png'), + size: 16, + ), + ), + errorText: state.password.errorMessage, + errorMaxLines: 3), + ), + ], + ), + const SizedBox( + height: 32, + ), + // show general error message if it exists + if (state.errorMessage != null) + Padding( + padding: const EdgeInsets.only(bottom: 15.0), + child: Text( + state.errorMessage!, + style: const TextStyle(color: Colors.red), + ), + ), + // show loading indicator when state is in a loading mode + if (state.isLoading) + const Padding( + padding: EdgeInsets.all(15.0), + child: Center( + child: SizedBox( + width: 30, + height: 30, + child: CircularProgressIndicator())), + ), + SizedBox( + width: double.infinity, + child: FilledButton( + // disable button when state is loading onPressed: state.isLoading ? null - : () => Navigator.of(context).pushReplacement( - MaterialPageRoute( - builder: (context) => const LoginPage())), - child: Text('Log in')) - ], - ) - ], - )), + : () { + context.read().add( + RegisterWithEmailAndPassword( + flowId: state.flowId!, + email: state.email.value, + password: state.password.value)); + }, + child: const Text('Sign up')), + ), + const SizedBox( + height: 20, + ), + Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + const Text('Already have an account?'), + TextButton( + // disable button when state is loading + onPressed: state.isLoading + ? null + : () => Navigator.of(context).pushReplacement( + MaterialPageRoute( + builder: (context) => const LoginPage())), + child: const Text('Sign in')) + ], + ) + ], + ), + ), ); } } diff --git a/kratos-flutter/lib/services/auth.dart b/kratos-flutter/lib/services/auth.dart index b09e1feb..5c757f32 100644 --- a/kratos-flutter/lib/services/auth.dart +++ b/kratos-flutter/lib/services/auth.dart @@ -38,7 +38,7 @@ class AuthService { Future createLoginFlow() async { try { final response = await _ory.createNativeLoginFlow(); - if (response.statusCode == 200) { + if (response.data != null) { // return flow id return response.data!.id; } else { @@ -53,7 +53,7 @@ class AuthService { Future createRegistrationFlow() async { try { final response = await _ory.createNativeRegistrationFlow(); - if (response.statusCode == 200) { + if (response.data != null) { // return flow id return response.data!.id; } else { @@ -81,7 +81,7 @@ class AuthService { updateLoginFlowBody: UpdateLoginFlowBody( (b) => b..oneOf = OneOf.fromValue1(value: loginFLowBuilder))); - if (response.statusCode == 200 && response.data?.session != null) { + if (response.data?.session != null) { // save session token after successful login await storage.persistToken(response.data!.sessionToken!); return; @@ -96,8 +96,10 @@ class AuthService { final messages = _checkFormForErrors(e.response?.data); throw CustomException.badRequest(messages: messages); } else if (e.response?.statusCode == 410) { + // login flow expired, use new flow id and add error message throw CustomException.flowExpired( - flowId: e.response?.data['use_flow_id']); + flowId: e.response?.data['use_flow_id'], + message: 'Login flow has expired. Please enter credentials again.'); } else { throw _handleUnknownException(e.response?.data); } @@ -120,7 +122,7 @@ class AuthService { flow: flowId, updateRegistrationFlowBody: UpdateRegistrationFlowBody( (b) => b..oneOf = OneOf.fromValue1(value: registrationFLow))); - if (response.statusCode == 200 && response.data?.sessionToken != null) { + if (response.data?.sessionToken != null) { // save session token after successful login await storage.persistToken(response.data!.sessionToken!); return; @@ -135,8 +137,11 @@ class AuthService { final messages = _checkFormForErrors(e.response?.data); throw CustomException.badRequest(messages: messages); } else if (e.response?.statusCode == 410) { + // registration flow expired, use new flow id and add error message throw CustomException.flowExpired( - flowId: e.response?.data['use_flow_id']); + flowId: e.response?.data['use_flow_id'], + message: + 'Registration flow has expired. Please enter credentials again.'); } else { throw _handleUnknownException(e.response?.data); } @@ -165,6 +170,7 @@ class AuthService { } } + /// Search for error messages and their context in [response] List _checkFormForErrors(Map response) { final ui = Map.from(response['ui']); final nodeList = ui['nodes'] as List; diff --git a/kratos-flutter/lib/services/exceptions.dart b/kratos-flutter/lib/services/exceptions.dart index cc8b2181..376df6ee 100644 --- a/kratos-flutter/lib/services/exceptions.dart +++ b/kratos-flutter/lib/services/exceptions.dart @@ -15,7 +15,8 @@ sealed class CustomException with _$CustomException { UnauthorizedException; const factory CustomException.flowExpired( {@Default(410) int statusCode, - required String flowId}) = FlowExpiredException; + required String flowId, + String? message}) = FlowExpiredException; const factory CustomException.unknown( {@Default('An error occured. Please try again later.') String? message}) = UnknownException; diff --git a/kratos-flutter/lib/services/exceptions.freezed.dart b/kratos-flutter/lib/services/exceptions.freezed.dart index 87924c68..a9bdb662 100644 --- a/kratos-flutter/lib/services/exceptions.freezed.dart +++ b/kratos-flutter/lib/services/exceptions.freezed.dart @@ -21,7 +21,8 @@ mixin _$CustomException { required TResult Function(List? messages, int statusCode) badRequest, required TResult Function(int statusCode) unauthorized, - required TResult Function(int statusCode, String flowId) flowExpired, + required TResult Function(int statusCode, String flowId, String? message) + flowExpired, required TResult Function(String? message) unknown, }) => throw _privateConstructorUsedError; @@ -29,7 +30,8 @@ mixin _$CustomException { TResult? whenOrNull({ TResult? Function(List? messages, int statusCode)? badRequest, TResult? Function(int statusCode)? unauthorized, - TResult? Function(int statusCode, String flowId)? flowExpired, + TResult? Function(int statusCode, String flowId, String? message)? + flowExpired, TResult? Function(String? message)? unknown, }) => throw _privateConstructorUsedError; @@ -37,7 +39,8 @@ mixin _$CustomException { TResult maybeWhen({ TResult Function(List? messages, int statusCode)? badRequest, TResult Function(int statusCode)? unauthorized, - TResult Function(int statusCode, String flowId)? flowExpired, + TResult Function(int statusCode, String flowId, String? message)? + flowExpired, TResult Function(String? message)? unknown, required TResult orElse(), }) => @@ -187,7 +190,8 @@ class _$BadRequestException extends BadRequestException required TResult Function(List? messages, int statusCode) badRequest, required TResult Function(int statusCode) unauthorized, - required TResult Function(int statusCode, String flowId) flowExpired, + required TResult Function(int statusCode, String flowId, String? message) + flowExpired, required TResult Function(String? message) unknown, }) { return badRequest(messages, statusCode); @@ -198,7 +202,8 @@ class _$BadRequestException extends BadRequestException TResult? whenOrNull({ TResult? Function(List? messages, int statusCode)? badRequest, TResult? Function(int statusCode)? unauthorized, - TResult? Function(int statusCode, String flowId)? flowExpired, + TResult? Function(int statusCode, String flowId, String? message)? + flowExpired, TResult? Function(String? message)? unknown, }) { return badRequest?.call(messages, statusCode); @@ -209,7 +214,8 @@ class _$BadRequestException extends BadRequestException TResult maybeWhen({ TResult Function(List? messages, int statusCode)? badRequest, TResult Function(int statusCode)? unauthorized, - TResult Function(int statusCode, String flowId)? flowExpired, + TResult Function(int statusCode, String flowId, String? message)? + flowExpired, TResult Function(String? message)? unknown, required TResult orElse(), }) { @@ -349,7 +355,8 @@ class _$UnauthorizedException extends UnauthorizedException required TResult Function(List? messages, int statusCode) badRequest, required TResult Function(int statusCode) unauthorized, - required TResult Function(int statusCode, String flowId) flowExpired, + required TResult Function(int statusCode, String flowId, String? message) + flowExpired, required TResult Function(String? message) unknown, }) { return unauthorized(statusCode); @@ -360,7 +367,8 @@ class _$UnauthorizedException extends UnauthorizedException TResult? whenOrNull({ TResult? Function(List? messages, int statusCode)? badRequest, TResult? Function(int statusCode)? unauthorized, - TResult? Function(int statusCode, String flowId)? flowExpired, + TResult? Function(int statusCode, String flowId, String? message)? + flowExpired, TResult? Function(String? message)? unknown, }) { return unauthorized?.call(statusCode); @@ -371,7 +379,8 @@ class _$UnauthorizedException extends UnauthorizedException TResult maybeWhen({ TResult Function(List? messages, int statusCode)? badRequest, TResult Function(int statusCode)? unauthorized, - TResult Function(int statusCode, String flowId)? flowExpired, + TResult Function(int statusCode, String flowId, String? message)? + flowExpired, TResult Function(String? message)? unknown, required TResult orElse(), }) { @@ -436,7 +445,7 @@ abstract class _$$FlowExpiredExceptionCopyWith<$Res> { $Res Function(_$FlowExpiredException) then) = __$$FlowExpiredExceptionCopyWithImpl<$Res>; @useResult - $Res call({int statusCode, String flowId}); + $Res call({int statusCode, String flowId, String? message}); } /// @nodoc @@ -452,6 +461,7 @@ class __$$FlowExpiredExceptionCopyWithImpl<$Res> $Res call({ Object? statusCode = null, Object? flowId = null, + Object? message = freezed, }) { return _then(_$FlowExpiredException( statusCode: null == statusCode @@ -462,6 +472,10 @@ class __$$FlowExpiredExceptionCopyWithImpl<$Res> ? _value.flowId : flowId // ignore: cast_nullable_to_non_nullable as String, + message: freezed == message + ? _value.message + : message // ignore: cast_nullable_to_non_nullable + as String?, )); } } @@ -470,7 +484,8 @@ class __$$FlowExpiredExceptionCopyWithImpl<$Res> class _$FlowExpiredException extends FlowExpiredException with DiagnosticableTreeMixin { - const _$FlowExpiredException({this.statusCode = 410, required this.flowId}) + const _$FlowExpiredException( + {this.statusCode = 410, required this.flowId, this.message}) : super._(); @override @@ -478,10 +493,12 @@ class _$FlowExpiredException extends FlowExpiredException final int statusCode; @override final String flowId; + @override + final String? message; @override String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { - return 'CustomException.flowExpired(statusCode: $statusCode, flowId: $flowId)'; + return 'CustomException.flowExpired(statusCode: $statusCode, flowId: $flowId, message: $message)'; } @override @@ -490,7 +507,8 @@ class _$FlowExpiredException extends FlowExpiredException properties ..add(DiagnosticsProperty('type', 'CustomException.flowExpired')) ..add(DiagnosticsProperty('statusCode', statusCode)) - ..add(DiagnosticsProperty('flowId', flowId)); + ..add(DiagnosticsProperty('flowId', flowId)) + ..add(DiagnosticsProperty('message', message)); } @override @@ -500,11 +518,12 @@ class _$FlowExpiredException extends FlowExpiredException other is _$FlowExpiredException && (identical(other.statusCode, statusCode) || other.statusCode == statusCode) && - (identical(other.flowId, flowId) || other.flowId == flowId)); + (identical(other.flowId, flowId) || other.flowId == flowId) && + (identical(other.message, message) || other.message == message)); } @override - int get hashCode => Object.hash(runtimeType, statusCode, flowId); + int get hashCode => Object.hash(runtimeType, statusCode, flowId, message); @JsonKey(ignore: true) @override @@ -519,10 +538,11 @@ class _$FlowExpiredException extends FlowExpiredException required TResult Function(List? messages, int statusCode) badRequest, required TResult Function(int statusCode) unauthorized, - required TResult Function(int statusCode, String flowId) flowExpired, + required TResult Function(int statusCode, String flowId, String? message) + flowExpired, required TResult Function(String? message) unknown, }) { - return flowExpired(statusCode, flowId); + return flowExpired(statusCode, flowId, message); } @override @@ -530,10 +550,11 @@ class _$FlowExpiredException extends FlowExpiredException TResult? whenOrNull({ TResult? Function(List? messages, int statusCode)? badRequest, TResult? Function(int statusCode)? unauthorized, - TResult? Function(int statusCode, String flowId)? flowExpired, + TResult? Function(int statusCode, String flowId, String? message)? + flowExpired, TResult? Function(String? message)? unknown, }) { - return flowExpired?.call(statusCode, flowId); + return flowExpired?.call(statusCode, flowId, message); } @override @@ -541,12 +562,13 @@ class _$FlowExpiredException extends FlowExpiredException TResult maybeWhen({ TResult Function(List? messages, int statusCode)? badRequest, TResult Function(int statusCode)? unauthorized, - TResult Function(int statusCode, String flowId)? flowExpired, + TResult Function(int statusCode, String flowId, String? message)? + flowExpired, TResult Function(String? message)? unknown, required TResult orElse(), }) { if (flowExpired != null) { - return flowExpired(statusCode, flowId); + return flowExpired(statusCode, flowId, message); } return orElse(); } @@ -592,11 +614,13 @@ class _$FlowExpiredException extends FlowExpiredException abstract class FlowExpiredException extends CustomException { const factory FlowExpiredException( {final int statusCode, - required final String flowId}) = _$FlowExpiredException; + required final String flowId, + final String? message}) = _$FlowExpiredException; const FlowExpiredException._() : super._(); int get statusCode; String get flowId; + String? get message; @JsonKey(ignore: true) _$$FlowExpiredExceptionCopyWith<_$FlowExpiredException> get copyWith => throw _privateConstructorUsedError; @@ -680,7 +704,8 @@ class _$UnknownException extends UnknownException with DiagnosticableTreeMixin { required TResult Function(List? messages, int statusCode) badRequest, required TResult Function(int statusCode) unauthorized, - required TResult Function(int statusCode, String flowId) flowExpired, + required TResult Function(int statusCode, String flowId, String? message) + flowExpired, required TResult Function(String? message) unknown, }) { return unknown(message); @@ -691,7 +716,8 @@ class _$UnknownException extends UnknownException with DiagnosticableTreeMixin { TResult? whenOrNull({ TResult? Function(List? messages, int statusCode)? badRequest, TResult? Function(int statusCode)? unauthorized, - TResult? Function(int statusCode, String flowId)? flowExpired, + TResult? Function(int statusCode, String flowId, String? message)? + flowExpired, TResult? Function(String? message)? unknown, }) { return unknown?.call(message); @@ -702,7 +728,8 @@ class _$UnknownException extends UnknownException with DiagnosticableTreeMixin { TResult maybeWhen({ TResult Function(List? messages, int statusCode)? badRequest, TResult Function(int statusCode)? unauthorized, - TResult Function(int statusCode, String flowId)? flowExpired, + TResult Function(int statusCode, String flowId, String? message)? + flowExpired, TResult Function(String? message)? unknown, required TResult orElse(), }) { diff --git a/kratos-flutter/lib/widgets/ory_theme.dart b/kratos-flutter/lib/widgets/ory_theme.dart new file mode 100644 index 00000000..1c4ed4fe --- /dev/null +++ b/kratos-flutter/lib/widgets/ory_theme.dart @@ -0,0 +1,80 @@ +import 'package:flutter/material.dart'; +import 'package:google_fonts/google_fonts.dart'; + +class OryTheme { + OryTheme._(); + + static const Color primaryColor = Color(0xFF1E293B); + static const Color linkColor = Color(0xFF4F46E5); + static const Color errorColor = Color(0xFFEF4444); + static const Color formDefaultColor = Color(0xFF64748B); + static const Color formBorderColor = Color(0xFFE2E8F0); + static const Color formBorderFocusColor = Color(0xFF0F172A); + + static MaterialColor primaryColorSwatch = MaterialColor( + primaryColor.value, + const { + 50: Color(0xFF1E293B), + 100: Color(0xFF1E293B), + 200: Color(0xFF1E293B), + 300: Color(0xFF1E293B), + 400: Color(0xFF1E293B), + 500: Color(0xFF1E293B), + 600: Color(0xFF1E293B), + 700: Color(0xFF1E293B), + 800: Color(0xFF1E293B), + 900: Color(0xFF1E293B), + }, + ); + + static const InputDecorationTheme textFieldTheme = InputDecorationTheme( + contentPadding: EdgeInsets.symmetric(vertical: 10, horizontal: 12), + hintStyle: TextStyle( + fontSize: 14, + fontWeight: FontWeight.w400, + height: 1.25, + color: formDefaultColor), + errorStyle: TextStyle(color: errorColor), + suffixIconColor: formDefaultColor, + focusedBorder: OutlineInputBorder( + borderSide: BorderSide(width: 1, color: formBorderFocusColor)), + enabledBorder: OutlineInputBorder( + borderSide: BorderSide(width: 1, color: formBorderColor), + ), + errorBorder: OutlineInputBorder( + borderSide: BorderSide(width: 1, color: errorColor)), + focusedErrorBorder: OutlineInputBorder( + borderSide: BorderSide(width: 1, color: errorColor))); + +// buttons + static final TextButtonThemeData textButtonThemeData = TextButtonThemeData( + style: ButtonStyle( + visualDensity: VisualDensity.compact, + tapTargetSize: MaterialTapTargetSize.shrinkWrap, + padding: MaterialStateProperty.all( + EdgeInsets.zero, + ), + foregroundColor: MaterialStateProperty.all(linkColor), + textStyle: MaterialStateProperty.all(const TextStyle( + fontSize: 14, fontWeight: FontWeight.w500, height: 1.5)), + )); + + static final FilledButtonThemeData filledButtonThemeData = + FilledButtonThemeData( + style: ButtonStyle( + padding: MaterialStateProperty.all( + const EdgeInsets.symmetric(vertical: 12, horizontal: 16)), + shape: MaterialStateProperty.all( + RoundedRectangleBorder( + borderRadius: BorderRadius.circular(4.0))))); + + static final ThemeData defaultTheme = ThemeData( + primarySwatch: primaryColorSwatch, + fontFamily: GoogleFonts.getFont('Inter').fontFamily, + textButtonTheme: textButtonThemeData, + appBarTheme: + const AppBarTheme(iconTheme: IconThemeData(color: primaryColor)), + filledButtonTheme: filledButtonThemeData, + inputDecorationTheme: textFieldTheme, + ); +} diff --git a/kratos-flutter/lib/widgets/social_provider_box.dart b/kratos-flutter/lib/widgets/social_provider_box.dart new file mode 100644 index 00000000..7f31fe67 --- /dev/null +++ b/kratos-flutter/lib/widgets/social_provider_box.dart @@ -0,0 +1,25 @@ +import 'package:flutter/material.dart'; + +class SocialProviderBox extends StatelessWidget { + final SocialProvider provider; + + const SocialProviderBox({super.key, required this.provider}); + @override + Widget build(BuildContext context) { + return Expanded( + child: AspectRatio( + aspectRatio: 1.6, + child: Container( + padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 16), + decoration: BoxDecoration( + border: Border.all(width: 1, color: const Color(0xFFE2E8F0))), + child: // get icon from assets depending on provider + Image.asset( + 'assets/images/flows-auth-buttons-social-${provider.name}.png'), + ), + ), + ); + } +} + +enum SocialProvider { google, github, apple, linkedin } diff --git a/kratos-flutter/pubspec.lock b/kratos-flutter/pubspec.lock index 5d053942..05b6ae29 100644 --- a/kratos-flutter/pubspec.lock +++ b/kratos-flutter/pubspec.lock @@ -149,10 +149,10 @@ packages: dependency: "direct main" description: name: collection - sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c" + sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687 url: "https://pub.dev" source: hosted - version: "1.17.1" + version: "1.17.2" convert: dependency: transitive description: @@ -368,6 +368,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.2" + google_fonts: + dependency: "direct main" + description: + name: google_fonts + sha256: e20ff62b158b96f392bfc8afe29dee1503c94fbea2cbe8186fd59b756b8ae982 + url: "https://pub.dev" + source: hosted + version: "5.1.0" graphs: dependency: transitive description: @@ -376,6 +384,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.3.1" + http: + dependency: transitive + description: + name: http + sha256: "759d1a329847dd0f39226c688d3e06a6b8679668e350e2891a6474f8b4bb8525" + url: "https://pub.dev" + source: hosted + version: "1.1.0" http_multi_server: dependency: transitive description: @@ -444,18 +460,18 @@ packages: dependency: transitive description: name: matcher - sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb" + sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" url: "https://pub.dev" source: hosted - version: "0.12.15" + version: "0.12.16" material_color_utilities: dependency: transitive description: name: material_color_utilities - sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724 + sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" url: "https://pub.dev" source: hosted - version: "0.2.0" + version: "0.5.0" meta: dependency: transitive description: @@ -520,6 +536,30 @@ packages: url: "https://pub.dev" source: hosted version: "1.8.3" + path_provider: + dependency: transitive + description: + name: path_provider + sha256: "909b84830485dbcd0308edf6f7368bc8fd76afa26a270420f34cabea2a6467a0" + url: "https://pub.dev" + source: hosted + version: "2.1.0" + path_provider_android: + dependency: transitive + description: + name: path_provider_android + sha256: "5d44fc3314d969b84816b569070d7ace0f1dea04bd94a83f74c4829615d22ad8" + url: "https://pub.dev" + source: hosted + version: "2.1.0" + path_provider_foundation: + dependency: transitive + description: + name: path_provider_foundation + sha256: "1b744d3d774e5a879bb76d6cd1ecee2ba2c6960c03b1020cd35212f6aa267ac5" + url: "https://pub.dev" + source: hosted + version: "2.3.0" path_provider_linux: dependency: transitive description: @@ -697,10 +737,10 @@ packages: dependency: transitive description: name: source_span - sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250 + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" url: "https://pub.dev" source: hosted - version: "1.9.1" + version: "1.10.0" stack_trace: dependency: transitive description: @@ -745,10 +785,10 @@ packages: dependency: transitive description: name: test_api - sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb + sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8" url: "https://pub.dev" source: hosted - version: "0.5.1" + version: "0.6.0" timing: dependency: transitive description: @@ -781,6 +821,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.1.0" + web: + dependency: transitive + description: + name: web + sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10 + url: "https://pub.dev" + source: hosted + version: "0.1.4-beta" web_socket_channel: dependency: transitive description: @@ -814,5 +862,5 @@ packages: source: hosted version: "3.1.2" sdks: - dart: ">=3.0.6 <4.0.0" + dart: ">=3.1.0-185.0.dev <4.0.0" flutter: ">=3.3.0" diff --git a/kratos-flutter/pubspec.yaml b/kratos-flutter/pubspec.yaml index c13e514c..95a3d42b 100644 --- a/kratos-flutter/pubspec.yaml +++ b/kratos-flutter/pubspec.yaml @@ -50,6 +50,7 @@ dependencies: dotenv: ^4.1.0 collection: ^1.17.1 built_value: ^8.6.1 + google_fonts: ^5.1.0 dev_dependencies: flutter_test: @@ -79,6 +80,8 @@ flutter: # To add assets to your application, add an assets section, like this: assets: - .env + - assets/images/ + - assets/icons/ # An image asset can refer to one or more resolution-specific "variants", see From e7658a3ef4c6507fc0c3acd387ce34b164ae0987 Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Fri, 1 Sep 2023 11:32:42 +0200 Subject: [PATCH 09/57] fix: change package and folder name --- .../.gitignore | 0 .../.metadata | 0 .../README.md | 0 .../analysis_options.yaml | 0 .../android/.gitignore | 0 .../android/app/build.gradle | 0 .../android/app/src/debug/AndroidManifest.xml | 0 .../android/app/src/main/AndroidManifest.xml | 0 .../example/kratos_flutter/MainActivity.kt | 0 .../res/drawable-v21/launch_background.xml | 0 .../main/res/drawable/launch_background.xml | 0 .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin .../app/src/main/res/values-night/styles.xml | 0 .../app/src/main/res/values/styles.xml | 0 .../app/src/profile/AndroidManifest.xml | 0 .../android/build.gradle | 0 .../android/gradle.properties | 0 .../gradle/wrapper/gradle-wrapper.properties | 0 .../android/settings.gradle | 0 .../assets/icons/eye-off.png | Bin .../assets/icons/eye.png | Bin .../flows-auth-buttons-social-apple.png | Bin .../flows-auth-buttons-social-github.png | Bin .../flows-auth-buttons-social-google.png | Bin .../flows-auth-buttons-social-linkedin.png | Bin .../assets/images/ory_logo.png | Bin .../ios/.gitignore | 0 .../ios/Flutter/AppFrameworkInfo.plist | 0 .../ios/Flutter/Debug.xcconfig | 0 .../ios/Flutter/Release.xcconfig | 0 .../ios/Podfile | 0 .../ios/Runner.xcodeproj/project.pbxproj | 0 .../contents.xcworkspacedata | 0 .../xcshareddata/IDEWorkspaceChecks.plist | 0 .../xcshareddata/WorkspaceSettings.xcsettings | 0 .../xcshareddata/xcschemes/Runner.xcscheme | 0 .../contents.xcworkspacedata | 0 .../xcshareddata/IDEWorkspaceChecks.plist | 0 .../xcshareddata/WorkspaceSettings.xcsettings | 0 .../ios/Runner/AppDelegate.swift | 0 .../AppIcon.appiconset/Contents.json | 0 .../Icon-App-1024x1024@1x.png | Bin .../AppIcon.appiconset/Icon-App-20x20@1x.png | Bin .../AppIcon.appiconset/Icon-App-20x20@2x.png | Bin .../AppIcon.appiconset/Icon-App-20x20@3x.png | Bin .../AppIcon.appiconset/Icon-App-29x29@1x.png | Bin .../AppIcon.appiconset/Icon-App-29x29@2x.png | Bin .../AppIcon.appiconset/Icon-App-29x29@3x.png | Bin .../AppIcon.appiconset/Icon-App-40x40@1x.png | Bin .../AppIcon.appiconset/Icon-App-40x40@2x.png | Bin .../AppIcon.appiconset/Icon-App-40x40@3x.png | Bin .../AppIcon.appiconset/Icon-App-60x60@2x.png | Bin .../AppIcon.appiconset/Icon-App-60x60@3x.png | Bin .../AppIcon.appiconset/Icon-App-76x76@1x.png | Bin .../AppIcon.appiconset/Icon-App-76x76@2x.png | Bin .../Icon-App-83.5x83.5@2x.png | Bin .../LaunchImage.imageset/Contents.json | 0 .../LaunchImage.imageset/LaunchImage.png | Bin .../LaunchImage.imageset/LaunchImage@2x.png | Bin .../LaunchImage.imageset/LaunchImage@3x.png | Bin .../LaunchImage.imageset/README.md | 0 .../Runner/Base.lproj/LaunchScreen.storyboard | 0 .../ios/Runner/Base.lproj/Main.storyboard | 0 .../ios/Runner/Info.plist | 0 .../ios/Runner/Runner-Bridging-Header.h | 0 .../ios/RunnerTests/RunnerTests.swift | 0 .../lib/blocs/auth/auth_bloc.dart | 0 .../lib/blocs/auth/auth_bloc.freezed.dart | 0 .../lib/blocs/auth/auth_event.dart | 0 .../lib/blocs/auth/auth_state.dart | 0 .../lib/blocs/login/login_bloc.dart | 0 .../lib/blocs/login/login_bloc.freezed.dart | 0 .../lib/blocs/login/login_event.dart | 0 .../lib/blocs/login/login_state.dart | 0 .../blocs/registration/registration_bloc.dart | 0 .../registration_bloc.freezed.dart | 0 .../registration/registration_event.dart | 0 .../registration/registration_state.dart | 0 .../lib/entities/form_node.dart | 0 .../lib/entities/form_node.freezed.dart | 0 .../lib/entities/form_node.g.dart | 0 .../lib/entities/formfield.dart | 0 .../lib/entities/formfield.freezed.dart | 0 .../lib/entities/message.dart | 0 .../lib/entities/message.freezed.dart | 0 .../lib/entities/message.g.dart | 0 .../lib/entities/node_attribute.dart | 0 .../lib/entities/node_attribute.freezed.dart | 0 .../lib/entities/node_attribute.g.dart | 0 .../lib/main.dart | 38 ++---------------- .../lib/pages/entry.dart | 0 .../lib/pages/home.dart | 0 .../lib/pages/login.dart | 0 .../lib/pages/registration.dart | 0 .../lib/repositories/auth.dart | 0 .../lib/services/auth.dart | 0 .../lib/services/exceptions.dart | 0 .../lib/services/exceptions.freezed.dart | 0 .../lib/services/storage.dart | 0 .../lib/widgets/ory_theme.dart | 0 .../lib/widgets/social_provider_box.dart | 0 .../pubspec.lock | 0 .../pubspec.yaml | 0 .../test/widget_test.dart | 0 108 files changed, 4 insertions(+), 34 deletions(-) rename {kratos-flutter => flutter-ory-network}/.gitignore (100%) rename {kratos-flutter => flutter-ory-network}/.metadata (100%) rename {kratos-flutter => flutter-ory-network}/README.md (100%) rename {kratos-flutter => flutter-ory-network}/analysis_options.yaml (100%) rename {kratos-flutter => flutter-ory-network}/android/.gitignore (100%) rename {kratos-flutter => flutter-ory-network}/android/app/build.gradle (100%) rename {kratos-flutter => flutter-ory-network}/android/app/src/debug/AndroidManifest.xml (100%) rename {kratos-flutter => flutter-ory-network}/android/app/src/main/AndroidManifest.xml (100%) rename {kratos-flutter => flutter-ory-network}/android/app/src/main/kotlin/com/example/kratos_flutter/MainActivity.kt (100%) rename {kratos-flutter => flutter-ory-network}/android/app/src/main/res/drawable-v21/launch_background.xml (100%) rename {kratos-flutter => flutter-ory-network}/android/app/src/main/res/drawable/launch_background.xml (100%) rename {kratos-flutter => flutter-ory-network}/android/app/src/main/res/mipmap-hdpi/ic_launcher.png (100%) rename {kratos-flutter => flutter-ory-network}/android/app/src/main/res/mipmap-mdpi/ic_launcher.png (100%) rename {kratos-flutter => flutter-ory-network}/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png (100%) rename {kratos-flutter => flutter-ory-network}/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png (100%) rename {kratos-flutter => flutter-ory-network}/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png (100%) rename {kratos-flutter => flutter-ory-network}/android/app/src/main/res/values-night/styles.xml (100%) rename {kratos-flutter => flutter-ory-network}/android/app/src/main/res/values/styles.xml (100%) rename {kratos-flutter => flutter-ory-network}/android/app/src/profile/AndroidManifest.xml (100%) rename {kratos-flutter => flutter-ory-network}/android/build.gradle (100%) rename {kratos-flutter => flutter-ory-network}/android/gradle.properties (100%) rename {kratos-flutter => flutter-ory-network}/android/gradle/wrapper/gradle-wrapper.properties (100%) rename {kratos-flutter => flutter-ory-network}/android/settings.gradle (100%) rename {kratos-flutter => flutter-ory-network}/assets/icons/eye-off.png (100%) rename {kratos-flutter => flutter-ory-network}/assets/icons/eye.png (100%) rename {kratos-flutter => flutter-ory-network}/assets/images/flows-auth-buttons-social-apple.png (100%) rename {kratos-flutter => flutter-ory-network}/assets/images/flows-auth-buttons-social-github.png (100%) rename {kratos-flutter => flutter-ory-network}/assets/images/flows-auth-buttons-social-google.png (100%) rename {kratos-flutter => flutter-ory-network}/assets/images/flows-auth-buttons-social-linkedin.png (100%) rename {kratos-flutter => flutter-ory-network}/assets/images/ory_logo.png (100%) rename {kratos-flutter => flutter-ory-network}/ios/.gitignore (100%) rename {kratos-flutter => flutter-ory-network}/ios/Flutter/AppFrameworkInfo.plist (100%) rename {kratos-flutter => flutter-ory-network}/ios/Flutter/Debug.xcconfig (100%) rename {kratos-flutter => flutter-ory-network}/ios/Flutter/Release.xcconfig (100%) rename {kratos-flutter => flutter-ory-network}/ios/Podfile (100%) rename {kratos-flutter => flutter-ory-network}/ios/Runner.xcodeproj/project.pbxproj (100%) rename {kratos-flutter => flutter-ory-network}/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata (100%) rename {kratos-flutter => flutter-ory-network}/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist (100%) rename {kratos-flutter => flutter-ory-network}/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings (100%) rename {kratos-flutter => flutter-ory-network}/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme (100%) rename {kratos-flutter => flutter-ory-network}/ios/Runner.xcworkspace/contents.xcworkspacedata (100%) rename {kratos-flutter => flutter-ory-network}/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist (100%) rename {kratos-flutter => flutter-ory-network}/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings (100%) rename {kratos-flutter => flutter-ory-network}/ios/Runner/AppDelegate.swift (100%) rename {kratos-flutter => flutter-ory-network}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json (100%) rename {kratos-flutter => flutter-ory-network}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png (100%) rename {kratos-flutter => flutter-ory-network}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png (100%) rename {kratos-flutter => flutter-ory-network}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png (100%) rename {kratos-flutter => flutter-ory-network}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png (100%) rename {kratos-flutter => flutter-ory-network}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png (100%) rename {kratos-flutter => flutter-ory-network}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png (100%) rename {kratos-flutter => flutter-ory-network}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png (100%) rename {kratos-flutter => flutter-ory-network}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png (100%) rename {kratos-flutter => flutter-ory-network}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png (100%) rename {kratos-flutter => flutter-ory-network}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png (100%) rename {kratos-flutter => flutter-ory-network}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png (100%) rename {kratos-flutter => flutter-ory-network}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png (100%) rename {kratos-flutter => flutter-ory-network}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png (100%) rename {kratos-flutter => flutter-ory-network}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png (100%) rename {kratos-flutter => flutter-ory-network}/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png (100%) rename {kratos-flutter => flutter-ory-network}/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json (100%) rename {kratos-flutter => flutter-ory-network}/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png (100%) rename {kratos-flutter => flutter-ory-network}/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png (100%) rename {kratos-flutter => flutter-ory-network}/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png (100%) rename {kratos-flutter => flutter-ory-network}/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md (100%) rename {kratos-flutter => flutter-ory-network}/ios/Runner/Base.lproj/LaunchScreen.storyboard (100%) rename {kratos-flutter => flutter-ory-network}/ios/Runner/Base.lproj/Main.storyboard (100%) rename {kratos-flutter => flutter-ory-network}/ios/Runner/Info.plist (100%) rename {kratos-flutter => flutter-ory-network}/ios/Runner/Runner-Bridging-Header.h (100%) rename {kratos-flutter => flutter-ory-network}/ios/RunnerTests/RunnerTests.swift (100%) rename {kratos-flutter => flutter-ory-network}/lib/blocs/auth/auth_bloc.dart (100%) rename {kratos-flutter => flutter-ory-network}/lib/blocs/auth/auth_bloc.freezed.dart (100%) rename {kratos-flutter => flutter-ory-network}/lib/blocs/auth/auth_event.dart (100%) rename {kratos-flutter => flutter-ory-network}/lib/blocs/auth/auth_state.dart (100%) rename {kratos-flutter => flutter-ory-network}/lib/blocs/login/login_bloc.dart (100%) rename {kratos-flutter => flutter-ory-network}/lib/blocs/login/login_bloc.freezed.dart (100%) rename {kratos-flutter => flutter-ory-network}/lib/blocs/login/login_event.dart (100%) rename {kratos-flutter => flutter-ory-network}/lib/blocs/login/login_state.dart (100%) rename {kratos-flutter => flutter-ory-network}/lib/blocs/registration/registration_bloc.dart (100%) rename {kratos-flutter => flutter-ory-network}/lib/blocs/registration/registration_bloc.freezed.dart (100%) rename {kratos-flutter => flutter-ory-network}/lib/blocs/registration/registration_event.dart (100%) rename {kratos-flutter => flutter-ory-network}/lib/blocs/registration/registration_state.dart (100%) rename {kratos-flutter => flutter-ory-network}/lib/entities/form_node.dart (100%) rename {kratos-flutter => flutter-ory-network}/lib/entities/form_node.freezed.dart (100%) rename {kratos-flutter => flutter-ory-network}/lib/entities/form_node.g.dart (100%) rename {kratos-flutter => flutter-ory-network}/lib/entities/formfield.dart (100%) rename {kratos-flutter => flutter-ory-network}/lib/entities/formfield.freezed.dart (100%) rename {kratos-flutter => flutter-ory-network}/lib/entities/message.dart (100%) rename {kratos-flutter => flutter-ory-network}/lib/entities/message.freezed.dart (100%) rename {kratos-flutter => flutter-ory-network}/lib/entities/message.g.dart (100%) rename {kratos-flutter => flutter-ory-network}/lib/entities/node_attribute.dart (100%) rename {kratos-flutter => flutter-ory-network}/lib/entities/node_attribute.freezed.dart (100%) rename {kratos-flutter => flutter-ory-network}/lib/entities/node_attribute.g.dart (100%) rename {kratos-flutter => flutter-ory-network}/lib/main.dart (66%) rename {kratos-flutter => flutter-ory-network}/lib/pages/entry.dart (100%) rename {kratos-flutter => flutter-ory-network}/lib/pages/home.dart (100%) rename {kratos-flutter => flutter-ory-network}/lib/pages/login.dart (100%) rename {kratos-flutter => flutter-ory-network}/lib/pages/registration.dart (100%) rename {kratos-flutter => flutter-ory-network}/lib/repositories/auth.dart (100%) rename {kratos-flutter => flutter-ory-network}/lib/services/auth.dart (100%) rename {kratos-flutter => flutter-ory-network}/lib/services/exceptions.dart (100%) rename {kratos-flutter => flutter-ory-network}/lib/services/exceptions.freezed.dart (100%) rename {kratos-flutter => flutter-ory-network}/lib/services/storage.dart (100%) rename {kratos-flutter => flutter-ory-network}/lib/widgets/ory_theme.dart (100%) rename {kratos-flutter => flutter-ory-network}/lib/widgets/social_provider_box.dart (100%) rename {kratos-flutter => flutter-ory-network}/pubspec.lock (100%) rename {kratos-flutter => flutter-ory-network}/pubspec.yaml (100%) rename {kratos-flutter => flutter-ory-network}/test/widget_test.dart (100%) diff --git a/kratos-flutter/.gitignore b/flutter-ory-network/.gitignore similarity index 100% rename from kratos-flutter/.gitignore rename to flutter-ory-network/.gitignore diff --git a/kratos-flutter/.metadata b/flutter-ory-network/.metadata similarity index 100% rename from kratos-flutter/.metadata rename to flutter-ory-network/.metadata diff --git a/kratos-flutter/README.md b/flutter-ory-network/README.md similarity index 100% rename from kratos-flutter/README.md rename to flutter-ory-network/README.md diff --git a/kratos-flutter/analysis_options.yaml b/flutter-ory-network/analysis_options.yaml similarity index 100% rename from kratos-flutter/analysis_options.yaml rename to flutter-ory-network/analysis_options.yaml diff --git a/kratos-flutter/android/.gitignore b/flutter-ory-network/android/.gitignore similarity index 100% rename from kratos-flutter/android/.gitignore rename to flutter-ory-network/android/.gitignore diff --git a/kratos-flutter/android/app/build.gradle b/flutter-ory-network/android/app/build.gradle similarity index 100% rename from kratos-flutter/android/app/build.gradle rename to flutter-ory-network/android/app/build.gradle diff --git a/kratos-flutter/android/app/src/debug/AndroidManifest.xml b/flutter-ory-network/android/app/src/debug/AndroidManifest.xml similarity index 100% rename from kratos-flutter/android/app/src/debug/AndroidManifest.xml rename to flutter-ory-network/android/app/src/debug/AndroidManifest.xml diff --git a/kratos-flutter/android/app/src/main/AndroidManifest.xml b/flutter-ory-network/android/app/src/main/AndroidManifest.xml similarity index 100% rename from kratos-flutter/android/app/src/main/AndroidManifest.xml rename to flutter-ory-network/android/app/src/main/AndroidManifest.xml diff --git a/kratos-flutter/android/app/src/main/kotlin/com/example/kratos_flutter/MainActivity.kt b/flutter-ory-network/android/app/src/main/kotlin/com/example/kratos_flutter/MainActivity.kt similarity index 100% rename from kratos-flutter/android/app/src/main/kotlin/com/example/kratos_flutter/MainActivity.kt rename to flutter-ory-network/android/app/src/main/kotlin/com/example/kratos_flutter/MainActivity.kt diff --git a/kratos-flutter/android/app/src/main/res/drawable-v21/launch_background.xml b/flutter-ory-network/android/app/src/main/res/drawable-v21/launch_background.xml similarity index 100% rename from kratos-flutter/android/app/src/main/res/drawable-v21/launch_background.xml rename to flutter-ory-network/android/app/src/main/res/drawable-v21/launch_background.xml diff --git a/kratos-flutter/android/app/src/main/res/drawable/launch_background.xml b/flutter-ory-network/android/app/src/main/res/drawable/launch_background.xml similarity index 100% rename from kratos-flutter/android/app/src/main/res/drawable/launch_background.xml rename to flutter-ory-network/android/app/src/main/res/drawable/launch_background.xml diff --git a/kratos-flutter/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/flutter-ory-network/android/app/src/main/res/mipmap-hdpi/ic_launcher.png similarity index 100% rename from kratos-flutter/android/app/src/main/res/mipmap-hdpi/ic_launcher.png rename to flutter-ory-network/android/app/src/main/res/mipmap-hdpi/ic_launcher.png diff --git a/kratos-flutter/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/flutter-ory-network/android/app/src/main/res/mipmap-mdpi/ic_launcher.png similarity index 100% rename from kratos-flutter/android/app/src/main/res/mipmap-mdpi/ic_launcher.png rename to flutter-ory-network/android/app/src/main/res/mipmap-mdpi/ic_launcher.png diff --git a/kratos-flutter/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/flutter-ory-network/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png similarity index 100% rename from kratos-flutter/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png rename to flutter-ory-network/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png diff --git a/kratos-flutter/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/flutter-ory-network/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png similarity index 100% rename from kratos-flutter/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png rename to flutter-ory-network/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png diff --git a/kratos-flutter/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/flutter-ory-network/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png similarity index 100% rename from kratos-flutter/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png rename to flutter-ory-network/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png diff --git a/kratos-flutter/android/app/src/main/res/values-night/styles.xml b/flutter-ory-network/android/app/src/main/res/values-night/styles.xml similarity index 100% rename from kratos-flutter/android/app/src/main/res/values-night/styles.xml rename to flutter-ory-network/android/app/src/main/res/values-night/styles.xml diff --git a/kratos-flutter/android/app/src/main/res/values/styles.xml b/flutter-ory-network/android/app/src/main/res/values/styles.xml similarity index 100% rename from kratos-flutter/android/app/src/main/res/values/styles.xml rename to flutter-ory-network/android/app/src/main/res/values/styles.xml diff --git a/kratos-flutter/android/app/src/profile/AndroidManifest.xml b/flutter-ory-network/android/app/src/profile/AndroidManifest.xml similarity index 100% rename from kratos-flutter/android/app/src/profile/AndroidManifest.xml rename to flutter-ory-network/android/app/src/profile/AndroidManifest.xml diff --git a/kratos-flutter/android/build.gradle b/flutter-ory-network/android/build.gradle similarity index 100% rename from kratos-flutter/android/build.gradle rename to flutter-ory-network/android/build.gradle diff --git a/kratos-flutter/android/gradle.properties b/flutter-ory-network/android/gradle.properties similarity index 100% rename from kratos-flutter/android/gradle.properties rename to flutter-ory-network/android/gradle.properties diff --git a/kratos-flutter/android/gradle/wrapper/gradle-wrapper.properties b/flutter-ory-network/android/gradle/wrapper/gradle-wrapper.properties similarity index 100% rename from kratos-flutter/android/gradle/wrapper/gradle-wrapper.properties rename to flutter-ory-network/android/gradle/wrapper/gradle-wrapper.properties diff --git a/kratos-flutter/android/settings.gradle b/flutter-ory-network/android/settings.gradle similarity index 100% rename from kratos-flutter/android/settings.gradle rename to flutter-ory-network/android/settings.gradle diff --git a/kratos-flutter/assets/icons/eye-off.png b/flutter-ory-network/assets/icons/eye-off.png similarity index 100% rename from kratos-flutter/assets/icons/eye-off.png rename to flutter-ory-network/assets/icons/eye-off.png diff --git a/kratos-flutter/assets/icons/eye.png b/flutter-ory-network/assets/icons/eye.png similarity index 100% rename from kratos-flutter/assets/icons/eye.png rename to flutter-ory-network/assets/icons/eye.png diff --git a/kratos-flutter/assets/images/flows-auth-buttons-social-apple.png b/flutter-ory-network/assets/images/flows-auth-buttons-social-apple.png similarity index 100% rename from kratos-flutter/assets/images/flows-auth-buttons-social-apple.png rename to flutter-ory-network/assets/images/flows-auth-buttons-social-apple.png diff --git a/kratos-flutter/assets/images/flows-auth-buttons-social-github.png b/flutter-ory-network/assets/images/flows-auth-buttons-social-github.png similarity index 100% rename from kratos-flutter/assets/images/flows-auth-buttons-social-github.png rename to flutter-ory-network/assets/images/flows-auth-buttons-social-github.png diff --git a/kratos-flutter/assets/images/flows-auth-buttons-social-google.png b/flutter-ory-network/assets/images/flows-auth-buttons-social-google.png similarity index 100% rename from kratos-flutter/assets/images/flows-auth-buttons-social-google.png rename to flutter-ory-network/assets/images/flows-auth-buttons-social-google.png diff --git a/kratos-flutter/assets/images/flows-auth-buttons-social-linkedin.png b/flutter-ory-network/assets/images/flows-auth-buttons-social-linkedin.png similarity index 100% rename from kratos-flutter/assets/images/flows-auth-buttons-social-linkedin.png rename to flutter-ory-network/assets/images/flows-auth-buttons-social-linkedin.png diff --git a/kratos-flutter/assets/images/ory_logo.png b/flutter-ory-network/assets/images/ory_logo.png similarity index 100% rename from kratos-flutter/assets/images/ory_logo.png rename to flutter-ory-network/assets/images/ory_logo.png diff --git a/kratos-flutter/ios/.gitignore b/flutter-ory-network/ios/.gitignore similarity index 100% rename from kratos-flutter/ios/.gitignore rename to flutter-ory-network/ios/.gitignore diff --git a/kratos-flutter/ios/Flutter/AppFrameworkInfo.plist b/flutter-ory-network/ios/Flutter/AppFrameworkInfo.plist similarity index 100% rename from kratos-flutter/ios/Flutter/AppFrameworkInfo.plist rename to flutter-ory-network/ios/Flutter/AppFrameworkInfo.plist diff --git a/kratos-flutter/ios/Flutter/Debug.xcconfig b/flutter-ory-network/ios/Flutter/Debug.xcconfig similarity index 100% rename from kratos-flutter/ios/Flutter/Debug.xcconfig rename to flutter-ory-network/ios/Flutter/Debug.xcconfig diff --git a/kratos-flutter/ios/Flutter/Release.xcconfig b/flutter-ory-network/ios/Flutter/Release.xcconfig similarity index 100% rename from kratos-flutter/ios/Flutter/Release.xcconfig rename to flutter-ory-network/ios/Flutter/Release.xcconfig diff --git a/kratos-flutter/ios/Podfile b/flutter-ory-network/ios/Podfile similarity index 100% rename from kratos-flutter/ios/Podfile rename to flutter-ory-network/ios/Podfile diff --git a/kratos-flutter/ios/Runner.xcodeproj/project.pbxproj b/flutter-ory-network/ios/Runner.xcodeproj/project.pbxproj similarity index 100% rename from kratos-flutter/ios/Runner.xcodeproj/project.pbxproj rename to flutter-ory-network/ios/Runner.xcodeproj/project.pbxproj diff --git a/kratos-flutter/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/flutter-ory-network/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata similarity index 100% rename from kratos-flutter/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata rename to flutter-ory-network/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata diff --git a/kratos-flutter/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/flutter-ory-network/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist similarity index 100% rename from kratos-flutter/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist rename to flutter-ory-network/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/kratos-flutter/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/flutter-ory-network/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings similarity index 100% rename from kratos-flutter/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings rename to flutter-ory-network/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings diff --git a/kratos-flutter/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/flutter-ory-network/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme similarity index 100% rename from kratos-flutter/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme rename to flutter-ory-network/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme diff --git a/kratos-flutter/ios/Runner.xcworkspace/contents.xcworkspacedata b/flutter-ory-network/ios/Runner.xcworkspace/contents.xcworkspacedata similarity index 100% rename from kratos-flutter/ios/Runner.xcworkspace/contents.xcworkspacedata rename to flutter-ory-network/ios/Runner.xcworkspace/contents.xcworkspacedata diff --git a/kratos-flutter/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/flutter-ory-network/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist similarity index 100% rename from kratos-flutter/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist rename to flutter-ory-network/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/kratos-flutter/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/flutter-ory-network/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings similarity index 100% rename from kratos-flutter/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings rename to flutter-ory-network/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings diff --git a/kratos-flutter/ios/Runner/AppDelegate.swift b/flutter-ory-network/ios/Runner/AppDelegate.swift similarity index 100% rename from kratos-flutter/ios/Runner/AppDelegate.swift rename to flutter-ory-network/ios/Runner/AppDelegate.swift diff --git a/kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json b/flutter-ory-network/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json similarity index 100% rename from kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json rename to flutter-ory-network/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json diff --git a/kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png b/flutter-ory-network/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png similarity index 100% rename from kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png rename to flutter-ory-network/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png diff --git a/kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png b/flutter-ory-network/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png similarity index 100% rename from kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png rename to flutter-ory-network/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png diff --git a/kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png b/flutter-ory-network/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png similarity index 100% rename from kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png rename to flutter-ory-network/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png diff --git a/kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png b/flutter-ory-network/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png similarity index 100% rename from kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png rename to flutter-ory-network/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png diff --git a/kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png b/flutter-ory-network/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png similarity index 100% rename from kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png rename to flutter-ory-network/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png diff --git a/kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png b/flutter-ory-network/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png similarity index 100% rename from kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png rename to flutter-ory-network/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png diff --git a/kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png b/flutter-ory-network/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png similarity index 100% rename from kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png rename to flutter-ory-network/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png diff --git a/kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png b/flutter-ory-network/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png similarity index 100% rename from kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png rename to flutter-ory-network/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png diff --git a/kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png b/flutter-ory-network/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png similarity index 100% rename from kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png rename to flutter-ory-network/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png diff --git a/kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png b/flutter-ory-network/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png similarity index 100% rename from kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png rename to flutter-ory-network/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png diff --git a/kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png b/flutter-ory-network/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png similarity index 100% rename from kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png rename to flutter-ory-network/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png diff --git a/kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png b/flutter-ory-network/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png similarity index 100% rename from kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png rename to flutter-ory-network/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png diff --git a/kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png b/flutter-ory-network/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png similarity index 100% rename from kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png rename to flutter-ory-network/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png diff --git a/kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png b/flutter-ory-network/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png similarity index 100% rename from kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png rename to flutter-ory-network/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png diff --git a/kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png b/flutter-ory-network/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png similarity index 100% rename from kratos-flutter/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png rename to flutter-ory-network/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png diff --git a/kratos-flutter/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json b/flutter-ory-network/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json similarity index 100% rename from kratos-flutter/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json rename to flutter-ory-network/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json diff --git a/kratos-flutter/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png b/flutter-ory-network/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png similarity index 100% rename from kratos-flutter/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png rename to flutter-ory-network/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png diff --git a/kratos-flutter/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png b/flutter-ory-network/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png similarity index 100% rename from kratos-flutter/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png rename to flutter-ory-network/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png diff --git a/kratos-flutter/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png b/flutter-ory-network/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png similarity index 100% rename from kratos-flutter/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png rename to flutter-ory-network/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png diff --git a/kratos-flutter/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md b/flutter-ory-network/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md similarity index 100% rename from kratos-flutter/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md rename to flutter-ory-network/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md diff --git a/kratos-flutter/ios/Runner/Base.lproj/LaunchScreen.storyboard b/flutter-ory-network/ios/Runner/Base.lproj/LaunchScreen.storyboard similarity index 100% rename from kratos-flutter/ios/Runner/Base.lproj/LaunchScreen.storyboard rename to flutter-ory-network/ios/Runner/Base.lproj/LaunchScreen.storyboard diff --git a/kratos-flutter/ios/Runner/Base.lproj/Main.storyboard b/flutter-ory-network/ios/Runner/Base.lproj/Main.storyboard similarity index 100% rename from kratos-flutter/ios/Runner/Base.lproj/Main.storyboard rename to flutter-ory-network/ios/Runner/Base.lproj/Main.storyboard diff --git a/kratos-flutter/ios/Runner/Info.plist b/flutter-ory-network/ios/Runner/Info.plist similarity index 100% rename from kratos-flutter/ios/Runner/Info.plist rename to flutter-ory-network/ios/Runner/Info.plist diff --git a/kratos-flutter/ios/Runner/Runner-Bridging-Header.h b/flutter-ory-network/ios/Runner/Runner-Bridging-Header.h similarity index 100% rename from kratos-flutter/ios/Runner/Runner-Bridging-Header.h rename to flutter-ory-network/ios/Runner/Runner-Bridging-Header.h diff --git a/kratos-flutter/ios/RunnerTests/RunnerTests.swift b/flutter-ory-network/ios/RunnerTests/RunnerTests.swift similarity index 100% rename from kratos-flutter/ios/RunnerTests/RunnerTests.swift rename to flutter-ory-network/ios/RunnerTests/RunnerTests.swift diff --git a/kratos-flutter/lib/blocs/auth/auth_bloc.dart b/flutter-ory-network/lib/blocs/auth/auth_bloc.dart similarity index 100% rename from kratos-flutter/lib/blocs/auth/auth_bloc.dart rename to flutter-ory-network/lib/blocs/auth/auth_bloc.dart diff --git a/kratos-flutter/lib/blocs/auth/auth_bloc.freezed.dart b/flutter-ory-network/lib/blocs/auth/auth_bloc.freezed.dart similarity index 100% rename from kratos-flutter/lib/blocs/auth/auth_bloc.freezed.dart rename to flutter-ory-network/lib/blocs/auth/auth_bloc.freezed.dart diff --git a/kratos-flutter/lib/blocs/auth/auth_event.dart b/flutter-ory-network/lib/blocs/auth/auth_event.dart similarity index 100% rename from kratos-flutter/lib/blocs/auth/auth_event.dart rename to flutter-ory-network/lib/blocs/auth/auth_event.dart diff --git a/kratos-flutter/lib/blocs/auth/auth_state.dart b/flutter-ory-network/lib/blocs/auth/auth_state.dart similarity index 100% rename from kratos-flutter/lib/blocs/auth/auth_state.dart rename to flutter-ory-network/lib/blocs/auth/auth_state.dart diff --git a/kratos-flutter/lib/blocs/login/login_bloc.dart b/flutter-ory-network/lib/blocs/login/login_bloc.dart similarity index 100% rename from kratos-flutter/lib/blocs/login/login_bloc.dart rename to flutter-ory-network/lib/blocs/login/login_bloc.dart diff --git a/kratos-flutter/lib/blocs/login/login_bloc.freezed.dart b/flutter-ory-network/lib/blocs/login/login_bloc.freezed.dart similarity index 100% rename from kratos-flutter/lib/blocs/login/login_bloc.freezed.dart rename to flutter-ory-network/lib/blocs/login/login_bloc.freezed.dart diff --git a/kratos-flutter/lib/blocs/login/login_event.dart b/flutter-ory-network/lib/blocs/login/login_event.dart similarity index 100% rename from kratos-flutter/lib/blocs/login/login_event.dart rename to flutter-ory-network/lib/blocs/login/login_event.dart diff --git a/kratos-flutter/lib/blocs/login/login_state.dart b/flutter-ory-network/lib/blocs/login/login_state.dart similarity index 100% rename from kratos-flutter/lib/blocs/login/login_state.dart rename to flutter-ory-network/lib/blocs/login/login_state.dart diff --git a/kratos-flutter/lib/blocs/registration/registration_bloc.dart b/flutter-ory-network/lib/blocs/registration/registration_bloc.dart similarity index 100% rename from kratos-flutter/lib/blocs/registration/registration_bloc.dart rename to flutter-ory-network/lib/blocs/registration/registration_bloc.dart diff --git a/kratos-flutter/lib/blocs/registration/registration_bloc.freezed.dart b/flutter-ory-network/lib/blocs/registration/registration_bloc.freezed.dart similarity index 100% rename from kratos-flutter/lib/blocs/registration/registration_bloc.freezed.dart rename to flutter-ory-network/lib/blocs/registration/registration_bloc.freezed.dart diff --git a/kratos-flutter/lib/blocs/registration/registration_event.dart b/flutter-ory-network/lib/blocs/registration/registration_event.dart similarity index 100% rename from kratos-flutter/lib/blocs/registration/registration_event.dart rename to flutter-ory-network/lib/blocs/registration/registration_event.dart diff --git a/kratos-flutter/lib/blocs/registration/registration_state.dart b/flutter-ory-network/lib/blocs/registration/registration_state.dart similarity index 100% rename from kratos-flutter/lib/blocs/registration/registration_state.dart rename to flutter-ory-network/lib/blocs/registration/registration_state.dart diff --git a/kratos-flutter/lib/entities/form_node.dart b/flutter-ory-network/lib/entities/form_node.dart similarity index 100% rename from kratos-flutter/lib/entities/form_node.dart rename to flutter-ory-network/lib/entities/form_node.dart diff --git a/kratos-flutter/lib/entities/form_node.freezed.dart b/flutter-ory-network/lib/entities/form_node.freezed.dart similarity index 100% rename from kratos-flutter/lib/entities/form_node.freezed.dart rename to flutter-ory-network/lib/entities/form_node.freezed.dart diff --git a/kratos-flutter/lib/entities/form_node.g.dart b/flutter-ory-network/lib/entities/form_node.g.dart similarity index 100% rename from kratos-flutter/lib/entities/form_node.g.dart rename to flutter-ory-network/lib/entities/form_node.g.dart diff --git a/kratos-flutter/lib/entities/formfield.dart b/flutter-ory-network/lib/entities/formfield.dart similarity index 100% rename from kratos-flutter/lib/entities/formfield.dart rename to flutter-ory-network/lib/entities/formfield.dart diff --git a/kratos-flutter/lib/entities/formfield.freezed.dart b/flutter-ory-network/lib/entities/formfield.freezed.dart similarity index 100% rename from kratos-flutter/lib/entities/formfield.freezed.dart rename to flutter-ory-network/lib/entities/formfield.freezed.dart diff --git a/kratos-flutter/lib/entities/message.dart b/flutter-ory-network/lib/entities/message.dart similarity index 100% rename from kratos-flutter/lib/entities/message.dart rename to flutter-ory-network/lib/entities/message.dart diff --git a/kratos-flutter/lib/entities/message.freezed.dart b/flutter-ory-network/lib/entities/message.freezed.dart similarity index 100% rename from kratos-flutter/lib/entities/message.freezed.dart rename to flutter-ory-network/lib/entities/message.freezed.dart diff --git a/kratos-flutter/lib/entities/message.g.dart b/flutter-ory-network/lib/entities/message.g.dart similarity index 100% rename from kratos-flutter/lib/entities/message.g.dart rename to flutter-ory-network/lib/entities/message.g.dart diff --git a/kratos-flutter/lib/entities/node_attribute.dart b/flutter-ory-network/lib/entities/node_attribute.dart similarity index 100% rename from kratos-flutter/lib/entities/node_attribute.dart rename to flutter-ory-network/lib/entities/node_attribute.dart diff --git a/kratos-flutter/lib/entities/node_attribute.freezed.dart b/flutter-ory-network/lib/entities/node_attribute.freezed.dart similarity index 100% rename from kratos-flutter/lib/entities/node_attribute.freezed.dart rename to flutter-ory-network/lib/entities/node_attribute.freezed.dart diff --git a/kratos-flutter/lib/entities/node_attribute.g.dart b/flutter-ory-network/lib/entities/node_attribute.g.dart similarity index 100% rename from kratos-flutter/lib/entities/node_attribute.g.dart rename to flutter-ory-network/lib/entities/node_attribute.g.dart diff --git a/kratos-flutter/lib/main.dart b/flutter-ory-network/lib/main.dart similarity index 66% rename from kratos-flutter/lib/main.dart rename to flutter-ory-network/lib/main.dart index 8da89d31..066c5d5c 100644 --- a/kratos-flutter/lib/main.dart +++ b/flutter-ory-network/lib/main.dart @@ -48,45 +48,15 @@ class MyApp extends StatelessWidget { // This widget is the root of your application. @override Widget build(BuildContext context) { - return MaterialApp( - title: 'Flutter Demo', - theme: ThemeData( - // This is the theme of your application. - // - // TRY THIS: Try running your application with "flutter run". You'll see - // the application has a blue toolbar. Then, without quitting the app, - // try changing the seedColor in the colorScheme below to Colors.green - // and then invoke "hot reload" (save your changes or press the "hot - // reload" button in a Flutter-supported IDE, or press "r" if you used - // the command line to start the app). - // - // Notice that the counter didn't reset back to zero; the application - // state is not lost during the reload. To reset the state, use hot - // restart instead. - // - // This works for code too, not just values: Most code changes can be - // tested with just a hot reload. - colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), - useMaterial3: true, - ), - home: const MyAppView(title: 'Flutter Demo Home Page'), + return const MaterialApp( + title: 'Flutter Ory Network Demo', + home: MyAppView(), ); } } class MyAppView extends StatefulWidget { - const MyAppView({super.key, required this.title}); - - // This widget is the home page of your application. It is stateful, meaning - // that it has a State object (defined below) that contains fields that affect - // how it looks. - - // This class is the configuration for the state. It holds the values (in this - // case the title) provided by the parent (in this case the App widget) and - // used by the build method of the State. Fields in a Widget subclass are - // always marked "final". - - final String title; + const MyAppView({super.key}); @override State createState() => _MyAppViewState(); diff --git a/kratos-flutter/lib/pages/entry.dart b/flutter-ory-network/lib/pages/entry.dart similarity index 100% rename from kratos-flutter/lib/pages/entry.dart rename to flutter-ory-network/lib/pages/entry.dart diff --git a/kratos-flutter/lib/pages/home.dart b/flutter-ory-network/lib/pages/home.dart similarity index 100% rename from kratos-flutter/lib/pages/home.dart rename to flutter-ory-network/lib/pages/home.dart diff --git a/kratos-flutter/lib/pages/login.dart b/flutter-ory-network/lib/pages/login.dart similarity index 100% rename from kratos-flutter/lib/pages/login.dart rename to flutter-ory-network/lib/pages/login.dart diff --git a/kratos-flutter/lib/pages/registration.dart b/flutter-ory-network/lib/pages/registration.dart similarity index 100% rename from kratos-flutter/lib/pages/registration.dart rename to flutter-ory-network/lib/pages/registration.dart diff --git a/kratos-flutter/lib/repositories/auth.dart b/flutter-ory-network/lib/repositories/auth.dart similarity index 100% rename from kratos-flutter/lib/repositories/auth.dart rename to flutter-ory-network/lib/repositories/auth.dart diff --git a/kratos-flutter/lib/services/auth.dart b/flutter-ory-network/lib/services/auth.dart similarity index 100% rename from kratos-flutter/lib/services/auth.dart rename to flutter-ory-network/lib/services/auth.dart diff --git a/kratos-flutter/lib/services/exceptions.dart b/flutter-ory-network/lib/services/exceptions.dart similarity index 100% rename from kratos-flutter/lib/services/exceptions.dart rename to flutter-ory-network/lib/services/exceptions.dart diff --git a/kratos-flutter/lib/services/exceptions.freezed.dart b/flutter-ory-network/lib/services/exceptions.freezed.dart similarity index 100% rename from kratos-flutter/lib/services/exceptions.freezed.dart rename to flutter-ory-network/lib/services/exceptions.freezed.dart diff --git a/kratos-flutter/lib/services/storage.dart b/flutter-ory-network/lib/services/storage.dart similarity index 100% rename from kratos-flutter/lib/services/storage.dart rename to flutter-ory-network/lib/services/storage.dart diff --git a/kratos-flutter/lib/widgets/ory_theme.dart b/flutter-ory-network/lib/widgets/ory_theme.dart similarity index 100% rename from kratos-flutter/lib/widgets/ory_theme.dart rename to flutter-ory-network/lib/widgets/ory_theme.dart diff --git a/kratos-flutter/lib/widgets/social_provider_box.dart b/flutter-ory-network/lib/widgets/social_provider_box.dart similarity index 100% rename from kratos-flutter/lib/widgets/social_provider_box.dart rename to flutter-ory-network/lib/widgets/social_provider_box.dart diff --git a/kratos-flutter/pubspec.lock b/flutter-ory-network/pubspec.lock similarity index 100% rename from kratos-flutter/pubspec.lock rename to flutter-ory-network/pubspec.lock diff --git a/kratos-flutter/pubspec.yaml b/flutter-ory-network/pubspec.yaml similarity index 100% rename from kratos-flutter/pubspec.yaml rename to flutter-ory-network/pubspec.yaml diff --git a/kratos-flutter/test/widget_test.dart b/flutter-ory-network/test/widget_test.dart similarity index 100% rename from kratos-flutter/test/widget_test.dart rename to flutter-ory-network/test/widget_test.dart From e033adf488727ba9ba98f3500ab23a3146b8d745 Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Fri, 1 Sep 2023 13:28:12 +0200 Subject: [PATCH 10/57] fix: change package name --- flutter-ory-network/android/app/build.gradle | 4 +- .../android/app/src/main/AndroidManifest.xml | 2 +- .../example/kratos_flutter/MainActivity.kt | 2 +- flutter-ory-network/ios/Podfile.lock | 36 +++++ .../ios/Runner.xcodeproj/project.pbxproj | 152 +++++++++++++++--- .../xcshareddata/xcschemes/Runner.xcscheme | 2 +- .../contents.xcworkspacedata | 3 + flutter-ory-network/ios/Runner/Info.plist | 12 +- flutter-ory-network/lib/main.dart | 2 +- .../lib/pages/registration.dart | 2 +- flutter-ory-network/pubspec.yaml | 2 +- flutter-ory-network/test/widget_test.dart | 2 +- 12 files changed, 184 insertions(+), 37 deletions(-) create mode 100644 flutter-ory-network/ios/Podfile.lock diff --git a/flutter-ory-network/android/app/build.gradle b/flutter-ory-network/android/app/build.gradle index 927aafcd..94108385 100644 --- a/flutter-ory-network/android/app/build.gradle +++ b/flutter-ory-network/android/app/build.gradle @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - namespace "com.example.kratos_flutter" + namespace "com.example.ory_network_flutter" compileSdkVersion flutter.compileSdkVersion ndkVersion flutter.ndkVersion @@ -45,7 +45,7 @@ android { defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). - applicationId "com.example.kratos_flutter" + applicationId "com.example.ory_network_flutter" // You can update the following values to match your application needs. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. minSdkVersion 18 diff --git a/flutter-ory-network/android/app/src/main/AndroidManifest.xml b/flutter-ory-network/android/app/src/main/AndroidManifest.xml index 86e04b93..097b25fe 100644 --- a/flutter-ory-network/android/app/src/main/AndroidManifest.xml +++ b/flutter-ory-network/android/app/src/main/AndroidManifest.xml @@ -1,6 +1,6 @@ /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { isa = PBXShellScriptBuildPhase; alwaysOutOfDate = 1; @@ -238,6 +324,28 @@ shellPath = /bin/sh; shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin"; }; + 41429A30DBA960B328EE0121 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; 9740EEB61CF901F6004384FC /* Run Script */ = { isa = PBXShellScriptBuildPhase; alwaysOutOfDate = 1; @@ -366,7 +474,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = com.example.kratosFlutter; + PRODUCT_BUNDLE_IDENTIFIER = com.example.ory_network_flutter; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_VERSION = 5.0; @@ -376,14 +484,14 @@ }; 331C8088294A63A400263BE5 /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = AE0B7B92F70575B8D7E0D07E /* Pods-RunnerTests.debug.xcconfig */; + baseConfigurationReference = 0CB57777B6627A48BB9FA8C8 /* Pods-RunnerTests.debug.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; GENERATE_INFOPLIST_FILE = YES; MARKETING_VERSION = 1.0; - PRODUCT_BUNDLE_IDENTIFIER = com.example.kratosFlutter.RunnerTests; + PRODUCT_BUNDLE_IDENTIFIER = com.example.ory_network_flutter.RunnerTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; @@ -394,14 +502,14 @@ }; 331C8089294A63A400263BE5 /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 89B67EB44CE7B6631473024E /* Pods-RunnerTests.release.xcconfig */; + baseConfigurationReference = 5049002C15409643EB52610C /* Pods-RunnerTests.release.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; GENERATE_INFOPLIST_FILE = YES; MARKETING_VERSION = 1.0; - PRODUCT_BUNDLE_IDENTIFIER = com.example.kratosFlutter.RunnerTests; + PRODUCT_BUNDLE_IDENTIFIER = com.example.ory_network_flutter.RunnerTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner"; @@ -410,14 +518,14 @@ }; 331C808A294A63A400263BE5 /* Profile */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 640959BDD8F10B91D80A66BE /* Pods-RunnerTests.profile.xcconfig */; + baseConfigurationReference = 572786F99F7DFEE344A536D0 /* Pods-RunnerTests.profile.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; GENERATE_INFOPLIST_FILE = YES; MARKETING_VERSION = 1.0; - PRODUCT_BUNDLE_IDENTIFIER = com.example.kratosFlutter.RunnerTests; + PRODUCT_BUNDLE_IDENTIFIER = com.example.ory_network_flutter.RunnerTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner"; @@ -544,7 +652,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = com.example.kratosFlutter; + PRODUCT_BUNDLE_IDENTIFIER = com.example.ory_network_flutter; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; @@ -566,7 +674,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = com.example.kratosFlutter; + PRODUCT_BUNDLE_IDENTIFIER = com.example.ory_network_flutter; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_VERSION = 5.0; diff --git a/flutter-ory-network/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/flutter-ory-network/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index e42adcb3..87131a09 100644 --- a/flutter-ory-network/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/flutter-ory-network/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ + + diff --git a/flutter-ory-network/ios/Runner/Info.plist b/flutter-ory-network/ios/Runner/Info.plist index 70201f08..f3fb7dd7 100644 --- a/flutter-ory-network/ios/Runner/Info.plist +++ b/flutter-ory-network/ios/Runner/Info.plist @@ -2,10 +2,12 @@ + CADisableMinimumFrameDurationOnPhone + CFBundleDevelopmentRegion $(DEVELOPMENT_LANGUAGE) CFBundleDisplayName - Kratos Flutter + Ory Network Flutter CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier @@ -13,7 +15,7 @@ CFBundleInfoDictionaryVersion 6.0 CFBundleName - kratos_flutter + ory_network_flutter CFBundlePackageType APPL CFBundleShortVersionString @@ -24,6 +26,8 @@ $(FLUTTER_BUILD_NUMBER) LSRequiresIPhoneOS + UIApplicationSupportsIndirectInputEvents + UILaunchStoryboardName LaunchScreen UIMainStoryboardFile @@ -43,9 +47,5 @@ UIViewControllerBasedStatusBarAppearance - CADisableMinimumFrameDurationOnPhone - - UIApplicationSupportsIndirectInputEvents - diff --git a/flutter-ory-network/lib/main.dart b/flutter-ory-network/lib/main.dart index 066c5d5c..c00fc05b 100644 --- a/flutter-ory-network/lib/main.dart +++ b/flutter-ory-network/lib/main.dart @@ -3,7 +3,7 @@ import 'package:dio/io.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; -import 'package:kratos_flutter/widgets/ory_theme.dart'; +import 'package:ory_network_flutter/widgets/ory_theme.dart'; import 'blocs/auth/auth_bloc.dart'; import 'pages/home.dart'; diff --git a/flutter-ory-network/lib/pages/registration.dart b/flutter-ory-network/lib/pages/registration.dart index 326d77a0..97efd3bc 100644 --- a/flutter-ory-network/lib/pages/registration.dart +++ b/flutter-ory-network/lib/pages/registration.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:kratos_flutter/widgets/social_provider_box.dart'; +import 'package:ory_network_flutter/widgets/social_provider_box.dart'; import '../blocs/auth/auth_bloc.dart'; import '../blocs/registration/registration_bloc.dart'; diff --git a/flutter-ory-network/pubspec.yaml b/flutter-ory-network/pubspec.yaml index 95a3d42b..3331a75c 100644 --- a/flutter-ory-network/pubspec.yaml +++ b/flutter-ory-network/pubspec.yaml @@ -1,4 +1,4 @@ -name: kratos_flutter +name: ory_network_flutter description: A new Flutter project. # The following line prevents the package from being accidentally published to # pub.dev using `flutter pub publish`. This is preferred for private packages. diff --git a/flutter-ory-network/test/widget_test.dart b/flutter-ory-network/test/widget_test.dart index 80f9a1a4..35bed1f9 100644 --- a/flutter-ory-network/test/widget_test.dart +++ b/flutter-ory-network/test/widget_test.dart @@ -8,7 +8,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:kratos_flutter/main.dart'; +import 'package:ory_network_flutter/main.dart'; void main() { testWidgets('Counter increments smoke test', (WidgetTester tester) async { From f2972358d668e58e6a51e709a709153ae61c87f4 Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Fri, 1 Sep 2023 13:41:34 +0200 Subject: [PATCH 11/57] docs: update README.md --- flutter-ory-network/README.md | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/flutter-ory-network/README.md b/flutter-ory-network/README.md index 177c296a..63d9a418 100644 --- a/flutter-ory-network/README.md +++ b/flutter-ory-network/README.md @@ -1,16 +1,27 @@ -# kratos_flutter +# Integrate Ory Network with Flutter -A new Flutter project. +This example demonstrates how to use Ory Network with a Flutter app. It includes login and registration with email and password. -## Getting Started +## Develop +### Prerequisites +1. [Flutter](https://docs.flutter.dev/get-started/install) version 3.13.1 +2. Xcode and Android Studio +3. iOS Simulator or Android Emulator +4. [Ory Network](https://console.ory.sh/) project -This project is a starting point for a Flutter application. +### Environmental variables +Create .env file with your project url in the root folder of the Flutter app +```env +ORY_BASE_URL=https://{your-project-slug}.projects.oryapis.com +``` -A few resources to get you started if this is your first Flutter project: - -- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab) -- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook) - -For help getting started with Flutter development, view the -[online documentation](https://docs.flutter.dev/), which offers tutorials, -samples, guidance on mobile development, and a full API reference. +### Run locally +1. Install dependancies from `pubspec.yaml` +```console +flutter pub get +``` +2. open iOS Simulator or Android Emulator +3. Start the app +```console +flutter run +``` From 7244c6cfacb6fe122d644a13080789aa51571976 Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Fri, 1 Sep 2023 14:14:31 +0200 Subject: [PATCH 12/57] refactor: delete unused icon --- .../images/flows-auth-buttons-social-linkedin.svg | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 assets/images/images/flows-auth-buttons-social-linkedin.svg diff --git a/assets/images/images/flows-auth-buttons-social-linkedin.svg b/assets/images/images/flows-auth-buttons-social-linkedin.svg deleted file mode 100644 index 100dc8ed..00000000 --- a/assets/images/images/flows-auth-buttons-social-linkedin.svg +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - From 6f7ddc6403cf1bc1dbb1a6b583050cf593214848 Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Fri, 1 Sep 2023 14:23:08 +0200 Subject: [PATCH 13/57] refactor: remove unused packages --- flutter-ory-network/ios/Podfile.lock | 7 --- flutter-ory-network/pubspec.lock | 68 +--------------------------- flutter-ory-network/pubspec.yaml | 4 -- 3 files changed, 2 insertions(+), 77 deletions(-) diff --git a/flutter-ory-network/ios/Podfile.lock b/flutter-ory-network/ios/Podfile.lock index fe7b953f..8d113103 100644 --- a/flutter-ory-network/ios/Podfile.lock +++ b/flutter-ory-network/ios/Podfile.lock @@ -5,15 +5,11 @@ PODS: - path_provider_foundation (0.0.1): - Flutter - FlutterMacOS - - shared_preferences_foundation (0.0.1): - - Flutter - - FlutterMacOS DEPENDENCIES: - Flutter (from `Flutter`) - flutter_secure_storage (from `.symlinks/plugins/flutter_secure_storage/ios`) - path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`) - - shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`) EXTERNAL SOURCES: Flutter: @@ -22,14 +18,11 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/flutter_secure_storage/ios" path_provider_foundation: :path: ".symlinks/plugins/path_provider_foundation/darwin" - shared_preferences_foundation: - :path: ".symlinks/plugins/shared_preferences_foundation/darwin" SPEC CHECKSUMS: Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854 flutter_secure_storage: 23fc622d89d073675f2eaa109381aefbcf5a49be path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943 - shared_preferences_foundation: 5b919d13b803cadd15ed2dc053125c68730e5126 PODFILE CHECKSUM: 70d9d25280d0dd177a5f637cdb0f0b0b12c6a189 diff --git a/flutter-ory-network/pubspec.lock b/flutter-ory-network/pubspec.lock index 05b6ae29..85398bad 100644 --- a/flutter-ory-network/pubspec.lock +++ b/flutter-ory-network/pubspec.lock @@ -106,7 +106,7 @@ packages: source: hosted version: "5.1.1" built_value: - dependency: "direct main" + dependency: transitive description: name: built_value sha256: "598a2a682e2a7a90f08ba39c0aaa9374c5112340f0a2e275f61b59389543d166" @@ -146,7 +146,7 @@ packages: source: hosted version: "4.5.0" collection: - dependency: "direct main" + dependency: transitive description: name: collection sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687 @@ -328,14 +328,6 @@ packages: description: flutter source: sdk version: "0.0.0" - formz: - dependency: "direct main" - description: - name: formz - sha256: b2b4cb99b228020d2c7185500eed1c02ca290dd4cc19edaf42df17f5dc546d5a - url: "https://pub.dev" - source: hosted - version: "0.6.0" freezed: dependency: "direct dev" description: @@ -640,62 +632,6 @@ packages: url: "https://pub.dev" source: hosted version: "3.2.1" - shared_preferences: - dependency: "direct main" - description: - name: shared_preferences - sha256: "0344316c947ffeb3a529eac929e1978fcd37c26be4e8468628bac399365a3ca1" - url: "https://pub.dev" - source: hosted - version: "2.2.0" - shared_preferences_android: - dependency: transitive - description: - name: shared_preferences_android - sha256: fe8401ec5b6dcd739a0fe9588802069e608c3fdbfd3c3c93e546cf2f90438076 - url: "https://pub.dev" - source: hosted - version: "2.2.0" - shared_preferences_foundation: - dependency: transitive - description: - name: shared_preferences_foundation - sha256: d29753996d8eb8f7619a1f13df6ce65e34bc107bef6330739ed76f18b22310ef - url: "https://pub.dev" - source: hosted - version: "2.3.3" - shared_preferences_linux: - dependency: transitive - description: - name: shared_preferences_linux - sha256: "71d6806d1449b0a9d4e85e0c7a917771e672a3d5dc61149cc9fac871115018e1" - url: "https://pub.dev" - source: hosted - version: "2.3.0" - shared_preferences_platform_interface: - dependency: transitive - description: - name: shared_preferences_platform_interface - sha256: "23b052f17a25b90ff2b61aad4cc962154da76fb62848a9ce088efe30d7c50ab1" - url: "https://pub.dev" - source: hosted - version: "2.3.0" - shared_preferences_web: - dependency: transitive - description: - name: shared_preferences_web - sha256: "7347b194fb0bbeb4058e6a4e87ee70350b6b2b90f8ac5f8bd5b3a01548f6d33a" - url: "https://pub.dev" - source: hosted - version: "2.2.0" - shared_preferences_windows: - dependency: transitive - description: - name: shared_preferences_windows - sha256: f95e6a43162bce43c9c3405f3eb6f39e5b5d11f65fab19196cf8225e2777624d - url: "https://pub.dev" - source: hosted - version: "2.3.0" shelf: dependency: transitive description: diff --git a/flutter-ory-network/pubspec.yaml b/flutter-ory-network/pubspec.yaml index 3331a75c..9ff71305 100644 --- a/flutter-ory-network/pubspec.yaml +++ b/flutter-ory-network/pubspec.yaml @@ -37,19 +37,15 @@ dependencies: cupertino_icons: ^1.0.2 bloc: ^8.1.2 flutter_bloc: ^8.1.3 - shared_preferences: ^2.2.0 dio: ^5.3.2 ory_client: ^1.1.44 flutter_dotenv: ^5.1.0 freezed_annotation: ^2.4.1 json_annotation: ^4.8.1 - formz: ^0.6.0 equatable: ^2.0.5 one_of: ^1.5.0 flutter_secure_storage: ^8.0.0 dotenv: ^4.1.0 - collection: ^1.17.1 - built_value: ^8.6.1 google_fonts: ^5.1.0 dev_dependencies: From b43fdd05beca062d772f1adfa86237e824a6e9d6 Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Fri, 1 Sep 2023 14:42:48 +0200 Subject: [PATCH 14/57] chore: format code --- flutter-ory-network/README.md | 13 +- flutter-ory-network/analysis_options.yaml | 1 - .../AppIcon.appiconset/Contents.json | 160 +++++++++--------- .../LaunchImage.imageset/Contents.json | 26 +-- .../LaunchImage.imageset/README.md | 7 +- .../lib/blocs/auth/auth_bloc.dart | 3 + .../lib/blocs/auth/auth_bloc.freezed.dart | 3 + .../lib/blocs/auth/auth_event.dart | 3 + .../lib/blocs/auth/auth_state.dart | 3 + .../lib/blocs/login/login_bloc.dart | 3 + .../lib/blocs/login/login_bloc.freezed.dart | 3 + .../lib/blocs/login/login_event.dart | 3 + .../lib/blocs/login/login_state.dart | 3 + .../blocs/registration/registration_bloc.dart | 3 + .../registration_bloc.freezed.dart | 3 + .../registration/registration_event.dart | 3 + .../registration/registration_state.dart | 3 + .../lib/entities/form_node.dart | 3 + .../lib/entities/form_node.freezed.dart | 3 + .../lib/entities/form_node.g.dart | 3 + .../lib/entities/formfield.dart | 3 + .../lib/entities/formfield.freezed.dart | 3 + flutter-ory-network/lib/entities/message.dart | 3 + .../lib/entities/message.freezed.dart | 3 + .../lib/entities/message.g.dart | 3 + .../lib/entities/node_attribute.dart | 3 + .../lib/entities/node_attribute.freezed.dart | 3 + .../lib/entities/node_attribute.g.dart | 3 + flutter-ory-network/lib/main.dart | 3 + flutter-ory-network/lib/pages/entry.dart | 3 + flutter-ory-network/lib/pages/home.dart | 3 + flutter-ory-network/lib/pages/login.dart | 3 + .../lib/pages/registration.dart | 3 + .../lib/repositories/auth.dart | 3 + flutter-ory-network/lib/services/auth.dart | 3 + .../lib/services/exceptions.dart | 3 + .../lib/services/exceptions.freezed.dart | 3 + flutter-ory-network/lib/services/storage.dart | 3 + .../lib/widgets/ory_theme.dart | 3 + .../lib/widgets/social_provider_box.dart | 3 + flutter-ory-network/pubspec.yaml | 7 +- flutter-ory-network/test/widget_test.dart | 3 + 42 files changed, 219 insertions(+), 103 deletions(-) diff --git a/flutter-ory-network/README.md b/flutter-ory-network/README.md index 63d9a418..77a624b1 100644 --- a/flutter-ory-network/README.md +++ b/flutter-ory-network/README.md @@ -1,27 +1,36 @@ # Integrate Ory Network with Flutter -This example demonstrates how to use Ory Network with a Flutter app. It includes login and registration with email and password. +This example demonstrates how to use Ory Network with a Flutter app. It includes +login and registration with email and password. ## Develop + ### Prerequisites + 1. [Flutter](https://docs.flutter.dev/get-started/install) version 3.13.1 2. Xcode and Android Studio 3. iOS Simulator or Android Emulator -4. [Ory Network](https://console.ory.sh/) project +4. [Ory Network](https://console.ory.sh/) project ### Environmental variables + Create .env file with your project url in the root folder of the Flutter app + ```env ORY_BASE_URL=https://{your-project-slug}.projects.oryapis.com ``` ### Run locally + 1. Install dependancies from `pubspec.yaml` + ```console flutter pub get ``` + 2. open iOS Simulator or Android Emulator 3. Start the app + ```console flutter run ``` diff --git a/flutter-ory-network/analysis_options.yaml b/flutter-ory-network/analysis_options.yaml index 61b6c4de..fd16f921 100644 --- a/flutter-ory-network/analysis_options.yaml +++ b/flutter-ory-network/analysis_options.yaml @@ -24,6 +24,5 @@ linter: rules: # avoid_print: false # Uncomment to disable the `avoid_print` rule # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule - # Additional information about this file can be found at # https://dart.dev/guides/language/analysis-options diff --git a/flutter-ory-network/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json b/flutter-ory-network/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json index d36b1fab..e882ab98 100644 --- a/flutter-ory-network/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/flutter-ory-network/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -1,122 +1,122 @@ { - "images" : [ + "images": [ { - "size" : "20x20", - "idiom" : "iphone", - "filename" : "Icon-App-20x20@2x.png", - "scale" : "2x" + "size": "20x20", + "idiom": "iphone", + "filename": "Icon-App-20x20@2x.png", + "scale": "2x" }, { - "size" : "20x20", - "idiom" : "iphone", - "filename" : "Icon-App-20x20@3x.png", - "scale" : "3x" + "size": "20x20", + "idiom": "iphone", + "filename": "Icon-App-20x20@3x.png", + "scale": "3x" }, { - "size" : "29x29", - "idiom" : "iphone", - "filename" : "Icon-App-29x29@1x.png", - "scale" : "1x" + "size": "29x29", + "idiom": "iphone", + "filename": "Icon-App-29x29@1x.png", + "scale": "1x" }, { - "size" : "29x29", - "idiom" : "iphone", - "filename" : "Icon-App-29x29@2x.png", - "scale" : "2x" + "size": "29x29", + "idiom": "iphone", + "filename": "Icon-App-29x29@2x.png", + "scale": "2x" }, { - "size" : "29x29", - "idiom" : "iphone", - "filename" : "Icon-App-29x29@3x.png", - "scale" : "3x" + "size": "29x29", + "idiom": "iphone", + "filename": "Icon-App-29x29@3x.png", + "scale": "3x" }, { - "size" : "40x40", - "idiom" : "iphone", - "filename" : "Icon-App-40x40@2x.png", - "scale" : "2x" + "size": "40x40", + "idiom": "iphone", + "filename": "Icon-App-40x40@2x.png", + "scale": "2x" }, { - "size" : "40x40", - "idiom" : "iphone", - "filename" : "Icon-App-40x40@3x.png", - "scale" : "3x" + "size": "40x40", + "idiom": "iphone", + "filename": "Icon-App-40x40@3x.png", + "scale": "3x" }, { - "size" : "60x60", - "idiom" : "iphone", - "filename" : "Icon-App-60x60@2x.png", - "scale" : "2x" + "size": "60x60", + "idiom": "iphone", + "filename": "Icon-App-60x60@2x.png", + "scale": "2x" }, { - "size" : "60x60", - "idiom" : "iphone", - "filename" : "Icon-App-60x60@3x.png", - "scale" : "3x" + "size": "60x60", + "idiom": "iphone", + "filename": "Icon-App-60x60@3x.png", + "scale": "3x" }, { - "size" : "20x20", - "idiom" : "ipad", - "filename" : "Icon-App-20x20@1x.png", - "scale" : "1x" + "size": "20x20", + "idiom": "ipad", + "filename": "Icon-App-20x20@1x.png", + "scale": "1x" }, { - "size" : "20x20", - "idiom" : "ipad", - "filename" : "Icon-App-20x20@2x.png", - "scale" : "2x" + "size": "20x20", + "idiom": "ipad", + "filename": "Icon-App-20x20@2x.png", + "scale": "2x" }, { - "size" : "29x29", - "idiom" : "ipad", - "filename" : "Icon-App-29x29@1x.png", - "scale" : "1x" + "size": "29x29", + "idiom": "ipad", + "filename": "Icon-App-29x29@1x.png", + "scale": "1x" }, { - "size" : "29x29", - "idiom" : "ipad", - "filename" : "Icon-App-29x29@2x.png", - "scale" : "2x" + "size": "29x29", + "idiom": "ipad", + "filename": "Icon-App-29x29@2x.png", + "scale": "2x" }, { - "size" : "40x40", - "idiom" : "ipad", - "filename" : "Icon-App-40x40@1x.png", - "scale" : "1x" + "size": "40x40", + "idiom": "ipad", + "filename": "Icon-App-40x40@1x.png", + "scale": "1x" }, { - "size" : "40x40", - "idiom" : "ipad", - "filename" : "Icon-App-40x40@2x.png", - "scale" : "2x" + "size": "40x40", + "idiom": "ipad", + "filename": "Icon-App-40x40@2x.png", + "scale": "2x" }, { - "size" : "76x76", - "idiom" : "ipad", - "filename" : "Icon-App-76x76@1x.png", - "scale" : "1x" + "size": "76x76", + "idiom": "ipad", + "filename": "Icon-App-76x76@1x.png", + "scale": "1x" }, { - "size" : "76x76", - "idiom" : "ipad", - "filename" : "Icon-App-76x76@2x.png", - "scale" : "2x" + "size": "76x76", + "idiom": "ipad", + "filename": "Icon-App-76x76@2x.png", + "scale": "2x" }, { - "size" : "83.5x83.5", - "idiom" : "ipad", - "filename" : "Icon-App-83.5x83.5@2x.png", - "scale" : "2x" + "size": "83.5x83.5", + "idiom": "ipad", + "filename": "Icon-App-83.5x83.5@2x.png", + "scale": "2x" }, { - "size" : "1024x1024", - "idiom" : "ios-marketing", - "filename" : "Icon-App-1024x1024@1x.png", - "scale" : "1x" + "size": "1024x1024", + "idiom": "ios-marketing", + "filename": "Icon-App-1024x1024@1x.png", + "scale": "1x" } ], - "info" : { - "version" : 1, - "author" : "xcode" + "info": { + "version": 1, + "author": "xcode" } } diff --git a/flutter-ory-network/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json b/flutter-ory-network/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json index 0bedcf2f..781d7cdc 100644 --- a/flutter-ory-network/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json +++ b/flutter-ory-network/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json @@ -1,23 +1,23 @@ { - "images" : [ + "images": [ { - "idiom" : "universal", - "filename" : "LaunchImage.png", - "scale" : "1x" + "idiom": "universal", + "filename": "LaunchImage.png", + "scale": "1x" }, { - "idiom" : "universal", - "filename" : "LaunchImage@2x.png", - "scale" : "2x" + "idiom": "universal", + "filename": "LaunchImage@2x.png", + "scale": "2x" }, { - "idiom" : "universal", - "filename" : "LaunchImage@3x.png", - "scale" : "3x" + "idiom": "universal", + "filename": "LaunchImage@3x.png", + "scale": "3x" } ], - "info" : { - "version" : 1, - "author" : "xcode" + "info": { + "version": 1, + "author": "xcode" } } diff --git a/flutter-ory-network/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md b/flutter-ory-network/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md index 89c2725b..09c4940e 100644 --- a/flutter-ory-network/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md +++ b/flutter-ory-network/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md @@ -1,5 +1,8 @@ # Launch Screen Assets -You can customize the launch screen with your own desired assets by replacing the image files in this directory. +You can customize the launch screen with your own desired assets by replacing +the image files in this directory. -You can also do it by opening your Flutter project's Xcode project with `open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project Navigator and dropping in the desired images. \ No newline at end of file +You can also do it by opening your Flutter project's Xcode project with +`open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project +Navigator and dropping in the desired images. diff --git a/flutter-ory-network/lib/blocs/auth/auth_bloc.dart b/flutter-ory-network/lib/blocs/auth/auth_bloc.dart index 2a0fb55d..6da7be0d 100644 --- a/flutter-ory-network/lib/blocs/auth/auth_bloc.dart +++ b/flutter-ory-network/lib/blocs/auth/auth_bloc.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + import 'package:bloc/bloc.dart'; import 'package:equatable/equatable.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; diff --git a/flutter-ory-network/lib/blocs/auth/auth_bloc.freezed.dart b/flutter-ory-network/lib/blocs/auth/auth_bloc.freezed.dart index 02acfd8b..c9fb0758 100644 --- a/flutter-ory-network/lib/blocs/auth/auth_bloc.freezed.dart +++ b/flutter-ory-network/lib/blocs/auth/auth_bloc.freezed.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint diff --git a/flutter-ory-network/lib/blocs/auth/auth_event.dart b/flutter-ory-network/lib/blocs/auth/auth_event.dart index 8a138130..7d9a6364 100644 --- a/flutter-ory-network/lib/blocs/auth/auth_event.dart +++ b/flutter-ory-network/lib/blocs/auth/auth_event.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + part of 'auth_bloc.dart'; @immutable diff --git a/flutter-ory-network/lib/blocs/auth/auth_state.dart b/flutter-ory-network/lib/blocs/auth/auth_state.dart index afc06e01..eaa742e2 100644 --- a/flutter-ory-network/lib/blocs/auth/auth_state.dart +++ b/flutter-ory-network/lib/blocs/auth/auth_state.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + part of 'auth_bloc.dart'; @freezed diff --git a/flutter-ory-network/lib/blocs/login/login_bloc.dart b/flutter-ory-network/lib/blocs/login/login_bloc.dart index 0e7d559c..a3b36554 100644 --- a/flutter-ory-network/lib/blocs/login/login_bloc.dart +++ b/flutter-ory-network/lib/blocs/login/login_bloc.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + import 'package:bloc/bloc.dart'; import 'package:equatable/equatable.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; diff --git a/flutter-ory-network/lib/blocs/login/login_bloc.freezed.dart b/flutter-ory-network/lib/blocs/login/login_bloc.freezed.dart index 17960491..8efa7a95 100644 --- a/flutter-ory-network/lib/blocs/login/login_bloc.freezed.dart +++ b/flutter-ory-network/lib/blocs/login/login_bloc.freezed.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint diff --git a/flutter-ory-network/lib/blocs/login/login_event.dart b/flutter-ory-network/lib/blocs/login/login_event.dart index ee140712..b80c7f36 100644 --- a/flutter-ory-network/lib/blocs/login/login_event.dart +++ b/flutter-ory-network/lib/blocs/login/login_event.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + part of 'login_bloc.dart'; @immutable diff --git a/flutter-ory-network/lib/blocs/login/login_state.dart b/flutter-ory-network/lib/blocs/login/login_state.dart index df977895..3c627c09 100644 --- a/flutter-ory-network/lib/blocs/login/login_state.dart +++ b/flutter-ory-network/lib/blocs/login/login_state.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + part of 'login_bloc.dart'; @freezed diff --git a/flutter-ory-network/lib/blocs/registration/registration_bloc.dart b/flutter-ory-network/lib/blocs/registration/registration_bloc.dart index 89eb5c02..84acbb8e 100644 --- a/flutter-ory-network/lib/blocs/registration/registration_bloc.dart +++ b/flutter-ory-network/lib/blocs/registration/registration_bloc.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + import 'package:bloc/bloc.dart'; import 'package:equatable/equatable.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; diff --git a/flutter-ory-network/lib/blocs/registration/registration_bloc.freezed.dart b/flutter-ory-network/lib/blocs/registration/registration_bloc.freezed.dart index edbeef53..c5f63b5c 100644 --- a/flutter-ory-network/lib/blocs/registration/registration_bloc.freezed.dart +++ b/flutter-ory-network/lib/blocs/registration/registration_bloc.freezed.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint diff --git a/flutter-ory-network/lib/blocs/registration/registration_event.dart b/flutter-ory-network/lib/blocs/registration/registration_event.dart index ea65684d..60dcffeb 100644 --- a/flutter-ory-network/lib/blocs/registration/registration_event.dart +++ b/flutter-ory-network/lib/blocs/registration/registration_event.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + part of 'registration_bloc.dart'; @immutable diff --git a/flutter-ory-network/lib/blocs/registration/registration_state.dart b/flutter-ory-network/lib/blocs/registration/registration_state.dart index cf258ee3..38eac5ba 100644 --- a/flutter-ory-network/lib/blocs/registration/registration_state.dart +++ b/flutter-ory-network/lib/blocs/registration/registration_state.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + part of 'registration_bloc.dart'; @freezed diff --git a/flutter-ory-network/lib/entities/form_node.dart b/flutter-ory-network/lib/entities/form_node.dart index f6679a67..57e2ed7a 100644 --- a/flutter-ory-network/lib/entities/form_node.dart +++ b/flutter-ory-network/lib/entities/form_node.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + import 'package:freezed_annotation/freezed_annotation.dart'; import 'message.dart'; diff --git a/flutter-ory-network/lib/entities/form_node.freezed.dart b/flutter-ory-network/lib/entities/form_node.freezed.dart index b66dacb6..96efd5ef 100644 --- a/flutter-ory-network/lib/entities/form_node.freezed.dart +++ b/flutter-ory-network/lib/entities/form_node.freezed.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint diff --git a/flutter-ory-network/lib/entities/form_node.g.dart b/flutter-ory-network/lib/entities/form_node.g.dart index 98e6de11..7b31b119 100644 --- a/flutter-ory-network/lib/entities/form_node.g.dart +++ b/flutter-ory-network/lib/entities/form_node.g.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + // GENERATED CODE - DO NOT MODIFY BY HAND part of 'form_node.dart'; diff --git a/flutter-ory-network/lib/entities/formfield.dart b/flutter-ory-network/lib/entities/formfield.dart index caeafe57..6407a49c 100644 --- a/flutter-ory-network/lib/entities/formfield.dart +++ b/flutter-ory-network/lib/entities/formfield.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + import 'package:freezed_annotation/freezed_annotation.dart'; part 'formfield.freezed.dart'; diff --git a/flutter-ory-network/lib/entities/formfield.freezed.dart b/flutter-ory-network/lib/entities/formfield.freezed.dart index 67e05f8d..d8e74a89 100644 --- a/flutter-ory-network/lib/entities/formfield.freezed.dart +++ b/flutter-ory-network/lib/entities/formfield.freezed.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint diff --git a/flutter-ory-network/lib/entities/message.dart b/flutter-ory-network/lib/entities/message.dart index 25eea025..58ca045b 100644 --- a/flutter-ory-network/lib/entities/message.dart +++ b/flutter-ory-network/lib/entities/message.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + import 'package:freezed_annotation/freezed_annotation.dart'; part 'message.freezed.dart'; diff --git a/flutter-ory-network/lib/entities/message.freezed.dart b/flutter-ory-network/lib/entities/message.freezed.dart index c3637139..3e50f419 100644 --- a/flutter-ory-network/lib/entities/message.freezed.dart +++ b/flutter-ory-network/lib/entities/message.freezed.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint diff --git a/flutter-ory-network/lib/entities/message.g.dart b/flutter-ory-network/lib/entities/message.g.dart index d63f9eb2..d91445c9 100644 --- a/flutter-ory-network/lib/entities/message.g.dart +++ b/flutter-ory-network/lib/entities/message.g.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + // GENERATED CODE - DO NOT MODIFY BY HAND part of 'message.dart'; diff --git a/flutter-ory-network/lib/entities/node_attribute.dart b/flutter-ory-network/lib/entities/node_attribute.dart index e2e8b408..2e98d390 100644 --- a/flutter-ory-network/lib/entities/node_attribute.dart +++ b/flutter-ory-network/lib/entities/node_attribute.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + import 'package:freezed_annotation/freezed_annotation.dart'; part 'node_attribute.freezed.dart'; part 'node_attribute.g.dart'; diff --git a/flutter-ory-network/lib/entities/node_attribute.freezed.dart b/flutter-ory-network/lib/entities/node_attribute.freezed.dart index 72ddae2d..08432654 100644 --- a/flutter-ory-network/lib/entities/node_attribute.freezed.dart +++ b/flutter-ory-network/lib/entities/node_attribute.freezed.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint diff --git a/flutter-ory-network/lib/entities/node_attribute.g.dart b/flutter-ory-network/lib/entities/node_attribute.g.dart index 92cd7317..92070a72 100644 --- a/flutter-ory-network/lib/entities/node_attribute.g.dart +++ b/flutter-ory-network/lib/entities/node_attribute.g.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + // GENERATED CODE - DO NOT MODIFY BY HAND part of 'node_attribute.dart'; diff --git a/flutter-ory-network/lib/main.dart b/flutter-ory-network/lib/main.dart index c00fc05b..529da379 100644 --- a/flutter-ory-network/lib/main.dart +++ b/flutter-ory-network/lib/main.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + import 'package:dio/dio.dart'; import 'package:dio/io.dart'; import 'package:flutter/material.dart'; diff --git a/flutter-ory-network/lib/pages/entry.dart b/flutter-ory-network/lib/pages/entry.dart index 7c3c3a92..3a961ace 100644 --- a/flutter-ory-network/lib/pages/entry.dart +++ b/flutter-ory-network/lib/pages/entry.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + import 'package:flutter/material.dart'; class EntryPage extends StatelessWidget { diff --git a/flutter-ory-network/lib/pages/home.dart b/flutter-ory-network/lib/pages/home.dart index c654c2cf..0f18adc5 100644 --- a/flutter-ory-network/lib/pages/home.dart +++ b/flutter-ory-network/lib/pages/home.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:ory_client/ory_client.dart'; diff --git a/flutter-ory-network/lib/pages/login.dart b/flutter-ory-network/lib/pages/login.dart index 6880d493..ccfdb0cb 100644 --- a/flutter-ory-network/lib/pages/login.dart +++ b/flutter-ory-network/lib/pages/login.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; diff --git a/flutter-ory-network/lib/pages/registration.dart b/flutter-ory-network/lib/pages/registration.dart index 97efd3bc..54465942 100644 --- a/flutter-ory-network/lib/pages/registration.dart +++ b/flutter-ory-network/lib/pages/registration.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:ory_network_flutter/widgets/social_provider_box.dart'; diff --git a/flutter-ory-network/lib/repositories/auth.dart b/flutter-ory-network/lib/repositories/auth.dart index ce368489..85e03ad1 100644 --- a/flutter-ory-network/lib/repositories/auth.dart +++ b/flutter-ory-network/lib/repositories/auth.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + import 'package:ory_client/ory_client.dart'; import '../services/auth.dart'; diff --git a/flutter-ory-network/lib/services/auth.dart b/flutter-ory-network/lib/services/auth.dart index 5c757f32..2a65bb4e 100644 --- a/flutter-ory-network/lib/services/auth.dart +++ b/flutter-ory-network/lib/services/auth.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + import 'package:built_value/json_object.dart'; import 'package:dio/dio.dart'; import 'package:one_of/one_of.dart'; diff --git a/flutter-ory-network/lib/services/exceptions.dart b/flutter-ory-network/lib/services/exceptions.dart index 376df6ee..8f058d12 100644 --- a/flutter-ory-network/lib/services/exceptions.dart +++ b/flutter-ory-network/lib/services/exceptions.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + import 'package:flutter/foundation.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; diff --git a/flutter-ory-network/lib/services/exceptions.freezed.dart b/flutter-ory-network/lib/services/exceptions.freezed.dart index a9bdb662..08979de0 100644 --- a/flutter-ory-network/lib/services/exceptions.freezed.dart +++ b/flutter-ory-network/lib/services/exceptions.freezed.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint diff --git a/flutter-ory-network/lib/services/storage.dart b/flutter-ory-network/lib/services/storage.dart index cad86b14..615cda05 100644 --- a/flutter-ory-network/lib/services/storage.dart +++ b/flutter-ory-network/lib/services/storage.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + import 'package:flutter_secure_storage/flutter_secure_storage.dart'; class SecureStorage { diff --git a/flutter-ory-network/lib/widgets/ory_theme.dart b/flutter-ory-network/lib/widgets/ory_theme.dart index 1c4ed4fe..e9bf9778 100644 --- a/flutter-ory-network/lib/widgets/ory_theme.dart +++ b/flutter-ory-network/lib/widgets/ory_theme.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; diff --git a/flutter-ory-network/lib/widgets/social_provider_box.dart b/flutter-ory-network/lib/widgets/social_provider_box.dart index 7f31fe67..5c1e7884 100644 --- a/flutter-ory-network/lib/widgets/social_provider_box.dart +++ b/flutter-ory-network/lib/widgets/social_provider_box.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + import 'package:flutter/material.dart'; class SocialProviderBox extends StatelessWidget { diff --git a/flutter-ory-network/pubspec.yaml b/flutter-ory-network/pubspec.yaml index 9ff71305..42d5637f 100644 --- a/flutter-ory-network/pubspec.yaml +++ b/flutter-ory-network/pubspec.yaml @@ -2,7 +2,7 @@ name: ory_network_flutter description: A new Flutter project. # The following line prevents the package from being accidentally published to # pub.dev using `flutter pub publish`. This is preferred for private packages. -publish_to: 'none' # Remove this line if you wish to publish to pub.dev +publish_to: "none" # Remove this line if you wish to publish to pub.dev # The following defines the version and build number for your application. # A version number is three numbers separated by dots, like 1.2.43 @@ -19,7 +19,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev version: 1.0.0+1 environment: - sdk: '>=3.0.6 <4.0.0' + sdk: ">=3.0.6 <4.0.0" # Dependencies specify other packages that your package needs in order to work. # To automatically upgrade your package dependencies to the latest versions @@ -31,7 +31,6 @@ dependencies: flutter: sdk: flutter - # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.2 @@ -67,7 +66,6 @@ dev_dependencies: # The following section is specific to Flutter packages. flutter: - # The following line ensures that the Material Icons font is # included with your application, so that you can use the icons in # the material Icons class. @@ -79,7 +77,6 @@ flutter: - assets/images/ - assets/icons/ - # An image asset can refer to one or more resolution-specific "variants", see # https://flutter.dev/assets-and-images/#resolution-aware diff --git a/flutter-ory-network/test/widget_test.dart b/flutter-ory-network/test/widget_test.dart index 35bed1f9..8312ddf1 100644 --- a/flutter-ory-network/test/widget_test.dart +++ b/flutter-ory-network/test/widget_test.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + // This is a basic Flutter widget test. // // To perform an interaction with a widget in your test, use the WidgetTester From 3cf26b017e91280ff6b156bd481ddbba229162b4 Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Mon, 4 Sep 2023 10:03:02 +0200 Subject: [PATCH 15/57] refactor: add missing package and delete unused test --- flutter-ory-network/pubspec.lock | 6 ++--- flutter-ory-network/pubspec.yaml | 1 + flutter-ory-network/test/widget_test.dart | 33 ----------------------- 3 files changed, 4 insertions(+), 36 deletions(-) delete mode 100644 flutter-ory-network/test/widget_test.dart diff --git a/flutter-ory-network/pubspec.lock b/flutter-ory-network/pubspec.lock index 85398bad..642803c1 100644 --- a/flutter-ory-network/pubspec.lock +++ b/flutter-ory-network/pubspec.lock @@ -106,13 +106,13 @@ packages: source: hosted version: "5.1.1" built_value: - dependency: transitive + dependency: "direct main" description: name: built_value - sha256: "598a2a682e2a7a90f08ba39c0aaa9374c5112340f0a2e275f61b59389543d166" + sha256: ff627b645b28fb8bdb69e645f910c2458fd6b65f6585c3a53e0626024897dedf url: "https://pub.dev" source: hosted - version: "8.6.1" + version: "8.6.2" characters: dependency: transitive description: diff --git a/flutter-ory-network/pubspec.yaml b/flutter-ory-network/pubspec.yaml index 42d5637f..2484a842 100644 --- a/flutter-ory-network/pubspec.yaml +++ b/flutter-ory-network/pubspec.yaml @@ -46,6 +46,7 @@ dependencies: flutter_secure_storage: ^8.0.0 dotenv: ^4.1.0 google_fonts: ^5.1.0 + built_value: ^8.6.2 dev_dependencies: flutter_test: diff --git a/flutter-ory-network/test/widget_test.dart b/flutter-ory-network/test/widget_test.dart deleted file mode 100644 index 8312ddf1..00000000 --- a/flutter-ory-network/test/widget_test.dart +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright © 2023 Ory Corp -// SPDX-License-Identifier: Apache-2.0 - -// This is a basic Flutter widget test. -// -// To perform an interaction with a widget in your test, use the WidgetTester -// utility in the flutter_test package. For example, you can send tap and scroll -// gestures. You can also use WidgetTester to find child widgets in the widget -// tree, read text, and verify that the values of widget properties are correct. - -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; - -import 'package:ory_network_flutter/main.dart'; - -void main() { - testWidgets('Counter increments smoke test', (WidgetTester tester) async { - // Build our app and trigger a frame. - await tester.pumpWidget(const MyApp()); - - // Verify that our counter starts at 0. - expect(find.text('0'), findsOneWidget); - expect(find.text('1'), findsNothing); - - // Tap the '+' icon and trigger a frame. - await tester.tap(find.byIcon(Icons.add)); - await tester.pump(); - - // Verify that our counter has incremented. - expect(find.text('0'), findsNothing); - expect(find.text('1'), findsOneWidget); - }); -} From 2f30a6f89efba19fd241378d8af1533681bbb8d5 Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Wed, 6 Sep 2023 14:59:50 +0200 Subject: [PATCH 16/57] feat: change password in settings --- flutter-ory-network/assets/icons/settings.png | Bin 0 -> 441 bytes .../lib/blocs/auth/auth_bloc.dart | 7 +- .../lib/blocs/settings/settings_bloc.dart | 117 +++++++ .../blocs/settings/settings_bloc.freezed.dart | 254 ++++++++++++++ .../lib/blocs/settings/settings_event.dart | 40 +++ .../lib/blocs/settings/settings_state.dart | 14 + flutter-ory-network/lib/entities/message.dart | 19 +- .../lib/entities/message.freezed.dart | 35 +- .../lib/entities/message.g.dart | 2 +- flutter-ory-network/lib/pages/home.dart | 9 +- flutter-ory-network/lib/pages/settings.dart | 208 +++++++++++ .../lib/repositories/auth.dart | 4 + .../lib/repositories/settings.dart | 24 ++ flutter-ory-network/lib/services/auth.dart | 139 +++++++- .../lib/services/exceptions.dart | 7 +- .../lib/services/exceptions.freezed.dart | 329 +++++++++++++++--- flutter-ory-network/pubspec.lock | 8 +- flutter-ory-network/pubspec.yaml | 2 + 18 files changed, 1131 insertions(+), 87 deletions(-) create mode 100644 flutter-ory-network/assets/icons/settings.png create mode 100644 flutter-ory-network/lib/blocs/settings/settings_bloc.dart create mode 100644 flutter-ory-network/lib/blocs/settings/settings_bloc.freezed.dart create mode 100644 flutter-ory-network/lib/blocs/settings/settings_event.dart create mode 100644 flutter-ory-network/lib/blocs/settings/settings_state.dart create mode 100644 flutter-ory-network/lib/pages/settings.dart create mode 100644 flutter-ory-network/lib/repositories/settings.dart diff --git a/flutter-ory-network/assets/icons/settings.png b/flutter-ory-network/assets/icons/settings.png new file mode 100644 index 0000000000000000000000000000000000000000..129b40c92977b1b249ace1aff1eb90327b9eb9c3 GIT binary patch literal 441 zcmV;q0Y?6bP)X1^@s6D=Y3@00009a7bBm000XU z000XU0RWnu7ytkO0drDELIAGL9O(c600d`2O+f$vv5yPb)7TVwEa=3PkKsw z-}c=ZICWg242IuN904oGkzC=xFph)coRlQj*aK4GhCy3?>p;JxtYNYZ3QlE%Y7K)~ z#qNeWL%t;JCa4^Hl%r$PKjH6quILQ5la%E%OBic`ds41qKswQ{xML-C6kGyUfy_5K z3|Lc^Y<8tMd3meYcT9w+7&+ljFJ_VQ$?;urdczd2N-=B3PGSX!jt js=Xk={d;6_#-Z>9j+s)cFnPF000000NkvXXu0mjf=pwDz literal 0 HcmV?d00001 diff --git a/flutter-ory-network/lib/blocs/auth/auth_bloc.dart b/flutter-ory-network/lib/blocs/auth/auth_bloc.dart index 6da7be0d..aa89cc20 100644 --- a/flutter-ory-network/lib/blocs/auth/auth_bloc.dart +++ b/flutter-ory-network/lib/blocs/auth/auth_bloc.dart @@ -22,7 +22,12 @@ class AuthBloc extends Bloc { on(_logOut); } - _changeAuthStatus(ChangeAuthStatus event, Emitter emit) { + Future _changeAuthStatus( + ChangeAuthStatus event, Emitter emit) async { + // if user auth status is changed to unauthenticated, remove old session token + if (event.status == AuthStatus.unauthenticated) { + await repository.deleteExpiredSessionToken(); + } emit(state.copyWith(status: event.status, isLoading: false)); } diff --git a/flutter-ory-network/lib/blocs/settings/settings_bloc.dart b/flutter-ory-network/lib/blocs/settings/settings_bloc.dart new file mode 100644 index 00000000..e23580a2 --- /dev/null +++ b/flutter-ory-network/lib/blocs/settings/settings_bloc.dart @@ -0,0 +1,117 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + +import 'package:bloc/bloc.dart'; +import 'package:equatable/equatable.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:collection/collection.dart'; +import 'package:ory_network_flutter/entities/message.dart'; +import 'package:ory_network_flutter/repositories/auth.dart'; + +import '../../entities/formfield.dart'; +import '../../repositories/settings.dart'; +import '../../services/exceptions.dart'; +import '../auth/auth_bloc.dart'; + +part 'settings_event.dart'; +part 'settings_state.dart'; + +part 'settings_bloc.freezed.dart'; + +class SettingsBloc extends Bloc { + final AuthBloc authBloc; + final SettingsRepository repository; + SettingsBloc({required this.authBloc, required this.repository}) + : super(SettingsState()) { + on(_onCreateSettingsFlow); + on(_onChangePassword); + on(_onChangePasswordVisibility); + on(_onSubmitNewPassword); + } + _onChangePassword(ChangePassword event, Emitter emit) { + // remove password and general error when changing email + emit(state.copyWith + .password(value: event.value, errorMessage: null) + .copyWith(message: null)); + } + + _onChangePasswordVisibility( + ChangePasswordVisibility event, Emitter emit) { + emit(state.copyWith(isPasswordHidden: event.value)); + } + + Future _onCreateSettingsFlow( + SettingsEvent event, Emitter emit) async { + try { + emit(state.copyWith(isLoading: true, message: null)); + + final flowId = await repository.createSettingsFlow(); + + emit(state.copyWith(isLoading: false, flowId: flowId)); + } on CustomException catch (e) { + if (e case UnauthorizedException _) { + // change auth status as the user is not authenticated + authBloc.add(ChangeAuthStatus(status: AuthStatus.unauthenticated)); + } else if (e case UnknownException _) { + emit(state.copyWith( + isLoading: false, + message: NodeMessage(text: e.message, type: MessageType.error))); + } else { + emit(state.copyWith(isLoading: false)); + } + } + } + + Future _onSubmitNewPassword( + SubmitNewPassword event, Emitter emit) async { + try { + emit(state + .copyWith(isLoading: true, message: null) + .copyWith + .password(errorMessage: null)); + + final messages = await repository.submitNewPassword( + flowId: event.flowId, password: event.value); + + // password was successfully changed, reset password field and show general message. + // for simplicity, only the first general message is shown in ui + emit(state + .copyWith(isLoading: false, message: messages?.first) + .copyWith + .password(value: '')); + } on CustomException catch (e) { + if (e case UnauthorizedException _) { + // change auth status as the user is not authenticated + authBloc.add(ChangeAuthStatus(status: AuthStatus.unauthenticated)); + } else if (e case BadRequestException _) { + // get input and general errors. + // for simplicity, only first messages of a specific context are shown in ui + final passwordMessage = e.messages + ?.firstWhereOrNull((element) => element.attr == 'password'); + final generalMessage = e.messages + ?.firstWhereOrNull((element) => element.attr == 'general'); + + // update state to new one with errors + emit(state + .copyWith(isLoading: false, message: generalMessage) + .copyWith + .password(errorMessage: passwordMessage?.text)); + } else if (e case FlowExpiredException _) { + // use new flow id, reset fields and show error + emit(state + .copyWith( + flowId: e.flowId, + message: NodeMessage(text: e.message, type: MessageType.error), + isLoading: false) + .copyWith + .password(value: '')); + } else if (e case UnknownException _) { + emit(state.copyWith( + isLoading: false, + message: NodeMessage(text: e.message, type: MessageType.error))); + } else { + emit(state.copyWith(isLoading: false)); + } + } + } +} diff --git a/flutter-ory-network/lib/blocs/settings/settings_bloc.freezed.dart b/flutter-ory-network/lib/blocs/settings/settings_bloc.freezed.dart new file mode 100644 index 00000000..4c60226d --- /dev/null +++ b/flutter-ory-network/lib/blocs/settings/settings_bloc.freezed.dart @@ -0,0 +1,254 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'settings_bloc.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +mixin _$SettingsState { + String? get flowId => throw _privateConstructorUsedError; + FormField get password => throw _privateConstructorUsedError; + bool get isPasswordHidden => throw _privateConstructorUsedError; + bool get isLoading => throw _privateConstructorUsedError; + NodeMessage? get message => throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $SettingsStateCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $SettingsStateCopyWith<$Res> { + factory $SettingsStateCopyWith( + SettingsState value, $Res Function(SettingsState) then) = + _$SettingsStateCopyWithImpl<$Res, SettingsState>; + @useResult + $Res call( + {String? flowId, + FormField password, + bool isPasswordHidden, + bool isLoading, + NodeMessage? message}); + + $FormFieldCopyWith get password; + $NodeMessageCopyWith<$Res>? get message; +} + +/// @nodoc +class _$SettingsStateCopyWithImpl<$Res, $Val extends SettingsState> + implements $SettingsStateCopyWith<$Res> { + _$SettingsStateCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? flowId = freezed, + Object? password = null, + Object? isPasswordHidden = null, + Object? isLoading = null, + Object? message = freezed, + }) { + return _then(_value.copyWith( + flowId: freezed == flowId + ? _value.flowId + : flowId // ignore: cast_nullable_to_non_nullable + as String?, + password: null == password + ? _value.password + : password // ignore: cast_nullable_to_non_nullable + as FormField, + isPasswordHidden: null == isPasswordHidden + ? _value.isPasswordHidden + : isPasswordHidden // ignore: cast_nullable_to_non_nullable + as bool, + isLoading: null == isLoading + ? _value.isLoading + : isLoading // ignore: cast_nullable_to_non_nullable + as bool, + message: freezed == message + ? _value.message + : message // ignore: cast_nullable_to_non_nullable + as NodeMessage?, + ) as $Val); + } + + @override + @pragma('vm:prefer-inline') + $FormFieldCopyWith get password { + return $FormFieldCopyWith(_value.password, (value) { + return _then(_value.copyWith(password: value) as $Val); + }); + } + + @override + @pragma('vm:prefer-inline') + $NodeMessageCopyWith<$Res>? get message { + if (_value.message == null) { + return null; + } + + return $NodeMessageCopyWith<$Res>(_value.message!, (value) { + return _then(_value.copyWith(message: value) as $Val); + }); + } +} + +/// @nodoc +abstract class _$$_SettingsStateCopyWith<$Res> + implements $SettingsStateCopyWith<$Res> { + factory _$$_SettingsStateCopyWith( + _$_SettingsState value, $Res Function(_$_SettingsState) then) = + __$$_SettingsStateCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {String? flowId, + FormField password, + bool isPasswordHidden, + bool isLoading, + NodeMessage? message}); + + @override + $FormFieldCopyWith get password; + @override + $NodeMessageCopyWith<$Res>? get message; +} + +/// @nodoc +class __$$_SettingsStateCopyWithImpl<$Res> + extends _$SettingsStateCopyWithImpl<$Res, _$_SettingsState> + implements _$$_SettingsStateCopyWith<$Res> { + __$$_SettingsStateCopyWithImpl( + _$_SettingsState _value, $Res Function(_$_SettingsState) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? flowId = freezed, + Object? password = null, + Object? isPasswordHidden = null, + Object? isLoading = null, + Object? message = freezed, + }) { + return _then(_$_SettingsState( + flowId: freezed == flowId + ? _value.flowId + : flowId // ignore: cast_nullable_to_non_nullable + as String?, + password: null == password + ? _value.password + : password // ignore: cast_nullable_to_non_nullable + as FormField, + isPasswordHidden: null == isPasswordHidden + ? _value.isPasswordHidden + : isPasswordHidden // ignore: cast_nullable_to_non_nullable + as bool, + isLoading: null == isLoading + ? _value.isLoading + : isLoading // ignore: cast_nullable_to_non_nullable + as bool, + message: freezed == message + ? _value.message + : message // ignore: cast_nullable_to_non_nullable + as NodeMessage?, + )); + } +} + +/// @nodoc + +class _$_SettingsState implements _SettingsState { + const _$_SettingsState( + {this.flowId, + this.password = const FormField(value: ''), + this.isPasswordHidden = true, + this.isLoading = false, + this.message}); + + @override + final String? flowId; + @override + @JsonKey() + final FormField password; + @override + @JsonKey() + final bool isPasswordHidden; + @override + @JsonKey() + final bool isLoading; + @override + final NodeMessage? message; + + @override + String toString() { + return 'SettingsState(flowId: $flowId, password: $password, isPasswordHidden: $isPasswordHidden, isLoading: $isLoading, message: $message)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$_SettingsState && + (identical(other.flowId, flowId) || other.flowId == flowId) && + (identical(other.password, password) || + other.password == password) && + (identical(other.isPasswordHidden, isPasswordHidden) || + other.isPasswordHidden == isPasswordHidden) && + (identical(other.isLoading, isLoading) || + other.isLoading == isLoading) && + (identical(other.message, message) || other.message == message)); + } + + @override + int get hashCode => Object.hash( + runtimeType, flowId, password, isPasswordHidden, isLoading, message); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$_SettingsStateCopyWith<_$_SettingsState> get copyWith => + __$$_SettingsStateCopyWithImpl<_$_SettingsState>(this, _$identity); +} + +abstract class _SettingsState implements SettingsState { + const factory _SettingsState( + {final String? flowId, + final FormField password, + final bool isPasswordHidden, + final bool isLoading, + final NodeMessage? message}) = _$_SettingsState; + + @override + String? get flowId; + @override + FormField get password; + @override + bool get isPasswordHidden; + @override + bool get isLoading; + @override + NodeMessage? get message; + @override + @JsonKey(ignore: true) + _$$_SettingsStateCopyWith<_$_SettingsState> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/flutter-ory-network/lib/blocs/settings/settings_event.dart b/flutter-ory-network/lib/blocs/settings/settings_event.dart new file mode 100644 index 00000000..c619b856 --- /dev/null +++ b/flutter-ory-network/lib/blocs/settings/settings_event.dart @@ -0,0 +1,40 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + +part of 'settings_bloc.dart'; + +@immutable +sealed class SettingsEvent extends Equatable { + @override + List get props => []; +} + +final class CreateSettingsFlow extends SettingsEvent {} + +final class ChangePassword extends SettingsEvent { + final String value; + + ChangePassword({required this.value}); + + @override + List get props => [value]; +} + +final class ChangePasswordVisibility extends SettingsEvent { + final bool value; + + ChangePasswordVisibility({required this.value}); + + @override + List get props => [value]; +} + +final class SubmitNewPassword extends SettingsEvent { + final String flowId; + final String value; + + SubmitNewPassword({required this.flowId, required this.value}); + + @override + List get props => [flowId, value]; +} diff --git a/flutter-ory-network/lib/blocs/settings/settings_state.dart b/flutter-ory-network/lib/blocs/settings/settings_state.dart new file mode 100644 index 00000000..e567d3f6 --- /dev/null +++ b/flutter-ory-network/lib/blocs/settings/settings_state.dart @@ -0,0 +1,14 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + +part of 'settings_bloc.dart'; + +@freezed +sealed class SettingsState with _$SettingsState { + const factory SettingsState( + {String? flowId, + @Default(FormField(value: '')) FormField password, + @Default(true) bool isPasswordHidden, + @Default(false) bool isLoading, + NodeMessage? message}) = _SettingsState; +} diff --git a/flutter-ory-network/lib/entities/message.dart b/flutter-ory-network/lib/entities/message.dart index 58ca045b..fcee0b3c 100644 --- a/flutter-ory-network/lib/entities/message.dart +++ b/flutter-ory-network/lib/entities/message.dart @@ -9,9 +9,10 @@ part 'message.g.dart'; @freezed class NodeMessage with _$NodeMessage { const factory NodeMessage( - {required int id, + {int? id, required String text, required MessageType type, + // allows to differentiate between contexts @Default('general') String attr}) = _NodeMessage; factory NodeMessage.fromJson(Map json) => @@ -20,3 +21,19 @@ class NodeMessage with _$NodeMessage { // specifies message type enum MessageType { info, error, success } + +// extension to convert string to enum value +extension MessageTypeExtension on String { + MessageType get messageType { + switch (this) { + case 'info': + return MessageType.info; + case 'error': + return MessageType.error; + case 'success': + return MessageType.success; + default: + return MessageType.info; + } + } +} diff --git a/flutter-ory-network/lib/entities/message.freezed.dart b/flutter-ory-network/lib/entities/message.freezed.dart index 3e50f419..11ded8db 100644 --- a/flutter-ory-network/lib/entities/message.freezed.dart +++ b/flutter-ory-network/lib/entities/message.freezed.dart @@ -23,9 +23,10 @@ NodeMessage _$NodeMessageFromJson(Map json) { /// @nodoc mixin _$NodeMessage { - int get id => throw _privateConstructorUsedError; + int? get id => throw _privateConstructorUsedError; String get text => throw _privateConstructorUsedError; - MessageType get type => throw _privateConstructorUsedError; + MessageType get type => + throw _privateConstructorUsedError; // allows to differentiate between contexts String get attr => throw _privateConstructorUsedError; Map toJson() => throw _privateConstructorUsedError; @@ -40,7 +41,7 @@ abstract class $NodeMessageCopyWith<$Res> { NodeMessage value, $Res Function(NodeMessage) then) = _$NodeMessageCopyWithImpl<$Res, NodeMessage>; @useResult - $Res call({int id, String text, MessageType type, String attr}); + $Res call({int? id, String text, MessageType type, String attr}); } /// @nodoc @@ -56,16 +57,16 @@ class _$NodeMessageCopyWithImpl<$Res, $Val extends NodeMessage> @pragma('vm:prefer-inline') @override $Res call({ - Object? id = null, + Object? id = freezed, Object? text = null, Object? type = null, Object? attr = null, }) { return _then(_value.copyWith( - id: null == id + id: freezed == id ? _value.id : id // ignore: cast_nullable_to_non_nullable - as int, + as int?, text: null == text ? _value.text : text // ignore: cast_nullable_to_non_nullable @@ -90,7 +91,7 @@ abstract class _$$_NodeMessageCopyWith<$Res> __$$_NodeMessageCopyWithImpl<$Res>; @override @useResult - $Res call({int id, String text, MessageType type, String attr}); + $Res call({int? id, String text, MessageType type, String attr}); } /// @nodoc @@ -104,16 +105,16 @@ class __$$_NodeMessageCopyWithImpl<$Res> @pragma('vm:prefer-inline') @override $Res call({ - Object? id = null, + Object? id = freezed, Object? text = null, Object? type = null, Object? attr = null, }) { return _then(_$_NodeMessage( - id: null == id + id: freezed == id ? _value.id : id // ignore: cast_nullable_to_non_nullable - as int, + as int?, text: null == text ? _value.text : text // ignore: cast_nullable_to_non_nullable @@ -134,20 +135,18 @@ class __$$_NodeMessageCopyWithImpl<$Res> @JsonSerializable() class _$_NodeMessage implements _NodeMessage { const _$_NodeMessage( - {required this.id, - required this.text, - required this.type, - this.attr = 'general'}); + {this.id, required this.text, required this.type, this.attr = 'general'}); factory _$_NodeMessage.fromJson(Map json) => _$$_NodeMessageFromJson(json); @override - final int id; + final int? id; @override final String text; @override final MessageType type; +// allows to differentiate between contexts @override @JsonKey() final String attr; @@ -188,7 +187,7 @@ class _$_NodeMessage implements _NodeMessage { abstract class _NodeMessage implements NodeMessage { const factory _NodeMessage( - {required final int id, + {final int? id, required final String text, required final MessageType type, final String attr}) = _$_NodeMessage; @@ -197,12 +196,12 @@ abstract class _NodeMessage implements NodeMessage { _$_NodeMessage.fromJson; @override - int get id; + int? get id; @override String get text; @override MessageType get type; - @override + @override // allows to differentiate between contexts String get attr; @override @JsonKey(ignore: true) diff --git a/flutter-ory-network/lib/entities/message.g.dart b/flutter-ory-network/lib/entities/message.g.dart index d91445c9..cdedc72c 100644 --- a/flutter-ory-network/lib/entities/message.g.dart +++ b/flutter-ory-network/lib/entities/message.g.dart @@ -11,7 +11,7 @@ part of 'message.dart'; _$_NodeMessage _$$_NodeMessageFromJson(Map json) => _$_NodeMessage( - id: json['id'] as int, + id: json['id'] as int?, text: json['text'] as String, type: $enumDecode(_$MessageTypeEnumMap, json['type']), attr: json['attr'] as String? ?? 'general', diff --git a/flutter-ory-network/lib/pages/home.dart b/flutter-ory-network/lib/pages/home.dart index 0f18adc5..e8372194 100644 --- a/flutter-ory-network/lib/pages/home.dart +++ b/flutter-ory-network/lib/pages/home.dart @@ -4,6 +4,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:ory_client/ory_client.dart'; +import 'package:ory_network_flutter/pages/settings.dart'; import '../blocs/auth/auth_bloc.dart'; @@ -36,8 +37,14 @@ class _HomePageState extends State { width: 40, ), elevation: 0, - //shape: Border(bottom: BorderSide(color: Colors.green, width: 1)), actions: [ + IconButton( + onPressed: () => Navigator.push( + context, + MaterialPageRoute( + builder: (context) => const SettingsPage())), + icon: Image.asset('assets/icons/settings.png'), + ), // if auth is loading, show progress indicator, otherwise a logout icon isLoading ? const Padding( diff --git a/flutter-ory-network/lib/pages/settings.dart b/flutter-ory-network/lib/pages/settings.dart new file mode 100644 index 00000000..9ad23af8 --- /dev/null +++ b/flutter-ory-network/lib/pages/settings.dart @@ -0,0 +1,208 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:ory_network_flutter/entities/message.dart'; +import 'package:ory_network_flutter/repositories/settings.dart'; + +import '../blocs/auth/auth_bloc.dart'; +import '../blocs/settings/settings_bloc.dart'; +import '../repositories/auth.dart'; + +class SettingsPage extends StatelessWidget { + const SettingsPage({super.key}); + + @override + Widget build(BuildContext context) { + final service = RepositoryProvider.of(context).service; + return Scaffold( + appBar: AppBar( + backgroundColor: Colors.transparent, + elevation: 0, + leadingWidth: 72, + toolbarHeight: 72, + // use row to avoid force resizing of leading widget + leading: Row( + children: [ + Padding( + padding: const EdgeInsets.only(left: 32, top: 32), + child: GestureDetector( + onTap: () => Navigator.of(context).pop(), + child: Container( + height: 40, + width: 40, + padding: const EdgeInsets.all(12), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(4), + border: Border.all( + width: 1, color: const Color(0xFFE2E8F0))), + child: const Icon(Icons.arrow_back, size: 16), + ), + ), + ), + ], + )), + body: BlocProvider( + create: (context) => SettingsBloc( + authBloc: context.read(), + repository: SettingsRepository(service: service)) + ..add(CreateSettingsFlow()), + child: const SettingsForm()), + ); + } +} + +class SettingsForm extends StatefulWidget { + const SettingsForm({super.key}); + + @override + State createState() => _SettingsFormState(); +} + +class _SettingsFormState extends State { + final passwordController = TextEditingController(); + + @override + Widget build(BuildContext context) { + final settingsBloc = BlocProvider.of(context); + return BlocConsumer( + bloc: settingsBloc, + // listen to password changes + listenWhen: (previous, current) { + return previous.password.value != current.password.value && + passwordController.text != current.password.value; + }, + // if password value has changed, update text controller value + listener: (BuildContext context, SettingsState state) { + passwordController.text = state.password.value; + }, + builder: (context, state) { + // settings flow was created + if (state.flowId != null) { + return _buildSettingsForm(context, state); + } // otherwise, show loading or error + else { + return _buildSettingsFlowNotCreated(context, state); + } + }); + } + + _getMessageColor(MessageType type) { + switch (type) { + case MessageType.success: + return Colors.green; + case MessageType.error: + return Colors.red; + case MessageType.info: + return Colors.grey; + } + } + + _buildSettingsFlowNotCreated(BuildContext context, SettingsState state) { + if (state.message != null) { + return Center( + child: Text( + state.message!.text, + style: TextStyle(color: _getMessageColor(state.message!.type)), + )); + } else { + return const Center(child: CircularProgressIndicator()); + } + } + + _buildSettingsForm(BuildContext context, SettingsState state) { + return Padding( + padding: const EdgeInsets.symmetric(horizontal: 32), + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const SizedBox( + height: 32, + ), + const Text('Set a new password', + style: TextStyle( + fontWeight: FontWeight.w600, height: 1.5, fontSize: 18)), + const Text( + 'The key aspects of a strong password are length, varying characters, no ties to your personal information and no dictionary words.'), + const SizedBox( + height: 32, + ), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text('New password'), + const SizedBox( + height: 4, + ), + TextFormField( + enabled: !state.isLoading, + controller: passwordController, + onChanged: (String value) => context + .read() + .add(ChangePassword(value: value)), + obscureText: state.isPasswordHidden, + decoration: InputDecoration( + border: const OutlineInputBorder(), + hintText: 'Enter a password', + // change password visibility + suffixIcon: GestureDetector( + onTap: () => context.read().add( + ChangePasswordVisibility( + value: !state.isPasswordHidden)), + child: ImageIcon( + state.isPasswordHidden + ? const AssetImage('assets/icons/eye.png') + : const AssetImage('assets/icons/eye-off.png'), + size: 16, + ), + ), + errorText: state.password.errorMessage, + errorMaxLines: 3), + ), + ], + ), + const SizedBox( + height: 32, + ), + // show general error message if it exists + if (state.message != null) + Padding( + padding: const EdgeInsets.only(bottom: 15.0), + child: Text( + state.message!.text, + style: + TextStyle(color: _getMessageColor(state.message!.type)), + maxLines: 3, + ), + ), + + // show loading indicator when state is in a loading mode + if (state.isLoading) + const Padding( + padding: EdgeInsets.all(15.0), + child: Center( + child: SizedBox( + width: 30, + height: 30, + child: CircularProgressIndicator())), + ), + SizedBox( + width: double.infinity, + child: FilledButton( + // disable button when state is loading + onPressed: state.isLoading + ? null + : () { + context.read().add(SubmitNewPassword( + flowId: state.flowId!, + value: state.password.value)); + }, + child: const Text('Submit'), + ), + ), + ]), + ); + } +} diff --git a/flutter-ory-network/lib/repositories/auth.dart b/flutter-ory-network/lib/repositories/auth.dart index 85e03ad1..55182f03 100644 --- a/flutter-ory-network/lib/repositories/auth.dart +++ b/flutter-ory-network/lib/repositories/auth.dart @@ -12,6 +12,10 @@ class AuthRepository { AuthRepository({required this.service}); + Future deleteExpiredSessionToken() async { + await service.deleteExpiredSessionToken(); + } + Future getCurrentSessionInformation() async { final session = await service.getCurrentSessionInformation(); return session; diff --git a/flutter-ory-network/lib/repositories/settings.dart b/flutter-ory-network/lib/repositories/settings.dart new file mode 100644 index 00000000..7a01d6d0 --- /dev/null +++ b/flutter-ory-network/lib/repositories/settings.dart @@ -0,0 +1,24 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + +import 'package:ory_network_flutter/entities/message.dart'; + +import '../services/auth.dart'; + +class SettingsRepository { + final AuthService service; + + SettingsRepository({required this.service}); + + Future createSettingsFlow() async { + final flowId = await service.createSettingsFlow(); + return flowId; + } + + Future?> submitNewPassword( + {required String flowId, required String password}) async { + final messages = + await service.submitNewPassword(flowId: flowId, password: password); + return messages; + } +} diff --git a/flutter-ory-network/lib/services/auth.dart b/flutter-ory-network/lib/services/auth.dart index 2a65bb4e..d68be22b 100644 --- a/flutter-ory-network/lib/services/auth.dart +++ b/flutter-ory-network/lib/services/auth.dart @@ -5,21 +5,25 @@ import 'package:built_value/json_object.dart'; import 'package:dio/dio.dart'; import 'package:one_of/one_of.dart'; import 'package:ory_client/ory_client.dart'; - import '../entities/form_node.dart'; import 'exceptions.dart'; import '../entities/message.dart'; import 'storage.dart'; class AuthService { - final storage = SecureStorage(); + final _storage = SecureStorage(); final FrontendApi _ory; AuthService(Dio dio) : _ory = OryClient(dio: dio).getFrontendApi(); + /// Delete expired session token from storage + Future deleteExpiredSessionToken() async { + await _storage.deleteToken(); + } + /// Get current session information Future getCurrentSessionInformation() async { try { - final token = await storage.getToken(); + final token = await _storage.getToken(); final response = await _ory.toSession(xSessionToken: token); if (response.data != null) { // return session @@ -29,7 +33,7 @@ class AuthService { } } on DioException catch (e) { if (e.response?.statusCode == 401) { - await storage.deleteToken(); + await _storage.deleteToken(); throw const CustomException.unauthorized(); } else { throw _handleUnknownException(e.response?.data); @@ -86,14 +90,14 @@ class AuthService { if (response.data?.session != null) { // save session token after successful login - await storage.persistToken(response.data!.sessionToken!); + await _storage.persistToken(response.data!.sessionToken!); return; } else { throw const CustomException.unknown(); } } on DioException catch (e) { if (e.response?.statusCode == 401) { - await storage.deleteToken(); + await _storage.deleteToken(); throw const CustomException.unauthorized(); } else if (e.response?.statusCode == 400) { final messages = _checkFormForErrors(e.response?.data); @@ -127,14 +131,14 @@ class AuthService { (b) => b..oneOf = OneOf.fromValue1(value: registrationFLow))); if (response.data?.sessionToken != null) { // save session token after successful login - await storage.persistToken(response.data!.sessionToken!); + await _storage.persistToken(response.data!.sessionToken!); return; } else { throw const CustomException.unknown(); } } on DioException catch (e) { if (e.response?.statusCode == 401) { - await storage.deleteToken(); + await _storage.deleteToken(); throw const CustomException.unauthorized(); } else if (e.response?.statusCode == 400) { final messages = _checkFormForErrors(e.response?.data); @@ -151,22 +155,127 @@ class AuthService { } } + /// Log out Future logout() async { try { - final token = await storage.getToken(); + final token = await _storage.getToken(); final PerformNativeLogoutBody logoutBody = PerformNativeLogoutBody((b) => b..sessionToken = token); final response = await _ory.performNativeLogout(performNativeLogoutBody: logoutBody); if (response.statusCode == 204) { - await storage.deleteToken(); + await _storage.deleteToken(); return; } } on DioException catch (e) { if (e.response?.statusCode == 401) { - await storage.deleteToken(); + await _storage.deleteToken(); + throw const CustomException.unauthorized(); + } else { + throw _handleUnknownException(e.response?.data); + } + } + } + + /// Create settings flow + Future createSettingsFlow() async { + try { + final token = await _storage.getToken(); + final response = + await _ory.createNativeSettingsFlow(xSessionToken: token); + + if (response.data != null) { + // return flow id + return response.data!.id; + } else { + throw const CustomException.unknown(); + } + } on DioException catch (e) { + if (e.response?.statusCode == 401) { + await _storage.deleteToken(); + throw const CustomException.unauthorized(); + } else { + throw _handleUnknownException(e.response?.data); + } + } + } + + /// Change old password to new [password] using settings flow with [flowId] + Future?> submitNewPassword( + {required String flowId, required String password}) async { + try { + final token = await _storage.getToken(); + final UpdateSettingsFlowWithPasswordMethod body = + UpdateSettingsFlowWithPasswordMethod((b) => b + ..method = 'password' + ..password = password); + + final response = await _ory.updateSettingsFlow( + flow: flowId, + xSessionToken: token, + updateSettingsFlowBody: UpdateSettingsFlowBody( + (b) => b..oneOf = OneOf.fromValue1(value: body))); + if (response.statusCode == 400) { + // get input nodes with messages + final inputNodesWithMessages = response.data?.ui.nodes + .asList() + .where((e) => + e.attributes.oneOf.isType(UiNodeInputAttributes) && + e.messages.isNotEmpty) + .toList(); + + // get input node messages + final nodeMessages = inputNodesWithMessages + ?.map((node) => node.messages + .asList() + .map((msg) => NodeMessage( + id: msg.id, + text: msg.text, + type: msg.type.name.messageType, + attr: (node.attributes.oneOf.value as UiNodeInputAttributes) + .name)) + .toList()) + .toList(); + + // get general messages + final generalMessages = response.data?.ui.messages + ?.asList() + .map((e) => NodeMessage( + id: e.id, text: e.text, type: e.type.name.messageType)) + .toList(); + + // add general messages to input node messages if they exist + if (generalMessages != null) { + nodeMessages?.add(generalMessages); + } + + // flatten message list + final flattedNodeMessages = + nodeMessages?.expand((element) => element).toList(); + + throw CustomException.badRequest(messages: flattedNodeMessages); + } + + // get messages on success + final messages = response.data?.ui.messages + ?.asList() + .map((msg) => NodeMessage( + id: msg.id, text: msg.text, type: msg.type.name.messageType)) + .toList(); + return messages; + } on DioException catch (e) { + if (e.response?.statusCode == 401) { + await _storage.deleteToken(); throw const CustomException.unauthorized(); + } else if (e.response?.statusCode == 403) { + throw const CustomException.sessionRefreshRequired(); + } else if (e.response?.statusCode == 410) { + // settings flow expired, use new flow id and add error message + throw CustomException.flowExpired( + flowId: e.response?.data['use_flow_id'], + message: + 'Settings flow has expired. Please enter credentials again.'); } else { throw _handleUnknownException(e.response?.data); } @@ -207,9 +316,11 @@ class AuthService { } CustomException _handleUnknownException(Map? response) { - // use error message if response contains it, otherwise use default value - if (response != null && response.containsKey('error')) { - return CustomException.unknown(message: response['error']['message']); + // use human-readable reason if response contains it, otherwise use default value + if (response != null && + response.containsKey('error') && + (response['error'] as Map).containsKey('reason')) { + return CustomException.unknown(message: response['error']['reason']); } else { return const CustomException.unknown(); } diff --git a/flutter-ory-network/lib/services/exceptions.dart b/flutter-ory-network/lib/services/exceptions.dart index 8f058d12..8fc9e91f 100644 --- a/flutter-ory-network/lib/services/exceptions.dart +++ b/flutter-ory-network/lib/services/exceptions.dart @@ -16,11 +16,14 @@ sealed class CustomException with _$CustomException { @Default(400) int statusCode}) = BadRequestException; const factory CustomException.unauthorized({@Default(401) int statusCode}) = UnauthorizedException; + const factory CustomException.sessionRefreshRequired( + {@Default(403) int statusCode, + String? message}) = SessionRefreshRequiredException; const factory CustomException.flowExpired( {@Default(410) int statusCode, required String flowId, - String? message}) = FlowExpiredException; + required String message}) = FlowExpiredException; const factory CustomException.unknown( {@Default('An error occured. Please try again later.') - String? message}) = UnknownException; + String message}) = UnknownException; } diff --git a/flutter-ory-network/lib/services/exceptions.freezed.dart b/flutter-ory-network/lib/services/exceptions.freezed.dart index 08979de0..fe7e1b48 100644 --- a/flutter-ory-network/lib/services/exceptions.freezed.dart +++ b/flutter-ory-network/lib/services/exceptions.freezed.dart @@ -24,27 +24,31 @@ mixin _$CustomException { required TResult Function(List? messages, int statusCode) badRequest, required TResult Function(int statusCode) unauthorized, - required TResult Function(int statusCode, String flowId, String? message) + required TResult Function(int statusCode, String? message) + sessionRefreshRequired, + required TResult Function(int statusCode, String flowId, String message) flowExpired, - required TResult Function(String? message) unknown, + required TResult Function(String message) unknown, }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult? whenOrNull({ TResult? Function(List? messages, int statusCode)? badRequest, TResult? Function(int statusCode)? unauthorized, - TResult? Function(int statusCode, String flowId, String? message)? + TResult? Function(int statusCode, String? message)? sessionRefreshRequired, + TResult? Function(int statusCode, String flowId, String message)? flowExpired, - TResult? Function(String? message)? unknown, + TResult? Function(String message)? unknown, }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult maybeWhen({ TResult Function(List? messages, int statusCode)? badRequest, TResult Function(int statusCode)? unauthorized, - TResult Function(int statusCode, String flowId, String? message)? + TResult Function(int statusCode, String? message)? sessionRefreshRequired, + TResult Function(int statusCode, String flowId, String message)? flowExpired, - TResult Function(String? message)? unknown, + TResult Function(String message)? unknown, required TResult orElse(), }) => throw _privateConstructorUsedError; @@ -52,6 +56,8 @@ mixin _$CustomException { TResult map({ required TResult Function(BadRequestException value) badRequest, required TResult Function(UnauthorizedException value) unauthorized, + required TResult Function(SessionRefreshRequiredException value) + sessionRefreshRequired, required TResult Function(FlowExpiredException value) flowExpired, required TResult Function(UnknownException value) unknown, }) => @@ -60,6 +66,8 @@ mixin _$CustomException { TResult? mapOrNull({ TResult? Function(BadRequestException value)? badRequest, TResult? Function(UnauthorizedException value)? unauthorized, + TResult? Function(SessionRefreshRequiredException value)? + sessionRefreshRequired, TResult? Function(FlowExpiredException value)? flowExpired, TResult? Function(UnknownException value)? unknown, }) => @@ -68,6 +76,8 @@ mixin _$CustomException { TResult maybeMap({ TResult Function(BadRequestException value)? badRequest, TResult Function(UnauthorizedException value)? unauthorized, + TResult Function(SessionRefreshRequiredException value)? + sessionRefreshRequired, TResult Function(FlowExpiredException value)? flowExpired, TResult Function(UnknownException value)? unknown, required TResult orElse(), @@ -193,9 +203,11 @@ class _$BadRequestException extends BadRequestException required TResult Function(List? messages, int statusCode) badRequest, required TResult Function(int statusCode) unauthorized, - required TResult Function(int statusCode, String flowId, String? message) + required TResult Function(int statusCode, String? message) + sessionRefreshRequired, + required TResult Function(int statusCode, String flowId, String message) flowExpired, - required TResult Function(String? message) unknown, + required TResult Function(String message) unknown, }) { return badRequest(messages, statusCode); } @@ -205,9 +217,10 @@ class _$BadRequestException extends BadRequestException TResult? whenOrNull({ TResult? Function(List? messages, int statusCode)? badRequest, TResult? Function(int statusCode)? unauthorized, - TResult? Function(int statusCode, String flowId, String? message)? + TResult? Function(int statusCode, String? message)? sessionRefreshRequired, + TResult? Function(int statusCode, String flowId, String message)? flowExpired, - TResult? Function(String? message)? unknown, + TResult? Function(String message)? unknown, }) { return badRequest?.call(messages, statusCode); } @@ -217,9 +230,10 @@ class _$BadRequestException extends BadRequestException TResult maybeWhen({ TResult Function(List? messages, int statusCode)? badRequest, TResult Function(int statusCode)? unauthorized, - TResult Function(int statusCode, String flowId, String? message)? + TResult Function(int statusCode, String? message)? sessionRefreshRequired, + TResult Function(int statusCode, String flowId, String message)? flowExpired, - TResult Function(String? message)? unknown, + TResult Function(String message)? unknown, required TResult orElse(), }) { if (badRequest != null) { @@ -233,6 +247,8 @@ class _$BadRequestException extends BadRequestException TResult map({ required TResult Function(BadRequestException value) badRequest, required TResult Function(UnauthorizedException value) unauthorized, + required TResult Function(SessionRefreshRequiredException value) + sessionRefreshRequired, required TResult Function(FlowExpiredException value) flowExpired, required TResult Function(UnknownException value) unknown, }) { @@ -244,6 +260,8 @@ class _$BadRequestException extends BadRequestException TResult? mapOrNull({ TResult? Function(BadRequestException value)? badRequest, TResult? Function(UnauthorizedException value)? unauthorized, + TResult? Function(SessionRefreshRequiredException value)? + sessionRefreshRequired, TResult? Function(FlowExpiredException value)? flowExpired, TResult? Function(UnknownException value)? unknown, }) { @@ -255,6 +273,8 @@ class _$BadRequestException extends BadRequestException TResult maybeMap({ TResult Function(BadRequestException value)? badRequest, TResult Function(UnauthorizedException value)? unauthorized, + TResult Function(SessionRefreshRequiredException value)? + sessionRefreshRequired, TResult Function(FlowExpiredException value)? flowExpired, TResult Function(UnknownException value)? unknown, required TResult orElse(), @@ -358,9 +378,11 @@ class _$UnauthorizedException extends UnauthorizedException required TResult Function(List? messages, int statusCode) badRequest, required TResult Function(int statusCode) unauthorized, - required TResult Function(int statusCode, String flowId, String? message) + required TResult Function(int statusCode, String? message) + sessionRefreshRequired, + required TResult Function(int statusCode, String flowId, String message) flowExpired, - required TResult Function(String? message) unknown, + required TResult Function(String message) unknown, }) { return unauthorized(statusCode); } @@ -370,9 +392,10 @@ class _$UnauthorizedException extends UnauthorizedException TResult? whenOrNull({ TResult? Function(List? messages, int statusCode)? badRequest, TResult? Function(int statusCode)? unauthorized, - TResult? Function(int statusCode, String flowId, String? message)? + TResult? Function(int statusCode, String? message)? sessionRefreshRequired, + TResult? Function(int statusCode, String flowId, String message)? flowExpired, - TResult? Function(String? message)? unknown, + TResult? Function(String message)? unknown, }) { return unauthorized?.call(statusCode); } @@ -382,9 +405,10 @@ class _$UnauthorizedException extends UnauthorizedException TResult maybeWhen({ TResult Function(List? messages, int statusCode)? badRequest, TResult Function(int statusCode)? unauthorized, - TResult Function(int statusCode, String flowId, String? message)? + TResult Function(int statusCode, String? message)? sessionRefreshRequired, + TResult Function(int statusCode, String flowId, String message)? flowExpired, - TResult Function(String? message)? unknown, + TResult Function(String message)? unknown, required TResult orElse(), }) { if (unauthorized != null) { @@ -398,6 +422,8 @@ class _$UnauthorizedException extends UnauthorizedException TResult map({ required TResult Function(BadRequestException value) badRequest, required TResult Function(UnauthorizedException value) unauthorized, + required TResult Function(SessionRefreshRequiredException value) + sessionRefreshRequired, required TResult Function(FlowExpiredException value) flowExpired, required TResult Function(UnknownException value) unknown, }) { @@ -409,6 +435,8 @@ class _$UnauthorizedException extends UnauthorizedException TResult? mapOrNull({ TResult? Function(BadRequestException value)? badRequest, TResult? Function(UnauthorizedException value)? unauthorized, + TResult? Function(SessionRefreshRequiredException value)? + sessionRefreshRequired, TResult? Function(FlowExpiredException value)? flowExpired, TResult? Function(UnknownException value)? unknown, }) { @@ -420,6 +448,8 @@ class _$UnauthorizedException extends UnauthorizedException TResult maybeMap({ TResult Function(BadRequestException value)? badRequest, TResult Function(UnauthorizedException value)? unauthorized, + TResult Function(SessionRefreshRequiredException value)? + sessionRefreshRequired, TResult Function(FlowExpiredException value)? flowExpired, TResult Function(UnknownException value)? unknown, required TResult orElse(), @@ -442,13 +472,202 @@ abstract class UnauthorizedException extends CustomException { throw _privateConstructorUsedError; } +/// @nodoc +abstract class _$$SessionRefreshRequiredExceptionCopyWith<$Res> { + factory _$$SessionRefreshRequiredExceptionCopyWith( + _$SessionRefreshRequiredException value, + $Res Function(_$SessionRefreshRequiredException) then) = + __$$SessionRefreshRequiredExceptionCopyWithImpl<$Res>; + @useResult + $Res call({int statusCode, String? message}); +} + +/// @nodoc +class __$$SessionRefreshRequiredExceptionCopyWithImpl<$Res> + extends _$CustomExceptionCopyWithImpl<$Res, + _$SessionRefreshRequiredException> + implements _$$SessionRefreshRequiredExceptionCopyWith<$Res> { + __$$SessionRefreshRequiredExceptionCopyWithImpl( + _$SessionRefreshRequiredException _value, + $Res Function(_$SessionRefreshRequiredException) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? statusCode = null, + Object? message = freezed, + }) { + return _then(_$SessionRefreshRequiredException( + statusCode: null == statusCode + ? _value.statusCode + : statusCode // ignore: cast_nullable_to_non_nullable + as int, + message: freezed == message + ? _value.message + : message // ignore: cast_nullable_to_non_nullable + as String?, + )); + } +} + +/// @nodoc + +class _$SessionRefreshRequiredException extends SessionRefreshRequiredException + with DiagnosticableTreeMixin { + const _$SessionRefreshRequiredException({this.statusCode = 403, this.message}) + : super._(); + + @override + @JsonKey() + final int statusCode; + @override + final String? message; + + @override + String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { + return 'CustomException.sessionRefreshRequired(statusCode: $statusCode, message: $message)'; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties + ..add( + DiagnosticsProperty('type', 'CustomException.sessionRefreshRequired')) + ..add(DiagnosticsProperty('statusCode', statusCode)) + ..add(DiagnosticsProperty('message', message)); + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$SessionRefreshRequiredException && + (identical(other.statusCode, statusCode) || + other.statusCode == statusCode) && + (identical(other.message, message) || other.message == message)); + } + + @override + int get hashCode => Object.hash(runtimeType, statusCode, message); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$SessionRefreshRequiredExceptionCopyWith<_$SessionRefreshRequiredException> + get copyWith => __$$SessionRefreshRequiredExceptionCopyWithImpl< + _$SessionRefreshRequiredException>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(List? messages, int statusCode) + badRequest, + required TResult Function(int statusCode) unauthorized, + required TResult Function(int statusCode, String? message) + sessionRefreshRequired, + required TResult Function(int statusCode, String flowId, String message) + flowExpired, + required TResult Function(String message) unknown, + }) { + return sessionRefreshRequired(statusCode, message); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(List? messages, int statusCode)? badRequest, + TResult? Function(int statusCode)? unauthorized, + TResult? Function(int statusCode, String? message)? sessionRefreshRequired, + TResult? Function(int statusCode, String flowId, String message)? + flowExpired, + TResult? Function(String message)? unknown, + }) { + return sessionRefreshRequired?.call(statusCode, message); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(List? messages, int statusCode)? badRequest, + TResult Function(int statusCode)? unauthorized, + TResult Function(int statusCode, String? message)? sessionRefreshRequired, + TResult Function(int statusCode, String flowId, String message)? + flowExpired, + TResult Function(String message)? unknown, + required TResult orElse(), + }) { + if (sessionRefreshRequired != null) { + return sessionRefreshRequired(statusCode, message); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(BadRequestException value) badRequest, + required TResult Function(UnauthorizedException value) unauthorized, + required TResult Function(SessionRefreshRequiredException value) + sessionRefreshRequired, + required TResult Function(FlowExpiredException value) flowExpired, + required TResult Function(UnknownException value) unknown, + }) { + return sessionRefreshRequired(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(BadRequestException value)? badRequest, + TResult? Function(UnauthorizedException value)? unauthorized, + TResult? Function(SessionRefreshRequiredException value)? + sessionRefreshRequired, + TResult? Function(FlowExpiredException value)? flowExpired, + TResult? Function(UnknownException value)? unknown, + }) { + return sessionRefreshRequired?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(BadRequestException value)? badRequest, + TResult Function(UnauthorizedException value)? unauthorized, + TResult Function(SessionRefreshRequiredException value)? + sessionRefreshRequired, + TResult Function(FlowExpiredException value)? flowExpired, + TResult Function(UnknownException value)? unknown, + required TResult orElse(), + }) { + if (sessionRefreshRequired != null) { + return sessionRefreshRequired(this); + } + return orElse(); + } +} + +abstract class SessionRefreshRequiredException extends CustomException { + const factory SessionRefreshRequiredException( + {final int statusCode, + final String? message}) = _$SessionRefreshRequiredException; + const SessionRefreshRequiredException._() : super._(); + + int get statusCode; + String? get message; + @JsonKey(ignore: true) + _$$SessionRefreshRequiredExceptionCopyWith<_$SessionRefreshRequiredException> + get copyWith => throw _privateConstructorUsedError; +} + /// @nodoc abstract class _$$FlowExpiredExceptionCopyWith<$Res> { factory _$$FlowExpiredExceptionCopyWith(_$FlowExpiredException value, $Res Function(_$FlowExpiredException) then) = __$$FlowExpiredExceptionCopyWithImpl<$Res>; @useResult - $Res call({int statusCode, String flowId, String? message}); + $Res call({int statusCode, String flowId, String message}); } /// @nodoc @@ -464,7 +683,7 @@ class __$$FlowExpiredExceptionCopyWithImpl<$Res> $Res call({ Object? statusCode = null, Object? flowId = null, - Object? message = freezed, + Object? message = null, }) { return _then(_$FlowExpiredException( statusCode: null == statusCode @@ -475,10 +694,10 @@ class __$$FlowExpiredExceptionCopyWithImpl<$Res> ? _value.flowId : flowId // ignore: cast_nullable_to_non_nullable as String, - message: freezed == message + message: null == message ? _value.message : message // ignore: cast_nullable_to_non_nullable - as String?, + as String, )); } } @@ -488,7 +707,7 @@ class __$$FlowExpiredExceptionCopyWithImpl<$Res> class _$FlowExpiredException extends FlowExpiredException with DiagnosticableTreeMixin { const _$FlowExpiredException( - {this.statusCode = 410, required this.flowId, this.message}) + {this.statusCode = 410, required this.flowId, required this.message}) : super._(); @override @@ -497,7 +716,7 @@ class _$FlowExpiredException extends FlowExpiredException @override final String flowId; @override - final String? message; + final String message; @override String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { @@ -541,9 +760,11 @@ class _$FlowExpiredException extends FlowExpiredException required TResult Function(List? messages, int statusCode) badRequest, required TResult Function(int statusCode) unauthorized, - required TResult Function(int statusCode, String flowId, String? message) + required TResult Function(int statusCode, String? message) + sessionRefreshRequired, + required TResult Function(int statusCode, String flowId, String message) flowExpired, - required TResult Function(String? message) unknown, + required TResult Function(String message) unknown, }) { return flowExpired(statusCode, flowId, message); } @@ -553,9 +774,10 @@ class _$FlowExpiredException extends FlowExpiredException TResult? whenOrNull({ TResult? Function(List? messages, int statusCode)? badRequest, TResult? Function(int statusCode)? unauthorized, - TResult? Function(int statusCode, String flowId, String? message)? + TResult? Function(int statusCode, String? message)? sessionRefreshRequired, + TResult? Function(int statusCode, String flowId, String message)? flowExpired, - TResult? Function(String? message)? unknown, + TResult? Function(String message)? unknown, }) { return flowExpired?.call(statusCode, flowId, message); } @@ -565,9 +787,10 @@ class _$FlowExpiredException extends FlowExpiredException TResult maybeWhen({ TResult Function(List? messages, int statusCode)? badRequest, TResult Function(int statusCode)? unauthorized, - TResult Function(int statusCode, String flowId, String? message)? + TResult Function(int statusCode, String? message)? sessionRefreshRequired, + TResult Function(int statusCode, String flowId, String message)? flowExpired, - TResult Function(String? message)? unknown, + TResult Function(String message)? unknown, required TResult orElse(), }) { if (flowExpired != null) { @@ -581,6 +804,8 @@ class _$FlowExpiredException extends FlowExpiredException TResult map({ required TResult Function(BadRequestException value) badRequest, required TResult Function(UnauthorizedException value) unauthorized, + required TResult Function(SessionRefreshRequiredException value) + sessionRefreshRequired, required TResult Function(FlowExpiredException value) flowExpired, required TResult Function(UnknownException value) unknown, }) { @@ -592,6 +817,8 @@ class _$FlowExpiredException extends FlowExpiredException TResult? mapOrNull({ TResult? Function(BadRequestException value)? badRequest, TResult? Function(UnauthorizedException value)? unauthorized, + TResult? Function(SessionRefreshRequiredException value)? + sessionRefreshRequired, TResult? Function(FlowExpiredException value)? flowExpired, TResult? Function(UnknownException value)? unknown, }) { @@ -603,6 +830,8 @@ class _$FlowExpiredException extends FlowExpiredException TResult maybeMap({ TResult Function(BadRequestException value)? badRequest, TResult Function(UnauthorizedException value)? unauthorized, + TResult Function(SessionRefreshRequiredException value)? + sessionRefreshRequired, TResult Function(FlowExpiredException value)? flowExpired, TResult Function(UnknownException value)? unknown, required TResult orElse(), @@ -618,12 +847,12 @@ abstract class FlowExpiredException extends CustomException { const factory FlowExpiredException( {final int statusCode, required final String flowId, - final String? message}) = _$FlowExpiredException; + required final String message}) = _$FlowExpiredException; const FlowExpiredException._() : super._(); int get statusCode; String get flowId; - String? get message; + String get message; @JsonKey(ignore: true) _$$FlowExpiredExceptionCopyWith<_$FlowExpiredException> get copyWith => throw _privateConstructorUsedError; @@ -635,7 +864,7 @@ abstract class _$$UnknownExceptionCopyWith<$Res> { _$UnknownException value, $Res Function(_$UnknownException) then) = __$$UnknownExceptionCopyWithImpl<$Res>; @useResult - $Res call({String? message}); + $Res call({String message}); } /// @nodoc @@ -649,13 +878,13 @@ class __$$UnknownExceptionCopyWithImpl<$Res> @pragma('vm:prefer-inline') @override $Res call({ - Object? message = freezed, + Object? message = null, }) { return _then(_$UnknownException( - message: freezed == message + message: null == message ? _value.message : message // ignore: cast_nullable_to_non_nullable - as String?, + as String, )); } } @@ -669,7 +898,7 @@ class _$UnknownException extends UnknownException with DiagnosticableTreeMixin { @override @JsonKey() - final String? message; + final String message; @override String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { @@ -707,9 +936,11 @@ class _$UnknownException extends UnknownException with DiagnosticableTreeMixin { required TResult Function(List? messages, int statusCode) badRequest, required TResult Function(int statusCode) unauthorized, - required TResult Function(int statusCode, String flowId, String? message) + required TResult Function(int statusCode, String? message) + sessionRefreshRequired, + required TResult Function(int statusCode, String flowId, String message) flowExpired, - required TResult Function(String? message) unknown, + required TResult Function(String message) unknown, }) { return unknown(message); } @@ -719,9 +950,10 @@ class _$UnknownException extends UnknownException with DiagnosticableTreeMixin { TResult? whenOrNull({ TResult? Function(List? messages, int statusCode)? badRequest, TResult? Function(int statusCode)? unauthorized, - TResult? Function(int statusCode, String flowId, String? message)? + TResult? Function(int statusCode, String? message)? sessionRefreshRequired, + TResult? Function(int statusCode, String flowId, String message)? flowExpired, - TResult? Function(String? message)? unknown, + TResult? Function(String message)? unknown, }) { return unknown?.call(message); } @@ -731,9 +963,10 @@ class _$UnknownException extends UnknownException with DiagnosticableTreeMixin { TResult maybeWhen({ TResult Function(List? messages, int statusCode)? badRequest, TResult Function(int statusCode)? unauthorized, - TResult Function(int statusCode, String flowId, String? message)? + TResult Function(int statusCode, String? message)? sessionRefreshRequired, + TResult Function(int statusCode, String flowId, String message)? flowExpired, - TResult Function(String? message)? unknown, + TResult Function(String message)? unknown, required TResult orElse(), }) { if (unknown != null) { @@ -747,6 +980,8 @@ class _$UnknownException extends UnknownException with DiagnosticableTreeMixin { TResult map({ required TResult Function(BadRequestException value) badRequest, required TResult Function(UnauthorizedException value) unauthorized, + required TResult Function(SessionRefreshRequiredException value) + sessionRefreshRequired, required TResult Function(FlowExpiredException value) flowExpired, required TResult Function(UnknownException value) unknown, }) { @@ -758,6 +993,8 @@ class _$UnknownException extends UnknownException with DiagnosticableTreeMixin { TResult? mapOrNull({ TResult? Function(BadRequestException value)? badRequest, TResult? Function(UnauthorizedException value)? unauthorized, + TResult? Function(SessionRefreshRequiredException value)? + sessionRefreshRequired, TResult? Function(FlowExpiredException value)? flowExpired, TResult? Function(UnknownException value)? unknown, }) { @@ -769,6 +1006,8 @@ class _$UnknownException extends UnknownException with DiagnosticableTreeMixin { TResult maybeMap({ TResult Function(BadRequestException value)? badRequest, TResult Function(UnauthorizedException value)? unauthorized, + TResult Function(SessionRefreshRequiredException value)? + sessionRefreshRequired, TResult Function(FlowExpiredException value)? flowExpired, TResult Function(UnknownException value)? unknown, required TResult orElse(), @@ -781,10 +1020,10 @@ class _$UnknownException extends UnknownException with DiagnosticableTreeMixin { } abstract class UnknownException extends CustomException { - const factory UnknownException({final String? message}) = _$UnknownException; + const factory UnknownException({final String message}) = _$UnknownException; const UnknownException._() : super._(); - String? get message; + String get message; @JsonKey(ignore: true) _$$UnknownExceptionCopyWith<_$UnknownException> get copyWith => throw _privateConstructorUsedError; diff --git a/flutter-ory-network/pubspec.lock b/flutter-ory-network/pubspec.lock index 85398bad..84b79d9f 100644 --- a/flutter-ory-network/pubspec.lock +++ b/flutter-ory-network/pubspec.lock @@ -106,13 +106,13 @@ packages: source: hosted version: "5.1.1" built_value: - dependency: transitive + dependency: "direct main" description: name: built_value - sha256: "598a2a682e2a7a90f08ba39c0aaa9374c5112340f0a2e275f61b59389543d166" + sha256: ff627b645b28fb8bdb69e645f910c2458fd6b65f6585c3a53e0626024897dedf url: "https://pub.dev" source: hosted - version: "8.6.1" + version: "8.6.2" characters: dependency: transitive description: @@ -146,7 +146,7 @@ packages: source: hosted version: "4.5.0" collection: - dependency: transitive + dependency: "direct main" description: name: collection sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687 diff --git a/flutter-ory-network/pubspec.yaml b/flutter-ory-network/pubspec.yaml index 42d5637f..e4a4b134 100644 --- a/flutter-ory-network/pubspec.yaml +++ b/flutter-ory-network/pubspec.yaml @@ -46,6 +46,8 @@ dependencies: flutter_secure_storage: ^8.0.0 dotenv: ^4.1.0 google_fonts: ^5.1.0 + built_value: ^8.6.2 + collection: ^1.17.2 dev_dependencies: flutter_test: From 12307ba6e5d2323129b29266cb6bfa097628848c Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Wed, 6 Sep 2023 16:02:41 +0200 Subject: [PATCH 17/57] design: add padding to messages --- flutter-ory-network/lib/pages/home.dart | 13 ++++++++----- flutter-ory-network/lib/pages/login.dart | 13 ++++++++----- flutter-ory-network/lib/pages/registration.dart | 13 ++++++++----- flutter-ory-network/lib/pages/settings.dart | 13 ++++++++----- 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/flutter-ory-network/lib/pages/home.dart b/flutter-ory-network/lib/pages/home.dart index e8372194..de7b2def 100644 --- a/flutter-ory-network/lib/pages/home.dart +++ b/flutter-ory-network/lib/pages/home.dart @@ -149,11 +149,14 @@ class _HomePageState extends State { _buildSessionNotFetched(BuildContext context, AuthState state) { if (state.errorMessage != null) { - return Center( - child: Text( - state.errorMessage!, - style: const TextStyle(color: Colors.red), - )); + return Padding( + padding: const EdgeInsets.symmetric(horizontal: 32), + child: Center( + child: Text( + state.errorMessage!, + style: const TextStyle(color: Colors.red), + )), + ); } else { return const Center(child: CircularProgressIndicator()); } diff --git a/flutter-ory-network/lib/pages/login.dart b/flutter-ory-network/lib/pages/login.dart index ccfdb0cb..e51c53e0 100644 --- a/flutter-ory-network/lib/pages/login.dart +++ b/flutter-ory-network/lib/pages/login.dart @@ -67,11 +67,14 @@ class LoginFormState extends State { _buildLoginFlowNotCreated(BuildContext context, LoginState state) { if (state.errorMessage != null) { - return Center( - child: Text( - state.errorMessage!, - style: const TextStyle(color: Colors.red), - )); + return Padding( + padding: const EdgeInsets.symmetric(horizontal: 32), + child: Center( + child: Text( + state.errorMessage!, + style: const TextStyle(color: Colors.red), + )), + ); } else { return const Center(child: CircularProgressIndicator()); } diff --git a/flutter-ory-network/lib/pages/registration.dart b/flutter-ory-network/lib/pages/registration.dart index 54465942..46e72bcb 100644 --- a/flutter-ory-network/lib/pages/registration.dart +++ b/flutter-ory-network/lib/pages/registration.dart @@ -68,11 +68,14 @@ class RegistrationFormState extends State { _buildRegistrationFlowNotCreated( BuildContext context, RegistrationState state) { if (state.errorMessage != null) { - return Center( - child: Text( - state.errorMessage!, - style: const TextStyle(color: Colors.red), - )); + return Padding( + padding: const EdgeInsets.symmetric(horizontal: 32), + child: Center( + child: Text( + state.errorMessage!, + style: const TextStyle(color: Colors.red), + )), + ); } else { return const Center(child: CircularProgressIndicator()); } diff --git a/flutter-ory-network/lib/pages/settings.dart b/flutter-ory-network/lib/pages/settings.dart index 9ad23af8..7b24e30f 100644 --- a/flutter-ory-network/lib/pages/settings.dart +++ b/flutter-ory-network/lib/pages/settings.dart @@ -101,11 +101,14 @@ class _SettingsFormState extends State { _buildSettingsFlowNotCreated(BuildContext context, SettingsState state) { if (state.message != null) { - return Center( - child: Text( - state.message!.text, - style: TextStyle(color: _getMessageColor(state.message!.type)), - )); + return Padding( + padding: const EdgeInsets.symmetric(horizontal: 32), + child: Center( + child: Text( + state.message!.text, + style: TextStyle(color: _getMessageColor(state.message!.type)), + )), + ); } else { return const Center(child: CircularProgressIndicator()); } From 0e9fac8fd794c9ecb58595951b7380911c2dadbb Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Wed, 6 Sep 2023 18:52:23 +0200 Subject: [PATCH 18/57] feat: refresh session when updating settings --- .../lib/blocs/auth/auth_bloc.dart | 3 +- .../lib/blocs/auth/auth_event.dart | 7 +- .../lib/blocs/login/login_bloc.dart | 5 +- .../lib/blocs/settings/settings_bloc.dart | 11 +- .../blocs/settings/settings_bloc.freezed.dart | 29 ++- .../lib/blocs/settings/settings_state.dart | 1 + flutter-ory-network/lib/pages/login.dart | 171 ++++++++++++------ flutter-ory-network/lib/pages/settings.dart | 60 ++++-- .../lib/repositories/auth.dart | 5 +- flutter-ory-network/lib/services/auth.dart | 11 +- 10 files changed, 212 insertions(+), 91 deletions(-) diff --git a/flutter-ory-network/lib/blocs/auth/auth_bloc.dart b/flutter-ory-network/lib/blocs/auth/auth_bloc.dart index aa89cc20..9af07311 100644 --- a/flutter-ory-network/lib/blocs/auth/auth_bloc.dart +++ b/flutter-ory-network/lib/blocs/auth/auth_bloc.dart @@ -28,7 +28,8 @@ class AuthBloc extends Bloc { if (event.status == AuthStatus.unauthenticated) { await repository.deleteExpiredSessionToken(); } - emit(state.copyWith(status: event.status, isLoading: false)); + emit(state.copyWith( + status: event.status, session: event.session, isLoading: false)); } Future _onGetCurrentSessionInformation( diff --git a/flutter-ory-network/lib/blocs/auth/auth_event.dart b/flutter-ory-network/lib/blocs/auth/auth_event.dart index 7d9a6364..582bd055 100644 --- a/flutter-ory-network/lib/blocs/auth/auth_event.dart +++ b/flutter-ory-network/lib/blocs/auth/auth_event.dart @@ -6,15 +6,16 @@ part of 'auth_bloc.dart'; @immutable sealed class AuthEvent extends Equatable { @override - List get props => []; + List get props => []; } final class ChangeAuthStatus extends AuthEvent { final AuthStatus status; + final Session? session; - ChangeAuthStatus({required this.status}); + ChangeAuthStatus({required this.status, this.session}); @override - List get props => [status]; + List get props => [status, session]; } //get current session information diff --git a/flutter-ory-network/lib/blocs/login/login_bloc.dart b/flutter-ory-network/lib/blocs/login/login_bloc.dart index a3b36554..3bd2b0c8 100644 --- a/flutter-ory-network/lib/blocs/login/login_bloc.dart +++ b/flutter-ory-network/lib/blocs/login/login_bloc.dart @@ -72,10 +72,11 @@ class LoginBloc extends Bloc { .copyWith .password(errorMessage: null)); - await repository.loginWithEmailAndPassword( + final session = await repository.loginWithEmailAndPassword( flowId: event.flowId, email: event.email, password: event.password); - authBloc.add(ChangeAuthStatus(status: AuthStatus.authenticated)); + authBloc.add( + ChangeAuthStatus(status: AuthStatus.authenticated, session: session)); } on CustomException catch (e) { if (e case BadRequestException _) { final emailMessage = e.messages diff --git a/flutter-ory-network/lib/blocs/settings/settings_bloc.dart b/flutter-ory-network/lib/blocs/settings/settings_bloc.dart index e23580a2..4371e2cd 100644 --- a/flutter-ory-network/lib/blocs/settings/settings_bloc.dart +++ b/flutter-ory-network/lib/blocs/settings/settings_bloc.dart @@ -32,12 +32,13 @@ class SettingsBloc extends Bloc { // remove password and general error when changing email emit(state.copyWith .password(value: event.value, errorMessage: null) - .copyWith(message: null)); + .copyWith(message: null, isSessionRefreshRequired: false)); } _onChangePasswordVisibility( ChangePasswordVisibility event, Emitter emit) { - emit(state.copyWith(isPasswordHidden: event.value)); + emit(state.copyWith( + isPasswordHidden: event.value, isSessionRefreshRequired: false)); } Future _onCreateSettingsFlow( @@ -66,7 +67,8 @@ class SettingsBloc extends Bloc { SubmitNewPassword event, Emitter emit) async { try { emit(state - .copyWith(isLoading: true, message: null) + .copyWith( + isLoading: true, message: null, isSessionRefreshRequired: false) .copyWith .password(errorMessage: null)); @@ -105,6 +107,9 @@ class SettingsBloc extends Bloc { isLoading: false) .copyWith .password(value: '')); + } else if (e case SessionRefreshRequiredException _) { + // set session required flag to navigate to login page and reset password field + emit(state.copyWith(isSessionRefreshRequired: true, isLoading: false)); } else if (e case UnknownException _) { emit(state.copyWith( isLoading: false, diff --git a/flutter-ory-network/lib/blocs/settings/settings_bloc.freezed.dart b/flutter-ory-network/lib/blocs/settings/settings_bloc.freezed.dart index 4c60226d..5acc5991 100644 --- a/flutter-ory-network/lib/blocs/settings/settings_bloc.freezed.dart +++ b/flutter-ory-network/lib/blocs/settings/settings_bloc.freezed.dart @@ -23,6 +23,7 @@ mixin _$SettingsState { FormField get password => throw _privateConstructorUsedError; bool get isPasswordHidden => throw _privateConstructorUsedError; bool get isLoading => throw _privateConstructorUsedError; + bool get isSessionRefreshRequired => throw _privateConstructorUsedError; NodeMessage? get message => throw _privateConstructorUsedError; @JsonKey(ignore: true) @@ -41,6 +42,7 @@ abstract class $SettingsStateCopyWith<$Res> { FormField password, bool isPasswordHidden, bool isLoading, + bool isSessionRefreshRequired, NodeMessage? message}); $FormFieldCopyWith get password; @@ -64,6 +66,7 @@ class _$SettingsStateCopyWithImpl<$Res, $Val extends SettingsState> Object? password = null, Object? isPasswordHidden = null, Object? isLoading = null, + Object? isSessionRefreshRequired = null, Object? message = freezed, }) { return _then(_value.copyWith( @@ -83,6 +86,10 @@ class _$SettingsStateCopyWithImpl<$Res, $Val extends SettingsState> ? _value.isLoading : isLoading // ignore: cast_nullable_to_non_nullable as bool, + isSessionRefreshRequired: null == isSessionRefreshRequired + ? _value.isSessionRefreshRequired + : isSessionRefreshRequired // ignore: cast_nullable_to_non_nullable + as bool, message: freezed == message ? _value.message : message // ignore: cast_nullable_to_non_nullable @@ -124,6 +131,7 @@ abstract class _$$_SettingsStateCopyWith<$Res> FormField password, bool isPasswordHidden, bool isLoading, + bool isSessionRefreshRequired, NodeMessage? message}); @override @@ -147,6 +155,7 @@ class __$$_SettingsStateCopyWithImpl<$Res> Object? password = null, Object? isPasswordHidden = null, Object? isLoading = null, + Object? isSessionRefreshRequired = null, Object? message = freezed, }) { return _then(_$_SettingsState( @@ -166,6 +175,10 @@ class __$$_SettingsStateCopyWithImpl<$Res> ? _value.isLoading : isLoading // ignore: cast_nullable_to_non_nullable as bool, + isSessionRefreshRequired: null == isSessionRefreshRequired + ? _value.isSessionRefreshRequired + : isSessionRefreshRequired // ignore: cast_nullable_to_non_nullable + as bool, message: freezed == message ? _value.message : message // ignore: cast_nullable_to_non_nullable @@ -182,6 +195,7 @@ class _$_SettingsState implements _SettingsState { this.password = const FormField(value: ''), this.isPasswordHidden = true, this.isLoading = false, + this.isSessionRefreshRequired = false, this.message}); @override @@ -196,11 +210,14 @@ class _$_SettingsState implements _SettingsState { @JsonKey() final bool isLoading; @override + @JsonKey() + final bool isSessionRefreshRequired; + @override final NodeMessage? message; @override String toString() { - return 'SettingsState(flowId: $flowId, password: $password, isPasswordHidden: $isPasswordHidden, isLoading: $isLoading, message: $message)'; + return 'SettingsState(flowId: $flowId, password: $password, isPasswordHidden: $isPasswordHidden, isLoading: $isLoading, isSessionRefreshRequired: $isSessionRefreshRequired, message: $message)'; } @override @@ -215,12 +232,15 @@ class _$_SettingsState implements _SettingsState { other.isPasswordHidden == isPasswordHidden) && (identical(other.isLoading, isLoading) || other.isLoading == isLoading) && + (identical( + other.isSessionRefreshRequired, isSessionRefreshRequired) || + other.isSessionRefreshRequired == isSessionRefreshRequired) && (identical(other.message, message) || other.message == message)); } @override - int get hashCode => Object.hash( - runtimeType, flowId, password, isPasswordHidden, isLoading, message); + int get hashCode => Object.hash(runtimeType, flowId, password, + isPasswordHidden, isLoading, isSessionRefreshRequired, message); @JsonKey(ignore: true) @override @@ -235,6 +255,7 @@ abstract class _SettingsState implements SettingsState { final FormField password, final bool isPasswordHidden, final bool isLoading, + final bool isSessionRefreshRequired, final NodeMessage? message}) = _$_SettingsState; @override @@ -246,6 +267,8 @@ abstract class _SettingsState implements SettingsState { @override bool get isLoading; @override + bool get isSessionRefreshRequired; + @override NodeMessage? get message; @override @JsonKey(ignore: true) diff --git a/flutter-ory-network/lib/blocs/settings/settings_state.dart b/flutter-ory-network/lib/blocs/settings/settings_state.dart index e567d3f6..07b4b765 100644 --- a/flutter-ory-network/lib/blocs/settings/settings_state.dart +++ b/flutter-ory-network/lib/blocs/settings/settings_state.dart @@ -10,5 +10,6 @@ sealed class SettingsState with _$SettingsState { @Default(FormField(value: '')) FormField password, @Default(true) bool isPasswordHidden, @Default(false) bool isLoading, + @Default(false) bool isSessionRefreshRequired, NodeMessage? message}) = _SettingsState; } diff --git a/flutter-ory-network/lib/pages/login.dart b/flutter-ory-network/lib/pages/login.dart index e51c53e0..4e63be19 100644 --- a/flutter-ory-network/lib/pages/login.dart +++ b/flutter-ory-network/lib/pages/login.dart @@ -11,24 +11,56 @@ import '../widgets/social_provider_box.dart'; import 'registration.dart'; class LoginPage extends StatelessWidget { - const LoginPage({super.key}); + final bool isSessionRefresh; + const LoginPage({super.key, this.isSessionRefresh = false}); @override Widget build(BuildContext context) { return Scaffold( - extendBodyBehindAppBar: true, + extendBodyBehindAppBar: !isSessionRefresh, + appBar: isSessionRefresh + ? AppBar( + backgroundColor: Colors.transparent, + elevation: 0, + leadingWidth: 72, + toolbarHeight: 72, + // use row to avoid force resizing of leading widget + leading: Row( + children: [ + Padding( + padding: const EdgeInsets.only(left: 32, top: 32), + child: GestureDetector( + onTap: () => Navigator.of(context).pop(), + child: Container( + height: 40, + width: 40, + padding: const EdgeInsets.all(12), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(4), + border: Border.all( + width: 1, color: const Color(0xFFE2E8F0))), + child: const Icon(Icons.arrow_back, size: 16), + ), + ), + ), + ], + )) + : null, body: BlocProvider( create: (context) => LoginBloc( authBloc: context.read(), repository: RepositoryProvider.of(context)) ..add(CreateLoginFlow()), - child: const LoginForm()), + child: LoginForm( + isSessionRefresh: isSessionRefresh, + )), ); } } class LoginForm extends StatefulWidget { - const LoginForm({super.key}); + final bool isSessionRefresh; + const LoginForm({super.key, required this.isSessionRefresh}); @override State createState() => LoginFormState(); @@ -40,29 +72,40 @@ class LoginFormState extends State { @override Widget build(BuildContext context) { final loginBloc = BlocProvider.of(context); - return BlocConsumer( - bloc: loginBloc, - // listen to email and password changes - listenWhen: (previous, current) { - return (previous.email.value != current.email.value && - emailController.text != current.email.value) || - (previous.password.value != current.password.value && - passwordController.text != current.password.value); - }, - // if email or password value have changed, update text controller values - listener: (BuildContext context, LoginState state) { - emailController.text = state.email.value; - passwordController.text = state.password.value; - }, - builder: (context, state) { - // login flow was created - if (state.flowId != null) { - return _buildLoginForm(context, state); - } // otherwise, show loading or error - else { - return _buildLoginFlowNotCreated(context, state); - } - }); + return BlocListener( + // listen when the user was already authenticated and session was updated + listenWhen: (previous, current) => + previous.session != null && + current.session != null && + previous.session != current.session, + listener: (context, state) { + // pop with true to trigger change password flow + Navigator.of(context).pop(true); + }, + child: BlocConsumer( + bloc: loginBloc, + // listen to email and password changes + listenWhen: (previous, current) { + return (previous.email.value != current.email.value && + emailController.text != current.email.value) || + (previous.password.value != current.password.value && + passwordController.text != current.password.value); + }, + // if email or password value have changed, update text controller values + listener: (BuildContext context, LoginState state) { + emailController.text = state.email.value; + passwordController.text = state.password.value; + }, + builder: (context, state) { + // login flow was created + if (state.flowId != null) { + return _buildLoginForm(context, state); + } // otherwise, show loading or error + else { + return _buildLoginFlowNotCreated(context, state); + } + }), + ); } _buildLoginFlowNotCreated(BuildContext context, LoginState state) { @@ -90,15 +133,17 @@ class LoginFormState extends State { mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.start, children: [ - Padding( - padding: EdgeInsets.only( - //status bar height + padding - top: MediaQuery.of(context).viewPadding.top + 48), - child: Image.asset( - 'assets/images/ory_logo.png', - width: 70, + // show Ory logo when the user is not authenticated, otherwise back button will be shown + if (!widget.isSessionRefresh) + Padding( + padding: EdgeInsets.only( + //status bar height + padding + top: MediaQuery.of(context).viewPadding.top + 48), + child: Image.asset( + 'assets/images/ory_logo.png', + width: 70, + ), ), - ), const SizedBox( height: 32, ), @@ -171,12 +216,14 @@ class LoginFormState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - const Row( + Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text('Password'), - TextButton( - onPressed: null, child: Text("Forgot password?")) + const Text('Password'), + // show forgot password only for initial login + if (!widget.isSessionRefresh) + const TextButton( + onPressed: null, child: Text("Forgot password?")) ], ), const SizedBox( @@ -251,21 +298,37 @@ class LoginFormState extends State { const SizedBox( height: 32, ), - Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - const Text('No account?'), - TextButton( - // disable button when state is loading - onPressed: state.isLoading - ? null - : () => Navigator.of(context).pushReplacement( - MaterialPageRoute( - builder: (context) => - const RegistrationPage())), - child: const Text('Sign up')) - ], - ) + // show logout button is session needs to be refreshed + if (widget.isSessionRefresh) + Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + const Text('Something not working?'), + TextButton( + // disable button when state is loading + onPressed: state.isLoading + ? null + : () => context.read()..add(LogOut()), + child: const Text('Logout')) + ], + ), + // show registration button only for initial login + if (!widget.isSessionRefresh) + Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + const Text('No account?'), + TextButton( + // disable button when state is loading + onPressed: state.isLoading + ? null + : () => Navigator.of(context).pushReplacement( + MaterialPageRoute( + builder: (context) => + const RegistrationPage())), + child: const Text('Sign up')) + ], + ) ], ), ), diff --git a/flutter-ory-network/lib/pages/settings.dart b/flutter-ory-network/lib/pages/settings.dart index 7b24e30f..a50a1a61 100644 --- a/flutter-ory-network/lib/pages/settings.dart +++ b/flutter-ory-network/lib/pages/settings.dart @@ -9,6 +9,7 @@ import 'package:ory_network_flutter/repositories/settings.dart'; import '../blocs/auth/auth_bloc.dart'; import '../blocs/settings/settings_bloc.dart'; import '../repositories/auth.dart'; +import 'login.dart'; class SettingsPage extends StatelessWidget { const SettingsPage({super.key}); @@ -66,26 +67,45 @@ class _SettingsFormState extends State { @override Widget build(BuildContext context) { final settingsBloc = BlocProvider.of(context); - return BlocConsumer( - bloc: settingsBloc, - // listen to password changes - listenWhen: (previous, current) { - return previous.password.value != current.password.value && - passwordController.text != current.password.value; - }, - // if password value has changed, update text controller value - listener: (BuildContext context, SettingsState state) { - passwordController.text = state.password.value; - }, - builder: (context, state) { - // settings flow was created - if (state.flowId != null) { - return _buildSettingsForm(context, state); - } // otherwise, show loading or error - else { - return _buildSettingsFlowNotCreated(context, state); - } - }); + return BlocListener( + listener: (context, state) async { + if (state.isSessionRefreshRequired) { + await Navigator.push( + context, + MaterialPageRoute( + builder: (context) => const LoginPage( + isSessionRefresh: true, + ))).then((value) { + if (value != null) { + if (value && state.flowId != null) { + settingsBloc.add(SubmitNewPassword( + flowId: state.flowId!, value: state.password.value)); + } + } + }); + } + }, + child: BlocConsumer( + bloc: settingsBloc, + // listen to password changes + listenWhen: (previous, current) { + return previous.password.value != current.password.value && + passwordController.text != current.password.value; + }, + // if password value has changed, update text controller value + listener: (BuildContext context, SettingsState state) { + passwordController.text = state.password.value; + }, + builder: (context, state) { + // settings flow was created + if (state.flowId != null) { + return _buildSettingsForm(context, state); + } // otherwise, show loading or error + else { + return _buildSettingsFlowNotCreated(context, state); + } + }), + ); } _getMessageColor(MessageType type) { diff --git a/flutter-ory-network/lib/repositories/auth.dart b/flutter-ory-network/lib/repositories/auth.dart index 55182f03..b9a143b6 100644 --- a/flutter-ory-network/lib/repositories/auth.dart +++ b/flutter-ory-network/lib/repositories/auth.dart @@ -31,12 +31,13 @@ class AuthRepository { return flowId; } - Future loginWithEmailAndPassword( + Future loginWithEmailAndPassword( {required String flowId, required String email, required String password}) async { - await service.loginWithEmailAndPassword( + final session = await service.loginWithEmailAndPassword( flowId: flowId, email: email, password: password); + return session; } Future registerWithEmailAndPassword( diff --git a/flutter-ory-network/lib/services/auth.dart b/flutter-ory-network/lib/services/auth.dart index d68be22b..d23efc8d 100644 --- a/flutter-ory-network/lib/services/auth.dart +++ b/flutter-ory-network/lib/services/auth.dart @@ -44,7 +44,10 @@ class AuthService { /// Create login flow Future createLoginFlow() async { try { - final response = await _ory.createNativeLoginFlow(); + final token = await _storage.getToken(); + // create native login flow. If session token is available, refresh the session + final response = await _ory.createNativeLoginFlow( + xSessionToken: token, refresh: token != null); if (response.data != null) { // return flow id return response.data!.id; @@ -72,11 +75,12 @@ class AuthService { } /// Log in with [email] and [password] using login flow with [flowId] - Future loginWithEmailAndPassword( + Future loginWithEmailAndPassword( {required String flowId, required String email, required String password}) async { try { + final token = await _storage.getToken(); final UpdateLoginFlowWithPasswordMethod loginFLowBuilder = UpdateLoginFlowWithPasswordMethod((b) => b ..identifier = email @@ -85,13 +89,14 @@ class AuthService { final response = await _ory.updateLoginFlow( flow: flowId, + xSessionToken: token, updateLoginFlowBody: UpdateLoginFlowBody( (b) => b..oneOf = OneOf.fromValue1(value: loginFLowBuilder))); if (response.data?.session != null) { // save session token after successful login await _storage.persistToken(response.data!.sessionToken!); - return; + return response.data!.session; } else { throw const CustomException.unknown(); } From 1ce89da5a2c1cf18322ed1804f1986ea4c5d7c6e Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Fri, 8 Sep 2023 13:40:44 +0200 Subject: [PATCH 19/57] design: add assets' variants --- .DS_Store | Bin 0 -> 6148 bytes .../assets/icons/1.5x/eye-off.png | Bin 0 -> 529 bytes flutter-ory-network/assets/icons/1.5x/eye.png | Bin 0 -> 497 bytes .../assets/icons/1.5x/logout.png | Bin 0 -> 435 bytes .../assets/icons/1.5x/settings.png | Bin 0 -> 619 bytes .../assets/icons/2.0x/eye-off.png | Bin 0 -> 697 bytes flutter-ory-network/assets/icons/2.0x/eye.png | Bin 0 -> 645 bytes .../assets/icons/2.0x/settings.png | Bin 0 -> 834 bytes .../assets/icons/3.0x/eye-off.png | Bin 0 -> 981 bytes flutter-ory-network/assets/icons/3.0x/eye.png | Bin 0 -> 904 bytes .../assets/icons/3.0x/logout.png | Bin 0 -> 680 bytes .../assets/icons/3.0x/settings.png | Bin 0 -> 1260 bytes .../assets/icons/4.0x/eye-off.png | Bin 0 -> 1258 bytes flutter-ory-network/assets/icons/4.0x/eye.png | Bin 0 -> 1218 bytes .../assets/icons/4.0x/logout.png | Bin 0 -> 831 bytes .../assets/icons/4.0x/settings.png | Bin 0 -> 1657 bytes flutter-ory-network/assets/icons/logout.png | Bin 0 -> 478 bytes .../assets/images/1.5x/apple.png | Bin 0 -> 641 bytes .../assets/images/1.5x/github.png | Bin 0 -> 929 bytes .../assets/images/1.5x/google.png | Bin 0 -> 944 bytes .../assets/images/1.5x/linkedin.png | Bin 0 -> 851 bytes .../assets/images/2.0x/apple.png | Bin 0 -> 780 bytes .../assets/images/2.0x/github.png | Bin 0 -> 1240 bytes .../assets/images/2.0x/google.png | Bin 0 -> 1223 bytes .../assets/images/2.0x/linkedin.png | Bin 0 -> 1026 bytes .../assets/images/3.0x/apple.png | Bin 0 -> 1097 bytes .../assets/images/3.0x/github.png | Bin 0 -> 1715 bytes .../assets/images/3.0x/google.png | Bin 0 -> 1712 bytes .../assets/images/3.0x/linkedin.png | Bin 0 -> 1409 bytes .../assets/images/4.0x/apple.png | Bin 0 -> 1401 bytes .../assets/images/4.0x/github.png | Bin 0 -> 2371 bytes .../assets/images/4.0x/google.png | Bin 0 -> 2147 bytes .../assets/images/4.0x/linkedin.png | Bin 0 -> 1744 bytes ...-auth-buttons-social-apple.png => apple.png} | Bin ...uth-buttons-social-github.png => github.png} | Bin ...uth-buttons-social-google.png => google.png} | Bin ...buttons-social-linkedin.png => linkedin.png} | Bin flutter-ory-network/lib/pages/home.dart | 2 +- flutter-ory-network/lib/pages/login.dart | 16 ++++++++++------ flutter-ory-network/lib/pages/registration.dart | 10 ++++++---- .../lib/widgets/social_provider_box.dart | 3 +-- flutter-ory-network/pubspec.yaml | 8 ++++++++ 42 files changed, 26 insertions(+), 13 deletions(-) create mode 100644 .DS_Store create mode 100644 flutter-ory-network/assets/icons/1.5x/eye-off.png create mode 100644 flutter-ory-network/assets/icons/1.5x/eye.png create mode 100644 flutter-ory-network/assets/icons/1.5x/logout.png create mode 100644 flutter-ory-network/assets/icons/1.5x/settings.png create mode 100644 flutter-ory-network/assets/icons/2.0x/eye-off.png create mode 100644 flutter-ory-network/assets/icons/2.0x/eye.png create mode 100644 flutter-ory-network/assets/icons/2.0x/settings.png create mode 100644 flutter-ory-network/assets/icons/3.0x/eye-off.png create mode 100644 flutter-ory-network/assets/icons/3.0x/eye.png create mode 100644 flutter-ory-network/assets/icons/3.0x/logout.png create mode 100644 flutter-ory-network/assets/icons/3.0x/settings.png create mode 100644 flutter-ory-network/assets/icons/4.0x/eye-off.png create mode 100644 flutter-ory-network/assets/icons/4.0x/eye.png create mode 100644 flutter-ory-network/assets/icons/4.0x/logout.png create mode 100644 flutter-ory-network/assets/icons/4.0x/settings.png create mode 100644 flutter-ory-network/assets/icons/logout.png create mode 100644 flutter-ory-network/assets/images/1.5x/apple.png create mode 100644 flutter-ory-network/assets/images/1.5x/github.png create mode 100644 flutter-ory-network/assets/images/1.5x/google.png create mode 100644 flutter-ory-network/assets/images/1.5x/linkedin.png create mode 100644 flutter-ory-network/assets/images/2.0x/apple.png create mode 100644 flutter-ory-network/assets/images/2.0x/github.png create mode 100644 flutter-ory-network/assets/images/2.0x/google.png create mode 100644 flutter-ory-network/assets/images/2.0x/linkedin.png create mode 100644 flutter-ory-network/assets/images/3.0x/apple.png create mode 100644 flutter-ory-network/assets/images/3.0x/github.png create mode 100644 flutter-ory-network/assets/images/3.0x/google.png create mode 100644 flutter-ory-network/assets/images/3.0x/linkedin.png create mode 100644 flutter-ory-network/assets/images/4.0x/apple.png create mode 100644 flutter-ory-network/assets/images/4.0x/github.png create mode 100644 flutter-ory-network/assets/images/4.0x/google.png create mode 100644 flutter-ory-network/assets/images/4.0x/linkedin.png rename flutter-ory-network/assets/images/{flows-auth-buttons-social-apple.png => apple.png} (100%) rename flutter-ory-network/assets/images/{flows-auth-buttons-social-github.png => github.png} (100%) rename flutter-ory-network/assets/images/{flows-auth-buttons-social-google.png => google.png} (100%) rename flutter-ory-network/assets/images/{flows-auth-buttons-social-linkedin.png => linkedin.png} (100%) diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..09548ee617ba6040e20fc327fd5d591542a26ace GIT binary patch literal 6148 zcmeHKyG{c^3>-s>NHmdXDE9{__=8mxz92t9!J{C$NKpc!yNd7P(-=R52q&a8G-xb& zXV>TP>ZUlK0od|ze*-K4%;}DJ_hoAS+OzY%~lhN z#qF%$A|2KfwMqdgaIC<29v9yKZ|T3x|HmYqq<|FoR|?o{wO%dxO4VB@FXz3s(eLP< t^FepxJ}6wG9TTG+^Wg3HDv~m<`JT^v;g}e7#)D4O&w%S9lLCLOz$f0J85jTn literal 0 HcmV?d00001 diff --git a/flutter-ory-network/assets/icons/1.5x/eye-off.png b/flutter-ory-network/assets/icons/1.5x/eye-off.png new file mode 100644 index 0000000000000000000000000000000000000000..f8b03985751400ec859269d18e7bc570932ea90d GIT binary patch literal 529 zcmV+s0`C2ZP)!8TKsE>)&<)Z~KsP8Gzy{Q6c#RB z;K6c>40RU@8$!QQJidZgg~3WKEgvmQ8QWRDpPTYap00gHq=dS)SleRtP216WyVaHArK8 zP%cu7)7(VYZ2Gr`@UAPw(FiFss7lsa#tgM`R$^CV1m*0b3OQqqoK8)4%oTeLeNH9i z5IW9d$8!Z=i7(LQlq)C6mD|X~jl#Bs&jmvKfozb8T|!V@5c-4S>%q@7gEpwtUYl^k zCXaV@5^DP#K7CxPl8UFMA95hHYCX&Shvlc`7kr1vHVgP*QD1>Ea;UikL`g&?Yyhs0c5az#FIuLwN1ttQ*#NH#!xDWgQ%1D~E TEi{we00000NkvXXu0mjf+@anf literal 0 HcmV?d00001 diff --git a/flutter-ory-network/assets/icons/1.5x/eye.png b/flutter-ory-network/assets/icons/1.5x/eye.png new file mode 100644 index 0000000000000000000000000000000000000000..0afa80dcbdeca742f1a63bf0f2e145f8d99b644b GIT binary patch literal 497 zcmVAbga(O;TuGDg%=^uZ0?>Kz2 z5VB+&NF)-8|K$$zScwduj!)5n&zrFp<)Th>nouh$7;F?V88V_ul<|Epdc%+v$BF?z zjO=RB^T=iqwxT0tF)Yz<7~1+w?ywLA9X7aP2{`A4J_^jFq9cp>So*4PCAl&fUpE=_ zK}Bb3s|;p?zOHWe9hGU^la&{ebfveN$v*`=jspXgn%#Erc#}2yo z+~E97J0jd=emjZYxh*H=3fl~dT7Z6Uo1}(5C~Yt`W@72coks@o81yxx?Oqjbz5Qvg zz2~^@%SZE6H4}RuvZ6=6??vyT4-7X%XLFD9v+Y&%goW=zmw~y|`xc+NF n4Zk@a&}ZwWcj`nUkyw&1tI>h02$j&400000NkvXXu0mjfANAAp literal 0 HcmV?d00001 diff --git a/flutter-ory-network/assets/icons/1.5x/logout.png b/flutter-ory-network/assets/icons/1.5x/logout.png new file mode 100644 index 0000000000000000000000000000000000000000..4bf0ffb41d9d4a74c8cb20318a9c6085a5616df9 GIT binary patch literal 435 zcmV;k0ZjghP)a)ipB+Md-=u#;PH{#qzAOy0H2n0}9vD2hxz} zepx+|$b!Bh;f*x5xX7H7$bvt{Q5f1XgH!TzN7&RYuG2Rh*wAL+yrdZ8_XkatFf@du z0*R3E$3atvG$feLwr48F&A$(MVW!Jh9;RQQ95KKs=)bgToyM(pqU?`cdJ(tDOK&yNTkk( z#^@SqlawY6h0DAf66t1Yna4oQlJ0;002ovPDHLkV1n76w%h;! literal 0 HcmV?d00001 diff --git a/flutter-ory-network/assets/icons/1.5x/settings.png b/flutter-ory-network/assets/icons/1.5x/settings.png new file mode 100644 index 0000000000000000000000000000000000000000..e1e39a2fc053e5bb46b106f3642562bac7437ce8 GIT binary patch literal 619 zcmV-x0+juUP)j9%bz@VIwy{- zIEp?D%*;%Wt>sY5k*+7@qn2weCz318O@g5fxM*%ma|SOYtEEKq2-ogW%abRFa8*ED9N^I1!k(Di&{0G!&Aht>!g zvYa3!iE2OC;Lw6V&wR*F< zvzLTjsl|{MBOWcrEJ6%z@gx?ZF-omtiI8O`n$Hlj%nIu^2p`+4CGFAF4yg`t;PMN& zOk5zp?5RrKMnOhW@nX=p-EYWy#vvWZoSg**pjGOwu!kH5FxbU+?9u$vB--(Vz4D9k zsK{<_kNen=PK*cWm3oQBv$38bTUxnjB}YhqmiVkJb@h#)$8y0)2YsK$4!7rMsTUbM z#$7?WCB{jPBnFR-n7v~#5$q+7jZW?0Rak_=XfZQ0G5->xuw;3heYyYu002ovPDHLk FV1n224`ToT literal 0 HcmV?d00001 diff --git a/flutter-ory-network/assets/icons/2.0x/eye-off.png b/flutter-ory-network/assets/icons/2.0x/eye-off.png new file mode 100644 index 0000000000000000000000000000000000000000..8f96a2b39f14956ca3223610724542812d0680c0 GIT binary patch literal 697 zcmV;q0!ICbP) z-^@RN(X;eRde6o{p-{MLZd;Bo{OeDylxL$qMjyFS1ZSX_xHLjBab9kFw0ShT!BwWE z(RZV79qngE?~Fcp&HXW}-(D9%IK2|9s7;%8Mr)k0$q~9u1Orb-4@Q;O7B}#HGq#;( zVuW!yu`t@;1|J(yOvERevp6QPHBBRToSAjh*_J#el+k^3t~F<(@*UXQ4DF8z`AV#& zzJ;mCOc=af?)~Z^Kn6Pt|Q9p9$Mn*iI`3qNoSd_at#L zjx`akDbEZnv0)kS6Jo-4%Vi==$c{wfeLqWx3s>6*@|c)WPoyNo{qJ0pMu>xaIkBYP zO1%j)xFwB{c*=hk#+#@ZP*!IQs{$Ji%bzgZM5uyYCA^h*=~T}cMQz;XgEgdMgl2`YMi%|U|Fx|+ ztW?P+ZWxZj8Hqc!PqV)oeev((r`zv+%z|bi*cko7U9>FP=ra?da9iP6?QfH9D>RJ= z16E?p3LHb>%AnQTz3+bDp6WgN*JB9vlL^hlE0GJ~LW!Ldp_q6X2(QS*(O+b5c=-rd f{BLQYP&mO~J{=YSJR>LL00000NkvXXu0mjfS92*3 literal 0 HcmV?d00001 diff --git a/flutter-ory-network/assets/icons/2.0x/eye.png b/flutter-ory-network/assets/icons/2.0x/eye.png new file mode 100644 index 0000000000000000000000000000000000000000..12c2c83c90441efa07143c1841dd204d577d23c0 GIT binary patch literal 645 zcmV;00($+4P)qVxN6#{fOVIqtIGu)mpm~s%_gTu7E=81zjgUw6qL>>$rrh zEoXOyk*LsQT_HWn+TPi*lH#1_=^nFs5Sk^GEQlrIHX1K4r8NueM`(gLdpXGs>zjFY zysxxY@DGH?a?5FfNJtFsYlNM5*<%N`R?t#lG)jhGr>sxE<*9Y=7qn!`(Eg=N%oj@#O(+ zpS<9yi>U$|4A<}q;q~2B!O#-EM@}7i_8~NZ^M2sq6`HadYfB*#R|P^g^Azn1n!Nb= zo+X61D%gRYc9o@ue-H$dwaRJ{&{vKbQnCJY#$_WUh!~EYCnSQ<1d-J6(HNsRF9(o8 zD5Rsn_zBuWXkXMqE@(scw$gE~P*JzebG{1^Odxadj8EBj ztvCB$p1Sw8Pl0xpH(F0H-;6E-!PM%$+CL<2TOz@7N&RJxU=AzR-O;-*m@L2Ig4xbw fGMP*!lM(y^!%g2SB8Pwx00000NkvXXu0mjfhM*!0 literal 0 HcmV?d00001 diff --git a/flutter-ory-network/assets/icons/2.0x/settings.png b/flutter-ory-network/assets/icons/2.0x/settings.png new file mode 100644 index 0000000000000000000000000000000000000000..74d2fd854d0eb4821b3f2d1291b11dbc5477fa04 GIT binary patch literal 834 zcmV-I1HJr-P)|3-!v_ZImvw__S+zs3f+)U7HkUr)u5hL&j$r1$lD4%_& z-yKdZ1wbT70;B^hEG*nKUoam%{wtZ9wQ)!l zJUcO8yAi#6v{Rx?z2%7Qigl03%)RJ@hO8AY{Qo`LbwkVX1=8T}kbx5IO6e8dc#H@g za09;LK(s?$g?6PcaVFhpR*J3@dZg$PQiPqN=h0q%lPhzDcE`suPaLerINsPPLVMOc zCJ-}@wVcPOTCxqnwx1$yqW%YQ>aJdYs1nB`gEfCgeM^y>dMqJLe`o-|__>9xBF6KJ zWy!5OHX4K`69r6%J839$_W}AqN~CqF%|apkmWtjArxzWkwwTcRb?EGszjm?BkIU>s=rRYs_$|pHgXa zVY<{?@klvd4#J^Hkuhb`xT_EQifuM%&#JZ1O-4G7IbK#uSuwTaghT&z^T0l3t;jyx zgwvlC!v{T@Xzie1YDjeOAZ)rmvs7LUhg4y^QQBcRgA8RdLNjY6E|Vlw9QyOPT!Ic) zPTU)z!xf9=5O*~Y`hR{u>qtDtC(K7#%Mbo{I1BA?V}Ge!SXj6K@73Wr?W0^8VE_OC M07*qoM6N<$f}inl#{d8T literal 0 HcmV?d00001 diff --git a/flutter-ory-network/assets/icons/3.0x/eye-off.png b/flutter-ory-network/assets/icons/3.0x/eye-off.png new file mode 100644 index 0000000000000000000000000000000000000000..9ef9e008147cb92255813384144ee830bbaa6557 GIT binary patch literal 981 zcmV;`11kK9P)zjGA8%MU}-+E6k&w@-QlgVTmcI&Fls zB6amSiAY`I$eFgn0!4CHEAg}!rWdIs5nG0d(;!SQQuM&>F6F{7gy}`v5DCTQfZP`$ zy-0i7DaZ{GIMB{m#{|7w(u(9RDr3ig!jAS6P>kb_v>CTX(N184#Un*nA6A?%W5gC| zwn&P$t6lVnA+Mfe&;&}U?5lOW zAl-|A(SKiC%yRh45Uy)pKghcEKFOm;oxJU=9{how$ zm0Yh;q^5nzmDHtEylN4Ki8R?;jiz(AKCP#0|l^^bIQdquUnd+;i8BBGQ;Wiar#zP@gWe z(Y2Tdj+>?an&a;{?pwU!{7R(H`9>WBwTo}9@AeGaGdUTG?%fw-OkYbl6;7C;yV*3` z=1PX`Q+(oBzg~O#5CV!6)5ZGGxQ{Y_n;G$JS>u935N7IbDG_GwZYdD5NM3|2k{2P1 zD<4AV&p+3cx$IF0w2;Hd@I(*f+Bi zPa<#Zuicd_84v_P5ClOG1VIo4K@bGtg*RA^O>L?*d+c(l?YXrl{3jH(?Q5%Q`#saD z_S^#h7!)15+J0ibC_{Fx?TCKVv6C{z6dGalNSkLg=|k!C!~5+$uIYC-;-jqXvGw&T z7>gMC?oiu(+is3eI;TVvJ)x-D;T2FId;=ADYllX-j?sTBtduR%3*%ED+##!qCJKKl zn0_ifARiiiq4rn-B+d!_s8Ps|3S7$x^J*O{A#n~^9)lH#6cWc^Js2!3(if~(9E(9e z^|P=8zc|#py7fgya~_3w3^EsPe<(MIL!lpyt{o9Cl<|Bf8(kH63o<=EoH6aW>ke_0 z=uSam{RMGvhK^&3o2NdEsqISIIGMv3g++*I*>!zDVJg&djJ&p_*M5BB0JH(;TO*hx<4oK|ea0lKRdJ_X)kqEo3W6<2d+-;#Dd~pmi zQG#D2ZhUb{WF)lYx+al)aZXr(kVs2!wQSH`d9dOvy0hW02%fQ?ZJ!DYisRx=B<%>4 zbK`J}{<{Ec*n;ZdueI1{(nv>ve$?ddoLMM@Cx4tm*(pI4_#YB0$$B$42E(tv95H`e zhuZ4)+#$aP2}u0{m8tFHNE=#8Ahm-5fp+Vg3{|ldpz|9ZKTl>?bp__kXs-hE0StItzZ|&Yzhj3AP9mW2!bF8 ef*=S&a{d5y+R{fz<9?t30000XC%(W4-giF*^D5#tVFAA~pln|MWBIp6U* zTt5j@QcRgxVf-W?OgthSrzRTfxHoZzOjAy}x&1U7#G%2s*WMvR6vo}XL0p=x>z^Pq z8Ve=WD5x`WZ5?YYkW_0AYT-#z z%_-KxgQVKWpcV@y9m7Pi#R5skGLvpGQ&NbDqD<1VD~%5H*c9FL@OiQC1mA+Ri5rxI z#=2s8yXy;FtU4-|zI#wNd@AJ0CC2G5<5IWpgb-s;hdhx%d0S5FI_X$aOyp?mc#<69 z7zE9hBh)TvksP6BL5t-GwF>egN2pPdh9@~f?PJg)IYJ3Vd*P5Ge7B=LixLEBY}R)& z(Yu{+P6tnvkYdVeN3RlavFd<=98i!03UWX}4h|8NYn?eLEnmhPhs_PXA>PZ}&2YV>TM?#gW|3a>grA#Pq`QB>KYy`)fxWT*)+6K1EP_JX z?NAB@pfFCi&>`t13)7^(o^!WkHVC)LP0AWQ)@ht{8v-GO5JCtcWG-L$aplAjIxkoN O0000EaEH4eU%nY#?fT<#E2N$(JkpQU_bzu%T}UCN*OcUAxVRLX}^e&d8tu&u;+${452NiDT2 z><50+Q*O)3UEvi#v#fAZzB?^Bryl zTLJW(!&Z2sOpOGf4)SH-6YBg1)!^Li+z8sZ8c?4rTST@fS2@(-9S(O~s+bQ$`~K+~=5{av7=)l6=K@sE%_%eM>~N zqBGbtq>vtNACKyb6znCFDtt*Q91%V{k4Q82h-yKE)Ca{Phdju95qNy^i1gsgOCu6I z-pP;-87A_P?=g;FrCij{3gKj^w(Q1FJfX@c-XaXeo*yuRu?qT#a7Y=Ku!B68qLekN zJW+u#qAhL}@mJR$0ypT6zy}!bd zpqa_h?z|She~w|6p*?M7kfA+o(Q;OJ0h-$fpZObM9SZhf?;z`}f*o`1AYU>D{ywiT z;j-(xeP~Y6QgYaXR0G~su$61%uRizDw_GQ?EpaVpi^_b5Rz5ax(+Cet&+7Nr2($i9 z)I=3#m?m)JfoW*!#9+c5jyu&c1JkUY8-%mQI4f+}O6z%xe)ue1BOJw^?-5SXQRh$| zr1cz95GTcy#*1@EK?QsMf^Z7<{2AeV>8Nuk-`VpRi*DUZv-he;Z25u{{ShS(G2Yar0yu&l^r&g@znHiAzMl-QkApDpc0B!akw08RTRLcj%L{#`vA7Pf;`h2E&(y z#xzHps5xn3T?<*1!rlrC>^}t_OVleVKKmKcAw!sdoD_{j)_DiqKN>`UTaQM17(|>v z_rrh`ad+9E_-9DE!)?5wK$<+&(s0ytP4rJo1Sm|<$Ixw_X66?AohvWpho>BMs@cMc z0^#@V4VkdM3-(Om!V`{+M*GmJ>c2JLFZ+%QJA^s)%bxmj*dKAahg6M7Y~b&(L}<3w=uNhX(tpgtm8pBmX~=^;Y1{t={QJgjPdTngX;SW0;Kot8r;O`+6iy5`$4yIU zQH$%(qGSYP)Ad=6D^b32P6-3_W)q{5(tj+Fp*oh(k)S|zggE-~U}k1!W@cvQWcUZ4 WJF7+^@b3Ho00005jgR3=A9lx&I`x0=e~`E{-7;jBn?3Pkn60F$i?=bgBH*>00($M{Al^xAg?xbKh>sevwir|*ElE2JTg*(FSOq*J)q@{K^ z3o?E5DwpYB=rou2s#W%%{oI0EHf=mN-MC-;RqhIb?=MyfZSMP&ZC&rQLtoHJE77~= zRT=N0+RhJchVxIppXapKQqgQ{-O&z*oqa;DL=+2Vye{cXJ$q=4kSOO9=M~{CH{71O zPW~j_K6kUCz0+K!9D_6LvppWhYdE{tWG-M6Oxk@^noHP%$2MNm*?G_BY(YiQw(hn? zvhA{h8i)6+ne|TH=g7Ngac)=NB^#y{ompPPTl%bJTC3B=poQs4_g0+T+WO072LH4^ zrZdhC-jUDd?&%Mh&ap8vvFur-{r5ff=VCq>{El1U+#;~@cpp;+$Bc3>!Eou9X{kr` zezH~z?ovHn|8&E_rPrLI_@u>VKjJJ?%27_u*EkdNF(_Nnu>ZDdowkm?Q^LXv!rB!p zw@#Q=aolX;{W2YOr#DJDn(Kd07oQerzm>(tbcgiY8)DytWH(=lx)GR^tr-1D*kbSc z&r_a?BuZP>uiUy}@e;T6PTqA<(+VQnrwcq(EsWdz`*5T4cm2xdMTr7RVnxgTw`Cr? z&sFIf5&V+bTk6!Vny#-AWzJCrivD+*3fE_?Xu0v#QFL*$jnbBh#alw$PCxG2u<+Bl z`5B$ZpRrZ9+;+*3Eb6(b*HN6=dERH+4dpAZmquoGc5gUb=RNO$)js-7beoYa`x|OKwthY0zRE*?y$>#xIbH}sSr6o+9+~fHowwc+ QSTr$sy85}Sb4q9e0F;hGv;Y7A literal 0 HcmV?d00001 diff --git a/flutter-ory-network/assets/icons/4.0x/eye.png b/flutter-ory-network/assets/icons/4.0x/eye.png new file mode 100644 index 0000000000000000000000000000000000000000..c5173de0fedd8c77649b1b45a454b683372b5a26 GIT binary patch literal 1218 zcmV;z1U>tSP)@~0drDELIAGL9O(c600d`2O+f$vv5yP?6CkPV zH?t#)CIxV@`{Tg}7=~dOhG7_nVHk#C7=~dOhG7_nVHk#C7{=)Q!7`A_*5UK7%2w~T zE6?HcwX*NwyV?^oXRZz4D*HQps^eD-LmT8N*#DJ1VkB{u-BZiD;Xqz}RtN7d)Il3wxH25+2-Ilz3?JzXL1=G? zBUjW>Z)uOVl8$d8v^T_-1*48t2ggqAEAxslA)TRLm^MfTA)K5XJD~^Wizgj0!a@+@ z(X{?=_mKK7iS=RFhinR4kVq~{eSmJ;-wVngdYCPFCJ zLFpP!pX&ri@+_`35zd1_eNnVij;(5L7#|@$Gxed& zoACEBvR|&~+%RE(u%X=Y!hwF8>nS%{d5Dzd$c%6vX-D$l=;!>J4P_jYlHsgUwB!8b zggi9M+VwcLnK`*KbWK4ia*@J3`DhOLT#sWNWwKQ96q2G+(o@qssXnQ_iX5MlX0RN( z9{4BSX*%FP%JQ0N-!XV>e0OA^+3V*T_t!MX+S23LrZ&Hj58*u9c4R;^py`y(sWyOS zN7`q~zhSz1sx%9kxMSGRa0s4Zv(4D>FjpP7l$ntJLbJtl%{F5hcPX_~7g2=q5ei99 ztl&~>A)fP-)UsS;U)>g4t@MmfEX%S=Pm>$Uw0>#{xIW=Su$Pv7a!_h5td-bW$d>UD zF5lOga=tJ=+elfH+-j4G&K&FTTGpQK&d+r-RV?#!$!{lw^YqVofx>ZWh?wN)wgdTA zB-h0IK4D@U<>rl2M{}m}AE`yGl5St&&B05Guh&$giGd$PV2%1@oaDI&^uFa0+ z;fVJ&o|)r`k4&~KhuG~li*SC8Cw>Au=6#=N+cOQGh2cq0kR0>Fk)H5PcJtLoX}h6H zBTbl|wuc9`?l~rwMG?}GrQ5em!zz@W3Xr8e({K?Ft?M@G3?V<49Iy7kGM{O@~0drDELIAGL9O(c600d`2O+f$vv5yPcg)MqIUg80I~BjP z^TS7m_EllScq{ut94p4{+fa#)*qwjxGvju4RA9~cY9p$0PyJ2>{;-^_s$+arw0Pxi zJ@*H$DXeW}dqbLX6?A*T-+EX?dtW226o4}Y;7kEHQvl8sfHMW)tmXi2Sb&-X`0>o^ z#ahHi`$ESsSMU;vVZd=skSWe325<@+zqECi@dkS_{DR z1PYmV0s)wPymA-rw|mtgC2(v6u?tGX9(d9^GUhB zQuosF#IPvL)}!t?vs3qg?ScPMYi&5voa=&YY$ftyu5&x8f99MIsA5e1NJqcdxmU(@ z)Fb8k#(1y($*@BE>~t0MAaVGd)^kA$V32U=d{6);;new{01}R!4{ZmKaPE9)H-JQd z&WAPwNCfG8XfJ?7pw5T(0tnUl&|U!Lx}Y9stp%_mQ0JSa1&}y>ZD+^J*Os2$(gJvV z4Brrx?h|&VJ7kyvy$Bsc z5D~u2!P>B4VN2l8IZO21ad-~)L93eY2oMnw5fKp)5fPCKxC1BLd;EcjiOK)~002ov JPDHLkV1m){d;b6c literal 0 HcmV?d00001 diff --git a/flutter-ory-network/assets/icons/4.0x/settings.png b/flutter-ory-network/assets/icons/4.0x/settings.png new file mode 100644 index 0000000000000000000000000000000000000000..609dbd861fa4c76843ecb7ff1a48084dd866c0fe GIT binary patch literal 1657 zcmV-<28Q{GP)@~0drDELIAGL9O(c600d`2O+f$vv5yPue%HyTPCk2Nhk`h&lLr2ZKa~c@-cd+|G(V*BPaEL|E9V=mpFcX$>>kf$$-kX^kLMLm|NpL&zfg!qVXWD&;nr+5{Eh#9^}S%tyg-;)ahWTNLNqm=SEgBz zhBsP`!jop+p||CC3)3i!&52r&?#7W$V;L&2jH^duti>ec%U77LP`b}eNr)!%XZqYy zJ(R^Yzo2{!HVA2n|9Mum-_5a+l1#3CFkT!sc4 zX@vKfet{bEp#&}uh{py#>(fyFsWR4BIR@@RYxXaTZiIKZ`nPud4gmEaFg)?*F(#$#mu8*18}Y>2$t<#BpaY**FWQW;P0}^-tCIP z7;GPd4LKKkj3-}Phr8AlR*XVMm+b+b-MZU3SF$(_WJ?atnh^NN*rBa|?!<8j=Tp|qo?;mUC z7E{4p=}VUO=1`E+)>Aa(JhKC&WP7+9V{REX8s&HxX_Hio=iE}rdzRF~x`KPG(Z~ST z{#5h8;gw_{2XEXrki%u>Qnu1e!XIKF3-8X7K|F=L%A+&q{{-)5(t{1pUz(ix^Tnve zTUSC(Nq$a9Tk@YEWIf=KT`S1K^Ox*lH#5&lvQ5q8IH$ z8h~$3`W3R3^f$ZKkb_SSB^Oqx4lKL(3K?*1(W7ev8FOJAc}tlg?qM0EGj(vBo~4ip z?oacHlR-SL2DV6N2ib$c%+QC`E-+h{IxBSt({tVO+inaVX56`ms0@cBUW= z;u^u#3u5z97@Ho+yttxBg*SoQ|_bpbi4_3h) zl(LA!!avTqUYPD_Oq&UdICc}|&{!dRj5RkF3%{A89##*MYk`PpSYFw}%@RnTCb95W z?3|?9W(}D!D+rV0fJV!%QwOLPz1{x-{S5QN%x{11 z^SkxVN(eK4_&Z(q9^bu~}O+24h>S zuw7EVymAq^_KOc%7l5>W6TKk&X_5<}Fn%wwFubG}q}lbg9MoL^-Iv48B-Y z4r*TuIS*>z;(GXzU9YltE5y5O3dh5DIeSjb#{&&E#ck%yel7rUKzYmyyDN1u% z5h2T)yi#L79;opJ6T7^rF>W}8m6CHNoC+?>>t>63!zDftI$)99Z>W|~+ zq>1AL6h%=K28)dE+y#5We13y{2lJ>51^yZAPsrB641`&n2!5Leqzrzg*EtMl&5=>WX&XBz4wv( z0iUDYX@l4w zrOqpI_a*^lG7 ztRfUF{OvuKz$tPOCj!}V!U+|lC=_nDQYD8<2(~x#7%OARqkt^$PseCd99F7+?GC-f z?{yw;a1!zM(W2toV*55Uga)3^Grfu=y1A}KL%EcA8Ld8?W^n>fh$4Q0uW8k8&-R1- zT?k=Da&AbI!x(uri+zNN3Xb}_G&#+Y>xpxTtb=o6U=y~AYtS=x(RtcObi!3FN==7{ bYtA?Y8pONpc>P@800000NkvXXu0mjfYGNa{ literal 0 HcmV?d00001 diff --git a/flutter-ory-network/assets/images/1.5x/github.png b/flutter-ory-network/assets/images/1.5x/github.png new file mode 100644 index 0000000000000000000000000000000000000000..d627e36cca70e6c2c168789db93803b156d5c44c GIT binary patch literal 929 zcmV;S177@zP)ZU3xRe1<`Ga)I-4b~fw6M!d(o#| z2|wHE*##WfAud8y@>TJ(J-z*P&rJUS{6pY0%64ue4`h`BqD@510}y{evKh&S>OjE- zJX&<6SC>ibB_g+TZyX}pV=^a+J`vW0NLQs__u!%AcCMHw>KrE}jX42$D6;Itgq@g3 zzO=eg7Q#AY6E@5S4{>43vgJQ87g#!fI(Pg*SO}uk1N;L?; zg~vZU>3MP}hg4prp7a~FJN-h1v*dU@80mjDem|VPYfV_jjfL*&RHmVhX?0?`bidWb&%nAf{>{ zTKmw;aK3g}+)FeT$L#W8q4#=)Sb3GQE_rfM{nm>dXrBjxwFg#5ov8zsHFfdfh)?8o zb7x#`tnE=ZQVyW29N=>gClWr>1L(n2{hd#X=l4d%v^KG^Cfn)&(OXXd@m>;N325HzT)-{UAq z1qZF$95$&VCQ4AJEW;^G$>;s53jGX#2LlLNM_9tZh#2D~?ld2>vY4813YE8hKSW3! z!+;!MLBweWV-$8SuTIyPX96DR6O^KotlXtl(M7Nv>+N{IlF=Jyj103k+%Bake{K{^ zMQvqSoi!R~48bZ+S`D)aJmQS62EZzOKh!EL8iEmsh=EW};X9m(6rw*`#~4C%tQ_2# zNCm+}RXN|h?w%)xdPb58DAbi$je&`N`rJXpV8Iz*n}QnBz;}{1LH^)O7e1b=0%HZd zonmSonkY@!IaPUVyZQs#9()C+eXrC{LOR}Ta1~r7mj^A`t{t%7{|4N}U$iN9E~moq z57cs4p&>_#B9vA|cFqr_VfTw80tsUWzL~8c)FFmJnfOGTsDZc0vH+<1&fza@i#6QM zLmk2@(De1}Tb4Q*B-a-bNC~}fYN0@d;Sl$Cr2phY@)5ah)NW$!@=#-ACWh%zGEF9!y8*}hzs~0{M&xmWo3tnhIz9+df zNwT12p&n!>cFB~>BJ3mQ|)oi|dPRE}Et7_66y%mHS zy7J&LL}GWs&O;pzNlYN5S#pqcbo(m1=dF1ih6^V-tCv8x2F#BDS$;0$6>xz z85aXF$z+ao(SJK;*g=F*<0nX8MGmIrTU`70xfN}f@B5uU+E9r_)cHb SPUg%20000N&+Qdf&-+oI7lLclhN1?4w_i)=mbtOkN}AgCdGk-v?i7fC+K8!d9@lH z7_3n?jU6!2!KQ(PnAmDtwKOSr=XbBZw(s?*?X%VRTkhWX?%x0IyYIet2k;Le;1Kts z?#dLpT(X{7zK{e5G%PN~a^L9$A#hoM7(MaVU#qtDc6Gw!*%7#UY6zTw0qPl;kKVQ0JM4xc zqqnfRyV|zoJAuN(<>&jacc59g5HlD<;m<*T+_YI{E@zFSoUnJ4GdCGM+6zwMKrOSk z1YG}IbWJ5b+;gSRMryW+vwb%>WEJCJG z`;)SOHlqQFRO(j3&}JBAF|%$-GMeBKPPA!zhs{I^gS5o2TQl-2 zko8|4Eh_svCh0^$m^0Z#d`YVn$_CMc69kJhif;J2%VCCZb`zzyAl?tcy~0=HKz z9rStac4d-D-SNi=@N3W-;;ftbK{=>8xbSDA5j;Q&X9q}}z)CvkpE>A#-SnElQwP_$ z7c;{OG$l%6xO2SqgiGxj#D%9E%D@9a$CZ}`0!j4HBe`AWvNiHe$JZqnUM6r)l&(u5 dYZU(%`~=AD7Lyx9QSJZ$002ovPDHLkV1geziNgQ@ literal 0 HcmV?d00001 diff --git a/flutter-ory-network/assets/images/2.0x/apple.png b/flutter-ory-network/assets/images/2.0x/apple.png new file mode 100644 index 0000000000000000000000000000000000000000..fb4601c60a45ac7b6c22f00e5df7dec415805d1a GIT binary patch literal 780 zcmV+n1M~ceP)(MR};#H&( z7oLn?6VV=^1uv;V|L86fvIbxSuwI=cKYAQFv13JuQLQRx~MA)QQT}%p*sW9e%;L*(XInCLUcN*H*obboswT zBJXT$)h>A6B9cH&-kSqVr<}Q!^89RG-1@)Kni@fntJ}mni4=trZ{heIE?Y_#NLr?}RI_P2X(%0>7?vOQIz1R7#9dA7};;SIJYnm$v# zPckklK9k|329FTJx=o-VR-`5`FUmPm^^f;m0xf4!dlSj$tm_&ZDbiF9_=Moxw)tz- zGUUIB41xQuv9T7kzPY9059d+BmPrYJ2(kHS&m}NcB#}OZM>MEr3WhDtlF6VAzX+~q zEt}AIk)xcMN&cx}bzoL{O&d7tJ(mzGQYlmP(~Y4?;ZDAqx(nhaw~i}-MMjRhR+00u zfZFhjWan%|ed%Q8+)gFFzexf?zm4mLR^Y(s$2XO~eQ&@&_X63|8T5~1li*wy=WSKy z+s<8iSg{2qs@?Q6XMRv3BWAZ64oz?3xqCkR2Q6Hhdr0y9Pcr}=A`IqMLchvfRbDQO zW!G@N)ku9mX)dKg=;!7+(9}hK*oeBR5F1Z-jNp)H-4=VpwdXf6y#BB!i>Ds|0000< KMNUMnLSTX&bzdt0 literal 0 HcmV?d00001 diff --git a/flutter-ory-network/assets/images/2.0x/github.png b/flutter-ory-network/assets/images/2.0x/github.png new file mode 100644 index 0000000000000000000000000000000000000000..33e2fce264f9624a7c7c4805ddb3183912928cca GIT binary patch literal 1240 zcmV;}1Sk86P)<_U0~Ae$#h`~-m`r!`No$&nM@+umXdOt?iH zs8R@3On^Y*A2mIe?Z}cwQWBY}d{wrjnV!)%Jw2`N2Dk!1$N{Ehn{d*%0muqX?|?y4 zzVEc*61Xr)v-C#=h#nA7jUTNPafb+70=ymhVQ(AGiF1=QOXWHdJYua?;9_tPu_4_~ zGwXoNB+WavO`^AT336d%CTlP*cI&B%(nMm>{5gbEHROm(&7ne7FB0&Y4zW4r(>xi|o((e|K z*djK5e*x?ZmGdT&qZOG*V6q>zM??5Di&g2qZk^3>ugU)NQDh-=xDxyT%!LKKZ{0P1 zp%obj^e*@;-M0>39-4Q`HvDqzNXLmadY=sMOyO%gB152vL`YH}*wsNbmZVv-EuwBc z?nNHLr?_@`$SXdCLtdI7fB61D%YB_N2Nw>^2uhov-Eu#Oo{(hL`hzhT zXno*}VW~d>R{+^a8bblkF#N3Q;i$iWCehJJ5{L&dD;SXA zn|)3JKWQYSo$6bvoPGWvqK$;km+EpxvTL*;akAb&kTXC5h6-ptyKh#<&k<)X-8Y*M++vk6 z(rJyOB$Myg!}7e!owNvv&FC3q21>3OHG(a3v0@&ql7QXuGi!4LZ(O^pDrZQ8b;6O~ zR7sbI4M>A0S|A9rfEUyVFFH1*J^6O%s??H){55JSP~R(Xw)nL0>ur}cy2HOCMB_P! zc<#y9kBI?Dq4*o8t(cm_^R7IR2YZ__?RrG)ldvhoJg>Cvz&W7OUm~%eB%|_hE?(7R z`yllN(?mzZSaT}B=G+=#J*_g9Mly+@LTVJG4ib{_5T*jtVNzygPR<7UC`uj1B!Zbp zD##D7wpAj=&OCZb$xA0{L<4HpUW+RlRkp#$X~Q!Iz3RkCcdw2fuEdf}!hmFioZG2t ziv}TFqGryuAaCA=8(&&UC67gI? z$t@JDLJx&T(e`HQrdAK7mqL~t8bhE`YRQScJM;Qx6FXXKza+~_4*6ZQt9di~=gpfp zZwBBw{eeLrs27Yh-`O=l!89V%4+m#xA*xm)HB!rz%?9*H&m!+#$QdBS6bUIIfF7fZ zi3qFOkZNXr+OVJtx)$k*Lq1232J{GhbVb$Fg}7p4ih6zc4RL?Sw^O&CI4&I`?Vl3{?Ppafkc5JBCk0-C%o?x!dJYCi zM+#yJbK^#NVINZO{tY81`6s2Pmu-2vw%k=0tW6L z93cZw36DsH2`kW$;S>y%C*kE;-L|UL5}f;Xxywh>@2yW5UldIfB0yA@RDml|c0y&} z(DdnkZHhpDk*D$xE&GNhr`)rEez(Wqvt|~y`KU}QCPZLfOU25i`-1C1?J4dYj^Vd( zR@+~`+v)8lh zh0t<83h71qPARCJoZ*>?4w2eL$K0~dm@|zjn&vZpV`Q~GbrE``Fpp_l@b#crln6y# zXn*&uCnwjgP`QTTMK6V30=26f)8AUqg}@!HCC^ORAR9)-bmfzjr_%CG=D$sUZ_+@^ z5RSo_T|K{cxdc&$6dse`U7q{rl@D&)$y?blTh7$0NB;{vh{?F4X^njllg9}lOqVd)52qo l(?i@ei{+lLqo30+{s&sP#*lY(asvPW002ovPDHLkV1h2OIOG5T literal 0 HcmV?d00001 diff --git a/flutter-ory-network/assets/images/2.0x/linkedin.png b/flutter-ory-network/assets/images/2.0x/linkedin.png new file mode 100644 index 0000000000000000000000000000000000000000..6fbb990cea2ce3eb6122a97e9fd79ab93083c0e7 GIT binary patch literal 1026 zcmV+d1pWJoP)2TdR^H2z5_*gAkoy?5U4=qo(l-UefB}m_d7$9I^<-=!XotWeoBLDYJXK%rL)@N$$waM62Y-#kb^mt* zaH2PLnSzqy#W2W4SHXy{CF7oJ)>mXf;0*Y$yK>2Lp|`w*dWx)oKod`)id!#SgM}$R zXn{xw$HFn49=eL;n`8hS*5H}rbuit19oC=4V78}K)FmM{CIl7P*qci5U7T=w*4K6c zZk%fp<;bZ980v_CEYNc_JxWC(h)4#?0JzX_wANCuud4x>FrwPVwuuxciHEBheg6$s zH#S8%x0Q#d(_cU)PS&)UfuAN1z=Ne9If#zUimAqO?r$Ds!-#T^|7qYV(&t3MjnY!s zEGRVndlOdq50?SfP5y8zFaFGl_V!4#=!5UhFRzRDJw*bbp?b`^#ZMOe;)2%)`r0nS zWBxOF_-X;BKBmQH!d-8IZD{GCn0;f7&n?3fpJigGN6uzPZtGaKtVzRA!ypN?o|8bN z`{sG*yw>8`U#0n|S+KHI&GXus5XpfyQ?;l3Nv0q zl~EYA7|M2bXP(Ek#@=bo?F^q^&cNud`r`L(H-qQ$=)14Q_N86!$7KA&3N#$61yA@? zXOeNv+T;L+N(K?RO~v7OV literal 0 HcmV?d00001 diff --git a/flutter-ory-network/assets/images/3.0x/apple.png b/flutter-ory-network/assets/images/3.0x/apple.png new file mode 100644 index 0000000000000000000000000000000000000000..2bdc9172b3154fdb358f6d3a5a021c68b7eb445c GIT binary patch literal 1097 zcmV-P1h)H$P)i3Zm*Wnpqu@o^MeqfHvZGUTINC1zx`{>z}2>ybWb=x3?4DrU&cOO2V6av#W!eb{vAutO6igV-oCB!8cd4`;gw1~JbdV{)~0%gP7e zI~^y&yl&LzkTLmMI&PLa9U`Koix6zcS2Q)t=l%^W=*C(F7evmY|Mz9FZj~sQ&>Qt> zTp;;QS@HE{3YsbjK8AOewNjZzUY*EvAPXOlm2iY|%=}WU7PZ}^CT3jGjjz?7*N93X z_7301F~5?5tSo0A_XgJH<=9-S6PbuM$pJIZo(&(*pqQx|42jSFSUZifT0)OXDX(#Q zEqSpry00z5lD}!Nc3V$b@!vy}0!Hu%+i=yY zd-sZ!^S~uOx9i?XM&u7nSagZctwc)&qYQsg0pfW$kXm$7o%G0;#mZIP_@>}MdP{TX zG%yc>YqS7IEV?&E@CV%<#@b@z(@)?D5_9)e9ZfBoPqUq?k5|S1v@oMD1EdyBNj~cf z9H9@=Tbg(q{t$-6rx6^n8NC&}BB;QTD=S+3dMc^7IA9^VS%qJOCgXzxR$11)N6&wm zo53SuqRQ{an$-f|HJiqTI}e`8d-5tA6|221+MDR5_Q)ZP@|6E`0*2pR%)4HbREoHhuo-q-Epr=9X!%zyA z;WfQy8Eet4hEmM>A!Mv zFl4q$DCC1eVRsIe^es9GSSX&r)cTDPEOw&xkOFAtAO67)S4Z5(icv-uU1`HT5z+3(SX)Slf><9Pr P00000NkvXXu0mjf$zS^! literal 0 HcmV?d00001 diff --git a/flutter-ory-network/assets/images/3.0x/github.png b/flutter-ory-network/assets/images/3.0x/github.png new file mode 100644 index 0000000000000000000000000000000000000000..88a204303b909301a076ea3e5623f4a4ce1160d2 GIT binary patch literal 1715 zcmV;k22A;hP)fLYcdz&ELJs66ZP|_$d~Du9pj%KJJj9vRtWqyQ4p>W$P0gbx{KVFv zSnyJ6topvz^u$Rx3L!o_ck!Tc`1V=i7%;$v#Vh~7c($r%>6jkM zwi@?cs-&&?3a?{&o;C(crR)Cxe?98CPW*1bP4=E{!0_;p=(hj*Rqq^@W6_x-(ZEC- zLx5ZF_IGbb&!>_$QR_4{5_9YOq|H=DJhAS*wkWW+nP*RqTCTkHkQNUNQaqe)s1n|X2|(z0 zpjiSTXla4=N*a|7X7H1|up+=~+bDSu0Q@BH5z@!D$;GTv6GK?T@P3dmM$&+`$;APX z2NMOUjF^C83>i*tR%Ap-vff`c@{?A8HcS+_D3}4gqzR2Gh3vrFFi|kRA5Z>7)-;%w zN9{tRt0)M5H5(WTHEO**FhzmURTNwfc1^}%Td2LHC6!}5Q&4nCN28q}Fw;7s7xLCi zx;gEEA^7RumB;Kqzen0V%rNpDE_z?%<8 z*plUO73Na+iR6HzF~do>KDX4?>h)pP1vvJY^bS9@foUVDHkvlW$hL_%x`bm~4o#&_ z4iuYo6N{}|J%VYc?Yer9ieLvaAlzDpFZr@SYTatxL24(0RP)Po3oi5N7qTJLs4 zW!>naInaGc56eqFL;3JJtPUEKxr-o4;@uO69-CxV(dH=V(YyLy<}E0Pq&4BBR*h~~*cjk>@@80P>*KyHAIb z#SPJ}Xd_)#oJtQ^*fCgg!z6r=yLcbQ=JFe=I_m$}`HpV^p8-)rpKx!55kLR{002ov JPDHLkV1fpiE_na| literal 0 HcmV?d00001 diff --git a/flutter-ory-network/assets/images/3.0x/google.png b/flutter-ory-network/assets/images/3.0x/google.png new file mode 100644 index 0000000000000000000000000000000000000000..71d2c039a432c4c7ce1ba131bf806e384d798e4c GIT binary patch literal 1712 zcmV;h22c5kP)$TfbNhOgMf5B8V?Lv z_j~X6d%szL6;}A)g0KW!R@-B;B1MssXui!fK@Ug6M)R0vK$WSw=&N1rDiAXcD0Lvv zI0cA7*#S|50;U1+41lEFcj~ML0aF#xH(qLwnOV|-1Lg=X#Y+C8WlKR~Aapm55!L*J9Tb9)MfaY#Nb7g7M zw75&hARrcEFnD>0UIlZ6MPKh~O%m#B4zo-Pjz~bXoTa1}4|Y;jqmj@|oKhb4a0koG zVx?|G5z`s7sk24%ma+=D_m!<}y@+raynrmB0Ll`I3!0m5SG!tO);Y;csus5U6+Azr z3M_=C2@fu45Wu(ZKYeZte83+#%fpkl<=F$AF;^%22)UYpXIHCqDawkTO@(9D59=ppwFiZ>tsva5+DPS2hKSkI`0SPF>Rpo{t;<3s zmV;nUSxaY6E0aj)=Q5dUfXp{7VEw(y@mfD2q}Ir#PMD`;9y;F5A7j{p#;32_kIB3g zxw`{}{!OWK8Y}}!yEjTZoSMVW{{>AiU$P&_ zV4lnUu#9k=)7g{~M++uEfZ3A|>1z*7w!kvNF%6Y05~Jl8_S-aV|3iaA;F)b7&ZMBq zphX8y9ay8~j~zu*DzoY(1tBP&03T3VwR+l}{~_CB)bhuU=A@wne@K&1YY=w`UTJ9WMJij`z9%IkPVGaP zC*b{mH^Vel3Y*o|V><&W+KI6BgPC5SV&RgNuJ6hiONv%rG&Lx2aqiB0rnbNrvyYUz zeX@P@jTqDd1Yyr&8=51F+oTFThWW?E+y>j7FXq;lyE_+1NAn++uewMLaYor>Z5~7EI`Xi!LMDzE%3-#S3aceW z=Rg2E4kPtc)?xo3&CRsi5pA=+SUhsGNTK++`CpUveKC)ZvW zlNiq&+r=%u7d&En3w!#Mz==rMOlyg;qU48*%;c09B|NRAJO=ZezG!Wb%nh*m&wYUG zvn+%TjvrVvP-ZORv>w~Vt*t^p(1mG(^WuaSKW^#pwKqYTexcMQI!kTKR%cxm5zIy_ z5oEQ5-7ALkdvfs?gwjoz-S{coTK~DzX`Q)sXQg|%PWIbJyV)Wo*TwHnirt;^_u-w| z{z%1|ou?g6y$KIrd)<&Sn}q~(JpXu(Cm`~iJm6<>3j%w(NmAncYhMXhWqtol(vHQ5 z$)&M6YLP}Wu{aV`>;(Z}yF17O>?J`D)CL17?LWW!+Y#_UAfofsK)k_{m0=d=hum7X zkU&M}$%|)q?+C{2QDc8jFjpS&Blh;)pvts;`D)zGvJgAiRyD>#OQq^56NNf^wRFa! zG`%)V#)1%9NYzC>`(=!FhmMb14@-4FeIX-Qpwg# zB~zpeyVmckyw-3Z)*h!c+q9}Sx^D|AG9?=m3RTV7+KG}}-gR)`9(9gj7 zxjF9e6`g=A5rQQK{QT-6BU_DzsEX*$bBifvunQhUy22Y_fvDu_#_aJdDnvy^AD&E) z0_q7aHigQg@dlWAFgLV-GO37Yi)T})K3cO%kKLag(GU;?WzsQ~`HmX&c1VH+iD!oL zPsh~a1q39pr@PLj#gC`?$9~j~Kwb|d`nllS{9^*O$G33bq9Z2Q#Fubiq9ZEU#ItbE zq9ZQYL~CuK@40noJZJB`p^9voK(t9b&Z$4RRr2I%(dl4NTu=7S>utC=)Q5rIPOLu6 z;nvDJ&SzE-I)t3r{AOt0_Ap%V8rI$IhmbvU6m18Z_Smo8S;eXAO9&aAhk1`(n7f9z z*RVeMQE!Q0!RPOHb9)RS6MvFZZ96ZHqJ@`vPiqt&kO_Wq>|is(hB7uGMtQPhj-sD? z*%R09tV!*wo4LaET?@8y%7o1BDB4ed`nP)<`1+^6_t=Es;VZwRW-y$VdD}LTdCl0x zh=i8pS^Uw{e4!y~4Ihq<6%R)pGK@Mbn#wOClxr2vGPr`H{B6N%i`iH9H&kpp*o48p zt`hs&=2QG?@%Uih5ni|SXU&`-65?R83&|sGg>wqbsJXRrAO2yV@s}~HMH=3(O{V(| zD0krl5!QFV`nbd{#GJbR@>HUZs9Vh8sSL(H?8Ve4Z`tgx@)&v3T9kg1@JcK|<}R1-f4NskR^r+fAw15zwzA|Xyxra2 zg1^=uc{(rG(rzt>-YK?2B)s#B%P-1nT)4>Cneh(_qqbs_Z?t+At$?)cEk}ea+{-e4 zT$bOaS{)Le8+M{YSyQrN=e4cvywq;q!-F8t-h_FJn>vAKC(T;6^R$LWg0O$BMMYkR zYG@$DN~pCg6>X@)DxvF_M%+DJfZ!$?0I|4VY_k>3uj?!# zz$zb_mILpY+$go#VB{ex*LR2$XtG6oThaPFpED-7jCzKVtjz2<*&m-s$CW1KAv_>@ zNMg35n6;wmBUwLMU^k!U^}I5uN_%w4f}ZONN5_{p=XpGwM%_UcHs^-MWJg>F9MquG zsJCmIU&~ZAX6z2TiY{E+jLx8r;PU}9y2CoP=k@9K$xNE;&MZb8`>;0gJf3EGV@!k% zqKr#en|Ky2!kjAfSY(9@!TkT}mE3+|66Y(K3gzq7EJBlqJ_PSp4?v`Z`xGn)G)E?W zAR?i@^66DW_}o&IHdwwS6u&JdqY$JNJ3F-1x7KmV@R z#~FCNKNUuA?7V^{yGP)@~0drDELIAGL9O(c600d`2O+f$vv5yPK~#7F?VL|; z+eQ?|zeh!`496|IP~##Sb{EuLFuUxmoS^Or5}zRL31Xk1%?WCspvnoNF1u5K*65-@ zS)dCgDG(;G9mTRZd5@F@Beo@RW=Lri{x;%bKtdni%sjq715{L0R8&+{RFr~$do%Pm zzGu z7$xAWh<-B+l{)=}FN5pG5Y)dY0VhRF1@s2bkh1AtQ!(oG zD2}>?Z8oKdnEtW;U^_|F7F$w_A1krGi)&n0De8J2<+iTN_rBH*isU&w{hy*yZ`%~L zP!Y2rY4V64)A~TPNklAYXPTgz_a4K~*!R3TuczGzh7=;ASV!`9@R&nU-@}ZEz>yfS z9-Ku;C)j-Jh*>+q&A&pa}8&yuMh$w+l#|0cg0s3bla$+o^yg7b@&)`1n{tWNxIPk_I zCMT!tX1KJ8T!wwe16n=N{`NN7SVsAdf8aLl*Ut~Xg8^oim<(o$G%qj_Ti^~1F%nVH zZ268w#Z~}UTf|YZPyk1fY@n_9qrN4oWE&1+GaINaq5^HfQ6v&>GYW37CaT;{>B69r zr?7~Yh<%BEbzu=bORSNVFx1>=+*kk+9mjU6KvP5&pkmBNX^A@Fu1RQ$ND*8{ zvVj)S6LF|Yt#z@^S<-?25GsZx4Gibb_Py|wux45>kr{?Y$& z<7QLVl?EJ!lT7zMS!?3m@ylPKiMEKs>doet{BsYEBh_SV5aH_j?ce%Gz1&`h*=HYl zOE9I!Y)k%p)TNLM<64~0Zhid`I+PQ)Aei)+ucxT&zbGtp2=co#hn(~f(GyD+3M z5#{aj`e;-OT`&@4u;P|kUlT8qu8-?q$Wc>^RuF3SsDpA^b+c3DwDK9!B+f~tE(Zn1 zO9O!d&hdnrO_J8niYTpVTxuGXrzRedc8+{Gus|HHPbSt?XLaL4enFCqpDt*2-{Fq! zvm#3Ey!SWm1iTFMpT+}R5|d&=asaBe^EZwMoJU^UR^aEJH8;b zqGVJo>J7TKtRoflcr8c^QKe>R?Kmp?oSce^ii(Pgih1)MT>|tf1%Z}%00000NkvXX Hu0mjfX*PKt literal 0 HcmV?d00001 diff --git a/flutter-ory-network/assets/images/4.0x/github.png b/flutter-ory-network/assets/images/4.0x/github.png new file mode 100644 index 0000000000000000000000000000000000000000..1896a22d6e544dac23d202948862d1a63cee4c35 GIT binary patch literal 2371 zcmV-J3B2}+P)@~0drDELIAGL9O(c600d`2O+f$vv5yPgwI`BKK==f}krT-$06qccMo)xO+Y{!-4KXEw zLuU{(wBrzF`a(%?oLH~Bk`)qLf1l-84*AW*Qe;Vf{(1N9pSLT36P(}##{>u&fo_y_ z*xsoCY6kuLy#z^H)WO*v1X}zmrL;5+-hwSn7||^8_o@j4!oWy$NNensiH$2n*gPFF zpeLZ97n8owW5AIWQ8z6(A{;r1dg+IXl=gM{=nBb`4*i3Pi1z?SYW*hkNJwOSU?0LvG zEYc7naB%Ym^y^kmtVYs18WKSfz^WW|xQr`+34+uPkb4jBgWfENin@?!B495$JiPS(5 z_V(@_IDP~&bh#&==;vo+e>Wu(T_ZB|b6^;l$VYmqY{WS^u{xifoW72Lcj4=Ri3Kt? zmMOwcO5`WHzl{BR%+q;Jc?O7e$Vk*eE|^7|8vVVdzY_iBBQ7b)Jv$%eM<$ZQbCWY~ zASNM*_LQi((EE7cJD(x2vX~*AhnJ~BCD~K%{LGebkloc zeeFj0JulEbHFlAV!`Gr|qck-sH%Xj@m&x9Tq;L(TZd3M~&Nb-&^5G0oTk`VTcZFq% zh|iDxog~?TkL#;9{oad3;U?|WrRYXEoI8)VmG?Ya50+qP9bA>LeNIp(7Mz=eUg-fC>)hwvA2fh># z6AI%bY2=m40|+G1vB-*{osD=AG7i1y#KvkrcB6U7^9Yf|-3llI)08s(yIk(&<`3I&HoJ6d9_5VM5xB~5eEq&Oo28ofHJ;FvcDvr zZdE`DC^WFMFNJNebI;KgD1gG&%ig{}iKs>*8KRZA(L!dhb9#wh75v&SR@#?DiW8Nr z>o7^72S=>|9)JqCAPWKwOY-@UGA6a5lR^)usfDPrPAMfmh<$@! zyCpG)Y7VHD8(5KLuV9r1HFwA07aw(2jC+SB=@5jZ$q2`Ge9zl%5|!iLJqv~yw4Cu4 z5<>=9XH-<@VTZ(XkQ~7-juLXYp(bB~lJKNVV(TlFU`Uh1p-IFBL23MsG4&xaxs~c+ z5Lto&$q_`NBINKEH~Fob!~sQV7H_*rY=M%~ECDXVu%aElCBKf=#=(!o-4P4apsW6( zgN6j{3aG*2mo5_9A&^@1Av51G&;_?hOR>^7m#gt6U`|9;mA=}!5|(w?c2m732yKfu zz9b?lXJquwm9Q*>r4SJoK@GwyNe+-itpUzP9?4=;qf{ zvogAr%_mt`Yp(c}y_HPwXTyC-bd8JJyx4}podsDX@=Wo<)!s{{TQzSl(Ah?*DXoGX zK$(bqo;B5G3Dh*L3O%56DI_>zX*%Y+*F>w~s5aLi4jBAna-C&LMf-;qwgL;^8;yFS zaHd$G-HQJiC}^SnAt0EVTjp2_xRuk0m>(}L7S2p;Ha=|}=`sQb0QqltvZd*2P?0*3vGno%+Oku2lHZ-@B6GbovqZ;lLws1AIYMsPz}7vL zWmkQ2`i3p>BKdq3=ySVAXIBIxMixgd1>X>s&P~odhdk&mfz#D?DlN%6uHi@v%1z~U zYm_TAmK2_75)P-%$Y+d^%|NXCh4JFIv>Vh2PIF)i<{0NC2m58T*nKDHeb0aNy_T!a#iG}UCIO9}$E>2_X z!?Q4>!A|e!SP^!%HoB6#jqQzkLx=|S0r~L>UT{idiNd0J@E7s!uUN)T`Qbto1J|O6 z^y20G_<7OzRQLTwIZSJadMc!*L?RP7m&EZ;WLP@E^96-@5EAAYu6i}O8PPgi7{C=( z$azO5cM7tB!~`;WB9Y+`IXNxD=EydT?kWk#lJ?C(P6BqdAiuSsGFPWk0l_{bS#9pL zw_ph2TH)0>Rb!W08Hv*q;yR^Ck`Dt03g`I_5l;z-LW)&ktlF=g@Q6F_A>&fX>WkRA z6!w6OxJZ>m4~}}1RMPsjT7O7?VY!bXSe;9&Wuz}8GI)TZ{%VnvnAsqcAFu(-q$yK= z&vEDleIwCB6q#OmS~}>ym#emT4GUXSaY8tyPlY3f`&^t{h3j_6!Q@4sn`w4pIUy-( pS5Vq70COv8OWg@haDrov{{bV<>Bygv5c&WB002ovPDHLkV1nRkWmf@~0drDELIAGL9O(c600d`2O+f$vv5yPoC%+N)=`C3oH%v)nn1M!Lp zOUzJ3oZb2SNR`~y7hFs=s`klhGeZ&a=I-te6Jbn7um}}o$!#Z2k3vACi+H`idl&(e z^=5tLAOXhJw*3CBlj#fyB2~oMo!tlN6ZgReBdB{vKmvCX<%NR?Fa#SAy6<>CYYBT! zU=f|X@Ag89cI&(SD^CV3=xf){q(Kk`0%FbIuKxg125Pqr(^5Nw2*?R!iM$OYR~Uc| z2p7<@l)gvw;AxJqh}U;@jZoqmW)R`U1%tY6+)CycV@~u$#3vZzg$am@dVov;IYQCd z$pdXT2eM(HQ$=P9ZKiv1u?w0OZ&T+r8x-;e)=LG5gxfW;1?2b^aU~L;L#Iq7?Iy;N z;o)u5XLSg`)t%i#z}QGRF~bm$<6A_jxgc4dX{vi=|5LNOx{}lz87VwQHOjPQDuc4W zi{negm14pL2u_CDy8U66s4i zE?BLdjV2(+lZg4_5sji=YW45jUk||2^rL`T)yw6fMa6o-Q=7;Xwx{s#mS=82+sA){ za(~Xt<)pv8w^0S;xSA5CAa2|0_p}=;JkDa4BPLi1SpRJ)e?2wq?K5Y;hX%&g67zPH z_l--IiMWuPcU^KezF*88H&zcpgQIvjq1Wx4P2IDl-5YVVk==L|*T9mSiC$pnt&7J4 z&C<-Hko)ri#|qnLPH%^MfQpuwOGP`p3drFu-TKDA5PRhceK6{9k5I7`rdW0Y1?sl3 zm#;wVrP;$U1JZcyo25j~&TCL(T9l}M?DNe=;jxM$l7JeBk%{ik>L3vl%mn?cV^Cvq zXziz$HNn!&%yxhnfy(W54YGBbxQQq>0*35&Xi%ssw62<7QAA{7A~FRHXi%_(VO12- zPh?*6MYd`{Z`yli7ccK*Y#_Jr1&9$k)y!z$b|7 zy|bc-mZItr%L2drwDctWxbzfN#DCL45-XLHy&#GHuWzS>rou2hUwo*dJ8$mG8UWsd z%RENm(8ANscGcdzr{m~A-Ok&l;HQBAiiPWnE3SDWRj8-H1DCB<*pumXtZ;>RBpa#A z`P=_YcRPg(#|7j<7F|1Bm)5AR9Rl_WMdtKma;x9y3=mcFlTgN` z3*DFRmmnU^DI-uv@CrEv2SH23k|jP@5m}!j;Njxq-0D7^d$G`cOMfl0eO(jpXiz8Q zZShH2%!bKQ$G!EP5!YP&>+)lc`~G9z@9A>JaI9zIy#&;l{%;qDQ9Oq=rVq5~rQYx) zVsy8u(+l4m*Zpd~vz+^ugr^b~%cpADK00n}SxFE_FZYJ$D$d#bgQFjb(=;*2U zj~E~kjoRLYW%XcW;n|_swGV-r4?zINPkeD-#qOqW5qWTkF00a)V8{@Yi+4Mx43o$3 zo|4o4DI{R)m0?hp9|sYrE!yC{44ZBYz^0pn;0qf^PaJ4Vx}7Gx-nr|@JM?SgK?o0?_b07w*3b{WpV8r z)DHR)kR#<85Ikb5S@jTOAXH+iC2QQVq^WY9}db*H!7u3(RhX*yT_5pZx4a zp-KAEAL&wss4bfe<&}eH-~UAiK|*=BP|w5wRc+Li%!E7)c%_<>{K23}ekdZYQrGTH zbpW!yBuF4s5jl=kf||s-2|7%VU}Ue%{(9&lu2Oq3nNIoaXppwA>?cE&SrwDMxwi^! zCUqHUd`MBoz4paLsJe)S@InUlg$HPCyBA7KC>Mc#7=wBcQ#3#}8HUxBqNXAi;*_zn z5iX<#3fn=0V{xh|C)k|=!1~2)EP)@~0drDELIAGL9O(c600d`2O+f$vv5yPFn-oBmbeEWOv z_j|wh2S`atNl8fw5r&ws;*)b3&W#M?*dzc=KxE7>1hjb-8H%z@XJ9&GC~%IO>SA^L z-m#qpG>C?Ys14*>A3Rihq!8U@!CDavDJmP60*|(+#`xVYaz)gMx{KIxzicltOOzD`a31 zn?S%hd{FFF*1vVq4$XS4f@{aYN=IMHn9N)tt*i zxKn6m7&|yUm>qUi6&@+~gIC}&klwnc1BZ9KfeovcVc82Uxb)Y3oc?{%e8m)9_K%%z z`o~4^h#bmEQx~2DJp9%=^vT!rkf`)pz5FG7`SYKMA+0oQmG9e~DthV@pEhIBi>7cob( z>l@u!qJljL!2TZ#I6qM-)I}+7_qUgk1O%%cfIG&C<+$($LV!Y=jjt{>KVQB5z}7tB&! zO!Zrp9?w)b77D(%u5GV*z4H@yPhOc*b*1TT!>TN#q0QV>>7f?TX?5_EH`h-ifwZ?gxZCe^3CoHKFe-!B_OeH+ggn6 z+k&8|Girr3+V_b}Xow-lvg`5g=GE{DMF(WP!4Td=lykG25JM=P<`=tUh#Pp7L5Hn~ z!eh!S36SF^bMp8{cg39*)WWQ*3LwV>K7Ks$`v_tSbai?T9 z^?H#=5wAMrALm9ZwFrAU!b!v;V#uV6A>3pL!@L?4tp$m+#M0wgGz^A{RG3q+-LP#9 zafJ!yO+*=N-$aT9@rSjWoh74hDXnK#psGKX%> zB@&L_Idv}oBYk;ZKAfYCGvip`$fi81 z*I29QYQ(~XaTE(2g|U&E-@yg|NmJ+0Yp z>l?jMahyQ2Bdu_Hu={npDxR`93g>&Vz>oVj5MHj+QQ0J<ePkhsfJEr$;N8aXT^wpRdzxAc zejKWtBc~}|{<1L=)Z==gVIo>-?agNt+I+->Mq5A3oeN9~TkT+8(0n*6NbzsddLcu` mdiqc { ) : IconButton( onPressed: () => context.read()..add(LogOut()), - icon: const Icon(Icons.logout), + icon: Image.asset('assets/icons/logout.png'), ), ], ), diff --git a/flutter-ory-network/lib/pages/login.dart b/flutter-ory-network/lib/pages/login.dart index 4e63be19..f8e070d0 100644 --- a/flutter-ory-network/lib/pages/login.dart +++ b/flutter-ory-network/lib/pages/login.dart @@ -147,11 +147,11 @@ class LoginFormState extends State { const SizedBox( height: 32, ), - const Text("Sign in", + const Text('Sign in', style: TextStyle( fontWeight: FontWeight.w600, height: 1.5, fontSize: 18)), const Text( - "Sign in with a social provider or with your email and password"), + 'Sign in with a social provider or with your email and password'), const SizedBox( height: 32, ), @@ -191,7 +191,8 @@ class LoginFormState extends State { Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - const Text('Email'), + const Text('Email', + style: TextStyle(fontWeight: FontWeight.w600)), const SizedBox( height: 4, ), @@ -219,11 +220,14 @@ class LoginFormState extends State { Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - const Text('Password'), + const Text( + 'Password', + style: TextStyle(fontWeight: FontWeight.w600), + ), // show forgot password only for initial login if (!widget.isSessionRefresh) const TextButton( - onPressed: null, child: Text("Forgot password?")) + onPressed: null, child: Text('Forgot password?')) ], ), const SizedBox( @@ -298,7 +302,7 @@ class LoginFormState extends State { const SizedBox( height: 32, ), - // show logout button is session needs to be refreshed + // show logout button if session needs to be refreshed if (widget.isSessionRefresh) Row( mainAxisAlignment: MainAxisAlignment.start, diff --git a/flutter-ory-network/lib/pages/registration.dart b/flutter-ory-network/lib/pages/registration.dart index 46e72bcb..32cf3d54 100644 --- a/flutter-ory-network/lib/pages/registration.dart +++ b/flutter-ory-network/lib/pages/registration.dart @@ -103,10 +103,10 @@ class RegistrationFormState extends State { const SizedBox( height: 32, ), - const Text("Sign up", + const Text('Sign up', style: TextStyle( fontWeight: FontWeight.w600, height: 1.5, fontSize: 18)), - const Text("Sign up with a social provider or with your email"), + const Text('Sign up with a social provider or with your email'), const SizedBox( height: 32, ), @@ -138,7 +138,8 @@ class RegistrationFormState extends State { Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - const Text('Email'), + const Text('Email', + style: TextStyle(fontWeight: FontWeight.w600)), const SizedBox( height: 4, ), @@ -162,7 +163,8 @@ class RegistrationFormState extends State { Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - const Text('Password'), + const Text('Password', + style: TextStyle(fontWeight: FontWeight.w600)), const SizedBox( height: 4, ), diff --git a/flutter-ory-network/lib/widgets/social_provider_box.dart b/flutter-ory-network/lib/widgets/social_provider_box.dart index 5c1e7884..1e48428a 100644 --- a/flutter-ory-network/lib/widgets/social_provider_box.dart +++ b/flutter-ory-network/lib/widgets/social_provider_box.dart @@ -17,8 +17,7 @@ class SocialProviderBox extends StatelessWidget { decoration: BoxDecoration( border: Border.all(width: 1, color: const Color(0xFFE2E8F0))), child: // get icon from assets depending on provider - Image.asset( - 'assets/images/flows-auth-buttons-social-${provider.name}.png'), + Image.asset('assets/images/${provider.name}.png'), ), ), ); diff --git a/flutter-ory-network/pubspec.yaml b/flutter-ory-network/pubspec.yaml index e4a4b134..350f2b84 100644 --- a/flutter-ory-network/pubspec.yaml +++ b/flutter-ory-network/pubspec.yaml @@ -77,7 +77,15 @@ flutter: assets: - .env - assets/images/ + - assets/images/1.5x/ + - assets/images/2.0x/ + - assets/images/3.0x/ + - assets/images/4.0x/ - assets/icons/ + - assets/icons/1.5x/ + - assets/icons/2.0x/ + - assets/icons/3.0x/ + - assets/icons/4.0x/ # An image asset can refer to one or more resolution-specific "variants", see # https://flutter.dev/assets-and-images/#resolution-aware From e6eb441f0e209d644f0f497e9d5db4705d59fd63 Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Mon, 18 Sep 2023 17:14:15 +0200 Subject: [PATCH 20/57] feat: display settings dynamically --- .../android/app/src/main/AndroidManifest.xml | 1 + .../lib/blocs/auth/auth_bloc.freezed.dart | 3 - .../lib/blocs/login/login_bloc.freezed.dart | 3 - .../registration_bloc.freezed.dart | 3 - .../lib/blocs/settings/settings_bloc.dart | 29 +- .../blocs/settings/settings_bloc.freezed.dart | 52 ++-- .../lib/blocs/settings/settings_event.dart | 16 + .../lib/blocs/settings/settings_state.dart | 2 +- .../lib/entities/form_node.freezed.dart | 3 - .../lib/entities/form_node.g.dart | 3 - .../lib/entities/formfield.freezed.dart | 3 - .../lib/entities/message.freezed.dart | 3 - .../lib/entities/message.g.dart | 3 - .../lib/entities/node_attribute.freezed.dart | 3 - .../lib/entities/node_attribute.g.dart | 3 - flutter-ory-network/lib/pages/home.dart | 8 +- flutter-ory-network/lib/pages/settings.dart | 288 ++++++++++-------- .../lib/repositories/settings.dart | 83 ++++- flutter-ory-network/lib/services/auth.dart | 63 +++- .../lib/services/exceptions.freezed.dart | 3 - .../lib/widgets/input_button.dart | 45 +++ .../lib/widgets/input_field.dart | 95 ++++++ flutter-ory-network/pubspec.lock | 16 + flutter-ory-network/pubspec.yaml | 1 + 24 files changed, 530 insertions(+), 202 deletions(-) create mode 100644 flutter-ory-network/lib/widgets/input_button.dart create mode 100644 flutter-ory-network/lib/widgets/input_field.dart diff --git a/flutter-ory-network/android/app/src/main/AndroidManifest.xml b/flutter-ory-network/android/app/src/main/AndroidManifest.xml index 097b25fe..f105f612 100644 --- a/flutter-ory-network/android/app/src/main/AndroidManifest.xml +++ b/flutter-ory-network/android/app/src/main/AndroidManifest.xml @@ -1,4 +1,5 @@ + { on(_onChangePassword); on(_onChangePasswordVisibility); on(_onSubmitNewPassword); + on(_changeNodeValue); + on(_onSubmitNewSettings); } _onChangePassword(ChangePassword event, Emitter emit) { // remove password and general error when changing email @@ -41,14 +44,34 @@ class SettingsBloc extends Bloc { isPasswordHidden: event.value, isSessionRefreshRequired: false)); } + _changeNodeValue(ChangeNodeValue event, Emitter emit) { + final newSettingsState = repository.changeNodeValue( + settings: state.settingsFlow, name: event.name, value: event.value); + emit(state.copyWith(settingsFlow: newSettingsState)); + } + + Future _onSubmitNewSettings( + SubmitNewSettings event, Emitter emit) async { + try { + emit(state.copyWith(isLoading: true)); + final settings = await repository.submitNewSettings( + flowId: event.flowId, + group: event.group, + nodes: state.settingsFlow?.ui.nodes.toList()); + emit(state.copyWith(isLoading: false, settingsFlow: settings)); + } catch (e) { + print(e); + } + } + Future _onCreateSettingsFlow( SettingsEvent event, Emitter emit) async { try { emit(state.copyWith(isLoading: true, message: null)); - final flowId = await repository.createSettingsFlow(); + final settingsFlow = await repository.createSettingsFlow(); - emit(state.copyWith(isLoading: false, flowId: flowId)); + emit(state.copyWith(isLoading: false, settingsFlow: settingsFlow)); } on CustomException catch (e) { if (e case UnauthorizedException _) { // change auth status as the user is not authenticated @@ -102,7 +125,7 @@ class SettingsBloc extends Bloc { // use new flow id, reset fields and show error emit(state .copyWith( - flowId: e.flowId, + // settings: e.flowId, message: NodeMessage(text: e.message, type: MessageType.error), isLoading: false) .copyWith diff --git a/flutter-ory-network/lib/blocs/settings/settings_bloc.freezed.dart b/flutter-ory-network/lib/blocs/settings/settings_bloc.freezed.dart index 5acc5991..d407b0d5 100644 --- a/flutter-ory-network/lib/blocs/settings/settings_bloc.freezed.dart +++ b/flutter-ory-network/lib/blocs/settings/settings_bloc.freezed.dart @@ -1,6 +1,3 @@ -// Copyright © 2023 Ory Corp -// SPDX-License-Identifier: Apache-2.0 - // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint @@ -19,7 +16,7 @@ final _privateConstructorUsedError = UnsupportedError( /// @nodoc mixin _$SettingsState { - String? get flowId => throw _privateConstructorUsedError; + SettingsFlow? get settingsFlow => throw _privateConstructorUsedError; FormField get password => throw _privateConstructorUsedError; bool get isPasswordHidden => throw _privateConstructorUsedError; bool get isLoading => throw _privateConstructorUsedError; @@ -38,7 +35,7 @@ abstract class $SettingsStateCopyWith<$Res> { _$SettingsStateCopyWithImpl<$Res, SettingsState>; @useResult $Res call( - {String? flowId, + {SettingsFlow? settingsFlow, FormField password, bool isPasswordHidden, bool isLoading, @@ -62,7 +59,7 @@ class _$SettingsStateCopyWithImpl<$Res, $Val extends SettingsState> @pragma('vm:prefer-inline') @override $Res call({ - Object? flowId = freezed, + Object? settingsFlow = freezed, Object? password = null, Object? isPasswordHidden = null, Object? isLoading = null, @@ -70,10 +67,10 @@ class _$SettingsStateCopyWithImpl<$Res, $Val extends SettingsState> Object? message = freezed, }) { return _then(_value.copyWith( - flowId: freezed == flowId - ? _value.flowId - : flowId // ignore: cast_nullable_to_non_nullable - as String?, + settingsFlow: freezed == settingsFlow + ? _value.settingsFlow + : settingsFlow // ignore: cast_nullable_to_non_nullable + as SettingsFlow?, password: null == password ? _value.password : password // ignore: cast_nullable_to_non_nullable @@ -127,7 +124,7 @@ abstract class _$$_SettingsStateCopyWith<$Res> @override @useResult $Res call( - {String? flowId, + {SettingsFlow? settingsFlow, FormField password, bool isPasswordHidden, bool isLoading, @@ -151,7 +148,7 @@ class __$$_SettingsStateCopyWithImpl<$Res> @pragma('vm:prefer-inline') @override $Res call({ - Object? flowId = freezed, + Object? settingsFlow = freezed, Object? password = null, Object? isPasswordHidden = null, Object? isLoading = null, @@ -159,10 +156,10 @@ class __$$_SettingsStateCopyWithImpl<$Res> Object? message = freezed, }) { return _then(_$_SettingsState( - flowId: freezed == flowId - ? _value.flowId - : flowId // ignore: cast_nullable_to_non_nullable - as String?, + settingsFlow: freezed == settingsFlow + ? _value.settingsFlow + : settingsFlow // ignore: cast_nullable_to_non_nullable + as SettingsFlow?, password: null == password ? _value.password : password // ignore: cast_nullable_to_non_nullable @@ -191,7 +188,7 @@ class __$$_SettingsStateCopyWithImpl<$Res> class _$_SettingsState implements _SettingsState { const _$_SettingsState( - {this.flowId, + {this.settingsFlow, this.password = const FormField(value: ''), this.isPasswordHidden = true, this.isLoading = false, @@ -199,7 +196,7 @@ class _$_SettingsState implements _SettingsState { this.message}); @override - final String? flowId; + final SettingsFlow? settingsFlow; @override @JsonKey() final FormField password; @@ -217,7 +214,7 @@ class _$_SettingsState implements _SettingsState { @override String toString() { - return 'SettingsState(flowId: $flowId, password: $password, isPasswordHidden: $isPasswordHidden, isLoading: $isLoading, isSessionRefreshRequired: $isSessionRefreshRequired, message: $message)'; + return 'SettingsState(settingsFlow: $settingsFlow, password: $password, isPasswordHidden: $isPasswordHidden, isLoading: $isLoading, isSessionRefreshRequired: $isSessionRefreshRequired, message: $message)'; } @override @@ -225,7 +222,8 @@ class _$_SettingsState implements _SettingsState { return identical(this, other) || (other.runtimeType == runtimeType && other is _$_SettingsState && - (identical(other.flowId, flowId) || other.flowId == flowId) && + const DeepCollectionEquality() + .equals(other.settingsFlow, settingsFlow) && (identical(other.password, password) || other.password == password) && (identical(other.isPasswordHidden, isPasswordHidden) || @@ -239,8 +237,14 @@ class _$_SettingsState implements _SettingsState { } @override - int get hashCode => Object.hash(runtimeType, flowId, password, - isPasswordHidden, isLoading, isSessionRefreshRequired, message); + int get hashCode => Object.hash( + runtimeType, + const DeepCollectionEquality().hash(settingsFlow), + password, + isPasswordHidden, + isLoading, + isSessionRefreshRequired, + message); @JsonKey(ignore: true) @override @@ -251,7 +255,7 @@ class _$_SettingsState implements _SettingsState { abstract class _SettingsState implements SettingsState { const factory _SettingsState( - {final String? flowId, + {final SettingsFlow? settingsFlow, final FormField password, final bool isPasswordHidden, final bool isLoading, @@ -259,7 +263,7 @@ abstract class _SettingsState implements SettingsState { final NodeMessage? message}) = _$_SettingsState; @override - String? get flowId; + SettingsFlow? get settingsFlow; @override FormField get password; @override diff --git a/flutter-ory-network/lib/blocs/settings/settings_event.dart b/flutter-ory-network/lib/blocs/settings/settings_event.dart index c619b856..03297657 100644 --- a/flutter-ory-network/lib/blocs/settings/settings_event.dart +++ b/flutter-ory-network/lib/blocs/settings/settings_event.dart @@ -38,3 +38,19 @@ final class SubmitNewPassword extends SettingsEvent { @override List get props => [flowId, value]; } + +class ChangeNodeValue extends SettingsEvent { + final T value; + final String name; + + ChangeNodeValue({required this.value, required this.name}); +} + +class SubmitNewSettings extends SettingsEvent { + final String flowId; + final UiNodeGroupEnum group; + + SubmitNewSettings({required this.flowId, required this.group}); + @override + List get props => [flowId, group]; +} diff --git a/flutter-ory-network/lib/blocs/settings/settings_state.dart b/flutter-ory-network/lib/blocs/settings/settings_state.dart index 07b4b765..dbd33579 100644 --- a/flutter-ory-network/lib/blocs/settings/settings_state.dart +++ b/flutter-ory-network/lib/blocs/settings/settings_state.dart @@ -6,7 +6,7 @@ part of 'settings_bloc.dart'; @freezed sealed class SettingsState with _$SettingsState { const factory SettingsState( - {String? flowId, + {SettingsFlow? settingsFlow, @Default(FormField(value: '')) FormField password, @Default(true) bool isPasswordHidden, @Default(false) bool isLoading, diff --git a/flutter-ory-network/lib/entities/form_node.freezed.dart b/flutter-ory-network/lib/entities/form_node.freezed.dart index 96efd5ef..b66dacb6 100644 --- a/flutter-ory-network/lib/entities/form_node.freezed.dart +++ b/flutter-ory-network/lib/entities/form_node.freezed.dart @@ -1,6 +1,3 @@ -// Copyright © 2023 Ory Corp -// SPDX-License-Identifier: Apache-2.0 - // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint diff --git a/flutter-ory-network/lib/entities/form_node.g.dart b/flutter-ory-network/lib/entities/form_node.g.dart index 7b31b119..98e6de11 100644 --- a/flutter-ory-network/lib/entities/form_node.g.dart +++ b/flutter-ory-network/lib/entities/form_node.g.dart @@ -1,6 +1,3 @@ -// Copyright © 2023 Ory Corp -// SPDX-License-Identifier: Apache-2.0 - // GENERATED CODE - DO NOT MODIFY BY HAND part of 'form_node.dart'; diff --git a/flutter-ory-network/lib/entities/formfield.freezed.dart b/flutter-ory-network/lib/entities/formfield.freezed.dart index d8e74a89..67e05f8d 100644 --- a/flutter-ory-network/lib/entities/formfield.freezed.dart +++ b/flutter-ory-network/lib/entities/formfield.freezed.dart @@ -1,6 +1,3 @@ -// Copyright © 2023 Ory Corp -// SPDX-License-Identifier: Apache-2.0 - // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint diff --git a/flutter-ory-network/lib/entities/message.freezed.dart b/flutter-ory-network/lib/entities/message.freezed.dart index 11ded8db..63b47250 100644 --- a/flutter-ory-network/lib/entities/message.freezed.dart +++ b/flutter-ory-network/lib/entities/message.freezed.dart @@ -1,6 +1,3 @@ -// Copyright © 2023 Ory Corp -// SPDX-License-Identifier: Apache-2.0 - // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint diff --git a/flutter-ory-network/lib/entities/message.g.dart b/flutter-ory-network/lib/entities/message.g.dart index cdedc72c..dba500c4 100644 --- a/flutter-ory-network/lib/entities/message.g.dart +++ b/flutter-ory-network/lib/entities/message.g.dart @@ -1,6 +1,3 @@ -// Copyright © 2023 Ory Corp -// SPDX-License-Identifier: Apache-2.0 - // GENERATED CODE - DO NOT MODIFY BY HAND part of 'message.dart'; diff --git a/flutter-ory-network/lib/entities/node_attribute.freezed.dart b/flutter-ory-network/lib/entities/node_attribute.freezed.dart index 08432654..72ddae2d 100644 --- a/flutter-ory-network/lib/entities/node_attribute.freezed.dart +++ b/flutter-ory-network/lib/entities/node_attribute.freezed.dart @@ -1,6 +1,3 @@ -// Copyright © 2023 Ory Corp -// SPDX-License-Identifier: Apache-2.0 - // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint diff --git a/flutter-ory-network/lib/entities/node_attribute.g.dart b/flutter-ory-network/lib/entities/node_attribute.g.dart index 92070a72..92cd7317 100644 --- a/flutter-ory-network/lib/entities/node_attribute.g.dart +++ b/flutter-ory-network/lib/entities/node_attribute.g.dart @@ -1,6 +1,3 @@ -// Copyright © 2023 Ory Corp -// SPDX-License-Identifier: Apache-2.0 - // GENERATED CODE - DO NOT MODIFY BY HAND part of 'node_attribute.dart'; diff --git a/flutter-ory-network/lib/pages/home.dart b/flutter-ory-network/lib/pages/home.dart index f4e6273e..4481c126 100644 --- a/flutter-ory-network/lib/pages/home.dart +++ b/flutter-ory-network/lib/pages/home.dart @@ -85,13 +85,13 @@ class _HomePageState extends State { child: Column( children: [ Text( - "Welcome back,\n${session.identity.id}!", + 'Welcome back,\n${session.identity.id}!', style: const TextStyle(fontWeight: FontWeight.w900, fontSize: 35), ), const Padding( padding: EdgeInsets.only(top: 15.0), child: Text( - "Hello, nice to have you! You signed up with this data:"), + 'Hello, nice to have you! You signed up with this data:'), ), Padding( padding: const EdgeInsets.only(top: 15.0), @@ -109,7 +109,7 @@ class _HomePageState extends State { const Padding( padding: EdgeInsets.only(top: 15.0), child: - Text("You are signed in using an ORY Kratos Session Token:"), + Text('You are signed in using an ORY Kratos Session Token:'), ), Padding( padding: const EdgeInsets.only(top: 15.0), @@ -127,7 +127,7 @@ class _HomePageState extends State { const Padding( padding: EdgeInsets.only(top: 15.0), child: Text( - "This app mackes REST requests to ORY Kratos' Public API to validate and decode the ORY Kratos Session payload:")), + 'This app mackes REST requests to ORY Kratos Public API to validate and decode the ORY Kratos Session payload:')), Padding( padding: const EdgeInsets.only(top: 15.0), child: Container( diff --git a/flutter-ory-network/lib/pages/settings.dart b/flutter-ory-network/lib/pages/settings.dart index a50a1a61..80034a24 100644 --- a/flutter-ory-network/lib/pages/settings.dart +++ b/flutter-ory-network/lib/pages/settings.dart @@ -1,14 +1,19 @@ // Copyright © 2023 Ory Corp // SPDX-License-Identifier: Apache-2.0 +import 'dart:convert'; +import 'dart:typed_data'; + import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:ory_network_flutter/entities/message.dart'; +import 'package:ory_client/ory_client.dart'; import 'package:ory_network_flutter/repositories/settings.dart'; import '../blocs/auth/auth_bloc.dart'; import '../blocs/settings/settings_bloc.dart'; import '../repositories/auth.dart'; +import '../widgets/input_button.dart'; +import '../widgets/input_field.dart'; import 'login.dart'; class SettingsPage extends StatelessWidget { @@ -67,54 +72,65 @@ class _SettingsFormState extends State { @override Widget build(BuildContext context) { final settingsBloc = BlocProvider.of(context); - return BlocListener( - listener: (context, state) async { - if (state.isSessionRefreshRequired) { - await Navigator.push( - context, - MaterialPageRoute( - builder: (context) => const LoginPage( - isSessionRefresh: true, - ))).then((value) { - if (value != null) { - if (value && state.flowId != null) { - settingsBloc.add(SubmitNewPassword( - flowId: state.flowId!, value: state.password.value)); + return MultiBlocListener( + listeners: [ + // if session needs to be refreshed, navigate to login flow screen + BlocListener( + bloc: settingsBloc, + listener: (BuildContext context, SettingsState state) async { + if (state.isSessionRefreshRequired) { + await Navigator.push( + context, + MaterialPageRoute( + builder: (context) => const LoginPage( + isSessionRefresh: true, + ))).then((value) { + if (value != null) { + // if (value && state.flowId != null) { + // settingsBloc.add(SubmitNewPassword( + // flowId: state.flowId!, value: state.password.value)); + // } + } + }); } - } - }); - } - }, - child: BlocConsumer( - bloc: settingsBloc, - // listen to password changes - listenWhen: (previous, current) { - return previous.password.value != current.password.value && - passwordController.text != current.password.value; - }, - // if password value has changed, update text controller value - listener: (BuildContext context, SettingsState state) { - passwordController.text = state.password.value; - }, + }, + ), + // listens to message changes and displays them as a snackbar + BlocListener( + bloc: settingsBloc, + listenWhen: (SettingsState previous, SettingsState current) => + previous.isLoading != current.isLoading && !current.isLoading, + listener: (BuildContext context, SettingsState state) { + if (state.settingsFlow!.ui.messages != null) { + // for simplicity, we will only show the first message in snackbar + ScaffoldMessenger.of(context).showSnackBar(SnackBar( + content: Text(state.settingsFlow!.ui.messages!.first.text), + )); + } + }), + ], + child: BlocBuilder( + buildWhen: (previous, current) => + previous.isLoading != current.isLoading, builder: (context, state) { // settings flow was created - if (state.flowId != null) { - return _buildSettingsForm(context, state); + if (state.settingsFlow != null) { + return _buildUi(context, state); } // otherwise, show loading or error else { return _buildSettingsFlowNotCreated(context, state); } - }), - ); + }, + )); } - _getMessageColor(MessageType type) { + _getMessageColor(UiTextTypeEnum type) { switch (type) { - case MessageType.success: + case UiTextTypeEnum.success: return Colors.green; - case MessageType.error: + case UiTextTypeEnum.error: return Colors.red; - case MessageType.info: + case UiTextTypeEnum.info: return Colors.grey; } } @@ -123,109 +139,117 @@ class _SettingsFormState extends State { if (state.message != null) { return Padding( padding: const EdgeInsets.symmetric(horizontal: 32), - child: Center( - child: Text( - state.message!.text, - style: TextStyle(color: _getMessageColor(state.message!.type)), - )), + child: Center(child: Text(state.message!.text)), ); } else { return const Center(child: CircularProgressIndicator()); } } - _buildSettingsForm(BuildContext context, SettingsState state) { - return Padding( - padding: const EdgeInsets.symmetric(horizontal: 32), - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const SizedBox( - height: 32, - ), - const Text('Set a new password', - style: TextStyle( - fontWeight: FontWeight.w600, height: 1.5, fontSize: 18)), - const Text( - 'The key aspects of a strong password are length, varying characters, no ties to your personal information and no dictionary words.'), - const SizedBox( - height: 32, - ), - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const Text('New password'), - const SizedBox( - height: 4, - ), - TextFormField( - enabled: !state.isLoading, - controller: passwordController, - onChanged: (String value) => context - .read() - .add(ChangePassword(value: value)), - obscureText: state.isPasswordHidden, - decoration: InputDecoration( - border: const OutlineInputBorder(), - hintText: 'Enter a password', - // change password visibility - suffixIcon: GestureDetector( - onTap: () => context.read().add( - ChangePasswordVisibility( - value: !state.isPasswordHidden)), - child: ImageIcon( - state.isPasswordHidden - ? const AssetImage('assets/icons/eye.png') - : const AssetImage('assets/icons/eye-off.png'), - size: 16, - ), - ), - errorText: state.password.errorMessage, - errorMaxLines: 3), - ), - ], - ), - const SizedBox( - height: 32, - ), - // show general error message if it exists - if (state.message != null) - Padding( - padding: const EdgeInsets.only(bottom: 15.0), - child: Text( - state.message!.text, - style: - TextStyle(color: _getMessageColor(state.message!.type)), - maxLines: 3, - ), - ), + _buildUi(BuildContext context, SettingsState state) { + final nodes = state.settingsFlow!.ui.nodes; + final profileNodes = + nodes.where((node) => node.group == UiNodeGroupEnum.profile).toList(); + final passwordNodes = + nodes.where((node) => node.group == UiNodeGroupEnum.password).toList(); + final lookupSecretNodes = nodes + .where((node) => node.group == UiNodeGroupEnum.lookupSecret) + .toList(); + final totpNodes = + nodes.where((node) => node.group == UiNodeGroupEnum.totp).toList(); - // show loading indicator when state is in a loading mode - if (state.isLoading) - const Padding( - padding: EdgeInsets.all(15.0), - child: Center( - child: SizedBox( - width: 30, - height: 30, - child: CircularProgressIndicator())), - ), - SizedBox( - width: double.infinity, - child: FilledButton( - // disable button when state is loading - onPressed: state.isLoading - ? null - : () { - context.read().add(SubmitNewPassword( - flowId: state.flowId!, - value: state.password.value)); - }, - child: const Text('Submit'), + return Stack(children: [ + Padding( + padding: const EdgeInsets.symmetric(horizontal: 32), + child: SingleChildScrollView( + child: Column( + children: [ + const SizedBox( + height: 32, ), - ), - ]), + _buildGroup(context, state.settingsFlow!.id, profileNodes), + _buildGroup(context, state.settingsFlow!.id, passwordNodes), + _buildGroup(context, state.settingsFlow!.id, lookupSecretNodes), + _buildGroup(context, state.settingsFlow!.id, totpNodes), + ], + ), + ), + ), + if (state.isLoading) + const Opacity( + opacity: 0.8, + child: ModalBarrier(dismissible: false, color: Colors.white30), + ), + if (state.isLoading) + const Center( + child: CircularProgressIndicator(), + ), + ]); + } + + _buildTextNode(BuildContext context, UiNode node) { + final attributes = node.attributes.oneOf.value as UiNodeTextAttributes; + return Text(attributes.text.text); + } + + _buildGroup(BuildContext context, String flowId, List nodes) { + final formKey = GlobalKey(); + return Form( + key: formKey, + child: Column( + children: [ + ListView.separated( + physics: NeverScrollableScrollPhysics(), + shrinkWrap: true, + itemBuilder: ((BuildContext context, index) { + final attributes = nodes[index].attributes.oneOf; + if (attributes.isType(UiNodeInputAttributes)) { + return _buildInputNode( + context, flowId, formKey, nodes[index]); + } else if (attributes.isType(UiNodeTextAttributes)) { + return _buildTextNode(context, nodes[index]); + } else if (attributes.isType(UiNodeImageAttributes)) { + return _buildImageNode( + context, flowId, formKey, nodes[index]); + } else { + return Container(); + } + }), + separatorBuilder: (BuildContext context, int index) => + const SizedBox( + height: 20, + ), + itemCount: nodes.length), + ], + ), + ); + } + + _buildInputNode(BuildContext context, String flowId, + GlobalKey formKey, UiNode node) { + final inputNode = node.attributes.oneOf.value as UiNodeInputAttributes; + switch (inputNode.type) { + case UiNodeInputAttributesTypeEnum.submit: + return InputButton(flowId: flowId, node: node, formKey: formKey); + case UiNodeInputAttributesTypeEnum.button: + return InputButton(flowId: flowId, node: node, formKey: formKey); + case UiNodeInputAttributesTypeEnum.hidden: + return Container(); + + default: + return InputField(node: node); + } + } + + _buildImageNode(BuildContext context, String flowId, + GlobalKey formKey, UiNode node) { + final imageNode = node.attributes.oneOf.value as UiNodeImageAttributes; + Uint8List bytes = base64.decode(imageNode.src.split(',').last); + return Center( + child: SizedBox( + width: imageNode.width.toDouble(), + height: imageNode.height.toDouble(), + child: Image.memory(bytes)), ); } } diff --git a/flutter-ory-network/lib/repositories/settings.dart b/flutter-ory-network/lib/repositories/settings.dart index 7a01d6d0..2d0f801f 100644 --- a/flutter-ory-network/lib/repositories/settings.dart +++ b/flutter-ory-network/lib/repositories/settings.dart @@ -1,7 +1,14 @@ // Copyright © 2023 Ory Corp // SPDX-License-Identifier: Apache-2.0 +import 'package:built_value/json_object.dart'; +import 'package:deep_collection/deep_collection.dart'; +import 'package:one_of/one_of.dart'; +import 'package:ory_client/ory_client.dart'; import 'package:ory_network_flutter/entities/message.dart'; +import 'package:collection/collection.dart'; + +import 'package:built_value/built_value.dart'; import '../services/auth.dart'; @@ -10,9 +17,9 @@ class SettingsRepository { SettingsRepository({required this.service}); - Future createSettingsFlow() async { - final flowId = await service.createSettingsFlow(); - return flowId; + Future createSettingsFlow() async { + final settingsFlow = await service.createSettingsFlow(); + return settingsFlow; } Future?> submitNewPassword( @@ -21,4 +28,74 @@ class SettingsRepository { await service.submitNewPassword(flowId: flowId, password: password); return messages; } + + Future submitNewSettings( + {required String flowId, + required UiNodeGroupEnum group, + List? nodes}) async { + // get input nodes of the same group + final inputNodes = nodes?.where((p0) { + if (p0.attributes.oneOf.isType(UiNodeInputAttributes)) { + final type = (p0.attributes.oneOf.value as UiNodeInputAttributes).type; + return p0.group == group && + type != UiNodeInputAttributesTypeEnum.button; + } else { + return false; + } + }); + +// create maps from attribute names and their values + final nestedMaps = inputNodes?.map((e) { + final attributes = e.attributes.oneOf.value as UiNodeInputAttributes; + + return generateNestedMap(attributes.name, attributes.value!.asString); + }).toList(); + + // merge nested maps into one + final mergedMap = + nestedMaps?.reduce((value, element) => value.deepMerge(element)); + print('mergedMap ${mergedMap}'); + + final updatedSettings = await service.submitNewSettings( + flowId: flowId, group: group, value: mergedMap!); + return updatedSettings; + } + + SettingsFlow? changeNodeValue( + {SettingsFlow? settings, required String name, required T value}) { + // get edited node + if (settings != null) { + final node = settings.ui.nodes.firstWhereOrNull((p0) => + p0.attributes.oneOf.isType(UiNodeInputAttributes) && + (p0.attributes.oneOf.value as UiNodeInputAttributes).name == name); + final updatedNode = node?.rebuild((p0) => p0 + ..attributes.update((b) { + final oldValue = b.oneOf?.value as UiNodeInputAttributes; + final newValue = + oldValue.rebuild((p0) => p0.value = JsonObject(value)); + b.oneOf = OneOf1(value: newValue); + })); + + final nodeIndex = settings.ui.nodes.indexOf(node!); + + final newList = settings.ui.nodes.rebuild((p0) => p0 + ..removeAt(nodeIndex) + ..insert(nodeIndex, updatedNode!)); + final newSettings = + settings.rebuild((p0) => p0..ui.nodes.replace(newList)); + return newSettings; + } else { + return settings; + } + } + + /// Generate nested map from [path] with [value] + Map generateNestedMap(String path, String value) { + var steps = path.split('.'); + Object result = value; + for (var step in steps.reversed) { + result = {step: result}; + } + return result as Map; + } } diff --git a/flutter-ory-network/lib/services/auth.dart b/flutter-ory-network/lib/services/auth.dart index d23efc8d..022dbd31 100644 --- a/flutter-ory-network/lib/services/auth.dart +++ b/flutter-ory-network/lib/services/auth.dart @@ -184,7 +184,7 @@ class AuthService { } /// Create settings flow - Future createSettingsFlow() async { + Future createSettingsFlow() async { try { final token = await _storage.getToken(); final response = @@ -192,7 +192,7 @@ class AuthService { if (response.data != null) { // return flow id - return response.data!.id; + return response.data!; } else { throw const CustomException.unknown(); } @@ -206,6 +206,65 @@ class AuthService { } } + Future submitNewSettings( + {required String flowId, + required UiNodeGroupEnum group, + required Map value}) async { + try { + final token = await _storage.getToken(); + final OneOf oneOf; + print(value); + + switch (group) { + case UiNodeGroupEnum.password: + oneOf = OneOf.fromValue1( + value: UpdateSettingsFlowWithPasswordMethod((b) => b + ..method = group.name + ..password = value['password'])); + case UiNodeGroupEnum.profile: + oneOf = OneOf.fromValue1( + value: UpdateSettingsFlowWithProfileMethod((b) => b + ..method = group.name + ..traits = JsonObject(value['traits']))); + case UiNodeGroupEnum.lookupSecret: + oneOf = OneOf.fromValue1( + value: UpdateSettingsFlowWithLookupMethod((b) => b + ..method = group.name + ..lookupSecretConfirm = + getLookupValue(value['lookup_secret_confirm']) + ..lookupSecretDisable = + getLookupValue(value['lookup_secret_disable']) + ..lookupSecretReveal = + getLookupValue(value['lookup_secret_reveal']) + ..lookupSecretRegenerate = + getLookupValue(value['lookup_secret_regenerate']))); + default: + oneOf = OneOf.fromValue1(value: null); + } + + final response = await _ory.updateSettingsFlow( + flow: flowId, + xSessionToken: token, + updateSettingsFlowBody: + UpdateSettingsFlowBody((b) => b..oneOf = oneOf)); + print(response.data?.ui.messages); + + return response.data; + } on DioException catch (e) { + print(e.error); + print(e.response?.data); + } + return null; + } + + bool? getLookupValue(String? value) { + if (value == null) { + return null; + } else { + return value == 'true' ? true : false; + } + } + /// Change old password to new [password] using settings flow with [flowId] Future?> submitNewPassword( {required String flowId, required String password}) async { diff --git a/flutter-ory-network/lib/services/exceptions.freezed.dart b/flutter-ory-network/lib/services/exceptions.freezed.dart index fe7e1b48..02d96051 100644 --- a/flutter-ory-network/lib/services/exceptions.freezed.dart +++ b/flutter-ory-network/lib/services/exceptions.freezed.dart @@ -1,6 +1,3 @@ -// Copyright © 2023 Ory Corp -// SPDX-License-Identifier: Apache-2.0 - // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint diff --git a/flutter-ory-network/lib/widgets/input_button.dart b/flutter-ory-network/lib/widgets/input_button.dart new file mode 100644 index 00000000..d7ed8691 --- /dev/null +++ b/flutter-ory-network/lib/widgets/input_button.dart @@ -0,0 +1,45 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:ory_client/ory_client.dart'; + +import '../blocs/settings/settings_bloc.dart'; + +class InputButton extends StatefulWidget { + final String flowId; + final GlobalKey formKey; + final UiNode node; + + const InputButton( + {super.key, + required this.node, + required this.formKey, + required this.flowId}); + @override + State createState() => _InputButtonState(); +} + +class _InputButtonState extends State { + @override + Widget build(BuildContext context) { + return Column( + children: [ + SizedBox( + width: double.infinity, + child: FilledButton( + // validate input fields that belong to this buttons group + onPressed: () { + if (widget.formKey.currentState!.validate()) { + context.read().add(SubmitNewSettings( + flowId: widget.flowId, group: widget.node.group)); + } + }, + child: Text(widget.node.meta.label?.text ?? ''), + ), + ), + const SizedBox( + height: 20, + ), + ], + ); + } +} diff --git a/flutter-ory-network/lib/widgets/input_field.dart b/flutter-ory-network/lib/widgets/input_field.dart new file mode 100644 index 00000000..b47c7ef7 --- /dev/null +++ b/flutter-ory-network/lib/widgets/input_field.dart @@ -0,0 +1,95 @@ +import 'package:collection/collection.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:ory_client/ory_client.dart'; + +import '../blocs/settings/settings_bloc.dart'; + +class InputField extends StatefulWidget { + final UiNode node; + + const InputField({super.key, required this.node}); + @override + State createState() => _InputFieldState(); +} + +class _InputFieldState extends State { + TextEditingController textEditingController = TextEditingController(); + + @override + void initState() { + super.initState(); + final fieldValue = + (widget.node.attributes.oneOf.value as UiNodeInputAttributes).value; + textEditingController.text = fieldValue != null ? fieldValue.asString : ''; + } + + _getMessageColor(UiTextTypeEnum type) { + switch (type) { + case UiTextTypeEnum.success: + return Colors.green; + case UiTextTypeEnum.error: + return Colors.red; + case UiTextTypeEnum.info: + return Colors.grey; + } + } + + @override + Widget build(BuildContext context) { + final attributes = + widget.node.attributes.oneOf.value as UiNodeInputAttributes; + + return BlocListener( + listenWhen: (previous, current) => + previous.settingsFlow != current.settingsFlow, + listener: (context, state) { + final node = state.settingsFlow?.ui.nodes.firstWhereOrNull((p0) => + (p0.attributes.oneOf.value as UiNodeInputAttributes).name == + attributes.name); + textEditingController.text = + (node?.attributes.oneOf.value as UiNodeInputAttributes) + .value + ?.asString ?? + ''; + }, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + if (widget.node.meta.label?.text != null) + Text( + widget.node.meta.label!.text, + style: const TextStyle(fontWeight: FontWeight.w600), + ), + const SizedBox( + height: 4, + ), + TextFormField( + controller: textEditingController, + enabled: !attributes.disabled, + onChanged: (value) => context + .read() + .add(ChangeNodeValue(value: value, name: attributes.name)), + validator: (value) { + if (attributes.required_ != null) { + if (attributes.required_! && (value == null || value.isEmpty)) { + return 'Property is required'; + } + } + return null; + }, + ), + SizedBox( + height: 20, + ), + for (var message in widget.node.messages) + Text(message.text, + style: TextStyle(color: _getMessageColor(message.type))), + const SizedBox( + height: 20, + ), + ], + ), + ); + } +} diff --git a/flutter-ory-network/pubspec.lock b/flutter-ory-network/pubspec.lock index 84b79d9f..4497a9a7 100644 --- a/flutter-ory-network/pubspec.lock +++ b/flutter-ory-network/pubspec.lock @@ -185,6 +185,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.3.2" + deep_collection: + dependency: "direct main" + description: + name: deep_collection + sha256: "59abffbfd9add6d47e04d623c50c3e2bcf3ed6a1606513dbe3325a738f77cb0c" + url: "https://pub.dev" + source: hosted + version: "1.0.2" dio: dependency: "direct main" description: @@ -201,6 +209,14 @@ packages: url: "https://pub.dev" source: hosted version: "4.1.0" + effective_dart: + dependency: transitive + description: + name: effective_dart + sha256: "6a69783c808344084b65667e87ff600823531e95810a8a15882cb542fe22de80" + url: "https://pub.dev" + source: hosted + version: "1.3.2" equatable: dependency: "direct main" description: diff --git a/flutter-ory-network/pubspec.yaml b/flutter-ory-network/pubspec.yaml index 350f2b84..f02c2220 100644 --- a/flutter-ory-network/pubspec.yaml +++ b/flutter-ory-network/pubspec.yaml @@ -48,6 +48,7 @@ dependencies: google_fonts: ^5.1.0 built_value: ^8.6.2 collection: ^1.17.2 + deep_collection: ^1.0.2 dev_dependencies: flutter_test: From 9d17c9df4e36cc5a5979d41c6a0991f3eeb616dd Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Wed, 20 Sep 2023 12:03:20 +0200 Subject: [PATCH 21/57] chore: create widgets --- flutter-ory-network/lib/pages/settings.dart | 118 ++++++++++-------- .../lib/repositories/settings.dart | 15 ++- flutter-ory-network/lib/services/auth.dart | 16 ++- .../lib/widgets/input_field.dart | 95 -------------- .../lib/widgets/nodes/image.dart | 27 ++++ .../lib/widgets/nodes/input.dart | 105 ++++++++++++++++ .../input_submit.dart} | 22 ++-- .../lib/widgets/nodes/text.dart | 25 ++++ 8 files changed, 252 insertions(+), 171 deletions(-) delete mode 100644 flutter-ory-network/lib/widgets/input_field.dart create mode 100644 flutter-ory-network/lib/widgets/nodes/image.dart create mode 100644 flutter-ory-network/lib/widgets/nodes/input.dart rename flutter-ory-network/lib/widgets/{input_button.dart => nodes/input_submit.dart} (54%) create mode 100644 flutter-ory-network/lib/widgets/nodes/text.dart diff --git a/flutter-ory-network/lib/pages/settings.dart b/flutter-ory-network/lib/pages/settings.dart index 80034a24..93ef3403 100644 --- a/flutter-ory-network/lib/pages/settings.dart +++ b/flutter-ory-network/lib/pages/settings.dart @@ -12,8 +12,10 @@ import 'package:ory_network_flutter/repositories/settings.dart'; import '../blocs/auth/auth_bloc.dart'; import '../blocs/settings/settings_bloc.dart'; import '../repositories/auth.dart'; -import '../widgets/input_button.dart'; -import '../widgets/input_field.dart'; +import '../widgets/nodes/image.dart'; +import '../widgets/nodes/input_submit.dart'; +import '../widgets/nodes/input.dart'; +import '../widgets/nodes/text.dart'; import 'login.dart'; class SettingsPage extends StatelessWidget { @@ -104,6 +106,8 @@ class _SettingsFormState extends State { if (state.settingsFlow!.ui.messages != null) { // for simplicity, we will only show the first message in snackbar ScaffoldMessenger.of(context).showSnackBar(SnackBar( + backgroundColor: _getMessageColor( + state.settingsFlow!.ui.messages!.first.type), content: Text(state.settingsFlow!.ui.messages!.first.text), )); } @@ -167,14 +171,19 @@ class _SettingsFormState extends State { const SizedBox( height: 32, ), - _buildGroup(context, state.settingsFlow!.id, profileNodes), - _buildGroup(context, state.settingsFlow!.id, passwordNodes), - _buildGroup(context, state.settingsFlow!.id, lookupSecretNodes), - _buildGroup(context, state.settingsFlow!.id, totpNodes), + _buildGroup(context, state.settingsFlow!.id, + UiNodeGroupEnum.profile, profileNodes), + _buildGroup(context, state.settingsFlow!.id, + UiNodeGroupEnum.password, passwordNodes), + _buildGroup(context, state.settingsFlow!.id, + UiNodeGroupEnum.lookupSecret, lookupSecretNodes), + _buildGroup(context, state.settingsFlow!.id, UiNodeGroupEnum.totp, + totpNodes), ], ), ), ), + // if state is loading, show loading indicator on screen to disable interaction if (state.isLoading) const Opacity( opacity: 0.8, @@ -187,40 +196,57 @@ class _SettingsFormState extends State { ]); } - _buildTextNode(BuildContext context, UiNode node) { - final attributes = node.attributes.oneOf.value as UiNodeTextAttributes; - return Text(attributes.text.text); + // get group heading + _buildGroupHeadingText(UiNodeGroupEnum group) { + switch (group) { + case UiNodeGroupEnum.lookupSecret: + return 'Backup Recovery Codes'; + case UiNodeGroupEnum.password: + return 'Change Password'; + case UiNodeGroupEnum.profile: + return 'Profile Settings'; + case UiNodeGroupEnum.totp: + return '2FA Authenticator'; + default: + return 'Settings'; + } } - _buildGroup(BuildContext context, String flowId, List nodes) { + _buildGroup(BuildContext context, String flowId, UiNodeGroupEnum group, + List nodes) { final formKey = GlobalKey(); - return Form( - key: formKey, - child: Column( - children: [ - ListView.separated( - physics: NeverScrollableScrollPhysics(), - shrinkWrap: true, - itemBuilder: ((BuildContext context, index) { - final attributes = nodes[index].attributes.oneOf; - if (attributes.isType(UiNodeInputAttributes)) { - return _buildInputNode( - context, flowId, formKey, nodes[index]); - } else if (attributes.isType(UiNodeTextAttributes)) { - return _buildTextNode(context, nodes[index]); - } else if (attributes.isType(UiNodeImageAttributes)) { - return _buildImageNode( - context, flowId, formKey, nodes[index]); - } else { - return Container(); - } - }), - separatorBuilder: (BuildContext context, int index) => - const SizedBox( - height: 20, - ), - itemCount: nodes.length), - ], + return Padding( + padding: const EdgeInsets.only(bottom: 20), + child: Form( + key: formKey, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(_buildGroupHeadingText(group), + style: const TextStyle( + fontWeight: FontWeight.bold, height: 1.5, fontSize: 18)), + const SizedBox( + height: 30, + ), + ListView.builder( + physics: const NeverScrollableScrollPhysics(), + shrinkWrap: true, + itemBuilder: ((BuildContext context, index) { + final attributes = nodes[index].attributes.oneOf; + if (attributes.isType(UiNodeInputAttributes)) { + return _buildInputNode( + context, flowId, formKey, nodes[index]); + } else if (attributes.isType(UiNodeTextAttributes)) { + return TextNode(node: nodes[index]); + } else if (attributes.isType(UiNodeImageAttributes)) { + return ImageNode(node: nodes[index]); + } else { + return Container(); + } + }), + itemCount: nodes.length), + ], + ), ), ); } @@ -230,26 +256,14 @@ class _SettingsFormState extends State { final inputNode = node.attributes.oneOf.value as UiNodeInputAttributes; switch (inputNode.type) { case UiNodeInputAttributesTypeEnum.submit: - return InputButton(flowId: flowId, node: node, formKey: formKey); + return InputSubmitNode(flowId: flowId, node: node, formKey: formKey); case UiNodeInputAttributesTypeEnum.button: - return InputButton(flowId: flowId, node: node, formKey: formKey); + return InputSubmitNode(flowId: flowId, node: node, formKey: formKey); case UiNodeInputAttributesTypeEnum.hidden: return Container(); default: - return InputField(node: node); + return InputNode(node: node); } } - - _buildImageNode(BuildContext context, String flowId, - GlobalKey formKey, UiNode node) { - final imageNode = node.attributes.oneOf.value as UiNodeImageAttributes; - Uint8List bytes = base64.decode(imageNode.src.split(',').last); - return Center( - child: SizedBox( - width: imageNode.width.toDouble(), - height: imageNode.height.toDouble(), - child: Image.memory(bytes)), - ); - } } diff --git a/flutter-ory-network/lib/repositories/settings.dart b/flutter-ory-network/lib/repositories/settings.dart index 2d0f801f..927a660b 100644 --- a/flutter-ory-network/lib/repositories/settings.dart +++ b/flutter-ory-network/lib/repositories/settings.dart @@ -8,8 +8,6 @@ import 'package:ory_client/ory_client.dart'; import 'package:ory_network_flutter/entities/message.dart'; import 'package:collection/collection.dart'; -import 'package:built_value/built_value.dart'; - import '../services/auth.dart'; class SettingsRepository { @@ -65,9 +63,16 @@ class SettingsRepository { {SettingsFlow? settings, required String name, required T value}) { // get edited node if (settings != null) { - final node = settings.ui.nodes.firstWhereOrNull((p0) => - p0.attributes.oneOf.isType(UiNodeInputAttributes) && - (p0.attributes.oneOf.value as UiNodeInputAttributes).name == name); + final node = settings.ui.nodes.firstWhereOrNull((element) { + if (element.attributes.oneOf.isType(UiNodeInputAttributes)) { + return (element.attributes.oneOf.value as UiNodeInputAttributes) + .name == + name; + } else { + return false; + } + }); + final updatedNode = node?.rebuild((p0) => p0 ..attributes.update((b) { final oldValue = b.oneOf?.value as UiNodeInputAttributes; diff --git a/flutter-ory-network/lib/services/auth.dart b/flutter-ory-network/lib/services/auth.dart index 022dbd31..ffdbf69c 100644 --- a/flutter-ory-network/lib/services/auth.dart +++ b/flutter-ory-network/lib/services/auth.dart @@ -231,13 +231,19 @@ class AuthService { value: UpdateSettingsFlowWithLookupMethod((b) => b ..method = group.name ..lookupSecretConfirm = - getLookupValue(value['lookup_secret_confirm']) + getBoolValue(value['lookup_secret_confirm']) ..lookupSecretDisable = - getLookupValue(value['lookup_secret_disable']) + getBoolValue(value['lookup_secret_disable']) ..lookupSecretReveal = - getLookupValue(value['lookup_secret_reveal']) + getBoolValue(value['lookup_secret_reveal']) ..lookupSecretRegenerate = - getLookupValue(value['lookup_secret_regenerate']))); + getBoolValue(value['lookup_secret_regenerate']))); + case UiNodeGroupEnum.totp: + oneOf = OneOf.fromValue1( + value: UpdateSettingsFlowWithTotpMethod((b) => b + ..method = group.name + ..totpCode = value['totp_code'] + ..totpUnlink = getBoolValue(value['totp_unlink']))); default: oneOf = OneOf.fromValue1(value: null); } @@ -257,7 +263,7 @@ class AuthService { return null; } - bool? getLookupValue(String? value) { + bool? getBoolValue(String? value) { if (value == null) { return null; } else { diff --git a/flutter-ory-network/lib/widgets/input_field.dart b/flutter-ory-network/lib/widgets/input_field.dart deleted file mode 100644 index b47c7ef7..00000000 --- a/flutter-ory-network/lib/widgets/input_field.dart +++ /dev/null @@ -1,95 +0,0 @@ -import 'package:collection/collection.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:ory_client/ory_client.dart'; - -import '../blocs/settings/settings_bloc.dart'; - -class InputField extends StatefulWidget { - final UiNode node; - - const InputField({super.key, required this.node}); - @override - State createState() => _InputFieldState(); -} - -class _InputFieldState extends State { - TextEditingController textEditingController = TextEditingController(); - - @override - void initState() { - super.initState(); - final fieldValue = - (widget.node.attributes.oneOf.value as UiNodeInputAttributes).value; - textEditingController.text = fieldValue != null ? fieldValue.asString : ''; - } - - _getMessageColor(UiTextTypeEnum type) { - switch (type) { - case UiTextTypeEnum.success: - return Colors.green; - case UiTextTypeEnum.error: - return Colors.red; - case UiTextTypeEnum.info: - return Colors.grey; - } - } - - @override - Widget build(BuildContext context) { - final attributes = - widget.node.attributes.oneOf.value as UiNodeInputAttributes; - - return BlocListener( - listenWhen: (previous, current) => - previous.settingsFlow != current.settingsFlow, - listener: (context, state) { - final node = state.settingsFlow?.ui.nodes.firstWhereOrNull((p0) => - (p0.attributes.oneOf.value as UiNodeInputAttributes).name == - attributes.name); - textEditingController.text = - (node?.attributes.oneOf.value as UiNodeInputAttributes) - .value - ?.asString ?? - ''; - }, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - if (widget.node.meta.label?.text != null) - Text( - widget.node.meta.label!.text, - style: const TextStyle(fontWeight: FontWeight.w600), - ), - const SizedBox( - height: 4, - ), - TextFormField( - controller: textEditingController, - enabled: !attributes.disabled, - onChanged: (value) => context - .read() - .add(ChangeNodeValue(value: value, name: attributes.name)), - validator: (value) { - if (attributes.required_ != null) { - if (attributes.required_! && (value == null || value.isEmpty)) { - return 'Property is required'; - } - } - return null; - }, - ), - SizedBox( - height: 20, - ), - for (var message in widget.node.messages) - Text(message.text, - style: TextStyle(color: _getMessageColor(message.type))), - const SizedBox( - height: 20, - ), - ], - ), - ); - } -} diff --git a/flutter-ory-network/lib/widgets/nodes/image.dart b/flutter-ory-network/lib/widgets/nodes/image.dart new file mode 100644 index 00000000..6b7b97f1 --- /dev/null +++ b/flutter-ory-network/lib/widgets/nodes/image.dart @@ -0,0 +1,27 @@ +import 'dart:convert'; +import 'dart:typed_data'; + +import 'package:flutter/material.dart'; +import 'package:ory_client/ory_client.dart'; + +class ImageNode extends StatelessWidget { + final UiNode node; + + const ImageNode({super.key, required this.node}); + + @override + Widget build(BuildContext context) { + final imageNode = node.attributes.oneOf.value as UiNodeImageAttributes; + // convert base64 string to bytes + Uint8List bytes = base64.decode(imageNode.src.split(',').last); + return Padding( + padding: const EdgeInsets.only(bottom: 20.0), + child: Center( + child: SizedBox( + width: imageNode.width.toDouble(), + height: imageNode.height.toDouble(), + child: Image.memory(bytes)), + ), + ); + } +} diff --git a/flutter-ory-network/lib/widgets/nodes/input.dart b/flutter-ory-network/lib/widgets/nodes/input.dart new file mode 100644 index 00000000..fa08d068 --- /dev/null +++ b/flutter-ory-network/lib/widgets/nodes/input.dart @@ -0,0 +1,105 @@ +import 'package:collection/collection.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:ory_client/ory_client.dart'; + +import '../../blocs/settings/settings_bloc.dart'; + +class InputNode extends StatefulWidget { + final UiNode node; + + const InputNode({super.key, required this.node}); + @override + State createState() => _InputNodeState(); +} + +class _InputNodeState extends State { + TextEditingController textEditingController = TextEditingController(); + + @override + void initState() { + super.initState(); + // ssign node value to text controller on init + final fieldValue = + (widget.node.attributes.oneOf.value as UiNodeInputAttributes).value; + textEditingController.text = fieldValue != null ? fieldValue.asString : ''; + } + + _getMessageColor(UiTextTypeEnum type) { + switch (type) { + case UiTextTypeEnum.success: + return Colors.green; + case UiTextTypeEnum.error: + return Colors.red; + case UiTextTypeEnum.info: + return Colors.grey; + } + } + + @override + Widget build(BuildContext context) { + final attributes = + widget.node.attributes.oneOf.value as UiNodeInputAttributes; + + return BlocListener( + listenWhen: (previous, current) => + previous.settingsFlow != current.settingsFlow, + listener: (context, state) { + // find current node in updated state + final node = state.settingsFlow?.ui.nodes.firstWhereOrNull((element) { + if (element.attributes.oneOf.isType(UiNodeInputAttributes)) { + return (element.attributes.oneOf.value as UiNodeInputAttributes) + .name == + attributes.name; + } else { + return false; + } + }); + // assign new value of node to text controller + textEditingController.text = + (node?.attributes.oneOf.value as UiNodeInputAttributes) + .value + ?.asString ?? + ''; + }, + child: Padding( + padding: const EdgeInsets.only(bottom: 20.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + if (widget.node.meta.label?.text != null) + Text( + widget.node.meta.label!.text, + style: const TextStyle(fontWeight: FontWeight.w600), + ), + const SizedBox( + height: 4, + ), + TextFormField( + controller: textEditingController, + enabled: !attributes.disabled, + onChanged: (value) => context + .read() + .add(ChangeNodeValue(value: value, name: attributes.name)), + validator: (value) { + if (attributes.required_ != null) { + if (attributes.required_! && + (value == null || value.isEmpty)) { + return 'Property is required'; + } + } + return null; + }, + ), + for (var message in widget.node.messages) + Padding( + padding: const EdgeInsets.only(top: 20), + child: Text(message.text, + style: TextStyle(color: _getMessageColor(message.type))), + ), + ], + ), + ), + ); + } +} diff --git a/flutter-ory-network/lib/widgets/input_button.dart b/flutter-ory-network/lib/widgets/nodes/input_submit.dart similarity index 54% rename from flutter-ory-network/lib/widgets/input_button.dart rename to flutter-ory-network/lib/widgets/nodes/input_submit.dart index d7ed8691..89c54060 100644 --- a/flutter-ory-network/lib/widgets/input_button.dart +++ b/flutter-ory-network/lib/widgets/nodes/input_submit.dart @@ -2,23 +2,19 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:ory_client/ory_client.dart'; -import '../blocs/settings/settings_bloc.dart'; +import '../../blocs/settings/settings_bloc.dart'; -class InputButton extends StatefulWidget { +class InputSubmitNode extends StatelessWidget { final String flowId; final GlobalKey formKey; final UiNode node; - const InputButton( + const InputSubmitNode( {super.key, required this.node, required this.formKey, required this.flowId}); - @override - State createState() => _InputButtonState(); -} -class _InputButtonState extends State { @override Widget build(BuildContext context) { return Column( @@ -28,17 +24,15 @@ class _InputButtonState extends State { child: FilledButton( // validate input fields that belong to this buttons group onPressed: () { - if (widget.formKey.currentState!.validate()) { - context.read().add(SubmitNewSettings( - flowId: widget.flowId, group: widget.node.group)); + if (formKey.currentState!.validate()) { + context + .read() + .add(SubmitNewSettings(flowId: flowId, group: node.group)); } }, - child: Text(widget.node.meta.label?.text ?? ''), + child: Text(node.meta.label?.text ?? ''), ), ), - const SizedBox( - height: 20, - ), ], ); } diff --git a/flutter-ory-network/lib/widgets/nodes/text.dart b/flutter-ory-network/lib/widgets/nodes/text.dart new file mode 100644 index 00000000..26bd54f1 --- /dev/null +++ b/flutter-ory-network/lib/widgets/nodes/text.dart @@ -0,0 +1,25 @@ +import 'package:flutter/material.dart'; +import 'package:ory_client/ory_client.dart'; + +class TextNode extends StatelessWidget { + final UiNode node; + + const TextNode({super.key, required this.node}); + @override + Widget build(BuildContext context) { + final attributes = node.attributes.oneOf.value as UiNodeTextAttributes; + return Padding( + padding: const EdgeInsets.only(bottom: 20.0), + child: Column( + children: [ + // show label test if it is available + if (node.meta.label?.text != null) Text(node.meta.label!.text), + const SizedBox( + height: 10, + ), + Text(attributes.text.text), + ], + ), + ); + } +} From 5598f8c64d48f319f548669415ac39ba914af310 Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Fri, 22 Sep 2023 17:36:36 +0200 Subject: [PATCH 22/57] fix: chnge submit button value --- .../lib/blocs/settings/settings_bloc.dart | 132 +++++++++--------- .../blocs/settings/settings_bloc.freezed.dart | 49 +------ .../lib/blocs/settings/settings_event.dart | 30 ++-- .../lib/blocs/settings/settings_state.dart | 1 - flutter-ory-network/lib/pages/settings.dart | 125 +++++++++++------ .../lib/repositories/settings.dart | 111 ++++++++------- flutter-ory-network/lib/services/auth.dart | 130 ++++++----------- .../lib/services/exceptions.dart | 2 +- .../lib/services/exceptions.freezed.dart | 52 +++---- .../lib/widgets/nodes/input.dart | 25 ++++ .../lib/widgets/nodes/input_submit.dart | 22 ++- flutter-ory-network/pubspec.lock | 8 ++ flutter-ory-network/pubspec.yaml | 1 + 13 files changed, 344 insertions(+), 344 deletions(-) diff --git a/flutter-ory-network/lib/blocs/settings/settings_bloc.dart b/flutter-ory-network/lib/blocs/settings/settings_bloc.dart index 50951027..b1024d73 100644 --- a/flutter-ory-network/lib/blocs/settings/settings_bloc.dart +++ b/flutter-ory-network/lib/blocs/settings/settings_bloc.dart @@ -2,14 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 import 'package:bloc/bloc.dart'; +import 'package:bloc_concurrency/bloc_concurrency.dart'; import 'package:equatable/equatable.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:collection/collection.dart'; import 'package:ory_client/ory_client.dart'; import 'package:ory_network_flutter/entities/message.dart'; import 'package:ory_network_flutter/repositories/auth.dart'; -import '../../entities/formfield.dart'; import '../../repositories/settings.dart'; import '../../services/exceptions.dart'; import '../auth/auth_bloc.dart'; @@ -22,20 +21,27 @@ part 'settings_bloc.freezed.dart'; class SettingsBloc extends Bloc { final AuthBloc authBloc; final SettingsRepository repository; + late SettingsEvent? _previousEvent; SettingsBloc({required this.authBloc, required this.repository}) : super(SettingsState()) { on(_onCreateSettingsFlow); - on(_onChangePassword); + on(_onGetSettingsFlow); on(_onChangePasswordVisibility); - on(_onSubmitNewPassword); - on(_changeNodeValue); - on(_onSubmitNewSettings); + on(_onChangeNodeValue, transformer: sequential()); + on(_onResetButtonValues); + on(_onUpdateSettingsFlow); } - _onChangePassword(ChangePassword event, Emitter emit) { - // remove password and general error when changing email - emit(state.copyWith - .password(value: event.value, errorMessage: null) - .copyWith(message: null, isSessionRefreshRequired: false)); + + @override + void onEvent(SettingsEvent event) { + _previousEvent = event; + super.onEvent(event); + } + + void retry() { + if (_previousEvent != null) { + add(_previousEvent!); + } } _onChangePasswordVisibility( @@ -44,23 +50,51 @@ class SettingsBloc extends Bloc { isPasswordHidden: event.value, isSessionRefreshRequired: false)); } - _changeNodeValue(ChangeNodeValue event, Emitter emit) { - final newSettingsState = repository.changeNodeValue( - settings: state.settingsFlow, name: event.name, value: event.value); - emit(state.copyWith(settingsFlow: newSettingsState)); + _onChangeNodeValue(ChangeNodeValue event, Emitter emit) { + if (state.settingsFlow != null) { + final newSettingsState = repository.changeNodeValue( + settings: state.settingsFlow!, name: event.name, value: event.value); + emit(state.copyWith(settingsFlow: newSettingsState, message: null)); + } } - Future _onSubmitNewSettings( - SubmitNewSettings event, Emitter emit) async { + _onResetButtonValues(ResetButtonValues event, Emitter emit) { + if (state.settingsFlow != null) { + final updatedSettings = + repository.resetButtonValues(settingsFlow: state.settingsFlow!); + emit(state.copyWith(settingsFlow: updatedSettings)); + } + } + + Future _onUpdateSettingsFlow( + UpdateSettingsFlow event, Emitter emit) async { try { - emit(state.copyWith(isLoading: true)); - final settings = await repository.submitNewSettings( - flowId: event.flowId, - group: event.group, - nodes: state.settingsFlow?.ui.nodes.toList()); - emit(state.copyWith(isLoading: false, settingsFlow: settings)); - } catch (e) { - print(e); + if (state.settingsFlow != null) { + emit(state.copyWith( + isLoading: true, isSessionRefreshRequired: false, message: null)); + final settings = await repository.updateSettingsFlow( + flowId: state.settingsFlow!.id, + group: event.group, + nodes: state.settingsFlow!.ui.nodes.toList()); + emit(state.copyWith(isLoading: false, settingsFlow: settings)); + } + } on CustomException catch (e) { + if (e case UnauthorizedException _) { + // change auth status as the user is not authenticated + authBloc.add(ChangeAuthStatus(status: AuthStatus.unauthenticated)); + } else if (e case FlowExpiredException _) { + // create new settings flow + add(GetSettingsFlow(flowId: e.flowId)); + } else if (e case SessionRefreshRequiredException _) { + // set session required flag to navigate to login page + emit(state.copyWith(isSessionRefreshRequired: true, isLoading: false)); + } else if (e case UnknownException _) { + emit(state.copyWith( + isLoading: false, + message: NodeMessage(text: e.message, type: MessageType.error))); + } else { + emit(state.copyWith(isLoading: false)); + } } } @@ -86,53 +120,17 @@ class SettingsBloc extends Bloc { } } - Future _onSubmitNewPassword( - SubmitNewPassword event, Emitter emit) async { + Future _onGetSettingsFlow( + GetSettingsFlow event, Emitter emit) async { try { - emit(state - .copyWith( - isLoading: true, message: null, isSessionRefreshRequired: false) - .copyWith - .password(errorMessage: null)); - - final messages = await repository.submitNewPassword( - flowId: event.flowId, password: event.value); - - // password was successfully changed, reset password field and show general message. - // for simplicity, only the first general message is shown in ui - emit(state - .copyWith(isLoading: false, message: messages?.first) - .copyWith - .password(value: '')); + emit(state.copyWith(isLoading: true)); + final settingsFlow = + await repository.getSettingsFlow(flowId: event.flowId); + emit(state.copyWith(isLoading: false, settingsFlow: settingsFlow)); } on CustomException catch (e) { if (e case UnauthorizedException _) { // change auth status as the user is not authenticated authBloc.add(ChangeAuthStatus(status: AuthStatus.unauthenticated)); - } else if (e case BadRequestException _) { - // get input and general errors. - // for simplicity, only first messages of a specific context are shown in ui - final passwordMessage = e.messages - ?.firstWhereOrNull((element) => element.attr == 'password'); - final generalMessage = e.messages - ?.firstWhereOrNull((element) => element.attr == 'general'); - - // update state to new one with errors - emit(state - .copyWith(isLoading: false, message: generalMessage) - .copyWith - .password(errorMessage: passwordMessage?.text)); - } else if (e case FlowExpiredException _) { - // use new flow id, reset fields and show error - emit(state - .copyWith( - // settings: e.flowId, - message: NodeMessage(text: e.message, type: MessageType.error), - isLoading: false) - .copyWith - .password(value: '')); - } else if (e case SessionRefreshRequiredException _) { - // set session required flag to navigate to login page and reset password field - emit(state.copyWith(isSessionRefreshRequired: true, isLoading: false)); } else if (e case UnknownException _) { emit(state.copyWith( isLoading: false, diff --git a/flutter-ory-network/lib/blocs/settings/settings_bloc.freezed.dart b/flutter-ory-network/lib/blocs/settings/settings_bloc.freezed.dart index d407b0d5..2858b243 100644 --- a/flutter-ory-network/lib/blocs/settings/settings_bloc.freezed.dart +++ b/flutter-ory-network/lib/blocs/settings/settings_bloc.freezed.dart @@ -17,7 +17,6 @@ final _privateConstructorUsedError = UnsupportedError( /// @nodoc mixin _$SettingsState { SettingsFlow? get settingsFlow => throw _privateConstructorUsedError; - FormField get password => throw _privateConstructorUsedError; bool get isPasswordHidden => throw _privateConstructorUsedError; bool get isLoading => throw _privateConstructorUsedError; bool get isSessionRefreshRequired => throw _privateConstructorUsedError; @@ -36,13 +35,11 @@ abstract class $SettingsStateCopyWith<$Res> { @useResult $Res call( {SettingsFlow? settingsFlow, - FormField password, bool isPasswordHidden, bool isLoading, bool isSessionRefreshRequired, NodeMessage? message}); - $FormFieldCopyWith get password; $NodeMessageCopyWith<$Res>? get message; } @@ -60,7 +57,6 @@ class _$SettingsStateCopyWithImpl<$Res, $Val extends SettingsState> @override $Res call({ Object? settingsFlow = freezed, - Object? password = null, Object? isPasswordHidden = null, Object? isLoading = null, Object? isSessionRefreshRequired = null, @@ -71,10 +67,6 @@ class _$SettingsStateCopyWithImpl<$Res, $Val extends SettingsState> ? _value.settingsFlow : settingsFlow // ignore: cast_nullable_to_non_nullable as SettingsFlow?, - password: null == password - ? _value.password - : password // ignore: cast_nullable_to_non_nullable - as FormField, isPasswordHidden: null == isPasswordHidden ? _value.isPasswordHidden : isPasswordHidden // ignore: cast_nullable_to_non_nullable @@ -94,14 +86,6 @@ class _$SettingsStateCopyWithImpl<$Res, $Val extends SettingsState> ) as $Val); } - @override - @pragma('vm:prefer-inline') - $FormFieldCopyWith get password { - return $FormFieldCopyWith(_value.password, (value) { - return _then(_value.copyWith(password: value) as $Val); - }); - } - @override @pragma('vm:prefer-inline') $NodeMessageCopyWith<$Res>? get message { @@ -125,14 +109,11 @@ abstract class _$$_SettingsStateCopyWith<$Res> @useResult $Res call( {SettingsFlow? settingsFlow, - FormField password, bool isPasswordHidden, bool isLoading, bool isSessionRefreshRequired, NodeMessage? message}); - @override - $FormFieldCopyWith get password; @override $NodeMessageCopyWith<$Res>? get message; } @@ -149,7 +130,6 @@ class __$$_SettingsStateCopyWithImpl<$Res> @override $Res call({ Object? settingsFlow = freezed, - Object? password = null, Object? isPasswordHidden = null, Object? isLoading = null, Object? isSessionRefreshRequired = null, @@ -160,10 +140,6 @@ class __$$_SettingsStateCopyWithImpl<$Res> ? _value.settingsFlow : settingsFlow // ignore: cast_nullable_to_non_nullable as SettingsFlow?, - password: null == password - ? _value.password - : password // ignore: cast_nullable_to_non_nullable - as FormField, isPasswordHidden: null == isPasswordHidden ? _value.isPasswordHidden : isPasswordHidden // ignore: cast_nullable_to_non_nullable @@ -189,7 +165,6 @@ class __$$_SettingsStateCopyWithImpl<$Res> class _$_SettingsState implements _SettingsState { const _$_SettingsState( {this.settingsFlow, - this.password = const FormField(value: ''), this.isPasswordHidden = true, this.isLoading = false, this.isSessionRefreshRequired = false, @@ -199,9 +174,6 @@ class _$_SettingsState implements _SettingsState { final SettingsFlow? settingsFlow; @override @JsonKey() - final FormField password; - @override - @JsonKey() final bool isPasswordHidden; @override @JsonKey() @@ -214,7 +186,7 @@ class _$_SettingsState implements _SettingsState { @override String toString() { - return 'SettingsState(settingsFlow: $settingsFlow, password: $password, isPasswordHidden: $isPasswordHidden, isLoading: $isLoading, isSessionRefreshRequired: $isSessionRefreshRequired, message: $message)'; + return 'SettingsState(settingsFlow: $settingsFlow, isPasswordHidden: $isPasswordHidden, isLoading: $isLoading, isSessionRefreshRequired: $isSessionRefreshRequired, message: $message)'; } @override @@ -222,10 +194,8 @@ class _$_SettingsState implements _SettingsState { return identical(this, other) || (other.runtimeType == runtimeType && other is _$_SettingsState && - const DeepCollectionEquality() - .equals(other.settingsFlow, settingsFlow) && - (identical(other.password, password) || - other.password == password) && + (identical(other.settingsFlow, settingsFlow) || + other.settingsFlow == settingsFlow) && (identical(other.isPasswordHidden, isPasswordHidden) || other.isPasswordHidden == isPasswordHidden) && (identical(other.isLoading, isLoading) || @@ -237,14 +207,8 @@ class _$_SettingsState implements _SettingsState { } @override - int get hashCode => Object.hash( - runtimeType, - const DeepCollectionEquality().hash(settingsFlow), - password, - isPasswordHidden, - isLoading, - isSessionRefreshRequired, - message); + int get hashCode => Object.hash(runtimeType, settingsFlow, isPasswordHidden, + isLoading, isSessionRefreshRequired, message); @JsonKey(ignore: true) @override @@ -256,7 +220,6 @@ class _$_SettingsState implements _SettingsState { abstract class _SettingsState implements SettingsState { const factory _SettingsState( {final SettingsFlow? settingsFlow, - final FormField password, final bool isPasswordHidden, final bool isLoading, final bool isSessionRefreshRequired, @@ -265,8 +228,6 @@ abstract class _SettingsState implements SettingsState { @override SettingsFlow? get settingsFlow; @override - FormField get password; - @override bool get isPasswordHidden; @override bool get isLoading; diff --git a/flutter-ory-network/lib/blocs/settings/settings_event.dart b/flutter-ory-network/lib/blocs/settings/settings_event.dart index 03297657..2a3c0ca6 100644 --- a/flutter-ory-network/lib/blocs/settings/settings_event.dart +++ b/flutter-ory-network/lib/blocs/settings/settings_event.dart @@ -11,13 +11,10 @@ sealed class SettingsEvent extends Equatable { final class CreateSettingsFlow extends SettingsEvent {} -final class ChangePassword extends SettingsEvent { - final String value; - - ChangePassword({required this.value}); +final class GetSettingsFlow extends SettingsEvent { + final String flowId; - @override - List get props => [value]; + GetSettingsFlow({required this.flowId}); } final class ChangePasswordVisibility extends SettingsEvent { @@ -29,28 +26,21 @@ final class ChangePasswordVisibility extends SettingsEvent { List get props => [value]; } -final class SubmitNewPassword extends SettingsEvent { - final String flowId; - final String value; - - SubmitNewPassword({required this.flowId, required this.value}); - - @override - List get props => [flowId, value]; -} - class ChangeNodeValue extends SettingsEvent { final T value; final String name; ChangeNodeValue({required this.value, required this.name}); + @override + List get props => [name]; } -class SubmitNewSettings extends SettingsEvent { - final String flowId; +class ResetButtonValues extends SettingsEvent {} + +class UpdateSettingsFlow extends SettingsEvent { final UiNodeGroupEnum group; - SubmitNewSettings({required this.flowId, required this.group}); + UpdateSettingsFlow({required this.group}); @override - List get props => [flowId, group]; + List get props => [group]; } diff --git a/flutter-ory-network/lib/blocs/settings/settings_state.dart b/flutter-ory-network/lib/blocs/settings/settings_state.dart index dbd33579..d7cc542e 100644 --- a/flutter-ory-network/lib/blocs/settings/settings_state.dart +++ b/flutter-ory-network/lib/blocs/settings/settings_state.dart @@ -7,7 +7,6 @@ part of 'settings_bloc.dart'; sealed class SettingsState with _$SettingsState { const factory SettingsState( {SettingsFlow? settingsFlow, - @Default(FormField(value: '')) FormField password, @Default(true) bool isPasswordHidden, @Default(false) bool isLoading, @Default(false) bool isSessionRefreshRequired, diff --git a/flutter-ory-network/lib/pages/settings.dart b/flutter-ory-network/lib/pages/settings.dart index 93ef3403..337d040f 100644 --- a/flutter-ory-network/lib/pages/settings.dart +++ b/flutter-ory-network/lib/pages/settings.dart @@ -1,9 +1,6 @@ // Copyright © 2023 Ory Corp // SPDX-License-Identifier: Apache-2.0 -import 'dart:convert'; -import 'dart:typed_data'; - import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:ory_client/ory_client.dart'; @@ -61,25 +58,21 @@ class SettingsPage extends StatelessWidget { } } -class SettingsForm extends StatefulWidget { +class SettingsForm extends StatelessWidget { const SettingsForm({super.key}); - @override - State createState() => _SettingsFormState(); -} - -class _SettingsFormState extends State { - final passwordController = TextEditingController(); - @override Widget build(BuildContext context) { final settingsBloc = BlocProvider.of(context); return MultiBlocListener( listeners: [ - // if session needs to be refreshed, navigate to login flow screen BlocListener( bloc: settingsBloc, + listenWhen: (SettingsState previous, SettingsState current) => + previous.isSessionRefreshRequired != + current.isSessionRefreshRequired, listener: (BuildContext context, SettingsState state) async { + // if session needs to be refreshed, navigate to login flow screen if (state.isSessionRefreshRequired) { await Navigator.push( context, @@ -87,21 +80,31 @@ class _SettingsFormState extends State { builder: (context) => const LoginPage( isSessionRefresh: true, ))).then((value) { + // retry updating settings when session was refreshed if (value != null) { - // if (value && state.flowId != null) { - // settingsBloc.add(SubmitNewPassword( - // flowId: state.flowId!, value: state.password.value)); - // } + if (value && state.settingsFlow?.id != null) { + settingsBloc.retry(); + } + } else { + // if user goes back without finishing login, + // reset button values to prevent submitting values that + // were selected prior to session refresh navigation + settingsBloc.add(ResetButtonValues()); } }); } }, ), - // listens to message changes and displays them as a snackbar + // listen to message changes and display them as a snackbar BlocListener( bloc: settingsBloc, listenWhen: (SettingsState previous, SettingsState current) => - previous.isLoading != current.isLoading && !current.isLoading, + // listen to changes only when previous + // state was loading (e.g. updating settings), + // current state is not loading and session refresh is not required + previous.isLoading != current.isLoading && + !current.isLoading && + !current.isSessionRefreshRequired, listener: (BuildContext context, SettingsState state) { if (state.settingsFlow!.ui.messages != null) { // for simplicity, we will only show the first message in snackbar @@ -112,6 +115,21 @@ class _SettingsFormState extends State { )); } }), + + // when there is a general message, + // jump to the page start in order to show the message + BlocListener( + bloc: settingsBloc, + listener: (BuildContext context, SettingsState state) { + if (state.message != null) { + // for simplicity, + // we will only show the first message in snackbar + ScaffoldMessenger.of(context).showSnackBar(SnackBar( + backgroundColor: Colors.red, + content: Text(state.message!.text), + )); + } + }) ], child: BlocBuilder( buildWhen: (previous, current) => @@ -152,13 +170,21 @@ class _SettingsFormState extends State { _buildUi(BuildContext context, SettingsState state) { final nodes = state.settingsFlow!.ui.nodes; + + // get profile nodes from all nodes final profileNodes = nodes.where((node) => node.group == UiNodeGroupEnum.profile).toList(); + + // get password nodes from all nodes final passwordNodes = nodes.where((node) => node.group == UiNodeGroupEnum.password).toList(); + + // get lookup secret nodes from all nodes final lookupSecretNodes = nodes .where((node) => node.group == UiNodeGroupEnum.lookupSecret) .toList(); + + // get totp nodes from all nodes final totpNodes = nodes.where((node) => node.group == UiNodeGroupEnum.totp).toList(); @@ -171,28 +197,41 @@ class _SettingsFormState extends State { const SizedBox( height: 32, ), - _buildGroup(context, state.settingsFlow!.id, - UiNodeGroupEnum.profile, profileNodes), - _buildGroup(context, state.settingsFlow!.id, - UiNodeGroupEnum.password, passwordNodes), - _buildGroup(context, state.settingsFlow!.id, - UiNodeGroupEnum.lookupSecret, lookupSecretNodes), - _buildGroup(context, state.settingsFlow!.id, UiNodeGroupEnum.totp, - totpNodes), + _buildGroup(context, UiNodeGroupEnum.profile, profileNodes), + _buildGroup(context, UiNodeGroupEnum.password, passwordNodes), + _buildGroup( + context, UiNodeGroupEnum.lookupSecret, lookupSecretNodes), + _buildGroup(context, UiNodeGroupEnum.totp, totpNodes), ], ), ), ), - // if state is loading, show loading indicator on screen to disable interaction - if (state.isLoading) - const Opacity( - opacity: 0.8, - child: ModalBarrier(dismissible: false, color: Colors.white30), - ), - if (state.isLoading) - const Center( - child: CircularProgressIndicator(), - ), + // build progress indicator when state is loading + BlocSelector( + bloc: (context).read(), + selector: (SettingsState state) => state.isLoading, + builder: (BuildContext context, bool booleanState) { + if (booleanState) { + return const Opacity( + opacity: 0.8, + child: ModalBarrier(dismissible: false, color: Colors.white30), + ); + } else { + return Container(); + } + }), + BlocSelector( + bloc: (context).read(), + selector: (SettingsState state) => state.isLoading, + builder: (BuildContext context, bool booleanState) { + if (booleanState) { + return const Center( + child: CircularProgressIndicator(), + ); + } else { + return Container(); + } + }) ]); } @@ -212,8 +251,7 @@ class _SettingsFormState extends State { } } - _buildGroup(BuildContext context, String flowId, UiNodeGroupEnum group, - List nodes) { + _buildGroup(BuildContext context, UiNodeGroupEnum group, List nodes) { final formKey = GlobalKey(); return Padding( padding: const EdgeInsets.only(bottom: 20), @@ -234,8 +272,7 @@ class _SettingsFormState extends State { itemBuilder: ((BuildContext context, index) { final attributes = nodes[index].attributes.oneOf; if (attributes.isType(UiNodeInputAttributes)) { - return _buildInputNode( - context, flowId, formKey, nodes[index]); + return _buildInputNode(context, formKey, nodes[index]); } else if (attributes.isType(UiNodeTextAttributes)) { return TextNode(node: nodes[index]); } else if (attributes.isType(UiNodeImageAttributes)) { @@ -251,14 +288,14 @@ class _SettingsFormState extends State { ); } - _buildInputNode(BuildContext context, String flowId, - GlobalKey formKey, UiNode node) { + _buildInputNode( + BuildContext context, GlobalKey formKey, UiNode node) { final inputNode = node.attributes.oneOf.value as UiNodeInputAttributes; switch (inputNode.type) { case UiNodeInputAttributesTypeEnum.submit: - return InputSubmitNode(flowId: flowId, node: node, formKey: formKey); + return InputSubmitNode(node: node, formKey: formKey); case UiNodeInputAttributesTypeEnum.button: - return InputSubmitNode(flowId: flowId, node: node, formKey: formKey); + return InputSubmitNode(node: node, formKey: formKey); case UiNodeInputAttributesTypeEnum.hidden: return Container(); diff --git a/flutter-ory-network/lib/repositories/settings.dart b/flutter-ory-network/lib/repositories/settings.dart index 927a660b..a8ede3c5 100644 --- a/flutter-ory-network/lib/repositories/settings.dart +++ b/flutter-ory-network/lib/repositories/settings.dart @@ -5,7 +5,6 @@ import 'package:built_value/json_object.dart'; import 'package:deep_collection/deep_collection.dart'; import 'package:one_of/one_of.dart'; import 'package:ory_client/ory_client.dart'; -import 'package:ory_network_flutter/entities/message.dart'; import 'package:collection/collection.dart'; import '../services/auth.dart'; @@ -17,22 +16,42 @@ class SettingsRepository { Future createSettingsFlow() async { final settingsFlow = await service.createSettingsFlow(); - return settingsFlow; + return resetButtonValues(settingsFlow: settingsFlow); + } + + Future getSettingsFlow({required String flowId}) async { + final settingsFlow = await service.getSettingsFlow(flowId: flowId); + return resetButtonValues(settingsFlow: settingsFlow); } - Future?> submitNewPassword( - {required String flowId, required String password}) async { - final messages = - await service.submitNewPassword(flowId: flowId, password: password); - return messages; + SettingsFlow resetButtonValues({required SettingsFlow settingsFlow}) { + final submitInputNodes = settingsFlow.ui.nodes.where((p0) { + if (p0.attributes.oneOf.isType(UiNodeInputAttributes)) { + final attributes = p0.attributes.oneOf.value as UiNodeInputAttributes; + final type = attributes.type; + if (type == UiNodeInputAttributesTypeEnum.button || + type == UiNodeInputAttributesTypeEnum.submit) { + return true; + } + } + return false; + }); + for (var node in submitInputNodes) { + final attributes = node.attributes.oneOf.value as UiNodeInputAttributes; + // reset button value to false + // to prevent submitting values that were not selected + settingsFlow = changeNodeValue( + settings: settingsFlow, name: attributes.name, value: 'false'); + } + return settingsFlow; } - Future submitNewSettings( + Future updateSettingsFlow( {required String flowId, required UiNodeGroupEnum group, - List? nodes}) async { + required List nodes}) async { // get input nodes of the same group - final inputNodes = nodes?.where((p0) { + final inputNodes = nodes.where((p0) { if (p0.attributes.oneOf.isType(UiNodeInputAttributes)) { final type = (p0.attributes.oneOf.value as UiNodeInputAttributes).type; return p0.group == group && @@ -42,8 +61,8 @@ class SettingsRepository { } }); -// create maps from attribute names and their values - final nestedMaps = inputNodes?.map((e) { + // create maps from attribute names and their values + final nestedMaps = inputNodes.map((e) { final attributes = e.attributes.oneOf.value as UiNodeInputAttributes; return generateNestedMap(attributes.name, attributes.value!.asString); @@ -51,47 +70,43 @@ class SettingsRepository { // merge nested maps into one final mergedMap = - nestedMaps?.reduce((value, element) => value.deepMerge(element)); - print('mergedMap ${mergedMap}'); + nestedMaps.reduce((value, element) => value.deepMerge(element)); - final updatedSettings = await service.submitNewSettings( - flowId: flowId, group: group, value: mergedMap!); - return updatedSettings; + final updatedSettings = await service.updateSettingsFlow( + flowId: flowId, group: group, value: mergedMap); + return resetButtonValues(settingsFlow: updatedSettings); } - SettingsFlow? changeNodeValue( - {SettingsFlow? settings, required String name, required T value}) { + SettingsFlow changeNodeValue( + {required SettingsFlow settings, + required String name, + required T value}) { // get edited node - if (settings != null) { - final node = settings.ui.nodes.firstWhereOrNull((element) { - if (element.attributes.oneOf.isType(UiNodeInputAttributes)) { - return (element.attributes.oneOf.value as UiNodeInputAttributes) - .name == - name; - } else { - return false; - } - }); - - final updatedNode = node?.rebuild((p0) => p0 - ..attributes.update((b) { - final oldValue = b.oneOf?.value as UiNodeInputAttributes; - final newValue = - oldValue.rebuild((p0) => p0.value = JsonObject(value)); - b.oneOf = OneOf1(value: newValue); - })); - - final nodeIndex = settings.ui.nodes.indexOf(node!); + final node = settings.ui.nodes.firstWhereOrNull((element) { + if (element.attributes.oneOf.isType(UiNodeInputAttributes)) { + return (element.attributes.oneOf.value as UiNodeInputAttributes).name == + name; + } else { + return false; + } + }); - final newList = settings.ui.nodes.rebuild((p0) => p0 - ..removeAt(nodeIndex) - ..insert(nodeIndex, updatedNode!)); - final newSettings = - settings.rebuild((p0) => p0..ui.nodes.replace(newList)); - return newSettings; - } else { - return settings; - } + // udate value of edited node + final updatedNode = node?.rebuild((p0) => p0 + ..attributes.update((b) { + final oldValue = b.oneOf?.value as UiNodeInputAttributes; + final newValue = oldValue.rebuild((p0) => p0.value = JsonObject(value)); + b.oneOf = OneOf1(value: newValue); + })); + // get index of to be updated node + final nodeIndex = settings.ui.nodes.indexOf(node!); + // update list of nodes to iclude updated node + final newList = settings.ui.nodes.rebuild((p0) => p0 + ..removeAt(nodeIndex) + ..insert(nodeIndex, updatedNode!)); + // update settings' node + final newSettings = settings.rebuild((p0) => p0..ui.nodes.replace(newList)); + return newSettings; } /// Generate nested map from [path] with [value] diff --git a/flutter-ory-network/lib/services/auth.dart b/flutter-ory-network/lib/services/auth.dart index ffdbf69c..94e36bf2 100644 --- a/flutter-ory-network/lib/services/auth.dart +++ b/flutter-ory-network/lib/services/auth.dart @@ -191,7 +191,7 @@ class AuthService { await _ory.createNativeSettingsFlow(xSessionToken: token); if (response.data != null) { - // return flow id + // return flow return response.data!; } else { throw const CustomException.unknown(); @@ -206,15 +206,39 @@ class AuthService { } } - Future submitNewSettings( + /// Get settings flow with [flowId] + Future getSettingsFlow({required String flowId}) async { + try { + final token = await _storage.getToken(); + final response = + await _ory.getSettingsFlow(id: flowId, xSessionToken: token); + + if (response.data != null) { + // return flow + return response.data!; + } else { + throw const CustomException.unknown(); + } + } on DioException catch (e) { + if (e.response?.statusCode == 401) { + await _storage.deleteToken(); + throw const CustomException.unauthorized(); + } else { + throw _handleUnknownException(e.response?.data); + } + } + } + + /// Update settings flow with [flowId] for [group] with [value] + Future updateSettingsFlow( {required String flowId, required UiNodeGroupEnum group, required Map value}) async { try { final token = await _storage.getToken(); final OneOf oneOf; - print(value); + // create update body depending on method switch (group) { case UiNodeGroupEnum.password: oneOf = OneOf.fromValue1( @@ -244,8 +268,9 @@ class AuthService { ..method = group.name ..totpCode = value['totp_code'] ..totpUnlink = getBoolValue(value['totp_unlink']))); + // if method is not implemented, throw exception default: - oneOf = OneOf.fromValue1(value: null); + throw const CustomException.unknown(); } final response = await _ory.updateSettingsFlow( @@ -253,87 +278,13 @@ class AuthService { xSessionToken: token, updateSettingsFlowBody: UpdateSettingsFlowBody((b) => b..oneOf = oneOf)); - print(response.data?.ui.messages); - - return response.data; - } on DioException catch (e) { - print(e.error); - print(e.response?.data); - } - return null; - } - - bool? getBoolValue(String? value) { - if (value == null) { - return null; - } else { - return value == 'true' ? true : false; - } - } - - /// Change old password to new [password] using settings flow with [flowId] - Future?> submitNewPassword( - {required String flowId, required String password}) async { - try { - final token = await _storage.getToken(); - final UpdateSettingsFlowWithPasswordMethod body = - UpdateSettingsFlowWithPasswordMethod((b) => b - ..method = 'password' - ..password = password); - final response = await _ory.updateSettingsFlow( - flow: flowId, - xSessionToken: token, - updateSettingsFlowBody: UpdateSettingsFlowBody( - (b) => b..oneOf = OneOf.fromValue1(value: body))); - if (response.statusCode == 400) { - // get input nodes with messages - final inputNodesWithMessages = response.data?.ui.nodes - .asList() - .where((e) => - e.attributes.oneOf.isType(UiNodeInputAttributes) && - e.messages.isNotEmpty) - .toList(); - - // get input node messages - final nodeMessages = inputNodesWithMessages - ?.map((node) => node.messages - .asList() - .map((msg) => NodeMessage( - id: msg.id, - text: msg.text, - type: msg.type.name.messageType, - attr: (node.attributes.oneOf.value as UiNodeInputAttributes) - .name)) - .toList()) - .toList(); - - // get general messages - final generalMessages = response.data?.ui.messages - ?.asList() - .map((e) => NodeMessage( - id: e.id, text: e.text, type: e.type.name.messageType)) - .toList(); - - // add general messages to input node messages if they exist - if (generalMessages != null) { - nodeMessages?.add(generalMessages); - } - - // flatten message list - final flattedNodeMessages = - nodeMessages?.expand((element) => element).toList(); - - throw CustomException.badRequest(messages: flattedNodeMessages); + if (response.data != null) { + // return updated settings flow + return response.data!; + } else { + throw const CustomException.unknown(); } - - // get messages on success - final messages = response.data?.ui.messages - ?.asList() - .map((msg) => NodeMessage( - id: msg.id, text: msg.text, type: msg.type.name.messageType)) - .toList(); - return messages; } on DioException catch (e) { if (e.response?.statusCode == 401) { await _storage.deleteToken(); @@ -343,15 +294,22 @@ class AuthService { } else if (e.response?.statusCode == 410) { // settings flow expired, use new flow id and add error message throw CustomException.flowExpired( - flowId: e.response?.data['use_flow_id'], - message: - 'Settings flow has expired. Please enter credentials again.'); + flowId: e.response?.data['use_flow_id']); } else { throw _handleUnknownException(e.response?.data); } } } + /// Get bool value of string [value] + bool? getBoolValue(String? value) { + if (value == null) { + return null; + } else { + return value == 'true' ? true : false; + } + } + /// Search for error messages and their context in [response] List _checkFormForErrors(Map response) { final ui = Map.from(response['ui']); diff --git a/flutter-ory-network/lib/services/exceptions.dart b/flutter-ory-network/lib/services/exceptions.dart index 8fc9e91f..9d59e0cf 100644 --- a/flutter-ory-network/lib/services/exceptions.dart +++ b/flutter-ory-network/lib/services/exceptions.dart @@ -22,7 +22,7 @@ sealed class CustomException with _$CustomException { const factory CustomException.flowExpired( {@Default(410) int statusCode, required String flowId, - required String message}) = FlowExpiredException; + String? message}) = FlowExpiredException; const factory CustomException.unknown( {@Default('An error occured. Please try again later.') String message}) = UnknownException; diff --git a/flutter-ory-network/lib/services/exceptions.freezed.dart b/flutter-ory-network/lib/services/exceptions.freezed.dart index 02d96051..8927a846 100644 --- a/flutter-ory-network/lib/services/exceptions.freezed.dart +++ b/flutter-ory-network/lib/services/exceptions.freezed.dart @@ -23,7 +23,7 @@ mixin _$CustomException { required TResult Function(int statusCode) unauthorized, required TResult Function(int statusCode, String? message) sessionRefreshRequired, - required TResult Function(int statusCode, String flowId, String message) + required TResult Function(int statusCode, String flowId, String? message) flowExpired, required TResult Function(String message) unknown, }) => @@ -33,7 +33,7 @@ mixin _$CustomException { TResult? Function(List? messages, int statusCode)? badRequest, TResult? Function(int statusCode)? unauthorized, TResult? Function(int statusCode, String? message)? sessionRefreshRequired, - TResult? Function(int statusCode, String flowId, String message)? + TResult? Function(int statusCode, String flowId, String? message)? flowExpired, TResult? Function(String message)? unknown, }) => @@ -43,7 +43,7 @@ mixin _$CustomException { TResult Function(List? messages, int statusCode)? badRequest, TResult Function(int statusCode)? unauthorized, TResult Function(int statusCode, String? message)? sessionRefreshRequired, - TResult Function(int statusCode, String flowId, String message)? + TResult Function(int statusCode, String flowId, String? message)? flowExpired, TResult Function(String message)? unknown, required TResult orElse(), @@ -202,7 +202,7 @@ class _$BadRequestException extends BadRequestException required TResult Function(int statusCode) unauthorized, required TResult Function(int statusCode, String? message) sessionRefreshRequired, - required TResult Function(int statusCode, String flowId, String message) + required TResult Function(int statusCode, String flowId, String? message) flowExpired, required TResult Function(String message) unknown, }) { @@ -215,7 +215,7 @@ class _$BadRequestException extends BadRequestException TResult? Function(List? messages, int statusCode)? badRequest, TResult? Function(int statusCode)? unauthorized, TResult? Function(int statusCode, String? message)? sessionRefreshRequired, - TResult? Function(int statusCode, String flowId, String message)? + TResult? Function(int statusCode, String flowId, String? message)? flowExpired, TResult? Function(String message)? unknown, }) { @@ -228,7 +228,7 @@ class _$BadRequestException extends BadRequestException TResult Function(List? messages, int statusCode)? badRequest, TResult Function(int statusCode)? unauthorized, TResult Function(int statusCode, String? message)? sessionRefreshRequired, - TResult Function(int statusCode, String flowId, String message)? + TResult Function(int statusCode, String flowId, String? message)? flowExpired, TResult Function(String message)? unknown, required TResult orElse(), @@ -377,7 +377,7 @@ class _$UnauthorizedException extends UnauthorizedException required TResult Function(int statusCode) unauthorized, required TResult Function(int statusCode, String? message) sessionRefreshRequired, - required TResult Function(int statusCode, String flowId, String message) + required TResult Function(int statusCode, String flowId, String? message) flowExpired, required TResult Function(String message) unknown, }) { @@ -390,7 +390,7 @@ class _$UnauthorizedException extends UnauthorizedException TResult? Function(List? messages, int statusCode)? badRequest, TResult? Function(int statusCode)? unauthorized, TResult? Function(int statusCode, String? message)? sessionRefreshRequired, - TResult? Function(int statusCode, String flowId, String message)? + TResult? Function(int statusCode, String flowId, String? message)? flowExpired, TResult? Function(String message)? unknown, }) { @@ -403,7 +403,7 @@ class _$UnauthorizedException extends UnauthorizedException TResult Function(List? messages, int statusCode)? badRequest, TResult Function(int statusCode)? unauthorized, TResult Function(int statusCode, String? message)? sessionRefreshRequired, - TResult Function(int statusCode, String flowId, String message)? + TResult Function(int statusCode, String flowId, String? message)? flowExpired, TResult Function(String message)? unknown, required TResult orElse(), @@ -564,7 +564,7 @@ class _$SessionRefreshRequiredException extends SessionRefreshRequiredException required TResult Function(int statusCode) unauthorized, required TResult Function(int statusCode, String? message) sessionRefreshRequired, - required TResult Function(int statusCode, String flowId, String message) + required TResult Function(int statusCode, String flowId, String? message) flowExpired, required TResult Function(String message) unknown, }) { @@ -577,7 +577,7 @@ class _$SessionRefreshRequiredException extends SessionRefreshRequiredException TResult? Function(List? messages, int statusCode)? badRequest, TResult? Function(int statusCode)? unauthorized, TResult? Function(int statusCode, String? message)? sessionRefreshRequired, - TResult? Function(int statusCode, String flowId, String message)? + TResult? Function(int statusCode, String flowId, String? message)? flowExpired, TResult? Function(String message)? unknown, }) { @@ -590,7 +590,7 @@ class _$SessionRefreshRequiredException extends SessionRefreshRequiredException TResult Function(List? messages, int statusCode)? badRequest, TResult Function(int statusCode)? unauthorized, TResult Function(int statusCode, String? message)? sessionRefreshRequired, - TResult Function(int statusCode, String flowId, String message)? + TResult Function(int statusCode, String flowId, String? message)? flowExpired, TResult Function(String message)? unknown, required TResult orElse(), @@ -664,7 +664,7 @@ abstract class _$$FlowExpiredExceptionCopyWith<$Res> { $Res Function(_$FlowExpiredException) then) = __$$FlowExpiredExceptionCopyWithImpl<$Res>; @useResult - $Res call({int statusCode, String flowId, String message}); + $Res call({int statusCode, String flowId, String? message}); } /// @nodoc @@ -680,7 +680,7 @@ class __$$FlowExpiredExceptionCopyWithImpl<$Res> $Res call({ Object? statusCode = null, Object? flowId = null, - Object? message = null, + Object? message = freezed, }) { return _then(_$FlowExpiredException( statusCode: null == statusCode @@ -691,10 +691,10 @@ class __$$FlowExpiredExceptionCopyWithImpl<$Res> ? _value.flowId : flowId // ignore: cast_nullable_to_non_nullable as String, - message: null == message + message: freezed == message ? _value.message : message // ignore: cast_nullable_to_non_nullable - as String, + as String?, )); } } @@ -704,7 +704,7 @@ class __$$FlowExpiredExceptionCopyWithImpl<$Res> class _$FlowExpiredException extends FlowExpiredException with DiagnosticableTreeMixin { const _$FlowExpiredException( - {this.statusCode = 410, required this.flowId, required this.message}) + {this.statusCode = 410, required this.flowId, this.message}) : super._(); @override @@ -713,7 +713,7 @@ class _$FlowExpiredException extends FlowExpiredException @override final String flowId; @override - final String message; + final String? message; @override String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { @@ -759,7 +759,7 @@ class _$FlowExpiredException extends FlowExpiredException required TResult Function(int statusCode) unauthorized, required TResult Function(int statusCode, String? message) sessionRefreshRequired, - required TResult Function(int statusCode, String flowId, String message) + required TResult Function(int statusCode, String flowId, String? message) flowExpired, required TResult Function(String message) unknown, }) { @@ -772,7 +772,7 @@ class _$FlowExpiredException extends FlowExpiredException TResult? Function(List? messages, int statusCode)? badRequest, TResult? Function(int statusCode)? unauthorized, TResult? Function(int statusCode, String? message)? sessionRefreshRequired, - TResult? Function(int statusCode, String flowId, String message)? + TResult? Function(int statusCode, String flowId, String? message)? flowExpired, TResult? Function(String message)? unknown, }) { @@ -785,7 +785,7 @@ class _$FlowExpiredException extends FlowExpiredException TResult Function(List? messages, int statusCode)? badRequest, TResult Function(int statusCode)? unauthorized, TResult Function(int statusCode, String? message)? sessionRefreshRequired, - TResult Function(int statusCode, String flowId, String message)? + TResult Function(int statusCode, String flowId, String? message)? flowExpired, TResult Function(String message)? unknown, required TResult orElse(), @@ -844,12 +844,12 @@ abstract class FlowExpiredException extends CustomException { const factory FlowExpiredException( {final int statusCode, required final String flowId, - required final String message}) = _$FlowExpiredException; + final String? message}) = _$FlowExpiredException; const FlowExpiredException._() : super._(); int get statusCode; String get flowId; - String get message; + String? get message; @JsonKey(ignore: true) _$$FlowExpiredExceptionCopyWith<_$FlowExpiredException> get copyWith => throw _privateConstructorUsedError; @@ -935,7 +935,7 @@ class _$UnknownException extends UnknownException with DiagnosticableTreeMixin { required TResult Function(int statusCode) unauthorized, required TResult Function(int statusCode, String? message) sessionRefreshRequired, - required TResult Function(int statusCode, String flowId, String message) + required TResult Function(int statusCode, String flowId, String? message) flowExpired, required TResult Function(String message) unknown, }) { @@ -948,7 +948,7 @@ class _$UnknownException extends UnknownException with DiagnosticableTreeMixin { TResult? Function(List? messages, int statusCode)? badRequest, TResult? Function(int statusCode)? unauthorized, TResult? Function(int statusCode, String? message)? sessionRefreshRequired, - TResult? Function(int statusCode, String flowId, String message)? + TResult? Function(int statusCode, String flowId, String? message)? flowExpired, TResult? Function(String message)? unknown, }) { @@ -961,7 +961,7 @@ class _$UnknownException extends UnknownException with DiagnosticableTreeMixin { TResult Function(List? messages, int statusCode)? badRequest, TResult Function(int statusCode)? unauthorized, TResult Function(int statusCode, String? message)? sessionRefreshRequired, - TResult Function(int statusCode, String flowId, String message)? + TResult Function(int statusCode, String flowId, String? message)? flowExpired, TResult Function(String message)? unknown, required TResult orElse(), diff --git a/flutter-ory-network/lib/widgets/nodes/input.dart b/flutter-ory-network/lib/widgets/nodes/input.dart index fa08d068..7f1da763 100644 --- a/flutter-ory-network/lib/widgets/nodes/input.dart +++ b/flutter-ory-network/lib/widgets/nodes/input.dart @@ -36,6 +36,30 @@ class _InputNodeState extends State { } } +// get text input type of a specific node + _getTextInputType(UiNodeInputAttributesTypeEnum type) { + switch (type) { + case UiNodeInputAttributesTypeEnum.datetimeLocal: + return TextInputType.datetime; + case UiNodeInputAttributesTypeEnum.email: + return TextInputType.emailAddress; + case UiNodeInputAttributesTypeEnum.hidden: + return TextInputType.none; + case UiNodeInputAttributesTypeEnum.number: + return TextInputType.number; + case UiNodeInputAttributesTypeEnum.password: + return TextInputType.text; + case UiNodeInputAttributesTypeEnum.tel: + return TextInputType.phone; + case UiNodeInputAttributesTypeEnum.text: + return TextInputType.text; + case UiNodeInputAttributesTypeEnum.url: + return TextInputType.url; + default: + return null; + } + } + @override Widget build(BuildContext context) { final attributes = @@ -78,6 +102,7 @@ class _InputNodeState extends State { TextFormField( controller: textEditingController, enabled: !attributes.disabled, + keyboardType: _getTextInputType(attributes.type), onChanged: (value) => context .read() .add(ChangeNodeValue(value: value, name: attributes.name)), diff --git a/flutter-ory-network/lib/widgets/nodes/input_submit.dart b/flutter-ory-network/lib/widgets/nodes/input_submit.dart index 89c54060..8908f2b0 100644 --- a/flutter-ory-network/lib/widgets/nodes/input_submit.dart +++ b/flutter-ory-network/lib/widgets/nodes/input_submit.dart @@ -5,15 +5,10 @@ import 'package:ory_client/ory_client.dart'; import '../../blocs/settings/settings_bloc.dart'; class InputSubmitNode extends StatelessWidget { - final String flowId; final GlobalKey formKey; final UiNode node; - const InputSubmitNode( - {super.key, - required this.node, - required this.formKey, - required this.flowId}); + const InputSubmitNode({super.key, required this.formKey, required this.node}); @override Widget build(BuildContext context) { @@ -25,9 +20,22 @@ class InputSubmitNode extends StatelessWidget { // validate input fields that belong to this buttons group onPressed: () { if (formKey.currentState!.validate()) { + final attributes = + node.attributes.oneOf.value as UiNodeInputAttributes; + final type = attributes.type; + // if attribute type is a button, set its value to true on submit + if (type == UiNodeInputAttributesTypeEnum.button || + type == UiNodeInputAttributesTypeEnum.submit) { + final nodeName = attributes.name; + + context + .read() + .add(ChangeNodeValue(value: 'true', name: nodeName)); + } + context .read() - .add(SubmitNewSettings(flowId: flowId, group: node.group)); + .add(UpdateSettingsFlow(group: node.group)); } }, child: Text(node.meta.label?.text ?? ''), diff --git a/flutter-ory-network/pubspec.lock b/flutter-ory-network/pubspec.lock index 4497a9a7..58dac916 100644 --- a/flutter-ory-network/pubspec.lock +++ b/flutter-ory-network/pubspec.lock @@ -41,6 +41,14 @@ packages: url: "https://pub.dev" source: hosted version: "8.1.2" + bloc_concurrency: + dependency: "direct main" + description: + name: bloc_concurrency + sha256: "44535c9f429cd7e91d548cf89fde1c23a8b4b3637decdb1865bb583091a00d4e" + url: "https://pub.dev" + source: hosted + version: "0.2.2" boolean_selector: dependency: transitive description: diff --git a/flutter-ory-network/pubspec.yaml b/flutter-ory-network/pubspec.yaml index f02c2220..b0b30646 100644 --- a/flutter-ory-network/pubspec.yaml +++ b/flutter-ory-network/pubspec.yaml @@ -49,6 +49,7 @@ dependencies: built_value: ^8.6.2 collection: ^1.17.2 deep_collection: ^1.0.2 + bloc_concurrency: ^0.2.2 dev_dependencies: flutter_test: From bd1e90f9fe6fabcb3593a83f858790728051d918 Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Fri, 22 Sep 2023 17:39:45 +0200 Subject: [PATCH 23/57] chore: format code --- flutter-ory-network/lib/blocs/auth/auth_bloc.freezed.dart | 3 +++ flutter-ory-network/lib/blocs/login/login_bloc.freezed.dart | 3 +++ .../lib/blocs/registration/registration_bloc.freezed.dart | 3 +++ .../lib/blocs/settings/settings_bloc.freezed.dart | 3 +++ flutter-ory-network/lib/entities/form_node.freezed.dart | 3 +++ flutter-ory-network/lib/entities/form_node.g.dart | 3 +++ flutter-ory-network/lib/entities/formfield.freezed.dart | 3 +++ flutter-ory-network/lib/entities/message.freezed.dart | 3 +++ flutter-ory-network/lib/entities/message.g.dart | 3 +++ flutter-ory-network/lib/entities/node_attribute.freezed.dart | 3 +++ flutter-ory-network/lib/entities/node_attribute.g.dart | 3 +++ flutter-ory-network/lib/services/exceptions.freezed.dart | 3 +++ flutter-ory-network/lib/widgets/nodes/image.dart | 3 +++ flutter-ory-network/lib/widgets/nodes/input.dart | 3 +++ flutter-ory-network/lib/widgets/nodes/input_submit.dart | 3 +++ flutter-ory-network/lib/widgets/nodes/text.dart | 3 +++ 16 files changed, 48 insertions(+) diff --git a/flutter-ory-network/lib/blocs/auth/auth_bloc.freezed.dart b/flutter-ory-network/lib/blocs/auth/auth_bloc.freezed.dart index 02acfd8b..c9fb0758 100644 --- a/flutter-ory-network/lib/blocs/auth/auth_bloc.freezed.dart +++ b/flutter-ory-network/lib/blocs/auth/auth_bloc.freezed.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint diff --git a/flutter-ory-network/lib/blocs/login/login_bloc.freezed.dart b/flutter-ory-network/lib/blocs/login/login_bloc.freezed.dart index 17960491..8efa7a95 100644 --- a/flutter-ory-network/lib/blocs/login/login_bloc.freezed.dart +++ b/flutter-ory-network/lib/blocs/login/login_bloc.freezed.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint diff --git a/flutter-ory-network/lib/blocs/registration/registration_bloc.freezed.dart b/flutter-ory-network/lib/blocs/registration/registration_bloc.freezed.dart index edbeef53..c5f63b5c 100644 --- a/flutter-ory-network/lib/blocs/registration/registration_bloc.freezed.dart +++ b/flutter-ory-network/lib/blocs/registration/registration_bloc.freezed.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint diff --git a/flutter-ory-network/lib/blocs/settings/settings_bloc.freezed.dart b/flutter-ory-network/lib/blocs/settings/settings_bloc.freezed.dart index 2858b243..c4cd6070 100644 --- a/flutter-ory-network/lib/blocs/settings/settings_bloc.freezed.dart +++ b/flutter-ory-network/lib/blocs/settings/settings_bloc.freezed.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint diff --git a/flutter-ory-network/lib/entities/form_node.freezed.dart b/flutter-ory-network/lib/entities/form_node.freezed.dart index b66dacb6..96efd5ef 100644 --- a/flutter-ory-network/lib/entities/form_node.freezed.dart +++ b/flutter-ory-network/lib/entities/form_node.freezed.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint diff --git a/flutter-ory-network/lib/entities/form_node.g.dart b/flutter-ory-network/lib/entities/form_node.g.dart index 98e6de11..7b31b119 100644 --- a/flutter-ory-network/lib/entities/form_node.g.dart +++ b/flutter-ory-network/lib/entities/form_node.g.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + // GENERATED CODE - DO NOT MODIFY BY HAND part of 'form_node.dart'; diff --git a/flutter-ory-network/lib/entities/formfield.freezed.dart b/flutter-ory-network/lib/entities/formfield.freezed.dart index 67e05f8d..d8e74a89 100644 --- a/flutter-ory-network/lib/entities/formfield.freezed.dart +++ b/flutter-ory-network/lib/entities/formfield.freezed.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint diff --git a/flutter-ory-network/lib/entities/message.freezed.dart b/flutter-ory-network/lib/entities/message.freezed.dart index 63b47250..11ded8db 100644 --- a/flutter-ory-network/lib/entities/message.freezed.dart +++ b/flutter-ory-network/lib/entities/message.freezed.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint diff --git a/flutter-ory-network/lib/entities/message.g.dart b/flutter-ory-network/lib/entities/message.g.dart index dba500c4..cdedc72c 100644 --- a/flutter-ory-network/lib/entities/message.g.dart +++ b/flutter-ory-network/lib/entities/message.g.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + // GENERATED CODE - DO NOT MODIFY BY HAND part of 'message.dart'; diff --git a/flutter-ory-network/lib/entities/node_attribute.freezed.dart b/flutter-ory-network/lib/entities/node_attribute.freezed.dart index 72ddae2d..08432654 100644 --- a/flutter-ory-network/lib/entities/node_attribute.freezed.dart +++ b/flutter-ory-network/lib/entities/node_attribute.freezed.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint diff --git a/flutter-ory-network/lib/entities/node_attribute.g.dart b/flutter-ory-network/lib/entities/node_attribute.g.dart index 92cd7317..92070a72 100644 --- a/flutter-ory-network/lib/entities/node_attribute.g.dart +++ b/flutter-ory-network/lib/entities/node_attribute.g.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + // GENERATED CODE - DO NOT MODIFY BY HAND part of 'node_attribute.dart'; diff --git a/flutter-ory-network/lib/services/exceptions.freezed.dart b/flutter-ory-network/lib/services/exceptions.freezed.dart index 8927a846..3be95550 100644 --- a/flutter-ory-network/lib/services/exceptions.freezed.dart +++ b/flutter-ory-network/lib/services/exceptions.freezed.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint diff --git a/flutter-ory-network/lib/widgets/nodes/image.dart b/flutter-ory-network/lib/widgets/nodes/image.dart index 6b7b97f1..184ee117 100644 --- a/flutter-ory-network/lib/widgets/nodes/image.dart +++ b/flutter-ory-network/lib/widgets/nodes/image.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + import 'dart:convert'; import 'dart:typed_data'; diff --git a/flutter-ory-network/lib/widgets/nodes/input.dart b/flutter-ory-network/lib/widgets/nodes/input.dart index 7f1da763..04f8d0ab 100644 --- a/flutter-ory-network/lib/widgets/nodes/input.dart +++ b/flutter-ory-network/lib/widgets/nodes/input.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + import 'package:collection/collection.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; diff --git a/flutter-ory-network/lib/widgets/nodes/input_submit.dart b/flutter-ory-network/lib/widgets/nodes/input_submit.dart index 8908f2b0..ba6ada79 100644 --- a/flutter-ory-network/lib/widgets/nodes/input_submit.dart +++ b/flutter-ory-network/lib/widgets/nodes/input_submit.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:ory_client/ory_client.dart'; diff --git a/flutter-ory-network/lib/widgets/nodes/text.dart b/flutter-ory-network/lib/widgets/nodes/text.dart index 26bd54f1..f8a115b0 100644 --- a/flutter-ory-network/lib/widgets/nodes/text.dart +++ b/flutter-ory-network/lib/widgets/nodes/text.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + import 'package:flutter/material.dart'; import 'package:ory_client/ory_client.dart'; From e631a1fea784cf08a390c8c742a67ee06a250099 Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Mon, 2 Oct 2023 10:55:25 +0200 Subject: [PATCH 24/57] chore: display components dynamically --- .../lib/blocs/auth/auth_bloc.dart | 11 +- .../lib/blocs/auth/auth_bloc.freezed.dart | 3 - .../lib/blocs/login/login_bloc.dart | 106 ++- .../lib/blocs/login/login_bloc.freezed.dart | 170 +--- .../lib/blocs/login/login_event.dart | 47 +- .../lib/blocs/login/login_state.dart | 7 +- .../blocs/registration/registration_bloc.dart | 111 ++- .../registration_bloc.freezed.dart | 168 +--- .../registration/registration_event.dart | 42 +- .../registration/registration_state.dart | 7 +- .../lib/entities/form_node.dart | 20 - .../lib/entities/form_node.freezed.dart | 191 ----- .../lib/entities/form_node.g.dart | 24 - .../lib/entities/formfield.dart | 11 - .../lib/entities/formfield.freezed.dart | 154 ---- flutter-ory-network/lib/entities/message.dart | 22 - .../lib/entities/message.freezed.dart | 211 ----- .../lib/entities/message.g.dart | 32 - .../lib/entities/node_attribute.dart | 14 - .../lib/entities/node_attribute.freezed.dart | 154 ---- .../lib/entities/node_attribute.g.dart | 20 - flutter-ory-network/lib/main.dart | 10 +- flutter-ory-network/lib/pages/home.dart | 4 +- flutter-ory-network/lib/pages/login.dart | 395 ++++------ .../lib/pages/registration.dart | 350 ++++----- .../lib/repositories/auth.dart | 197 ++++- flutter-ory-network/lib/services/auth.dart | 213 +++-- .../lib/services/exceptions.dart | 19 +- .../lib/services/exceptions.freezed.dart | 740 ++++++++++-------- flutter-ory-network/lib/widgets/helpers.dart | 95 +++ .../lib/widgets/nodes/input.dart | 156 ++++ .../lib/widgets/nodes/input_submit.dart | 53 ++ .../lib/widgets/nodes/provider.dart | 26 + .../lib/widgets/nodes/text.dart | 25 + flutter-ory-network/pubspec.lock | 24 +- flutter-ory-network/pubspec.yaml | 3 + 36 files changed, 1663 insertions(+), 2172 deletions(-) delete mode 100644 flutter-ory-network/lib/entities/form_node.dart delete mode 100644 flutter-ory-network/lib/entities/form_node.freezed.dart delete mode 100644 flutter-ory-network/lib/entities/form_node.g.dart delete mode 100644 flutter-ory-network/lib/entities/formfield.dart delete mode 100644 flutter-ory-network/lib/entities/formfield.freezed.dart delete mode 100644 flutter-ory-network/lib/entities/message.dart delete mode 100644 flutter-ory-network/lib/entities/message.freezed.dart delete mode 100644 flutter-ory-network/lib/entities/message.g.dart delete mode 100644 flutter-ory-network/lib/entities/node_attribute.dart delete mode 100644 flutter-ory-network/lib/entities/node_attribute.freezed.dart delete mode 100644 flutter-ory-network/lib/entities/node_attribute.g.dart create mode 100644 flutter-ory-network/lib/widgets/helpers.dart create mode 100644 flutter-ory-network/lib/widgets/nodes/input.dart create mode 100644 flutter-ory-network/lib/widgets/nodes/input_submit.dart create mode 100644 flutter-ory-network/lib/widgets/nodes/provider.dart create mode 100644 flutter-ory-network/lib/widgets/nodes/text.dart diff --git a/flutter-ory-network/lib/blocs/auth/auth_bloc.dart b/flutter-ory-network/lib/blocs/auth/auth_bloc.dart index 6da7be0d..2fcdd21c 100644 --- a/flutter-ory-network/lib/blocs/auth/auth_bloc.dart +++ b/flutter-ory-network/lib/blocs/auth/auth_bloc.dart @@ -18,11 +18,11 @@ class AuthBloc extends Bloc { AuthBloc({required this.repository}) : super(const AuthState(status: AuthStatus.uninitialized)) { on(_onGetCurrentSessionInformation); - on(_changeAuthStatus); - on(_logOut); + on(_onChangeAuthStatus); + on(_onLogOut); } - _changeAuthStatus(ChangeAuthStatus event, Emitter emit) { + _onChangeAuthStatus(ChangeAuthStatus event, Emitter emit) { emit(state.copyWith(status: event.status, isLoading: false)); } @@ -43,6 +43,9 @@ class AuthBloc extends Bloc { status: AuthStatus.unauthenticated, session: null, isLoading: false)); + } else if (e case TwoFactorAuthRequiredException _) { + emit(state.copyWith( + isLoading: false, session: null, status: AuthStatus.aal2Requested)); } else if (e case UnknownException _) { emit(state.copyWith(isLoading: false, errorMessage: e.message)); } else { @@ -51,7 +54,7 @@ class AuthBloc extends Bloc { } } - Future _logOut(LogOut event, Emitter emit) async { + Future _onLogOut(LogOut event, Emitter emit) async { try { emit(state.copyWith(isLoading: true, errorMessage: null)); diff --git a/flutter-ory-network/lib/blocs/auth/auth_bloc.freezed.dart b/flutter-ory-network/lib/blocs/auth/auth_bloc.freezed.dart index c9fb0758..02acfd8b 100644 --- a/flutter-ory-network/lib/blocs/auth/auth_bloc.freezed.dart +++ b/flutter-ory-network/lib/blocs/auth/auth_bloc.freezed.dart @@ -1,6 +1,3 @@ -// Copyright © 2023 Ory Corp -// SPDX-License-Identifier: Apache-2.0 - // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint diff --git a/flutter-ory-network/lib/blocs/login/login_bloc.dart b/flutter-ory-network/lib/blocs/login/login_bloc.dart index a3b36554..fcdcd638 100644 --- a/flutter-ory-network/lib/blocs/login/login_bloc.dart +++ b/flutter-ory-network/lib/blocs/login/login_bloc.dart @@ -4,9 +4,8 @@ import 'package:bloc/bloc.dart'; import 'package:equatable/equatable.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:collection/collection.dart'; +import 'package:ory_client/ory_client.dart'; -import '../../entities/formfield.dart'; import '../../repositories/auth.dart'; import '../../services/exceptions.dart'; import '../auth/auth_bloc.dart'; @@ -21,88 +20,71 @@ class LoginBloc extends Bloc { LoginBloc({required this.authBloc, required this.repository}) : super(LoginState()) { on(_onCreateLoginFlow); - on(_onChangeEmail); - on(_onChangePassword); - on(_onChangePasswordVisibility); - on(_onLoginWithEmailAndPassword); + on(_onGetLoginFlow); + on(_onChangeNodeValue); + on(_onUpdateLoginFlow); } Future _onCreateLoginFlow( CreateLoginFlow event, Emitter emit) async { try { - emit(state.copyWith(isLoading: true, errorMessage: null)); - final flowId = await repository.createLoginFlow(); - emit(state.copyWith(flowId: flowId, isLoading: false)); + emit(state.copyWith(isLoading: true, message: null)); + final loginFlow = await repository.createLoginFlow(aal: event.aal); + if (event.aal == 'aal2') { + authBloc.add(ChangeAuthStatus(status: AuthStatus.aal2Requested)); + } + emit(state.copyWith(loginFlow: loginFlow, isLoading: false)); } on CustomException catch (e) { if (e case UnknownException _) { - emit(state.copyWith(isLoading: false, errorMessage: e.message)); + emit(state.copyWith(isLoading: false, message: e.message)); } else { emit(state.copyWith(isLoading: false)); } } } - _onChangeEmail(ChangeEmail event, Emitter emit) { - // remove email and general error when changing email - emit(state.copyWith - .email(value: event.value, errorMessage: null) - .copyWith(errorMessage: null)); - } - - _onChangePassword(ChangePassword event, Emitter emit) { - // remove password and general error when changing email - emit(state.copyWith - .password(value: event.value, errorMessage: null) - .copyWith(errorMessage: null)); + Future _onGetLoginFlow( + GetLoginFlow event, Emitter emit) async { + try { + emit(state.copyWith(isLoading: true, message: null)); + final loginFlow = await repository.getLoginFlow(flowId: event.flowId); + emit(state.copyWith(loginFlow: loginFlow, isLoading: false)); + } on CustomException catch (e) { + if (e case UnknownException _) { + emit(state.copyWith(isLoading: false, message: e.message)); + } else { + emit(state.copyWith(isLoading: false)); + } + } } - _onChangePasswordVisibility( - ChangePasswordVisibility event, Emitter emit) { - emit(state.copyWith(isPasswordHidden: event.value)); + _onChangeNodeValue(ChangeNodeValue event, Emitter emit) { + if (state.loginFlow != null) { + final newLoginState = repository.changeLoginNodeValue( + settings: state.loginFlow!, name: event.name, value: event.value); + emit(state.copyWith(loginFlow: newLoginState, message: null)); + } } - Future _onLoginWithEmailAndPassword( - LoginWithEmailAndPassword event, Emitter emit) async { + _onUpdateLoginFlow(UpdateLoginFlow event, Emitter emit) async { try { - // remove error messages when performing login - emit(state - .copyWith(isLoading: true, errorMessage: null) - .copyWith - .email(errorMessage: null) - .copyWith - .password(errorMessage: null)); - - await repository.loginWithEmailAndPassword( - flowId: event.flowId, email: event.email, password: event.password); - + emit(state.copyWith(isLoading: true, message: null)); + await repository.updateLoginFlow( + flowId: state.loginFlow!.id, + group: event.group, + name: event.name, + value: event.value, + nodes: state.loginFlow!.ui.nodes.toList()); authBloc.add(ChangeAuthStatus(status: AuthStatus.authenticated)); } on CustomException catch (e) { - if (e case BadRequestException _) { - final emailMessage = e.messages - ?.firstWhereOrNull((element) => element.attr == 'identifier'); - final passwordMessage = e.messages - ?.firstWhereOrNull((element) => element.attr == 'password'); - final generalMessage = e.messages - ?.firstWhereOrNull((element) => element.attr == 'general'); - - // update state to new one with errors - emit(state - .copyWith(isLoading: false, errorMessage: generalMessage?.text) - .copyWith - .email(errorMessage: emailMessage?.text) - .copyWith - .password(errorMessage: passwordMessage?.text)); + if (e case BadRequestException _) { + emit(state.copyWith(loginFlow: e.flow, isLoading: false)); } else if (e case FlowExpiredException _) { - // use new flow id, reset fields and show error - emit(state - .copyWith( - flowId: e.flowId, errorMessage: e.message, isLoading: false) - .copyWith - .email(value: '') - .copyWith - .password(value: '')); + add(GetLoginFlow(flowId: e.flowId)); + } else if (e case TwoFactorAuthRequiredException _) { + add(CreateLoginFlow(aal: 'aal2')); } else if (e case UnknownException _) { - emit(state.copyWith(isLoading: false, errorMessage: e.message)); + emit(state.copyWith(isLoading: false, message: e.message)); } else { emit(state.copyWith(isLoading: false)); } diff --git a/flutter-ory-network/lib/blocs/login/login_bloc.freezed.dart b/flutter-ory-network/lib/blocs/login/login_bloc.freezed.dart index 8efa7a95..d09b7b6b 100644 --- a/flutter-ory-network/lib/blocs/login/login_bloc.freezed.dart +++ b/flutter-ory-network/lib/blocs/login/login_bloc.freezed.dart @@ -1,6 +1,3 @@ -// Copyright © 2023 Ory Corp -// SPDX-License-Identifier: Apache-2.0 - // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint @@ -19,12 +16,9 @@ final _privateConstructorUsedError = UnsupportedError( /// @nodoc mixin _$LoginState { - String? get flowId => throw _privateConstructorUsedError; - FormField get email => throw _privateConstructorUsedError; - FormField get password => throw _privateConstructorUsedError; - bool get isPasswordHidden => throw _privateConstructorUsedError; + LoginFlow? get loginFlow => throw _privateConstructorUsedError; bool get isLoading => throw _privateConstructorUsedError; - String? get errorMessage => throw _privateConstructorUsedError; + String? get message => throw _privateConstructorUsedError; @JsonKey(ignore: true) $LoginStateCopyWith get copyWith => @@ -37,16 +31,7 @@ abstract class $LoginStateCopyWith<$Res> { LoginState value, $Res Function(LoginState) then) = _$LoginStateCopyWithImpl<$Res, LoginState>; @useResult - $Res call( - {String? flowId, - FormField email, - FormField password, - bool isPasswordHidden, - bool isLoading, - String? errorMessage}); - - $FormFieldCopyWith get email; - $FormFieldCopyWith get password; + $Res call({LoginFlow? loginFlow, bool isLoading, String? message}); } /// @nodoc @@ -62,56 +47,25 @@ class _$LoginStateCopyWithImpl<$Res, $Val extends LoginState> @pragma('vm:prefer-inline') @override $Res call({ - Object? flowId = freezed, - Object? email = null, - Object? password = null, - Object? isPasswordHidden = null, + Object? loginFlow = freezed, Object? isLoading = null, - Object? errorMessage = freezed, + Object? message = freezed, }) { return _then(_value.copyWith( - flowId: freezed == flowId - ? _value.flowId - : flowId // ignore: cast_nullable_to_non_nullable - as String?, - email: null == email - ? _value.email - : email // ignore: cast_nullable_to_non_nullable - as FormField, - password: null == password - ? _value.password - : password // ignore: cast_nullable_to_non_nullable - as FormField, - isPasswordHidden: null == isPasswordHidden - ? _value.isPasswordHidden - : isPasswordHidden // ignore: cast_nullable_to_non_nullable - as bool, + loginFlow: freezed == loginFlow + ? _value.loginFlow + : loginFlow // ignore: cast_nullable_to_non_nullable + as LoginFlow?, isLoading: null == isLoading ? _value.isLoading : isLoading // ignore: cast_nullable_to_non_nullable as bool, - errorMessage: freezed == errorMessage - ? _value.errorMessage - : errorMessage // ignore: cast_nullable_to_non_nullable + message: freezed == message + ? _value.message + : message // ignore: cast_nullable_to_non_nullable as String?, ) as $Val); } - - @override - @pragma('vm:prefer-inline') - $FormFieldCopyWith get email { - return $FormFieldCopyWith(_value.email, (value) { - return _then(_value.copyWith(email: value) as $Val); - }); - } - - @override - @pragma('vm:prefer-inline') - $FormFieldCopyWith get password { - return $FormFieldCopyWith(_value.password, (value) { - return _then(_value.copyWith(password: value) as $Val); - }); - } } /// @nodoc @@ -122,18 +76,7 @@ abstract class _$$_LoginStateCopyWith<$Res> __$$_LoginStateCopyWithImpl<$Res>; @override @useResult - $Res call( - {String? flowId, - FormField email, - FormField password, - bool isPasswordHidden, - bool isLoading, - String? errorMessage}); - - @override - $FormFieldCopyWith get email; - @override - $FormFieldCopyWith get password; + $Res call({LoginFlow? loginFlow, bool isLoading, String? message}); } /// @nodoc @@ -147,37 +90,22 @@ class __$$_LoginStateCopyWithImpl<$Res> @pragma('vm:prefer-inline') @override $Res call({ - Object? flowId = freezed, - Object? email = null, - Object? password = null, - Object? isPasswordHidden = null, + Object? loginFlow = freezed, Object? isLoading = null, - Object? errorMessage = freezed, + Object? message = freezed, }) { return _then(_$_LoginState( - flowId: freezed == flowId - ? _value.flowId - : flowId // ignore: cast_nullable_to_non_nullable - as String?, - email: null == email - ? _value.email - : email // ignore: cast_nullable_to_non_nullable - as FormField, - password: null == password - ? _value.password - : password // ignore: cast_nullable_to_non_nullable - as FormField, - isPasswordHidden: null == isPasswordHidden - ? _value.isPasswordHidden - : isPasswordHidden // ignore: cast_nullable_to_non_nullable - as bool, + loginFlow: freezed == loginFlow + ? _value.loginFlow + : loginFlow // ignore: cast_nullable_to_non_nullable + as LoginFlow?, isLoading: null == isLoading ? _value.isLoading : isLoading // ignore: cast_nullable_to_non_nullable as bool, - errorMessage: freezed == errorMessage - ? _value.errorMessage - : errorMessage // ignore: cast_nullable_to_non_nullable + message: freezed == message + ? _value.message + : message // ignore: cast_nullable_to_non_nullable as String?, )); } @@ -186,34 +114,19 @@ class __$$_LoginStateCopyWithImpl<$Res> /// @nodoc class _$_LoginState implements _LoginState { - const _$_LoginState( - {this.flowId, - this.email = const FormField(value: ''), - this.password = const FormField(value: ''), - this.isPasswordHidden = true, - this.isLoading = false, - this.errorMessage}); + const _$_LoginState({this.loginFlow, this.isLoading = false, this.message}); @override - final String? flowId; - @override - @JsonKey() - final FormField email; - @override - @JsonKey() - final FormField password; - @override - @JsonKey() - final bool isPasswordHidden; + final LoginFlow? loginFlow; @override @JsonKey() final bool isLoading; @override - final String? errorMessage; + final String? message; @override String toString() { - return 'LoginState(flowId: $flowId, email: $email, password: $password, isPasswordHidden: $isPasswordHidden, isLoading: $isLoading, errorMessage: $errorMessage)'; + return 'LoginState(loginFlow: $loginFlow, isLoading: $isLoading, message: $message)'; } @override @@ -221,21 +134,15 @@ class _$_LoginState implements _LoginState { return identical(this, other) || (other.runtimeType == runtimeType && other is _$_LoginState && - (identical(other.flowId, flowId) || other.flowId == flowId) && - (identical(other.email, email) || other.email == email) && - (identical(other.password, password) || - other.password == password) && - (identical(other.isPasswordHidden, isPasswordHidden) || - other.isPasswordHidden == isPasswordHidden) && + (identical(other.loginFlow, loginFlow) || + other.loginFlow == loginFlow) && (identical(other.isLoading, isLoading) || other.isLoading == isLoading) && - (identical(other.errorMessage, errorMessage) || - other.errorMessage == errorMessage)); + (identical(other.message, message) || other.message == message)); } @override - int get hashCode => Object.hash(runtimeType, flowId, email, password, - isPasswordHidden, isLoading, errorMessage); + int get hashCode => Object.hash(runtimeType, loginFlow, isLoading, message); @JsonKey(ignore: true) @override @@ -246,25 +153,16 @@ class _$_LoginState implements _LoginState { abstract class _LoginState implements LoginState { const factory _LoginState( - {final String? flowId, - final FormField email, - final FormField password, - final bool isPasswordHidden, + {final LoginFlow? loginFlow, final bool isLoading, - final String? errorMessage}) = _$_LoginState; + final String? message}) = _$_LoginState; @override - String? get flowId; - @override - FormField get email; - @override - FormField get password; - @override - bool get isPasswordHidden; + LoginFlow? get loginFlow; @override bool get isLoading; @override - String? get errorMessage; + String? get message; @override @JsonKey(ignore: true) _$$_LoginStateCopyWith<_$_LoginState> get copyWith => diff --git a/flutter-ory-network/lib/blocs/login/login_event.dart b/flutter-ory-network/lib/blocs/login/login_event.dart index b80c7f36..b048895f 100644 --- a/flutter-ory-network/lib/blocs/login/login_event.dart +++ b/flutter-ory-network/lib/blocs/login/login_event.dart @@ -6,48 +6,41 @@ part of 'login_bloc.dart'; @immutable sealed class LoginEvent extends Equatable { @override - List get props => []; + List get props => []; } -//create login flow -final class CreateLoginFlow extends LoginEvent {} - -final class ChangeEmail extends LoginEvent { - final String value; - - ChangeEmail({required this.value}); +final class CreateLoginFlow extends LoginEvent { + final String aal; + CreateLoginFlow({required this.aal}); @override - List get props => [value]; + List get props => [aal]; } -final class ChangePassword extends LoginEvent { +class ChangeNodeValue extends LoginEvent { final String value; + final String name; - ChangePassword({required this.value}); - + ChangeNodeValue({required this.value, required this.name}); @override - List get props => [value]; + List get props => [value, name]; } -final class ChangePasswordVisibility extends LoginEvent { - final bool value; - - ChangePasswordVisibility({required this.value}); +class GetLoginFlow extends LoginEvent { + final String flowId; + GetLoginFlow({required this.flowId}); @override - List get props => [value]; + List get props => [flowId]; } -//log in -final class LoginWithEmailAndPassword extends LoginEvent { - final String flowId; - final String email; - final String password; - - LoginWithEmailAndPassword( - {required this.flowId, required this.email, required this.password}); +class UpdateLoginFlow extends LoginEvent { + final UiNodeGroupEnum group; + final String name; + final String value; + UpdateLoginFlow( + {required this.group, required this.name, required this.value}); @override - List get props => [flowId, email, password]; + List get props => [group, name, value]; } diff --git a/flutter-ory-network/lib/blocs/login/login_state.dart b/flutter-ory-network/lib/blocs/login/login_state.dart index 3c627c09..f28cce9b 100644 --- a/flutter-ory-network/lib/blocs/login/login_state.dart +++ b/flutter-ory-network/lib/blocs/login/login_state.dart @@ -6,10 +6,7 @@ part of 'login_bloc.dart'; @freezed sealed class LoginState with _$LoginState { const factory LoginState( - {String? flowId, - @Default(FormField(value: '')) FormField email, - @Default(FormField(value: '')) FormField password, - @Default(true) bool isPasswordHidden, + {LoginFlow? loginFlow, @Default(false) bool isLoading, - String? errorMessage}) = _LoginState; + String? message}) = _LoginState; } diff --git a/flutter-ory-network/lib/blocs/registration/registration_bloc.dart b/flutter-ory-network/lib/blocs/registration/registration_bloc.dart index 84acbb8e..d4f42249 100644 --- a/flutter-ory-network/lib/blocs/registration/registration_bloc.dart +++ b/flutter-ory-network/lib/blocs/registration/registration_bloc.dart @@ -4,9 +4,8 @@ import 'package:bloc/bloc.dart'; import 'package:equatable/equatable.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:collection/collection.dart'; +import 'package:ory_client/ory_client.dart'; -import '../../entities/formfield.dart'; import '../../repositories/auth.dart'; import '../../services/exceptions.dart'; import '../auth/auth_bloc.dart'; @@ -21,90 +20,72 @@ class RegistrationBloc extends Bloc { RegistrationBloc({required this.authBloc, required this.repository}) : super(RegistrationState()) { on(_onCreateRegistrationFlow); - on(_onChangeEmail); - on(_onChangePassword); - on(_onChangePasswordVisibility); - on(_onRegisterWithEmailAndPassword); + on(_onGetRegistrationFlow); + on(_onChangeNodeValue); + on(_onUpdateRegistrationFlow); } Future _onCreateRegistrationFlow( CreateRegistrationFlow event, Emitter emit) async { try { - emit(state.copyWith(isLoading: true, errorMessage: null)); - final flowId = await repository.createRegistrationFlow(); - emit(state.copyWith(flowId: flowId, isLoading: false)); + emit(state.copyWith(isLoading: true, message: null)); + final flow = await repository.createRegistrationFlow(); + emit(state.copyWith(registrationFlow: flow, isLoading: false)); } on CustomException catch (e) { if (e case UnknownException _) { - emit(state.copyWith(isLoading: false, errorMessage: e.message)); + emit(state.copyWith(isLoading: false, message: e.message)); } else { emit(state.copyWith(isLoading: false)); } } } - _onChangeEmail(ChangeEmail event, Emitter emit) { - // remove email and general error when changing email - emit(state.copyWith - .email(value: event.value, errorMessage: null) - .copyWith(errorMessage: null)); - } - - _onChangePassword(ChangePassword event, Emitter emit) { - // remove password and general error when changing email - emit(state.copyWith - .password(value: event.value, errorMessage: null) - .copyWith(errorMessage: null)); + Future _onGetRegistrationFlow( + GetRegistrationFlow event, Emitter emit) async { + try { + emit(state.copyWith(isLoading: true, message: null)); + final flow = await repository.getRegistrationFlow(flowId: event.flowId); + emit(state.copyWith(registrationFlow: flow, isLoading: false)); + } on CustomException catch (e) { + if (e case UnknownException _) { + emit(state.copyWith(isLoading: false, message: e.message)); + } else { + emit(state.copyWith(isLoading: false)); + } + } } - _onChangePasswordVisibility( - ChangePasswordVisibility event, Emitter emit) { - emit(state.copyWith(isPasswordHidden: event.value)); + _onChangeNodeValue(ChangeNodeValue event, Emitter emit) { + if (state.registrationFlow != null) { + final newRegistrationState = repository.changeRegistrationNodeValue( + settings: state.registrationFlow!, + name: event.name, + value: event.value); + emit(state.copyWith( + registrationFlow: newRegistrationState, message: null)); + } } - Future _onRegisterWithEmailAndPassword( - RegisterWithEmailAndPassword event, - Emitter emit) async { + Future _onUpdateRegistrationFlow( + UpdateRegistrationFlow event, Emitter emit) async { try { - // remove error messages when performing registration - emit(state - .copyWith(isLoading: true, errorMessage: null) - .copyWith - .email(errorMessage: null) - .copyWith - .password(errorMessage: null)); - - await repository.registerWithEmailAndPassword( - flowId: event.flowId, email: event.email, password: event.password); - - authBloc.add(ChangeAuthStatus(status: AuthStatus.authenticated)); + if (state.registrationFlow != null) { + emit(state.copyWith(isLoading: true, message: null)); + await repository.updateRegistrationFlow( + flowId: state.registrationFlow!.id, + group: event.group, + name: event.name, + value: event.value, + nodes: state.registrationFlow!.ui.nodes.toList()); + authBloc.add(ChangeAuthStatus(status: AuthStatus.authenticated)); + } } on CustomException catch (e) { - if (e case BadRequestException _) { - // get credential errors - final emailMessage = e.messages - ?.firstWhereOrNull((element) => element.attr == 'traits.email'); - final passwordMessage = e.messages - ?.firstWhereOrNull((element) => element.attr == 'password'); - final generalMessage = e.messages - ?.firstWhereOrNull((element) => element.attr == 'general'); - - // update state to new one with errors - emit(state - .copyWith(isLoading: false, errorMessage: generalMessage?.text) - .copyWith - .email(errorMessage: emailMessage?.text) - .copyWith - .password(errorMessage: passwordMessage?.text)); + if (e case BadRequestException _) { + emit(state.copyWith(registrationFlow: e.flow, isLoading: false)); } else if (e case FlowExpiredException _) { - // use new flow id, reset fields and show error - emit(state - .copyWith( - flowId: e.flowId, errorMessage: e.message, isLoading: false) - .copyWith - .email(value: '') - .copyWith - .password(value: '')); + add(GetRegistrationFlow(flowId: e.flowId)); } else if (e case UnknownException _) { - emit(state.copyWith(isLoading: false, errorMessage: e.message)); + emit(state.copyWith(isLoading: false, message: e.message)); } else { emit(state.copyWith(isLoading: false)); } diff --git a/flutter-ory-network/lib/blocs/registration/registration_bloc.freezed.dart b/flutter-ory-network/lib/blocs/registration/registration_bloc.freezed.dart index c5f63b5c..d1f90d5e 100644 --- a/flutter-ory-network/lib/blocs/registration/registration_bloc.freezed.dart +++ b/flutter-ory-network/lib/blocs/registration/registration_bloc.freezed.dart @@ -1,6 +1,3 @@ -// Copyright © 2023 Ory Corp -// SPDX-License-Identifier: Apache-2.0 - // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint @@ -19,12 +16,9 @@ final _privateConstructorUsedError = UnsupportedError( /// @nodoc mixin _$RegistrationState { - String? get flowId => throw _privateConstructorUsedError; - FormField get email => throw _privateConstructorUsedError; - FormField get password => throw _privateConstructorUsedError; - bool get isPasswordHidden => throw _privateConstructorUsedError; + RegistrationFlow? get registrationFlow => throw _privateConstructorUsedError; bool get isLoading => throw _privateConstructorUsedError; - String? get errorMessage => throw _privateConstructorUsedError; + String? get message => throw _privateConstructorUsedError; @JsonKey(ignore: true) $RegistrationStateCopyWith get copyWith => @@ -38,15 +32,7 @@ abstract class $RegistrationStateCopyWith<$Res> { _$RegistrationStateCopyWithImpl<$Res, RegistrationState>; @useResult $Res call( - {String? flowId, - FormField email, - FormField password, - bool isPasswordHidden, - bool isLoading, - String? errorMessage}); - - $FormFieldCopyWith get email; - $FormFieldCopyWith get password; + {RegistrationFlow? registrationFlow, bool isLoading, String? message}); } /// @nodoc @@ -62,56 +48,25 @@ class _$RegistrationStateCopyWithImpl<$Res, $Val extends RegistrationState> @pragma('vm:prefer-inline') @override $Res call({ - Object? flowId = freezed, - Object? email = null, - Object? password = null, - Object? isPasswordHidden = null, + Object? registrationFlow = freezed, Object? isLoading = null, - Object? errorMessage = freezed, + Object? message = freezed, }) { return _then(_value.copyWith( - flowId: freezed == flowId - ? _value.flowId - : flowId // ignore: cast_nullable_to_non_nullable - as String?, - email: null == email - ? _value.email - : email // ignore: cast_nullable_to_non_nullable - as FormField, - password: null == password - ? _value.password - : password // ignore: cast_nullable_to_non_nullable - as FormField, - isPasswordHidden: null == isPasswordHidden - ? _value.isPasswordHidden - : isPasswordHidden // ignore: cast_nullable_to_non_nullable - as bool, + registrationFlow: freezed == registrationFlow + ? _value.registrationFlow + : registrationFlow // ignore: cast_nullable_to_non_nullable + as RegistrationFlow?, isLoading: null == isLoading ? _value.isLoading : isLoading // ignore: cast_nullable_to_non_nullable as bool, - errorMessage: freezed == errorMessage - ? _value.errorMessage - : errorMessage // ignore: cast_nullable_to_non_nullable + message: freezed == message + ? _value.message + : message // ignore: cast_nullable_to_non_nullable as String?, ) as $Val); } - - @override - @pragma('vm:prefer-inline') - $FormFieldCopyWith get email { - return $FormFieldCopyWith(_value.email, (value) { - return _then(_value.copyWith(email: value) as $Val); - }); - } - - @override - @pragma('vm:prefer-inline') - $FormFieldCopyWith get password { - return $FormFieldCopyWith(_value.password, (value) { - return _then(_value.copyWith(password: value) as $Val); - }); - } } /// @nodoc @@ -123,17 +78,7 @@ abstract class _$$_RegistrationStateCopyWith<$Res> @override @useResult $Res call( - {String? flowId, - FormField email, - FormField password, - bool isPasswordHidden, - bool isLoading, - String? errorMessage}); - - @override - $FormFieldCopyWith get email; - @override - $FormFieldCopyWith get password; + {RegistrationFlow? registrationFlow, bool isLoading, String? message}); } /// @nodoc @@ -147,37 +92,22 @@ class __$$_RegistrationStateCopyWithImpl<$Res> @pragma('vm:prefer-inline') @override $Res call({ - Object? flowId = freezed, - Object? email = null, - Object? password = null, - Object? isPasswordHidden = null, + Object? registrationFlow = freezed, Object? isLoading = null, - Object? errorMessage = freezed, + Object? message = freezed, }) { return _then(_$_RegistrationState( - flowId: freezed == flowId - ? _value.flowId - : flowId // ignore: cast_nullable_to_non_nullable - as String?, - email: null == email - ? _value.email - : email // ignore: cast_nullable_to_non_nullable - as FormField, - password: null == password - ? _value.password - : password // ignore: cast_nullable_to_non_nullable - as FormField, - isPasswordHidden: null == isPasswordHidden - ? _value.isPasswordHidden - : isPasswordHidden // ignore: cast_nullable_to_non_nullable - as bool, + registrationFlow: freezed == registrationFlow + ? _value.registrationFlow + : registrationFlow // ignore: cast_nullable_to_non_nullable + as RegistrationFlow?, isLoading: null == isLoading ? _value.isLoading : isLoading // ignore: cast_nullable_to_non_nullable as bool, - errorMessage: freezed == errorMessage - ? _value.errorMessage - : errorMessage // ignore: cast_nullable_to_non_nullable + message: freezed == message + ? _value.message + : message // ignore: cast_nullable_to_non_nullable as String?, )); } @@ -187,33 +117,19 @@ class __$$_RegistrationStateCopyWithImpl<$Res> class _$_RegistrationState implements _RegistrationState { const _$_RegistrationState( - {this.flowId, - this.email = const FormField(value: ''), - this.password = const FormField(value: ''), - this.isPasswordHidden = true, - this.isLoading = false, - this.errorMessage}); + {this.registrationFlow, this.isLoading = false, this.message}); @override - final String? flowId; - @override - @JsonKey() - final FormField email; - @override - @JsonKey() - final FormField password; - @override - @JsonKey() - final bool isPasswordHidden; + final RegistrationFlow? registrationFlow; @override @JsonKey() final bool isLoading; @override - final String? errorMessage; + final String? message; @override String toString() { - return 'RegistrationState(flowId: $flowId, email: $email, password: $password, isPasswordHidden: $isPasswordHidden, isLoading: $isLoading, errorMessage: $errorMessage)'; + return 'RegistrationState(registrationFlow: $registrationFlow, isLoading: $isLoading, message: $message)'; } @override @@ -221,21 +137,16 @@ class _$_RegistrationState implements _RegistrationState { return identical(this, other) || (other.runtimeType == runtimeType && other is _$_RegistrationState && - (identical(other.flowId, flowId) || other.flowId == flowId) && - (identical(other.email, email) || other.email == email) && - (identical(other.password, password) || - other.password == password) && - (identical(other.isPasswordHidden, isPasswordHidden) || - other.isPasswordHidden == isPasswordHidden) && + (identical(other.registrationFlow, registrationFlow) || + other.registrationFlow == registrationFlow) && (identical(other.isLoading, isLoading) || other.isLoading == isLoading) && - (identical(other.errorMessage, errorMessage) || - other.errorMessage == errorMessage)); + (identical(other.message, message) || other.message == message)); } @override - int get hashCode => Object.hash(runtimeType, flowId, email, password, - isPasswordHidden, isLoading, errorMessage); + int get hashCode => + Object.hash(runtimeType, registrationFlow, isLoading, message); @JsonKey(ignore: true) @override @@ -247,25 +158,16 @@ class _$_RegistrationState implements _RegistrationState { abstract class _RegistrationState implements RegistrationState { const factory _RegistrationState( - {final String? flowId, - final FormField email, - final FormField password, - final bool isPasswordHidden, + {final RegistrationFlow? registrationFlow, final bool isLoading, - final String? errorMessage}) = _$_RegistrationState; + final String? message}) = _$_RegistrationState; @override - String? get flowId; - @override - FormField get email; - @override - FormField get password; - @override - bool get isPasswordHidden; + RegistrationFlow? get registrationFlow; @override bool get isLoading; @override - String? get errorMessage; + String? get message; @override @JsonKey(ignore: true) _$$_RegistrationStateCopyWith<_$_RegistrationState> get copyWith => diff --git a/flutter-ory-network/lib/blocs/registration/registration_event.dart b/flutter-ory-network/lib/blocs/registration/registration_event.dart index 60dcffeb..164cac05 100644 --- a/flutter-ory-network/lib/blocs/registration/registration_event.dart +++ b/flutter-ory-network/lib/blocs/registration/registration_event.dart @@ -9,44 +9,32 @@ sealed class RegistrationEvent extends Equatable { List get props => []; } -//create registration flow final class CreateRegistrationFlow extends RegistrationEvent {} -final class ChangeEmail extends RegistrationEvent { - final String value; - - ChangeEmail({required this.value}); +final class GetRegistrationFlow extends RegistrationEvent { + final String flowId; + GetRegistrationFlow({required this.flowId}); @override - List get props => [value]; + List get props => [flowId]; } -final class ChangePassword extends RegistrationEvent { +class ChangeNodeValue extends RegistrationEvent { final String value; + final String name; - ChangePassword({required this.value}); - + ChangeNodeValue({required this.value, required this.name}); @override - List get props => [value]; + List get props => [value, name]; } -final class ChangePasswordVisibility extends RegistrationEvent { - final bool value; - - ChangePasswordVisibility({required this.value}); - - @override - List get props => [value]; -} //log in - -final class RegisterWithEmailAndPassword extends RegistrationEvent { - final String flowId; - final String email; - final String password; - - RegisterWithEmailAndPassword( - {required this.flowId, required this.email, required this.password}); +class UpdateRegistrationFlow extends RegistrationEvent { + final UiNodeGroupEnum group; + final String name; + final String value; + UpdateRegistrationFlow( + {required this.group, required this.name, required this.value}); @override - List get props => [flowId, email, password]; + List get props => [group, name, value]; } diff --git a/flutter-ory-network/lib/blocs/registration/registration_state.dart b/flutter-ory-network/lib/blocs/registration/registration_state.dart index 38eac5ba..35eb520b 100644 --- a/flutter-ory-network/lib/blocs/registration/registration_state.dart +++ b/flutter-ory-network/lib/blocs/registration/registration_state.dart @@ -6,10 +6,7 @@ part of 'registration_bloc.dart'; @freezed sealed class RegistrationState with _$RegistrationState { const factory RegistrationState( - {String? flowId, - @Default(FormField(value: '')) FormField email, - @Default(FormField(value: '')) FormField password, - @Default(true) bool isPasswordHidden, + {RegistrationFlow? registrationFlow, @Default(false) bool isLoading, - String? errorMessage}) = _RegistrationState; + String? message}) = _RegistrationState; } diff --git a/flutter-ory-network/lib/entities/form_node.dart b/flutter-ory-network/lib/entities/form_node.dart deleted file mode 100644 index 57e2ed7a..00000000 --- a/flutter-ory-network/lib/entities/form_node.dart +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright © 2023 Ory Corp -// SPDX-License-Identifier: Apache-2.0 - -import 'package:freezed_annotation/freezed_annotation.dart'; - -import 'message.dart'; -import 'node_attribute.dart'; - -part 'form_node.freezed.dart'; -part 'form_node.g.dart'; - -@freezed -sealed class FormNode with _$FormNode { - const factory FormNode( - {required NodeAttribute attributes, - required List messages}) = _FormNode; - - factory FormNode.fromJson(Map json) => - _$FormNodeFromJson(json); -} diff --git a/flutter-ory-network/lib/entities/form_node.freezed.dart b/flutter-ory-network/lib/entities/form_node.freezed.dart deleted file mode 100644 index 96efd5ef..00000000 --- a/flutter-ory-network/lib/entities/form_node.freezed.dart +++ /dev/null @@ -1,191 +0,0 @@ -// Copyright © 2023 Ory Corp -// SPDX-License-Identifier: Apache-2.0 - -// coverage:ignore-file -// GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: type=lint -// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark - -part of 'form_node.dart'; - -// ************************************************************************** -// FreezedGenerator -// ************************************************************************** - -T _$identity(T value) => value; - -final _privateConstructorUsedError = UnsupportedError( - 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); - -FormNode _$FormNodeFromJson(Map json) { - return _FormNode.fromJson(json); -} - -/// @nodoc -mixin _$FormNode { - NodeAttribute get attributes => throw _privateConstructorUsedError; - List get messages => throw _privateConstructorUsedError; - - Map toJson() => throw _privateConstructorUsedError; - @JsonKey(ignore: true) - $FormNodeCopyWith get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $FormNodeCopyWith<$Res> { - factory $FormNodeCopyWith(FormNode value, $Res Function(FormNode) then) = - _$FormNodeCopyWithImpl<$Res, FormNode>; - @useResult - $Res call({NodeAttribute attributes, List messages}); - - $NodeAttributeCopyWith<$Res> get attributes; -} - -/// @nodoc -class _$FormNodeCopyWithImpl<$Res, $Val extends FormNode> - implements $FormNodeCopyWith<$Res> { - _$FormNodeCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? attributes = null, - Object? messages = null, - }) { - return _then(_value.copyWith( - attributes: null == attributes - ? _value.attributes - : attributes // ignore: cast_nullable_to_non_nullable - as NodeAttribute, - messages: null == messages - ? _value.messages - : messages // ignore: cast_nullable_to_non_nullable - as List, - ) as $Val); - } - - @override - @pragma('vm:prefer-inline') - $NodeAttributeCopyWith<$Res> get attributes { - return $NodeAttributeCopyWith<$Res>(_value.attributes, (value) { - return _then(_value.copyWith(attributes: value) as $Val); - }); - } -} - -/// @nodoc -abstract class _$$_FormNodeCopyWith<$Res> implements $FormNodeCopyWith<$Res> { - factory _$$_FormNodeCopyWith( - _$_FormNode value, $Res Function(_$_FormNode) then) = - __$$_FormNodeCopyWithImpl<$Res>; - @override - @useResult - $Res call({NodeAttribute attributes, List messages}); - - @override - $NodeAttributeCopyWith<$Res> get attributes; -} - -/// @nodoc -class __$$_FormNodeCopyWithImpl<$Res> - extends _$FormNodeCopyWithImpl<$Res, _$_FormNode> - implements _$$_FormNodeCopyWith<$Res> { - __$$_FormNodeCopyWithImpl( - _$_FormNode _value, $Res Function(_$_FormNode) _then) - : super(_value, _then); - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? attributes = null, - Object? messages = null, - }) { - return _then(_$_FormNode( - attributes: null == attributes - ? _value.attributes - : attributes // ignore: cast_nullable_to_non_nullable - as NodeAttribute, - messages: null == messages - ? _value._messages - : messages // ignore: cast_nullable_to_non_nullable - as List, - )); - } -} - -/// @nodoc -@JsonSerializable() -class _$_FormNode implements _FormNode { - const _$_FormNode( - {required this.attributes, required final List messages}) - : _messages = messages; - - factory _$_FormNode.fromJson(Map json) => - _$$_FormNodeFromJson(json); - - @override - final NodeAttribute attributes; - final List _messages; - @override - List get messages { - if (_messages is EqualUnmodifiableListView) return _messages; - // ignore: implicit_dynamic_type - return EqualUnmodifiableListView(_messages); - } - - @override - String toString() { - return 'FormNode(attributes: $attributes, messages: $messages)'; - } - - @override - bool operator ==(dynamic other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$_FormNode && - (identical(other.attributes, attributes) || - other.attributes == attributes) && - const DeepCollectionEquality().equals(other._messages, _messages)); - } - - @JsonKey(ignore: true) - @override - int get hashCode => Object.hash( - runtimeType, attributes, const DeepCollectionEquality().hash(_messages)); - - @JsonKey(ignore: true) - @override - @pragma('vm:prefer-inline') - _$$_FormNodeCopyWith<_$_FormNode> get copyWith => - __$$_FormNodeCopyWithImpl<_$_FormNode>(this, _$identity); - - @override - Map toJson() { - return _$$_FormNodeToJson( - this, - ); - } -} - -abstract class _FormNode implements FormNode { - const factory _FormNode( - {required final NodeAttribute attributes, - required final List messages}) = _$_FormNode; - - factory _FormNode.fromJson(Map json) = _$_FormNode.fromJson; - - @override - NodeAttribute get attributes; - @override - List get messages; - @override - @JsonKey(ignore: true) - _$$_FormNodeCopyWith<_$_FormNode> get copyWith => - throw _privateConstructorUsedError; -} diff --git a/flutter-ory-network/lib/entities/form_node.g.dart b/flutter-ory-network/lib/entities/form_node.g.dart deleted file mode 100644 index 7b31b119..00000000 --- a/flutter-ory-network/lib/entities/form_node.g.dart +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright © 2023 Ory Corp -// SPDX-License-Identifier: Apache-2.0 - -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'form_node.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -_$_FormNode _$$_FormNodeFromJson(Map json) => _$_FormNode( - attributes: - NodeAttribute.fromJson(json['attributes'] as Map), - messages: (json['messages'] as List) - .map((e) => NodeMessage.fromJson(e as Map)) - .toList(), - ); - -Map _$$_FormNodeToJson(_$_FormNode instance) => - { - 'attributes': instance.attributes, - 'messages': instance.messages, - }; diff --git a/flutter-ory-network/lib/entities/formfield.dart b/flutter-ory-network/lib/entities/formfield.dart deleted file mode 100644 index 6407a49c..00000000 --- a/flutter-ory-network/lib/entities/formfield.dart +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright © 2023 Ory Corp -// SPDX-License-Identifier: Apache-2.0 - -import 'package:freezed_annotation/freezed_annotation.dart'; - -part 'formfield.freezed.dart'; - -@freezed -sealed class FormField with _$FormField { - const factory FormField({T? value, String? errorMessage}) = _FormField; -} diff --git a/flutter-ory-network/lib/entities/formfield.freezed.dart b/flutter-ory-network/lib/entities/formfield.freezed.dart deleted file mode 100644 index d8e74a89..00000000 --- a/flutter-ory-network/lib/entities/formfield.freezed.dart +++ /dev/null @@ -1,154 +0,0 @@ -// Copyright © 2023 Ory Corp -// SPDX-License-Identifier: Apache-2.0 - -// coverage:ignore-file -// GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: type=lint -// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark - -part of 'formfield.dart'; - -// ************************************************************************** -// FreezedGenerator -// ************************************************************************** - -T _$identity(T value) => value; - -final _privateConstructorUsedError = UnsupportedError( - 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); - -/// @nodoc -mixin _$FormField { - T? get value => throw _privateConstructorUsedError; - String? get errorMessage => throw _privateConstructorUsedError; - - @JsonKey(ignore: true) - $FormFieldCopyWith> get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $FormFieldCopyWith { - factory $FormFieldCopyWith( - FormField value, $Res Function(FormField) then) = - _$FormFieldCopyWithImpl>; - @useResult - $Res call({T? value, String? errorMessage}); -} - -/// @nodoc -class _$FormFieldCopyWithImpl> - implements $FormFieldCopyWith { - _$FormFieldCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? value = freezed, - Object? errorMessage = freezed, - }) { - return _then(_value.copyWith( - value: freezed == value - ? _value.value - : value // ignore: cast_nullable_to_non_nullable - as T?, - errorMessage: freezed == errorMessage - ? _value.errorMessage - : errorMessage // ignore: cast_nullable_to_non_nullable - as String?, - ) as $Val); - } -} - -/// @nodoc -abstract class _$$_FormFieldCopyWith - implements $FormFieldCopyWith { - factory _$$_FormFieldCopyWith( - _$_FormField value, $Res Function(_$_FormField) then) = - __$$_FormFieldCopyWithImpl; - @override - @useResult - $Res call({T? value, String? errorMessage}); -} - -/// @nodoc -class __$$_FormFieldCopyWithImpl - extends _$FormFieldCopyWithImpl> - implements _$$_FormFieldCopyWith { - __$$_FormFieldCopyWithImpl( - _$_FormField _value, $Res Function(_$_FormField) _then) - : super(_value, _then); - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? value = freezed, - Object? errorMessage = freezed, - }) { - return _then(_$_FormField( - value: freezed == value - ? _value.value - : value // ignore: cast_nullable_to_non_nullable - as T?, - errorMessage: freezed == errorMessage - ? _value.errorMessage - : errorMessage // ignore: cast_nullable_to_non_nullable - as String?, - )); - } -} - -/// @nodoc - -class _$_FormField implements _FormField { - const _$_FormField({this.value, this.errorMessage}); - - @override - final T? value; - @override - final String? errorMessage; - - @override - String toString() { - return 'FormField<$T>(value: $value, errorMessage: $errorMessage)'; - } - - @override - bool operator ==(dynamic other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$_FormField && - const DeepCollectionEquality().equals(other.value, value) && - (identical(other.errorMessage, errorMessage) || - other.errorMessage == errorMessage)); - } - - @override - int get hashCode => Object.hash( - runtimeType, const DeepCollectionEquality().hash(value), errorMessage); - - @JsonKey(ignore: true) - @override - @pragma('vm:prefer-inline') - _$$_FormFieldCopyWith> get copyWith => - __$$_FormFieldCopyWithImpl>(this, _$identity); -} - -abstract class _FormField implements FormField { - const factory _FormField({final T? value, final String? errorMessage}) = - _$_FormField; - - @override - T? get value; - @override - String? get errorMessage; - @override - @JsonKey(ignore: true) - _$$_FormFieldCopyWith> get copyWith => - throw _privateConstructorUsedError; -} diff --git a/flutter-ory-network/lib/entities/message.dart b/flutter-ory-network/lib/entities/message.dart deleted file mode 100644 index 58ca045b..00000000 --- a/flutter-ory-network/lib/entities/message.dart +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright © 2023 Ory Corp -// SPDX-License-Identifier: Apache-2.0 - -import 'package:freezed_annotation/freezed_annotation.dart'; - -part 'message.freezed.dart'; -part 'message.g.dart'; - -@freezed -class NodeMessage with _$NodeMessage { - const factory NodeMessage( - {required int id, - required String text, - required MessageType type, - @Default('general') String attr}) = _NodeMessage; - - factory NodeMessage.fromJson(Map json) => - _$NodeMessageFromJson(json); -} - -// specifies message type -enum MessageType { info, error, success } diff --git a/flutter-ory-network/lib/entities/message.freezed.dart b/flutter-ory-network/lib/entities/message.freezed.dart deleted file mode 100644 index 3e50f419..00000000 --- a/flutter-ory-network/lib/entities/message.freezed.dart +++ /dev/null @@ -1,211 +0,0 @@ -// Copyright © 2023 Ory Corp -// SPDX-License-Identifier: Apache-2.0 - -// coverage:ignore-file -// GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: type=lint -// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark - -part of 'message.dart'; - -// ************************************************************************** -// FreezedGenerator -// ************************************************************************** - -T _$identity(T value) => value; - -final _privateConstructorUsedError = UnsupportedError( - 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); - -NodeMessage _$NodeMessageFromJson(Map json) { - return _NodeMessage.fromJson(json); -} - -/// @nodoc -mixin _$NodeMessage { - int get id => throw _privateConstructorUsedError; - String get text => throw _privateConstructorUsedError; - MessageType get type => throw _privateConstructorUsedError; - String get attr => throw _privateConstructorUsedError; - - Map toJson() => throw _privateConstructorUsedError; - @JsonKey(ignore: true) - $NodeMessageCopyWith get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $NodeMessageCopyWith<$Res> { - factory $NodeMessageCopyWith( - NodeMessage value, $Res Function(NodeMessage) then) = - _$NodeMessageCopyWithImpl<$Res, NodeMessage>; - @useResult - $Res call({int id, String text, MessageType type, String attr}); -} - -/// @nodoc -class _$NodeMessageCopyWithImpl<$Res, $Val extends NodeMessage> - implements $NodeMessageCopyWith<$Res> { - _$NodeMessageCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? id = null, - Object? text = null, - Object? type = null, - Object? attr = null, - }) { - return _then(_value.copyWith( - id: null == id - ? _value.id - : id // ignore: cast_nullable_to_non_nullable - as int, - text: null == text - ? _value.text - : text // ignore: cast_nullable_to_non_nullable - as String, - type: null == type - ? _value.type - : type // ignore: cast_nullable_to_non_nullable - as MessageType, - attr: null == attr - ? _value.attr - : attr // ignore: cast_nullable_to_non_nullable - as String, - ) as $Val); - } -} - -/// @nodoc -abstract class _$$_NodeMessageCopyWith<$Res> - implements $NodeMessageCopyWith<$Res> { - factory _$$_NodeMessageCopyWith( - _$_NodeMessage value, $Res Function(_$_NodeMessage) then) = - __$$_NodeMessageCopyWithImpl<$Res>; - @override - @useResult - $Res call({int id, String text, MessageType type, String attr}); -} - -/// @nodoc -class __$$_NodeMessageCopyWithImpl<$Res> - extends _$NodeMessageCopyWithImpl<$Res, _$_NodeMessage> - implements _$$_NodeMessageCopyWith<$Res> { - __$$_NodeMessageCopyWithImpl( - _$_NodeMessage _value, $Res Function(_$_NodeMessage) _then) - : super(_value, _then); - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? id = null, - Object? text = null, - Object? type = null, - Object? attr = null, - }) { - return _then(_$_NodeMessage( - id: null == id - ? _value.id - : id // ignore: cast_nullable_to_non_nullable - as int, - text: null == text - ? _value.text - : text // ignore: cast_nullable_to_non_nullable - as String, - type: null == type - ? _value.type - : type // ignore: cast_nullable_to_non_nullable - as MessageType, - attr: null == attr - ? _value.attr - : attr // ignore: cast_nullable_to_non_nullable - as String, - )); - } -} - -/// @nodoc -@JsonSerializable() -class _$_NodeMessage implements _NodeMessage { - const _$_NodeMessage( - {required this.id, - required this.text, - required this.type, - this.attr = 'general'}); - - factory _$_NodeMessage.fromJson(Map json) => - _$$_NodeMessageFromJson(json); - - @override - final int id; - @override - final String text; - @override - final MessageType type; - @override - @JsonKey() - final String attr; - - @override - String toString() { - return 'NodeMessage(id: $id, text: $text, type: $type, attr: $attr)'; - } - - @override - bool operator ==(dynamic other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$_NodeMessage && - (identical(other.id, id) || other.id == id) && - (identical(other.text, text) || other.text == text) && - (identical(other.type, type) || other.type == type) && - (identical(other.attr, attr) || other.attr == attr)); - } - - @JsonKey(ignore: true) - @override - int get hashCode => Object.hash(runtimeType, id, text, type, attr); - - @JsonKey(ignore: true) - @override - @pragma('vm:prefer-inline') - _$$_NodeMessageCopyWith<_$_NodeMessage> get copyWith => - __$$_NodeMessageCopyWithImpl<_$_NodeMessage>(this, _$identity); - - @override - Map toJson() { - return _$$_NodeMessageToJson( - this, - ); - } -} - -abstract class _NodeMessage implements NodeMessage { - const factory _NodeMessage( - {required final int id, - required final String text, - required final MessageType type, - final String attr}) = _$_NodeMessage; - - factory _NodeMessage.fromJson(Map json) = - _$_NodeMessage.fromJson; - - @override - int get id; - @override - String get text; - @override - MessageType get type; - @override - String get attr; - @override - @JsonKey(ignore: true) - _$$_NodeMessageCopyWith<_$_NodeMessage> get copyWith => - throw _privateConstructorUsedError; -} diff --git a/flutter-ory-network/lib/entities/message.g.dart b/flutter-ory-network/lib/entities/message.g.dart deleted file mode 100644 index d91445c9..00000000 --- a/flutter-ory-network/lib/entities/message.g.dart +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright © 2023 Ory Corp -// SPDX-License-Identifier: Apache-2.0 - -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'message.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -_$_NodeMessage _$$_NodeMessageFromJson(Map json) => - _$_NodeMessage( - id: json['id'] as int, - text: json['text'] as String, - type: $enumDecode(_$MessageTypeEnumMap, json['type']), - attr: json['attr'] as String? ?? 'general', - ); - -Map _$$_NodeMessageToJson(_$_NodeMessage instance) => - { - 'id': instance.id, - 'text': instance.text, - 'type': _$MessageTypeEnumMap[instance.type]!, - 'attr': instance.attr, - }; - -const _$MessageTypeEnumMap = { - MessageType.info: 'info', - MessageType.error: 'error', - MessageType.success: 'success', -}; diff --git a/flutter-ory-network/lib/entities/node_attribute.dart b/flutter-ory-network/lib/entities/node_attribute.dart deleted file mode 100644 index 2e98d390..00000000 --- a/flutter-ory-network/lib/entities/node_attribute.dart +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright © 2023 Ory Corp -// SPDX-License-Identifier: Apache-2.0 - -import 'package:freezed_annotation/freezed_annotation.dart'; -part 'node_attribute.freezed.dart'; -part 'node_attribute.g.dart'; - -@freezed -sealed class NodeAttribute with _$NodeAttribute { - const factory NodeAttribute({required String name}) = _NodeAttribute; - - factory NodeAttribute.fromJson(Map json) => - _$NodeAttributeFromJson(json); -} diff --git a/flutter-ory-network/lib/entities/node_attribute.freezed.dart b/flutter-ory-network/lib/entities/node_attribute.freezed.dart deleted file mode 100644 index 08432654..00000000 --- a/flutter-ory-network/lib/entities/node_attribute.freezed.dart +++ /dev/null @@ -1,154 +0,0 @@ -// Copyright © 2023 Ory Corp -// SPDX-License-Identifier: Apache-2.0 - -// coverage:ignore-file -// GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: type=lint -// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark - -part of 'node_attribute.dart'; - -// ************************************************************************** -// FreezedGenerator -// ************************************************************************** - -T _$identity(T value) => value; - -final _privateConstructorUsedError = UnsupportedError( - 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); - -NodeAttribute _$NodeAttributeFromJson(Map json) { - return _NodeAttribute.fromJson(json); -} - -/// @nodoc -mixin _$NodeAttribute { - String get name => throw _privateConstructorUsedError; - - Map toJson() => throw _privateConstructorUsedError; - @JsonKey(ignore: true) - $NodeAttributeCopyWith get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $NodeAttributeCopyWith<$Res> { - factory $NodeAttributeCopyWith( - NodeAttribute value, $Res Function(NodeAttribute) then) = - _$NodeAttributeCopyWithImpl<$Res, NodeAttribute>; - @useResult - $Res call({String name}); -} - -/// @nodoc -class _$NodeAttributeCopyWithImpl<$Res, $Val extends NodeAttribute> - implements $NodeAttributeCopyWith<$Res> { - _$NodeAttributeCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? name = null, - }) { - return _then(_value.copyWith( - name: null == name - ? _value.name - : name // ignore: cast_nullable_to_non_nullable - as String, - ) as $Val); - } -} - -/// @nodoc -abstract class _$$_NodeAttributeCopyWith<$Res> - implements $NodeAttributeCopyWith<$Res> { - factory _$$_NodeAttributeCopyWith( - _$_NodeAttribute value, $Res Function(_$_NodeAttribute) then) = - __$$_NodeAttributeCopyWithImpl<$Res>; - @override - @useResult - $Res call({String name}); -} - -/// @nodoc -class __$$_NodeAttributeCopyWithImpl<$Res> - extends _$NodeAttributeCopyWithImpl<$Res, _$_NodeAttribute> - implements _$$_NodeAttributeCopyWith<$Res> { - __$$_NodeAttributeCopyWithImpl( - _$_NodeAttribute _value, $Res Function(_$_NodeAttribute) _then) - : super(_value, _then); - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? name = null, - }) { - return _then(_$_NodeAttribute( - name: null == name - ? _value.name - : name // ignore: cast_nullable_to_non_nullable - as String, - )); - } -} - -/// @nodoc -@JsonSerializable() -class _$_NodeAttribute implements _NodeAttribute { - const _$_NodeAttribute({required this.name}); - - factory _$_NodeAttribute.fromJson(Map json) => - _$$_NodeAttributeFromJson(json); - - @override - final String name; - - @override - String toString() { - return 'NodeAttribute(name: $name)'; - } - - @override - bool operator ==(dynamic other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$_NodeAttribute && - (identical(other.name, name) || other.name == name)); - } - - @JsonKey(ignore: true) - @override - int get hashCode => Object.hash(runtimeType, name); - - @JsonKey(ignore: true) - @override - @pragma('vm:prefer-inline') - _$$_NodeAttributeCopyWith<_$_NodeAttribute> get copyWith => - __$$_NodeAttributeCopyWithImpl<_$_NodeAttribute>(this, _$identity); - - @override - Map toJson() { - return _$$_NodeAttributeToJson( - this, - ); - } -} - -abstract class _NodeAttribute implements NodeAttribute { - const factory _NodeAttribute({required final String name}) = _$_NodeAttribute; - - factory _NodeAttribute.fromJson(Map json) = - _$_NodeAttribute.fromJson; - - @override - String get name; - @override - @JsonKey(ignore: true) - _$$_NodeAttributeCopyWith<_$_NodeAttribute> get copyWith => - throw _privateConstructorUsedError; -} diff --git a/flutter-ory-network/lib/entities/node_attribute.g.dart b/flutter-ory-network/lib/entities/node_attribute.g.dart deleted file mode 100644 index 92070a72..00000000 --- a/flutter-ory-network/lib/entities/node_attribute.g.dart +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright © 2023 Ory Corp -// SPDX-License-Identifier: Apache-2.0 - -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'node_attribute.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -_$_NodeAttribute _$$_NodeAttributeFromJson(Map json) => - _$_NodeAttribute( - name: json['name'] as String, - ); - -Map _$$_NodeAttributeToJson(_$_NodeAttribute instance) => - { - 'name': instance.name, - }; diff --git a/flutter-ory-network/lib/main.dart b/flutter-ory-network/lib/main.dart index 529da379..ea93cfc1 100644 --- a/flutter-ory-network/lib/main.dart +++ b/flutter-ory-network/lib/main.dart @@ -12,6 +12,7 @@ import 'blocs/auth/auth_bloc.dart'; import 'pages/home.dart'; import 'pages/login.dart'; import 'pages/entry.dart'; + import 'repositories/auth.dart'; import 'services/auth.dart'; @@ -89,7 +90,14 @@ class _MyAppViewState extends State { case AuthStatus.unauthenticated: _navigator.pushAndRemoveUntil( MaterialPageRoute( - builder: (BuildContext context) => const LoginPage()), + builder: (BuildContext context) => + const LoginPage(aal: 'aal1')), + (Route route) => false); + case AuthStatus.aal2Requested: + _navigator.pushAndRemoveUntil( + MaterialPageRoute( + builder: (BuildContext context) => + const LoginPage(aal: 'aal2')), (Route route) => false); case AuthStatus.uninitialized: break; diff --git a/flutter-ory-network/lib/pages/home.dart b/flutter-ory-network/lib/pages/home.dart index 0f18adc5..af459fee 100644 --- a/flutter-ory-network/lib/pages/home.dart +++ b/flutter-ory-network/lib/pages/home.dart @@ -78,7 +78,7 @@ class _HomePageState extends State { child: Column( children: [ Text( - "Welcome back,\n${session.identity.id}!", + "Welcome back,\n${session.identity!.id}!", style: const TextStyle(fontWeight: FontWeight.w900, fontSize: 35), ), const Padding( @@ -94,7 +94,7 @@ class _HomePageState extends State { decoration: BoxDecoration( borderRadius: BorderRadius.circular(8), color: Colors.grey[600]), - child: Text(session.identity.traits.toString(), + child: Text(session.identity!.traits.toString(), style: const TextStyle( fontWeight: FontWeight.w500, color: Colors.white)), ), diff --git a/flutter-ory-network/lib/pages/login.dart b/flutter-ory-network/lib/pages/login.dart index ccfdb0cb..17dd68f8 100644 --- a/flutter-ory-network/lib/pages/login.dart +++ b/flutter-ory-network/lib/pages/login.dart @@ -1,17 +1,17 @@ -// Copyright © 2023 Ory Corp -// SPDX-License-Identifier: Apache-2.0 - import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:ory_client/ory_client.dart'; +import 'package:ory_network_flutter/widgets/nodes/provider.dart'; import '../blocs/auth/auth_bloc.dart'; import '../blocs/login/login_bloc.dart'; import '../repositories/auth.dart'; -import '../widgets/social_provider_box.dart'; +import '../widgets/helpers.dart'; import 'registration.dart'; class LoginPage extends StatelessWidget { - const LoginPage({super.key}); + final String aal; + const LoginPage({super.key, required this.aal}); @override Widget build(BuildContext context) { @@ -21,251 +21,186 @@ class LoginPage extends StatelessWidget { create: (context) => LoginBloc( authBloc: context.read(), repository: RepositoryProvider.of(context)) - ..add(CreateLoginFlow()), + ..add(CreateLoginFlow(aal: aal)), child: const LoginForm()), ); } } -class LoginForm extends StatefulWidget { +class LoginForm extends StatelessWidget { const LoginForm({super.key}); - @override - State createState() => LoginFormState(); -} - -class LoginFormState extends State { - final emailController = TextEditingController(); - final passwordController = TextEditingController(); @override Widget build(BuildContext context) { - final loginBloc = BlocProvider.of(context); - return BlocConsumer( - bloc: loginBloc, - // listen to email and password changes - listenWhen: (previous, current) { - return (previous.email.value != current.email.value && - emailController.text != current.email.value) || - (previous.password.value != current.password.value && - passwordController.text != current.password.value); - }, - // if email or password value have changed, update text controller values - listener: (BuildContext context, LoginState state) { - emailController.text = state.email.value; - passwordController.text = state.password.value; - }, - builder: (context, state) { - // login flow was created - if (state.flowId != null) { - return _buildLoginForm(context, state); - } // otherwise, show loading or error - else { - return _buildLoginFlowNotCreated(context, state); - } - }); + return BlocBuilder( + buildWhen: (previous, current) => previous.isLoading != current.isLoading, + builder: (context, state) { + if (state.loginFlow != null) { + return _buildUi(context, state); + } else { + return buildFlowNotCreated(context, state.message); + } + }, + ); } - _buildLoginFlowNotCreated(BuildContext context, LoginState state) { - if (state.errorMessage != null) { - return Center( - child: Text( - state.errorMessage!, - style: const TextStyle(color: Colors.red), - )); - } else { - return const Center(child: CircularProgressIndicator()); - } - } + _buildUi(BuildContext context, LoginState state) { + final nodes = state.loginFlow!.ui.nodes; - _buildLoginForm(BuildContext context, LoginState state) { - return Padding( - padding: const EdgeInsets.symmetric(horizontal: 32), - child: SingleChildScrollView( - // do not show scrolling indicator - physics: const BouncingScrollPhysics(), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Padding( - padding: EdgeInsets.only( - //status bar height + padding - top: MediaQuery.of(context).viewPadding.top + 48), - child: Image.asset( - 'assets/images/ory_logo.png', - width: 70, - ), - ), - const SizedBox( - height: 32, - ), - const Text("Sign in", - style: TextStyle( - fontWeight: FontWeight.w600, height: 1.5, fontSize: 18)), - const Text( - "Sign in with a social provider or with your email and password"), - const SizedBox( - height: 32, - ), - const Row( - children: [ - SocialProviderBox(provider: SocialProvider.google), - SizedBox( - width: 12, - ), - SocialProviderBox(provider: SocialProvider.github), - SizedBox( - width: 12, - ), - SocialProviderBox(provider: SocialProvider.apple), - SizedBox( - width: 12, - ), - SocialProviderBox(provider: SocialProvider.linkedin) - ], - ), - const SizedBox( - height: 32, - ), - const Divider( - color: Color.fromRGBO(226, 232, 240, 1), thickness: 1), - const SizedBox( - height: 32, - ), + // get default nodes from all nodes + final defaultNodes = + nodes.where((node) => node.group == UiNodeGroupEnum.default_).toList(); - const SizedBox( - height: 20, - ), + // get password nodes from all nodes + final passwordNodes = + nodes.where((node) => node.group == UiNodeGroupEnum.password).toList(); - const SizedBox( - height: 32, - ), - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const Text('Email'), - const SizedBox( - height: 4, - ), - TextFormField( - enabled: !state.isLoading, - controller: emailController, - onChanged: (String value) => - context.read().add(ChangeEmail(value: value)), - decoration: InputDecoration( - border: const OutlineInputBorder(), - hintText: 'Enter your email', - errorText: state.email.errorMessage, - errorMaxLines: 3), - ), - ], - ), - const SizedBox( - height: 20, - ), - Container( - padding: EdgeInsets.zero, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text('Password'), - TextButton( - onPressed: null, child: Text("Forgot password?")) - ], - ), - const SizedBox( - height: 4, - ), - TextFormField( - enabled: !state.isLoading, - controller: passwordController, - onChanged: (String value) => context - .read() - .add(ChangePassword(value: value)), - obscureText: state.isPasswordHidden, - decoration: InputDecoration( - border: const OutlineInputBorder(), - hintText: 'Enter your password', - // change password visibility - suffixIcon: GestureDetector( - onTap: () => context.read().add( - ChangePasswordVisibility( - value: !state.isPasswordHidden)), - child: ImageIcon( - state.isPasswordHidden - ? const AssetImage('assets/icons/eye.png') - : const AssetImage('assets/icons/eye-off.png'), - size: 16, - ), - ), - errorText: state.password.errorMessage, - errorMaxLines: 3), - ), - ], - ), - ), - const SizedBox( - height: 32, - ), - // show general error message if it exists - if (state.errorMessage != null) + // get lookup secret nodes from all nodes + final lookupSecretNodes = nodes + .where((node) => node.group == UiNodeGroupEnum.lookupSecret) + .toList(); + + // get totp nodes from all nodes + final totpNodes = + nodes.where((node) => node.group == UiNodeGroupEnum.totp).toList(); + + // get oidc nodes from all nodes + final oidcNodes = + nodes.where((node) => node.group == UiNodeGroupEnum.oidc).toList(); + + return Stack(children: [ + Padding( + padding: const EdgeInsets.symmetric(horizontal: 32), + child: SingleChildScrollView( + // do not show scrolling indicator + physics: const BouncingScrollPhysics(), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ Padding( - padding: const EdgeInsets.only(bottom: 15.0), - child: Text( - state.errorMessage!, - style: const TextStyle(color: Colors.red), - maxLines: 3, + padding: EdgeInsets.only( + //status bar height + padding + top: MediaQuery.of(context).viewPadding.top + 48), + child: Image.asset( + 'assets/images/ory_logo.png', + width: 70, ), ), - // show loading indicator when state is in a loading mode - if (state.isLoading) - const Padding( - padding: EdgeInsets.all(15.0), - child: Center( - child: SizedBox( - width: 30, - height: 30, - child: CircularProgressIndicator())), + const SizedBox( + height: 32, ), - SizedBox( - width: double.infinity, - child: FilledButton( - // disable button when state is loading - onPressed: state.isLoading - ? null - : () { - context.read().add(LoginWithEmailAndPassword( - flowId: state.flowId!, - email: state.email.value, - password: state.password.value)); - }, - child: const Text('Sign in'), + const Text('Sign in', + style: TextStyle( + fontWeight: FontWeight.w600, height: 1.5, fontSize: 18)), + if (oidcNodes.isNotEmpty) + Padding( + padding: const EdgeInsets.only(top: 32.0), + child: Column( + mainAxisSize: MainAxisSize.max, + children: oidcNodes + .map((node) => SocialProviderInput(node: node)) + .toList()), + ), + if (defaultNodes.isNotEmpty) + buildGroup(context, UiNodeGroupEnum.default_, + defaultNodes, _onInputChange, _onInputSubmit), + if (passwordNodes.isNotEmpty) + buildGroup(context, UiNodeGroupEnum.password, + passwordNodes, _onInputChange, _onInputSubmit), + if (lookupSecretNodes.isNotEmpty) + buildGroup(context, UiNodeGroupEnum.lookupSecret, + lookupSecretNodes, _onInputChange, _onInputSubmit), + if (totpNodes.isNotEmpty) + buildGroup(context, UiNodeGroupEnum.totp, totpNodes, + _onInputChange, _onInputSubmit), + const SizedBox( + height: 32, ), - ), - const SizedBox( - height: 32, - ), - Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - const Text('No account?'), - TextButton( - // disable button when state is loading - onPressed: state.isLoading - ? null - : () => Navigator.of(context).pushReplacement( - MaterialPageRoute( - builder: (context) => - const RegistrationPage())), - child: const Text('Sign up')) - ], - ) - ], + if (state.loginFlow?.ui.messages != null) + for (var message in state.loginFlow!.ui.messages!) + Text( + message.text, + style: TextStyle(color: getMessageColor(message.type)), + ), + // build progress indicator when state is loading + BlocSelector( + bloc: (context).read(), + selector: (AuthState state) => + state.status == AuthStatus.aal2Requested, + builder: (BuildContext context, bool booleanState) { + print(booleanState); + if (booleanState) { + return Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + const Text('Something\'s not working?'), + TextButton( + // disable button when state is loading + onPressed: () => + (context).read().add(LogOut()), + child: const Text('Logout')) + ], + ); + } else { + return Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + const Text('No account?'), + TextButton( + // disable button when state is loading + onPressed: state.isLoading + ? null + : () => Navigator.of(context).pushReplacement( + MaterialPageRoute( + builder: (context) => + const RegistrationPage())), + child: const Text('Sign up')) + ], + ); + } + }), + ], + ), ), ), - ); + // build progress indicator when state is loading + BlocSelector( + bloc: (context).read(), + selector: (LoginState state) => state.isLoading, + builder: (BuildContext context, bool booleanState) { + if (booleanState) { + return const Opacity( + opacity: 0.8, + child: ModalBarrier(dismissible: false, color: Colors.white30), + ); + } else { + return Container(); + } + }), + BlocSelector( + bloc: (context).read(), + selector: (LoginState state) => state.isLoading, + builder: (BuildContext context, bool booleanState) { + if (booleanState) { + return const Center( + child: CircularProgressIndicator(), + ); + } else { + return Container(); + } + }) + ]); + } + + _onInputChange(BuildContext context, String value, String name) { + context.read().add(ChangeNodeValue(value: value, name: name)); + } + + _onInputSubmit( + BuildContext context, UiNodeGroupEnum group, String name, String value) { + context + .read() + .add(UpdateLoginFlow(group: group, name: name, value: value)); } } diff --git a/flutter-ory-network/lib/pages/registration.dart b/flutter-ory-network/lib/pages/registration.dart index 54465942..72c84e59 100644 --- a/flutter-ory-network/lib/pages/registration.dart +++ b/flutter-ory-network/lib/pages/registration.dart @@ -3,11 +3,13 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:ory_network_flutter/widgets/social_provider_box.dart'; +import 'package:ory_client/ory_client.dart'; import '../blocs/auth/auth_bloc.dart'; import '../blocs/registration/registration_bloc.dart'; import '../repositories/auth.dart'; +import '../widgets/helpers.dart'; +import '../widgets/nodes/provider.dart'; import 'login.dart'; class RegistrationPage extends StatelessWidget { @@ -39,214 +41,160 @@ class RegistrationFormState extends State { @override Widget build(BuildContext context) { - final registrationBloc = BlocProvider.of(context); - return BlocConsumer( - bloc: registrationBloc, - // listen to email and password changes - listenWhen: (previous, current) { - return (previous.email.value != current.email.value && - emailController.text != current.email.value) || - (previous.password.value != current.password.value && - passwordController.text != current.password.value); - }, - // if email or password value have changed, update text controller values - listener: (BuildContext context, RegistrationState state) { - emailController.text = state.email.value; - passwordController.text = state.password.value; - }, - builder: (context, state) { - // registration flow was created - if (state.flowId != null) { - return _buildRegistrationForm(context, state); - } // otherwise, show loading or error - else { - return _buildRegistrationFlowNotCreated(context, state); - } - }); + return BlocBuilder( + buildWhen: (previous, current) => previous.isLoading != current.isLoading, + builder: (context, state) { + if (state.registrationFlow != null) { + return _buildUi(context, state); + } else { + return buildFlowNotCreated(context, state.message); + } + }, + ); } - _buildRegistrationFlowNotCreated( - BuildContext context, RegistrationState state) { - if (state.errorMessage != null) { - return Center( - child: Text( - state.errorMessage!, - style: const TextStyle(color: Colors.red), - )); - } else { - return const Center(child: CircularProgressIndicator()); - } - } + _buildUi(BuildContext context, RegistrationState state) { + final nodes = state.registrationFlow!.ui.nodes; - _buildRegistrationForm(BuildContext context, RegistrationState state) { - return Padding( - padding: const EdgeInsets.symmetric(horizontal: 32), - child: SingleChildScrollView( - // do not show scrolling indicator - physics: const BouncingScrollPhysics(), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Padding( - padding: EdgeInsets.only( - //status bar height + padding - top: MediaQuery.of(context).viewPadding.top + 48), - child: Image.asset( - 'assets/images/ory_logo.png', - width: 70, - ), - ), - const SizedBox( - height: 32, - ), - const Text("Sign up", - style: TextStyle( - fontWeight: FontWeight.w600, height: 1.5, fontSize: 18)), - const Text("Sign up with a social provider or with your email"), - const SizedBox( - height: 32, - ), - const Row( - children: [ - SocialProviderBox(provider: SocialProvider.google), - SizedBox( - width: 12, - ), - SocialProviderBox(provider: SocialProvider.github), - SizedBox( - width: 12, - ), - SocialProviderBox(provider: SocialProvider.apple), - SizedBox( - width: 12, - ), - SocialProviderBox(provider: SocialProvider.linkedin) - ], - ), - const SizedBox( - height: 32, - ), - const Divider( - color: Color.fromRGBO(226, 232, 240, 1), thickness: 1), - const SizedBox( - height: 32, - ), - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const Text('Email'), - const SizedBox( - height: 4, - ), - TextFormField( - enabled: !state.isLoading, - controller: emailController, - onChanged: (String value) => context - .read() - .add(ChangeEmail(value: value)), - decoration: InputDecoration( - border: const OutlineInputBorder(), - hintText: 'Enter your email', - errorText: state.email.errorMessage, - errorMaxLines: 3), - ), - ], - ), - const SizedBox( - height: 20, - ), - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const Text('Password'), - const SizedBox( - height: 4, - ), - TextFormField( - enabled: !state.isLoading, - controller: passwordController, - onChanged: (String value) => context - .read() - .add(ChangePassword(value: value)), - obscureText: state.isPasswordHidden, - decoration: InputDecoration( - border: const OutlineInputBorder(), - hintText: 'Enter a password', - // change password visibility - suffixIcon: GestureDetector( - onTap: () => context.read().add( - ChangePasswordVisibility( - value: !state.isPasswordHidden)), - child: ImageIcon( - state.isPasswordHidden - ? const AssetImage('assets/icons/eye.png') - : const AssetImage('assets/icons/eye-off.png'), - size: 16, - ), - ), - errorText: state.password.errorMessage, - errorMaxLines: 3), - ), - ], - ), - const SizedBox( - height: 32, - ), - // show general error message if it exists - if (state.errorMessage != null) + // get default nodes from all nodes + final defaultNodes = + nodes.where((node) => node.group == UiNodeGroupEnum.default_).toList(); + + // get password nodes from all nodes + final passwordNodes = + nodes.where((node) => node.group == UiNodeGroupEnum.password).toList(); + + // get lookup secret nodes from all nodes + final lookupSecretNodes = nodes + .where((node) => node.group == UiNodeGroupEnum.lookupSecret) + .toList(); + + // get totp nodes from all nodes + final totpNodes = + nodes.where((node) => node.group == UiNodeGroupEnum.totp).toList(); + + // get oidc nodes from all nodes + final oidcNodes = + nodes.where((node) => node.group == UiNodeGroupEnum.oidc).toList(); + + return Stack(children: [ + Padding( + padding: const EdgeInsets.symmetric(horizontal: 32), + child: SingleChildScrollView( + // do not show scrolling indicator + physics: const BouncingScrollPhysics(), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ Padding( - padding: const EdgeInsets.only(bottom: 15.0), - child: Text( - state.errorMessage!, - style: const TextStyle(color: Colors.red), + padding: EdgeInsets.only( + //status bar height + padding + top: MediaQuery.of(context).viewPadding.top + 48), + child: Image.asset( + 'assets/images/ory_logo.png', + width: 70, ), ), - // show loading indicator when state is in a loading mode - if (state.isLoading) - const Padding( - padding: EdgeInsets.all(15.0), - child: Center( - child: SizedBox( - width: 30, - height: 30, - child: CircularProgressIndicator())), + const SizedBox( + height: 32, + ), + const Text('Sign up', + style: TextStyle( + fontWeight: FontWeight.w600, height: 1.5, fontSize: 18)), + if (oidcNodes.isNotEmpty) + Padding( + padding: const EdgeInsets.only(top: 32.0), + child: Column( + mainAxisSize: MainAxisSize.max, + children: oidcNodes + .map((node) => SocialProviderInput(node: node)) + .toList()), + ), + if (defaultNodes.isNotEmpty) + buildGroup(context, UiNodeGroupEnum.default_, + defaultNodes, _onInputChange, _onInputSubmit), + if (passwordNodes.isNotEmpty) + buildGroup(context, UiNodeGroupEnum.password, + passwordNodes, _onInputChange, _onInputSubmit), + if (lookupSecretNodes.isNotEmpty) + buildGroup( + context, + UiNodeGroupEnum.lookupSecret, + lookupSecretNodes, + _onInputChange, + _onInputSubmit), + if (totpNodes.isNotEmpty) + buildGroup(context, UiNodeGroupEnum.totp, + totpNodes, _onInputChange, _onInputSubmit), + const SizedBox( + height: 32, ), - SizedBox( - width: double.infinity, - child: FilledButton( - // disable button when state is loading - onPressed: state.isLoading - ? null - : () { - context.read().add( - RegisterWithEmailAndPassword( - flowId: state.flowId!, - email: state.email.value, - password: state.password.value)); - }, - child: const Text('Sign up')), - ), - const SizedBox( - height: 20, - ), - Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - const Text('Already have an account?'), - TextButton( - // disable button when state is loading - onPressed: state.isLoading - ? null - : () => Navigator.of(context).pushReplacement( - MaterialPageRoute( - builder: (context) => const LoginPage())), - child: const Text('Sign in')) - ], - ) - ], + if (state.registrationFlow?.ui.messages != null) + for (var message in state.registrationFlow!.ui.messages!) + Text( + message.text, + style: TextStyle(color: getMessageColor(message.type)), + ), + Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + const Text('Already have an account?'), + TextButton( + // disable button when state is loading + onPressed: state.isLoading + ? null + : () => Navigator.of(context) + .pushReplacement(MaterialPageRoute( + builder: (context) => const LoginPage( + aal: 'aal1', + ))), + child: const Text('Sign in')) + ], + ) + ], + ), ), ), - ); + // build progress indicator when state is loading + BlocSelector( + bloc: (context).read(), + selector: (RegistrationState state) => state.isLoading, + builder: (BuildContext context, bool booleanState) { + if (booleanState) { + return const Opacity( + opacity: 0.8, + child: ModalBarrier(dismissible: false, color: Colors.white30), + ); + } else { + return Container(); + } + }), + BlocSelector( + bloc: (context).read(), + selector: (RegistrationState state) => state.isLoading, + builder: (BuildContext context, bool booleanState) { + if (booleanState) { + return const Center( + child: CircularProgressIndicator(), + ); + } else { + return Container(); + } + }) + ]); + } + + _onInputChange(BuildContext context, String value, String name) { + context + .read() + .add(ChangeNodeValue(value: value, name: name)); + } + + _onInputSubmit( + BuildContext context, UiNodeGroupEnum group, String name, String value) { + context + .read() + .add(UpdateRegistrationFlow(group: group, name: name, value: value)); } } diff --git a/flutter-ory-network/lib/repositories/auth.dart b/flutter-ory-network/lib/repositories/auth.dart index 85e03ad1..8c92006e 100644 --- a/flutter-ory-network/lib/repositories/auth.dart +++ b/flutter-ory-network/lib/repositories/auth.dart @@ -1,11 +1,16 @@ // Copyright © 2023 Ory Corp // SPDX-License-Identifier: Apache-2.0 +import 'package:built_collection/built_collection.dart'; +import 'package:built_value/json_object.dart'; +import 'package:deep_collection/deep_collection.dart'; +import 'package:one_of/one_of.dart'; import 'package:ory_client/ory_client.dart'; +import 'package:collection/collection.dart'; import '../services/auth.dart'; -enum AuthStatus { uninitialized, authenticated, unauthenticated } +enum AuthStatus { uninitialized, authenticated, unauthenticated, aal2Requested } class AuthRepository { final AuthService service; @@ -17,33 +22,187 @@ class AuthRepository { return session; } - Future createLoginFlow() async { - final flowId = await service.createLoginFlow(); - return flowId; + Future createLoginFlow({required String aal}) async { + final flow = await service.createLoginFlow(aal: aal); + return flow; } - Future createRegistrationFlow() async { - final flowId = await service.createRegistrationFlow(); - return flowId; + Future createRegistrationFlow() async { + final flow = await service.createRegistrationFlow(); + return flow; } - Future loginWithEmailAndPassword( - {required String flowId, - required String email, - required String password}) async { - await service.loginWithEmailAndPassword( - flowId: flowId, email: email, password: password); + Future getLoginFlow({required String flowId}) async { + final flow = await service.getLoginFlow(flowId: flowId); + return flow; } - Future registerWithEmailAndPassword( - {required String flowId, - required String email, - required String password}) async { - await service.registerWithEmailAndPassword( - flowId: flowId, email: email, password: password); + Future getRegistrationFlow({required String flowId}) async { + final flow = await service.getRegistrationFlow(flowId: flowId); + return flow; } Future logout() async { await service.logout(); } + + Future updateRegistrationFlow( + {required String flowId, + required UiNodeGroupEnum group, + required String name, + required String value, + required List nodes}) async { + // create request body + final body = _createRequestBody( + group: group, name: name, value: value, nodes: nodes); + // submit registration + final registration = await service.updateRegistrationFlow( + flowId: flowId, group: group, value: body); + return registration; + } + + Future updateLoginFlow( + {required String flowId, + required UiNodeGroupEnum group, + required String name, + required String value, + required List nodes}) async { + // create request body + final body = _createRequestBody( + group: group, name: name, value: value, nodes: nodes); + // submit login + print(body); + final login = await service.updateLoginFlow( + flowId: flowId, group: group, value: body); + return login; + } + + Map _createRequestBody( + {required UiNodeGroupEnum group, + required String name, + required String value, + required List nodes}) { + // if name of submitted node is method, find all nodes that belong to the group + if (name == 'method') { + // get input nodes of the same group + final inputNodes = nodes.where((p0) { + if (p0.attributes.oneOf.isType(UiNodeInputAttributes)) { + final attributes = p0.attributes.oneOf.value as UiNodeInputAttributes; + // if group is password, find identifier + if (group == UiNodeGroupEnum.password && + p0.group == UiNodeGroupEnum.default_ && + attributes.name == 'identifier') { + return true; + } + return p0.group == group && + attributes.type != UiNodeInputAttributesTypeEnum.button && + attributes.type != UiNodeInputAttributesTypeEnum.submit; + } else { + return false; + } + }); + // create maps from attribute names and their values + final nestedMaps = inputNodes.map((e) { + final attributes = e.attributes.oneOf.value as UiNodeInputAttributes; + + return generateNestedMap( + attributes.name, attributes.value?.asString ?? ''); + }).toList(); + + // merge nested maps into one + final mergedMap = + nestedMaps.reduce((value, element) => value.deepMerge(element)); + + return mergedMap; + } else { + return {name: value}; + } + } + + LoginFlow resetButtonValues({required LoginFlow loginFlow}) { + final submitInputNodes = loginFlow.ui.nodes.where((p0) { + if (p0.attributes.oneOf.isType(UiNodeInputAttributes)) { + final attributes = p0.attributes.oneOf.value as UiNodeInputAttributes; + final type = attributes.type; + if ((type == UiNodeInputAttributesTypeEnum.button || + type == UiNodeInputAttributesTypeEnum.submit) && + attributes.value?.asString == 'true') { + return true; + } + } + return false; + }); + for (var node in submitInputNodes) { + final attributes = node.attributes.oneOf.value as UiNodeInputAttributes; + // reset button value to false + // to prevent submitting values that were not selected + loginFlow = changeLoginNodeValue( + settings: loginFlow, name: attributes.name, value: 'false'); + } + return loginFlow; + } + + RegistrationFlow changeRegistrationNodeValue( + {required RegistrationFlow settings, + required String name, + required String value}) { + // update node value + final updatedNodes = + updateNodes(nodes: settings.ui.nodes, name: name, value: value); + // update settings' node + final newFlow = + settings.rebuild((p0) => p0..ui.nodes.replace(updatedNodes)); + return newFlow; + } + + LoginFlow changeLoginNodeValue( + {required LoginFlow settings, + required String name, + required String value}) { + // update node value + final updatedNodes = + updateNodes(nodes: settings.ui.nodes, name: name, value: value); + // update settings' node + final newFlow = + settings.rebuild((p0) => p0..ui.nodes.replace(updatedNodes)); + return newFlow; + } + + BuiltList updateNodes( + {required BuiltList nodes, + required String name, + required String value}) { + // get edited node + final node = nodes.firstWhereOrNull((element) { + if (element.attributes.oneOf.isType(UiNodeInputAttributes)) { + return (element.attributes.oneOf.value as UiNodeInputAttributes).name == + name; + } else { + return false; + } + }); + + // udate value of edited node + final updatedNode = node?.rebuild((p0) => p0 + ..attributes.update((b) { + final oldValue = b.oneOf?.value as UiNodeInputAttributes; + final newValue = oldValue.rebuild((p0) => p0.value = JsonObject(value)); + b.oneOf = OneOf1(value: newValue); + })); + // get index of to be updated node + final nodeIndex = nodes.indexOf(node!); + // update list of nodes to iclude updated node + return nodes.rebuild((p0) => p0 + ..removeAt(nodeIndex) + ..insert(nodeIndex, updatedNode!)); + } + + Map generateNestedMap(String path, String value) { + var steps = path.split('.'); + Object? result = value; + for (var step in steps.reversed) { + result = {step: result}; + } + return result as Map; + } } diff --git a/flutter-ory-network/lib/services/auth.dart b/flutter-ory-network/lib/services/auth.dart index 2a65bb4e..43cffef2 100644 --- a/flutter-ory-network/lib/services/auth.dart +++ b/flutter-ory-network/lib/services/auth.dart @@ -6,9 +6,7 @@ import 'package:dio/dio.dart'; import 'package:one_of/one_of.dart'; import 'package:ory_client/ory_client.dart'; -import '../entities/form_node.dart'; import 'exceptions.dart'; -import '../entities/message.dart'; import 'storage.dart'; class AuthService { @@ -21,6 +19,7 @@ class AuthService { try { final token = await storage.getToken(); final response = await _ory.toSession(xSessionToken: token); + if (response.data != null) { // return session return response.data!; @@ -31,6 +30,12 @@ class AuthService { if (e.response?.statusCode == 401) { await storage.deleteToken(); throw const CustomException.unauthorized(); + } else if (e.response?.statusCode == 403) { + if (e.response?.data['error']['id'] == 'session_aal2_required') { + throw const CustomException.twoFactorAuthRequired(); + } else { + throw _handleUnknownException(e.response?.data); + } } else { throw _handleUnknownException(e.response?.data); } @@ -38,12 +43,14 @@ class AuthService { } /// Create login flow - Future createLoginFlow() async { + Future createLoginFlow({required String aal}) async { try { - final response = await _ory.createNativeLoginFlow(); + final token = await storage.getToken(); + final response = + await _ory.createNativeLoginFlow(aal: aal, xSessionToken: token); if (response.data != null) { // return flow id - return response.data!.id; + return response.data!; } else { throw const CustomException.unknown(); } @@ -53,12 +60,12 @@ class AuthService { } /// Create registration flow - Future createRegistrationFlow() async { + Future createRegistrationFlow() async { try { final response = await _ory.createNativeRegistrationFlow(); if (response.data != null) { // return flow id - return response.data!.id; + return response.data!; } else { throw const CustomException.unknown(); } @@ -67,27 +74,53 @@ class AuthService { } } - /// Log in with [email] and [password] using login flow with [flowId] - Future loginWithEmailAndPassword( + /// Update login flow with [flowId] for [group] with [value] + Future updateLoginFlow( {required String flowId, - required String email, - required String password}) async { + required UiNodeGroupEnum group, + required Map value}) async { try { - final UpdateLoginFlowWithPasswordMethod loginFLowBuilder = - UpdateLoginFlowWithPasswordMethod((b) => b - ..identifier = email - ..password = password - ..method = 'password'); + final token = await storage.getToken(); + final OneOf oneOf; + + // create update body depending on method + switch (group) { + case UiNodeGroupEnum.password: + oneOf = OneOf.fromValue1( + value: UpdateLoginFlowWithPasswordMethod((b) => b + ..method = group.name + ..identifier = value['identifier'] + ..password = value['password'])); + case UiNodeGroupEnum.lookupSecret: + oneOf = OneOf.fromValue1( + value: UpdateLoginFlowWithLookupSecretMethod((b) => b + ..method = group.name + ..lookupSecret = value['lookup_secret'])); + case UiNodeGroupEnum.totp: + oneOf = OneOf.fromValue1( + value: UpdateLoginFlowWithTotpMethod((b) => b + ..method = group.name + ..totpCode = value['totp_code'])); + + // if method is not implemented, throw exception + default: + throw const CustomException.unknown(); + } final response = await _ory.updateLoginFlow( flow: flowId, - updateLoginFlowBody: UpdateLoginFlowBody( - (b) => b..oneOf = OneOf.fromValue1(value: loginFLowBuilder))); + xSessionToken: token, + updateLoginFlowBody: UpdateLoginFlowBody((b) => b..oneOf = oneOf)); if (response.data?.session != null) { // save session token after successful login await storage.persistToken(response.data!.sessionToken!); - return; + if (response.data!.session.identity != null) { + return response.data!; + } else { + throw CustomException.twoFactorAuthRequired( + session: response.data!.session); + } } else { throw const CustomException.unknown(); } @@ -96,39 +129,96 @@ class AuthService { await storage.deleteToken(); throw const CustomException.unauthorized(); } else if (e.response?.statusCode == 400) { - final messages = _checkFormForErrors(e.response?.data); - throw CustomException.badRequest(messages: messages); + final loginFlow = standardSerializers.deserializeWith( + LoginFlow.serializer, e.response?.data); + if (loginFlow != null) { + throw CustomException.badRequest(flow: loginFlow); + } else { + throw const CustomException.unknown(); + } } else if (e.response?.statusCode == 410) { - // login flow expired, use new flow id and add error message + // settings flow expired, use new flow id and add error message throw CustomException.flowExpired( - flowId: e.response?.data['use_flow_id'], - message: 'Login flow has expired. Please enter credentials again.'); + flowId: e.response?.data['use_flow_id']); + } else { + throw _handleUnknownException(e.response?.data); + } + } + } + + /// Get login flow with [flowId] + Future getLoginFlow({required String flowId}) async { + try { + final response = await _ory.getLoginFlow(id: flowId); + + if (response.data != null) { + // return flow + return response.data!; + } else { + throw const CustomException.unknown(); + } + } on DioException catch (e) { + if (e.response?.statusCode == 401) { + await storage.deleteToken(); + throw const CustomException.unauthorized(); } else { throw _handleUnknownException(e.response?.data); } } } - /// Register with [email] and [password] using registration flow with [flowId] - Future registerWithEmailAndPassword( + /// Get registration flow with [flowId] + Future getRegistrationFlow({required String flowId}) async { + try { + final response = await _ory.getRegistrationFlow(id: flowId); + + if (response.data != null) { + // return flow + return response.data!; + } else { + throw const CustomException.unknown(); + } + } on DioException catch (e) { + if (e.response?.statusCode == 401) { + await storage.deleteToken(); + throw const CustomException.unauthorized(); + } else { + throw _handleUnknownException(e.response?.data); + } + } + } + + /// Update registration flow with [flowId] for [group] with [value] + Future updateRegistrationFlow( {required String flowId, - required String email, - required String password}) async { + required UiNodeGroupEnum group, + required Map value}) async { try { - final UpdateRegistrationFlowWithPasswordMethod registrationFLow = - UpdateRegistrationFlowWithPasswordMethod((b) => b - ..traits = JsonObject({'email': email}) - ..password = password - ..method = 'password'); + final OneOf oneOf; + + // create update body depending on method + switch (group) { + case UiNodeGroupEnum.password: + oneOf = OneOf.fromValue1( + value: UpdateRegistrationFlowWithPasswordMethod((b) => b + ..method = group.name + ..traits = JsonObject(value['traits']) + ..password = value['password'])); + + // if method is not implemented, throw exception + default: + throw const CustomException.unknown(); + } final response = await _ory.updateRegistrationFlow( flow: flowId, - updateRegistrationFlowBody: UpdateRegistrationFlowBody( - (b) => b..oneOf = OneOf.fromValue1(value: registrationFLow))); - if (response.data?.sessionToken != null) { + updateRegistrationFlowBody: + UpdateRegistrationFlowBody((b) => b..oneOf = oneOf)); + + if (response.data?.session != null) { // save session token after successful login await storage.persistToken(response.data!.sessionToken!); - return; + return response.data!; } else { throw const CustomException.unknown(); } @@ -137,14 +227,18 @@ class AuthService { await storage.deleteToken(); throw const CustomException.unauthorized(); } else if (e.response?.statusCode == 400) { - final messages = _checkFormForErrors(e.response?.data); - throw CustomException.badRequest(messages: messages); + final registrationFlow = standardSerializers.deserializeWith( + RegistrationFlow.serializer, e.response?.data); + if (registrationFlow != null) { + throw CustomException.badRequest( + flow: registrationFlow); + } else { + throw const CustomException.unknown(); + } } else if (e.response?.statusCode == 410) { - // registration flow expired, use new flow id and add error message + // settings flow expired, use new flow id and add error message throw CustomException.flowExpired( - flowId: e.response?.data['use_flow_id'], - message: - 'Registration flow has expired. Please enter credentials again.'); + flowId: e.response?.data['use_flow_id']); } else { throw _handleUnknownException(e.response?.data); } @@ -173,39 +267,6 @@ class AuthService { } } - /// Search for error messages and their context in [response] - List _checkFormForErrors(Map response) { - final ui = Map.from(response['ui']); - final nodeList = ui['nodes'] as List; - - // parse ui nodes - final nodes = nodeList.map((e) => FormNode.fromJson(e)).toList(); - - // get only nodes that have messages - final nonEmptyNodes = - nodes.where((element) => element.messages.isNotEmpty).toList(); - - // get node messages - final nodeMessages = nonEmptyNodes - .map((node) => node.messages - .map((msg) => msg.copyWith(attr: node.attributes.name)) - .toList()) - .toList(); - - // get general message if it exists - if (ui['messages'] != null) { - final messageList = ui['messages'] as List; - final messages = - messageList.map((e) => NodeMessage.fromJson(e)).toList(); - nodeMessages.add(messages); - } - // flatten message lists - final flattedNodeMessages = - nodeMessages.expand((element) => element).toList(); - - return flattedNodeMessages; - } - CustomException _handleUnknownException(Map? response) { // use error message if response contains it, otherwise use default value if (response != null && response.containsKey('error')) { diff --git a/flutter-ory-network/lib/services/exceptions.dart b/flutter-ory-network/lib/services/exceptions.dart index 8f058d12..677d5b98 100644 --- a/flutter-ory-network/lib/services/exceptions.dart +++ b/flutter-ory-network/lib/services/exceptions.dart @@ -3,23 +3,20 @@ import 'package:flutter/foundation.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; - -import '../entities/message.dart'; +import 'package:ory_client/ory_client.dart'; part 'exceptions.freezed.dart'; @freezed -sealed class CustomException with _$CustomException { +sealed class CustomException with _$CustomException { const CustomException._(); - const factory CustomException.badRequest( - {List? messages, - @Default(400) int statusCode}) = BadRequestException; - const factory CustomException.unauthorized({@Default(401) int statusCode}) = - UnauthorizedException; + const factory CustomException.badRequest({required T flow}) = + BadRequestException; + const factory CustomException.unauthorized() = UnauthorizedException; const factory CustomException.flowExpired( - {@Default(410) int statusCode, - required String flowId, - String? message}) = FlowExpiredException; + {required String flowId, String? message}) = FlowExpiredException; + const factory CustomException.twoFactorAuthRequired({Session? session}) = + TwoFactorAuthRequiredException; const factory CustomException.unknown( {@Default('An error occured. Please try again later.') String? message}) = UnknownException; diff --git a/flutter-ory-network/lib/services/exceptions.freezed.dart b/flutter-ory-network/lib/services/exceptions.freezed.dart index 08979de0..01e7d71f 100644 --- a/flutter-ory-network/lib/services/exceptions.freezed.dart +++ b/flutter-ory-network/lib/services/exceptions.freezed.dart @@ -1,6 +1,3 @@ -// Copyright © 2023 Ory Corp -// SPDX-License-Identifier: Apache-2.0 - // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint @@ -18,73 +15,78 @@ final _privateConstructorUsedError = UnsupportedError( 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); /// @nodoc -mixin _$CustomException { +mixin _$CustomException { @optionalTypeArgs TResult when({ - required TResult Function(List? messages, int statusCode) - badRequest, - required TResult Function(int statusCode) unauthorized, - required TResult Function(int statusCode, String flowId, String? message) - flowExpired, + required TResult Function(T flow) badRequest, + required TResult Function() unauthorized, + required TResult Function(String flowId, String? message) flowExpired, + required TResult Function(Session? session) twoFactorAuthRequired, required TResult Function(String? message) unknown, }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult? whenOrNull({ - TResult? Function(List? messages, int statusCode)? badRequest, - TResult? Function(int statusCode)? unauthorized, - TResult? Function(int statusCode, String flowId, String? message)? - flowExpired, + TResult? Function(T flow)? badRequest, + TResult? Function()? unauthorized, + TResult? Function(String flowId, String? message)? flowExpired, + TResult? Function(Session? session)? twoFactorAuthRequired, TResult? Function(String? message)? unknown, }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult maybeWhen({ - TResult Function(List? messages, int statusCode)? badRequest, - TResult Function(int statusCode)? unauthorized, - TResult Function(int statusCode, String flowId, String? message)? - flowExpired, + TResult Function(T flow)? badRequest, + TResult Function()? unauthorized, + TResult Function(String flowId, String? message)? flowExpired, + TResult Function(Session? session)? twoFactorAuthRequired, TResult Function(String? message)? unknown, required TResult orElse(), }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult map({ - required TResult Function(BadRequestException value) badRequest, - required TResult Function(UnauthorizedException value) unauthorized, - required TResult Function(FlowExpiredException value) flowExpired, - required TResult Function(UnknownException value) unknown, + required TResult Function(BadRequestException value) badRequest, + required TResult Function(UnauthorizedException value) unauthorized, + required TResult Function(FlowExpiredException value) flowExpired, + required TResult Function(TwoFactorAuthRequiredException value) + twoFactorAuthRequired, + required TResult Function(UnknownException value) unknown, }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult? mapOrNull({ - TResult? Function(BadRequestException value)? badRequest, - TResult? Function(UnauthorizedException value)? unauthorized, - TResult? Function(FlowExpiredException value)? flowExpired, - TResult? Function(UnknownException value)? unknown, + TResult? Function(BadRequestException value)? badRequest, + TResult? Function(UnauthorizedException value)? unauthorized, + TResult? Function(FlowExpiredException value)? flowExpired, + TResult? Function(TwoFactorAuthRequiredException value)? + twoFactorAuthRequired, + TResult? Function(UnknownException value)? unknown, }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult maybeMap({ - TResult Function(BadRequestException value)? badRequest, - TResult Function(UnauthorizedException value)? unauthorized, - TResult Function(FlowExpiredException value)? flowExpired, - TResult Function(UnknownException value)? unknown, + TResult Function(BadRequestException value)? badRequest, + TResult Function(UnauthorizedException value)? unauthorized, + TResult Function(FlowExpiredException value)? flowExpired, + TResult Function(TwoFactorAuthRequiredException value)? + twoFactorAuthRequired, + TResult Function(UnknownException value)? unknown, required TResult orElse(), }) => throw _privateConstructorUsedError; } /// @nodoc -abstract class $CustomExceptionCopyWith<$Res> { +abstract class $CustomExceptionCopyWith { factory $CustomExceptionCopyWith( - CustomException value, $Res Function(CustomException) then) = - _$CustomExceptionCopyWithImpl<$Res, CustomException>; + CustomException value, $Res Function(CustomException) then) = + _$CustomExceptionCopyWithImpl>; } /// @nodoc -class _$CustomExceptionCopyWithImpl<$Res, $Val extends CustomException> - implements $CustomExceptionCopyWith<$Res> { +class _$CustomExceptionCopyWithImpl> + implements $CustomExceptionCopyWith { _$CustomExceptionCopyWithImpl(this._value, this._then); // ignore: unused_field @@ -94,136 +96,113 @@ class _$CustomExceptionCopyWithImpl<$Res, $Val extends CustomException> } /// @nodoc -abstract class _$$BadRequestExceptionCopyWith<$Res> { - factory _$$BadRequestExceptionCopyWith(_$BadRequestException value, - $Res Function(_$BadRequestException) then) = - __$$BadRequestExceptionCopyWithImpl<$Res>; +abstract class _$$BadRequestExceptionCopyWith { + factory _$$BadRequestExceptionCopyWith(_$BadRequestException value, + $Res Function(_$BadRequestException) then) = + __$$BadRequestExceptionCopyWithImpl; @useResult - $Res call({List? messages, int statusCode}); + $Res call({T flow}); } /// @nodoc -class __$$BadRequestExceptionCopyWithImpl<$Res> - extends _$CustomExceptionCopyWithImpl<$Res, _$BadRequestException> - implements _$$BadRequestExceptionCopyWith<$Res> { - __$$BadRequestExceptionCopyWithImpl( - _$BadRequestException _value, $Res Function(_$BadRequestException) _then) +class __$$BadRequestExceptionCopyWithImpl + extends _$CustomExceptionCopyWithImpl> + implements _$$BadRequestExceptionCopyWith { + __$$BadRequestExceptionCopyWithImpl(_$BadRequestException _value, + $Res Function(_$BadRequestException) _then) : super(_value, _then); @pragma('vm:prefer-inline') @override $Res call({ - Object? messages = freezed, - Object? statusCode = null, - }) { - return _then(_$BadRequestException( - messages: freezed == messages - ? _value._messages - : messages // ignore: cast_nullable_to_non_nullable - as List?, - statusCode: null == statusCode - ? _value.statusCode - : statusCode // ignore: cast_nullable_to_non_nullable - as int, + Object? flow = freezed, + }) { + return _then(_$BadRequestException( + flow: freezed == flow + ? _value.flow + : flow // ignore: cast_nullable_to_non_nullable + as T, )); } } /// @nodoc -class _$BadRequestException extends BadRequestException +class _$BadRequestException extends BadRequestException with DiagnosticableTreeMixin { - const _$BadRequestException( - {final List? messages, this.statusCode = 400}) - : _messages = messages, - super._(); - - final List? _messages; - @override - List? get messages { - final value = _messages; - if (value == null) return null; - if (_messages is EqualUnmodifiableListView) return _messages; - // ignore: implicit_dynamic_type - return EqualUnmodifiableListView(value); - } + const _$BadRequestException({required this.flow}) : super._(); @override - @JsonKey() - final int statusCode; + final T flow; @override String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { - return 'CustomException.badRequest(messages: $messages, statusCode: $statusCode)'; + return 'CustomException<$T>.badRequest(flow: $flow)'; } @override void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); properties - ..add(DiagnosticsProperty('type', 'CustomException.badRequest')) - ..add(DiagnosticsProperty('messages', messages)) - ..add(DiagnosticsProperty('statusCode', statusCode)); + ..add(DiagnosticsProperty('type', 'CustomException<$T>.badRequest')) + ..add(DiagnosticsProperty('flow', flow)); } @override bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$BadRequestException && - const DeepCollectionEquality().equals(other._messages, _messages) && - (identical(other.statusCode, statusCode) || - other.statusCode == statusCode)); + other is _$BadRequestException && + const DeepCollectionEquality().equals(other.flow, flow)); } @override - int get hashCode => Object.hash( - runtimeType, const DeepCollectionEquality().hash(_messages), statusCode); + int get hashCode => + Object.hash(runtimeType, const DeepCollectionEquality().hash(flow)); @JsonKey(ignore: true) @override @pragma('vm:prefer-inline') - _$$BadRequestExceptionCopyWith<_$BadRequestException> get copyWith => - __$$BadRequestExceptionCopyWithImpl<_$BadRequestException>( + _$$BadRequestExceptionCopyWith> get copyWith => + __$$BadRequestExceptionCopyWithImpl>( this, _$identity); @override @optionalTypeArgs TResult when({ - required TResult Function(List? messages, int statusCode) - badRequest, - required TResult Function(int statusCode) unauthorized, - required TResult Function(int statusCode, String flowId, String? message) - flowExpired, + required TResult Function(T flow) badRequest, + required TResult Function() unauthorized, + required TResult Function(String flowId, String? message) flowExpired, + required TResult Function(Session? session) twoFactorAuthRequired, required TResult Function(String? message) unknown, }) { - return badRequest(messages, statusCode); + return badRequest(flow); } @override @optionalTypeArgs TResult? whenOrNull({ - TResult? Function(List? messages, int statusCode)? badRequest, - TResult? Function(int statusCode)? unauthorized, - TResult? Function(int statusCode, String flowId, String? message)? - flowExpired, + TResult? Function(T flow)? badRequest, + TResult? Function()? unauthorized, + TResult? Function(String flowId, String? message)? flowExpired, + TResult? Function(Session? session)? twoFactorAuthRequired, TResult? Function(String? message)? unknown, }) { - return badRequest?.call(messages, statusCode); + return badRequest?.call(flow); } @override @optionalTypeArgs TResult maybeWhen({ - TResult Function(List? messages, int statusCode)? badRequest, - TResult Function(int statusCode)? unauthorized, - TResult Function(int statusCode, String flowId, String? message)? - flowExpired, + TResult Function(T flow)? badRequest, + TResult Function()? unauthorized, + TResult Function(String flowId, String? message)? flowExpired, + TResult Function(Session? session)? twoFactorAuthRequired, TResult Function(String? message)? unknown, required TResult orElse(), }) { if (badRequest != null) { - return badRequest(messages, statusCode); + return badRequest(flow); } return orElse(); } @@ -231,10 +210,12 @@ class _$BadRequestException extends BadRequestException @override @optionalTypeArgs TResult map({ - required TResult Function(BadRequestException value) badRequest, - required TResult Function(UnauthorizedException value) unauthorized, - required TResult Function(FlowExpiredException value) flowExpired, - required TResult Function(UnknownException value) unknown, + required TResult Function(BadRequestException value) badRequest, + required TResult Function(UnauthorizedException value) unauthorized, + required TResult Function(FlowExpiredException value) flowExpired, + required TResult Function(TwoFactorAuthRequiredException value) + twoFactorAuthRequired, + required TResult Function(UnknownException value) unknown, }) { return badRequest(this); } @@ -242,10 +223,12 @@ class _$BadRequestException extends BadRequestException @override @optionalTypeArgs TResult? mapOrNull({ - TResult? Function(BadRequestException value)? badRequest, - TResult? Function(UnauthorizedException value)? unauthorized, - TResult? Function(FlowExpiredException value)? flowExpired, - TResult? Function(UnknownException value)? unknown, + TResult? Function(BadRequestException value)? badRequest, + TResult? Function(UnauthorizedException value)? unauthorized, + TResult? Function(FlowExpiredException value)? flowExpired, + TResult? Function(TwoFactorAuthRequiredException value)? + twoFactorAuthRequired, + TResult? Function(UnknownException value)? unknown, }) { return badRequest?.call(this); } @@ -253,10 +236,12 @@ class _$BadRequestException extends BadRequestException @override @optionalTypeArgs TResult maybeMap({ - TResult Function(BadRequestException value)? badRequest, - TResult Function(UnauthorizedException value)? unauthorized, - TResult Function(FlowExpiredException value)? flowExpired, - TResult Function(UnknownException value)? unknown, + TResult Function(BadRequestException value)? badRequest, + TResult Function(UnauthorizedException value)? unauthorized, + TResult Function(FlowExpiredException value)? flowExpired, + TResult Function(TwoFactorAuthRequiredException value)? + twoFactorAuthRequired, + TResult Function(UnknownException value)? unknown, required TResult orElse(), }) { if (badRequest != null) { @@ -266,129 +251,97 @@ class _$BadRequestException extends BadRequestException } } -abstract class BadRequestException extends CustomException { - const factory BadRequestException( - {final List? messages, - final int statusCode}) = _$BadRequestException; +abstract class BadRequestException extends CustomException { + const factory BadRequestException({required final T flow}) = + _$BadRequestException; const BadRequestException._() : super._(); - List? get messages; - int get statusCode; + T get flow; @JsonKey(ignore: true) - _$$BadRequestExceptionCopyWith<_$BadRequestException> get copyWith => + _$$BadRequestExceptionCopyWith> get copyWith => throw _privateConstructorUsedError; } /// @nodoc -abstract class _$$UnauthorizedExceptionCopyWith<$Res> { - factory _$$UnauthorizedExceptionCopyWith(_$UnauthorizedException value, - $Res Function(_$UnauthorizedException) then) = - __$$UnauthorizedExceptionCopyWithImpl<$Res>; - @useResult - $Res call({int statusCode}); +abstract class _$$UnauthorizedExceptionCopyWith { + factory _$$UnauthorizedExceptionCopyWith(_$UnauthorizedException value, + $Res Function(_$UnauthorizedException) then) = + __$$UnauthorizedExceptionCopyWithImpl; } /// @nodoc -class __$$UnauthorizedExceptionCopyWithImpl<$Res> - extends _$CustomExceptionCopyWithImpl<$Res, _$UnauthorizedException> - implements _$$UnauthorizedExceptionCopyWith<$Res> { - __$$UnauthorizedExceptionCopyWithImpl(_$UnauthorizedException _value, - $Res Function(_$UnauthorizedException) _then) +class __$$UnauthorizedExceptionCopyWithImpl + extends _$CustomExceptionCopyWithImpl> + implements _$$UnauthorizedExceptionCopyWith { + __$$UnauthorizedExceptionCopyWithImpl(_$UnauthorizedException _value, + $Res Function(_$UnauthorizedException) _then) : super(_value, _then); - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? statusCode = null, - }) { - return _then(_$UnauthorizedException( - statusCode: null == statusCode - ? _value.statusCode - : statusCode // ignore: cast_nullable_to_non_nullable - as int, - )); - } } /// @nodoc -class _$UnauthorizedException extends UnauthorizedException +class _$UnauthorizedException extends UnauthorizedException with DiagnosticableTreeMixin { - const _$UnauthorizedException({this.statusCode = 401}) : super._(); - - @override - @JsonKey() - final int statusCode; + const _$UnauthorizedException() : super._(); @override String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { - return 'CustomException.unauthorized(statusCode: $statusCode)'; + return 'CustomException<$T>.unauthorized()'; } @override void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); properties - ..add(DiagnosticsProperty('type', 'CustomException.unauthorized')) - ..add(DiagnosticsProperty('statusCode', statusCode)); + .add(DiagnosticsProperty('type', 'CustomException<$T>.unauthorized')); } @override bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$UnauthorizedException && - (identical(other.statusCode, statusCode) || - other.statusCode == statusCode)); + other is _$UnauthorizedException); } @override - int get hashCode => Object.hash(runtimeType, statusCode); - - @JsonKey(ignore: true) - @override - @pragma('vm:prefer-inline') - _$$UnauthorizedExceptionCopyWith<_$UnauthorizedException> get copyWith => - __$$UnauthorizedExceptionCopyWithImpl<_$UnauthorizedException>( - this, _$identity); + int get hashCode => runtimeType.hashCode; @override @optionalTypeArgs TResult when({ - required TResult Function(List? messages, int statusCode) - badRequest, - required TResult Function(int statusCode) unauthorized, - required TResult Function(int statusCode, String flowId, String? message) - flowExpired, + required TResult Function(T flow) badRequest, + required TResult Function() unauthorized, + required TResult Function(String flowId, String? message) flowExpired, + required TResult Function(Session? session) twoFactorAuthRequired, required TResult Function(String? message) unknown, }) { - return unauthorized(statusCode); + return unauthorized(); } @override @optionalTypeArgs TResult? whenOrNull({ - TResult? Function(List? messages, int statusCode)? badRequest, - TResult? Function(int statusCode)? unauthorized, - TResult? Function(int statusCode, String flowId, String? message)? - flowExpired, + TResult? Function(T flow)? badRequest, + TResult? Function()? unauthorized, + TResult? Function(String flowId, String? message)? flowExpired, + TResult? Function(Session? session)? twoFactorAuthRequired, TResult? Function(String? message)? unknown, }) { - return unauthorized?.call(statusCode); + return unauthorized?.call(); } @override @optionalTypeArgs TResult maybeWhen({ - TResult Function(List? messages, int statusCode)? badRequest, - TResult Function(int statusCode)? unauthorized, - TResult Function(int statusCode, String flowId, String? message)? - flowExpired, + TResult Function(T flow)? badRequest, + TResult Function()? unauthorized, + TResult Function(String flowId, String? message)? flowExpired, + TResult Function(Session? session)? twoFactorAuthRequired, TResult Function(String? message)? unknown, required TResult orElse(), }) { if (unauthorized != null) { - return unauthorized(statusCode); + return unauthorized(); } return orElse(); } @@ -396,10 +349,12 @@ class _$UnauthorizedException extends UnauthorizedException @override @optionalTypeArgs TResult map({ - required TResult Function(BadRequestException value) badRequest, - required TResult Function(UnauthorizedException value) unauthorized, - required TResult Function(FlowExpiredException value) flowExpired, - required TResult Function(UnknownException value) unknown, + required TResult Function(BadRequestException value) badRequest, + required TResult Function(UnauthorizedException value) unauthorized, + required TResult Function(FlowExpiredException value) flowExpired, + required TResult Function(TwoFactorAuthRequiredException value) + twoFactorAuthRequired, + required TResult Function(UnknownException value) unknown, }) { return unauthorized(this); } @@ -407,10 +362,12 @@ class _$UnauthorizedException extends UnauthorizedException @override @optionalTypeArgs TResult? mapOrNull({ - TResult? Function(BadRequestException value)? badRequest, - TResult? Function(UnauthorizedException value)? unauthorized, - TResult? Function(FlowExpiredException value)? flowExpired, - TResult? Function(UnknownException value)? unknown, + TResult? Function(BadRequestException value)? badRequest, + TResult? Function(UnauthorizedException value)? unauthorized, + TResult? Function(FlowExpiredException value)? flowExpired, + TResult? Function(TwoFactorAuthRequiredException value)? + twoFactorAuthRequired, + TResult? Function(UnknownException value)? unknown, }) { return unauthorized?.call(this); } @@ -418,10 +375,12 @@ class _$UnauthorizedException extends UnauthorizedException @override @optionalTypeArgs TResult maybeMap({ - TResult Function(BadRequestException value)? badRequest, - TResult Function(UnauthorizedException value)? unauthorized, - TResult Function(FlowExpiredException value)? flowExpired, - TResult Function(UnknownException value)? unknown, + TResult Function(BadRequestException value)? badRequest, + TResult Function(UnauthorizedException value)? unauthorized, + TResult Function(FlowExpiredException value)? flowExpired, + TResult Function(TwoFactorAuthRequiredException value)? + twoFactorAuthRequired, + TResult Function(UnknownException value)? unknown, required TResult orElse(), }) { if (unauthorized != null) { @@ -431,46 +390,35 @@ class _$UnauthorizedException extends UnauthorizedException } } -abstract class UnauthorizedException extends CustomException { - const factory UnauthorizedException({final int statusCode}) = - _$UnauthorizedException; +abstract class UnauthorizedException extends CustomException { + const factory UnauthorizedException() = _$UnauthorizedException; const UnauthorizedException._() : super._(); - - int get statusCode; - @JsonKey(ignore: true) - _$$UnauthorizedExceptionCopyWith<_$UnauthorizedException> get copyWith => - throw _privateConstructorUsedError; } /// @nodoc -abstract class _$$FlowExpiredExceptionCopyWith<$Res> { - factory _$$FlowExpiredExceptionCopyWith(_$FlowExpiredException value, - $Res Function(_$FlowExpiredException) then) = - __$$FlowExpiredExceptionCopyWithImpl<$Res>; +abstract class _$$FlowExpiredExceptionCopyWith { + factory _$$FlowExpiredExceptionCopyWith(_$FlowExpiredException value, + $Res Function(_$FlowExpiredException) then) = + __$$FlowExpiredExceptionCopyWithImpl; @useResult - $Res call({int statusCode, String flowId, String? message}); + $Res call({String flowId, String? message}); } /// @nodoc -class __$$FlowExpiredExceptionCopyWithImpl<$Res> - extends _$CustomExceptionCopyWithImpl<$Res, _$FlowExpiredException> - implements _$$FlowExpiredExceptionCopyWith<$Res> { - __$$FlowExpiredExceptionCopyWithImpl(_$FlowExpiredException _value, - $Res Function(_$FlowExpiredException) _then) +class __$$FlowExpiredExceptionCopyWithImpl + extends _$CustomExceptionCopyWithImpl> + implements _$$FlowExpiredExceptionCopyWith { + __$$FlowExpiredExceptionCopyWithImpl(_$FlowExpiredException _value, + $Res Function(_$FlowExpiredException) _then) : super(_value, _then); @pragma('vm:prefer-inline') @override $Res call({ - Object? statusCode = null, Object? flowId = null, Object? message = freezed, }) { - return _then(_$FlowExpiredException( - statusCode: null == statusCode - ? _value.statusCode - : statusCode // ignore: cast_nullable_to_non_nullable - as int, + return _then(_$FlowExpiredException( flowId: null == flowId ? _value.flowId : flowId // ignore: cast_nullable_to_non_nullable @@ -485,15 +433,11 @@ class __$$FlowExpiredExceptionCopyWithImpl<$Res> /// @nodoc -class _$FlowExpiredException extends FlowExpiredException +class _$FlowExpiredException extends FlowExpiredException with DiagnosticableTreeMixin { - const _$FlowExpiredException( - {this.statusCode = 410, required this.flowId, this.message}) + const _$FlowExpiredException({required this.flowId, this.message}) : super._(); - @override - @JsonKey() - final int statusCode; @override final String flowId; @override @@ -501,15 +445,14 @@ class _$FlowExpiredException extends FlowExpiredException @override String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { - return 'CustomException.flowExpired(statusCode: $statusCode, flowId: $flowId, message: $message)'; + return 'CustomException<$T>.flowExpired(flowId: $flowId, message: $message)'; } @override void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); properties - ..add(DiagnosticsProperty('type', 'CustomException.flowExpired')) - ..add(DiagnosticsProperty('statusCode', statusCode)) + ..add(DiagnosticsProperty('type', 'CustomException<$T>.flowExpired')) ..add(DiagnosticsProperty('flowId', flowId)) ..add(DiagnosticsProperty('message', message)); } @@ -518,60 +461,57 @@ class _$FlowExpiredException extends FlowExpiredException bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$FlowExpiredException && - (identical(other.statusCode, statusCode) || - other.statusCode == statusCode) && + other is _$FlowExpiredException && (identical(other.flowId, flowId) || other.flowId == flowId) && (identical(other.message, message) || other.message == message)); } @override - int get hashCode => Object.hash(runtimeType, statusCode, flowId, message); + int get hashCode => Object.hash(runtimeType, flowId, message); @JsonKey(ignore: true) @override @pragma('vm:prefer-inline') - _$$FlowExpiredExceptionCopyWith<_$FlowExpiredException> get copyWith => - __$$FlowExpiredExceptionCopyWithImpl<_$FlowExpiredException>( + _$$FlowExpiredExceptionCopyWith> get copyWith => + __$$FlowExpiredExceptionCopyWithImpl>( this, _$identity); @override @optionalTypeArgs TResult when({ - required TResult Function(List? messages, int statusCode) - badRequest, - required TResult Function(int statusCode) unauthorized, - required TResult Function(int statusCode, String flowId, String? message) - flowExpired, + required TResult Function(T flow) badRequest, + required TResult Function() unauthorized, + required TResult Function(String flowId, String? message) flowExpired, + required TResult Function(Session? session) twoFactorAuthRequired, required TResult Function(String? message) unknown, }) { - return flowExpired(statusCode, flowId, message); + return flowExpired(flowId, message); } @override @optionalTypeArgs TResult? whenOrNull({ - TResult? Function(List? messages, int statusCode)? badRequest, - TResult? Function(int statusCode)? unauthorized, - TResult? Function(int statusCode, String flowId, String? message)? - flowExpired, + TResult? Function(T flow)? badRequest, + TResult? Function()? unauthorized, + TResult? Function(String flowId, String? message)? flowExpired, + TResult? Function(Session? session)? twoFactorAuthRequired, TResult? Function(String? message)? unknown, }) { - return flowExpired?.call(statusCode, flowId, message); + return flowExpired?.call(flowId, message); } @override @optionalTypeArgs TResult maybeWhen({ - TResult Function(List? messages, int statusCode)? badRequest, - TResult Function(int statusCode)? unauthorized, - TResult Function(int statusCode, String flowId, String? message)? - flowExpired, + TResult Function(T flow)? badRequest, + TResult Function()? unauthorized, + TResult Function(String flowId, String? message)? flowExpired, + TResult Function(Session? session)? twoFactorAuthRequired, TResult Function(String? message)? unknown, required TResult orElse(), }) { if (flowExpired != null) { - return flowExpired(statusCode, flowId, message); + return flowExpired(flowId, message); } return orElse(); } @@ -579,10 +519,12 @@ class _$FlowExpiredException extends FlowExpiredException @override @optionalTypeArgs TResult map({ - required TResult Function(BadRequestException value) badRequest, - required TResult Function(UnauthorizedException value) unauthorized, - required TResult Function(FlowExpiredException value) flowExpired, - required TResult Function(UnknownException value) unknown, + required TResult Function(BadRequestException value) badRequest, + required TResult Function(UnauthorizedException value) unauthorized, + required TResult Function(FlowExpiredException value) flowExpired, + required TResult Function(TwoFactorAuthRequiredException value) + twoFactorAuthRequired, + required TResult Function(UnknownException value) unknown, }) { return flowExpired(this); } @@ -590,10 +532,12 @@ class _$FlowExpiredException extends FlowExpiredException @override @optionalTypeArgs TResult? mapOrNull({ - TResult? Function(BadRequestException value)? badRequest, - TResult? Function(UnauthorizedException value)? unauthorized, - TResult? Function(FlowExpiredException value)? flowExpired, - TResult? Function(UnknownException value)? unknown, + TResult? Function(BadRequestException value)? badRequest, + TResult? Function(UnauthorizedException value)? unauthorized, + TResult? Function(FlowExpiredException value)? flowExpired, + TResult? Function(TwoFactorAuthRequiredException value)? + twoFactorAuthRequired, + TResult? Function(UnknownException value)? unknown, }) { return flowExpired?.call(this); } @@ -601,10 +545,12 @@ class _$FlowExpiredException extends FlowExpiredException @override @optionalTypeArgs TResult maybeMap({ - TResult Function(BadRequestException value)? badRequest, - TResult Function(UnauthorizedException value)? unauthorized, - TResult Function(FlowExpiredException value)? flowExpired, - TResult Function(UnknownException value)? unknown, + TResult Function(BadRequestException value)? badRequest, + TResult Function(UnauthorizedException value)? unauthorized, + TResult Function(FlowExpiredException value)? flowExpired, + TResult Function(TwoFactorAuthRequiredException value)? + twoFactorAuthRequired, + TResult Function(UnknownException value)? unknown, required TResult orElse(), }) { if (flowExpired != null) { @@ -614,36 +560,206 @@ class _$FlowExpiredException extends FlowExpiredException } } -abstract class FlowExpiredException extends CustomException { +abstract class FlowExpiredException extends CustomException { const factory FlowExpiredException( - {final int statusCode, - required final String flowId, - final String? message}) = _$FlowExpiredException; + {required final String flowId, + final String? message}) = _$FlowExpiredException; const FlowExpiredException._() : super._(); - int get statusCode; String get flowId; String? get message; @JsonKey(ignore: true) - _$$FlowExpiredExceptionCopyWith<_$FlowExpiredException> get copyWith => + _$$FlowExpiredExceptionCopyWith> get copyWith => throw _privateConstructorUsedError; } /// @nodoc -abstract class _$$UnknownExceptionCopyWith<$Res> { - factory _$$UnknownExceptionCopyWith( - _$UnknownException value, $Res Function(_$UnknownException) then) = - __$$UnknownExceptionCopyWithImpl<$Res>; +abstract class _$$TwoFactorAuthRequiredExceptionCopyWith { + factory _$$TwoFactorAuthRequiredExceptionCopyWith( + _$TwoFactorAuthRequiredException value, + $Res Function(_$TwoFactorAuthRequiredException) then) = + __$$TwoFactorAuthRequiredExceptionCopyWithImpl; + @useResult + $Res call({Session? session}); +} + +/// @nodoc +class __$$TwoFactorAuthRequiredExceptionCopyWithImpl + extends _$CustomExceptionCopyWithImpl> + implements _$$TwoFactorAuthRequiredExceptionCopyWith { + __$$TwoFactorAuthRequiredExceptionCopyWithImpl( + _$TwoFactorAuthRequiredException _value, + $Res Function(_$TwoFactorAuthRequiredException) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? session = freezed, + }) { + return _then(_$TwoFactorAuthRequiredException( + session: freezed == session + ? _value.session + : session // ignore: cast_nullable_to_non_nullable + as Session?, + )); + } +} + +/// @nodoc + +class _$TwoFactorAuthRequiredException + extends TwoFactorAuthRequiredException with DiagnosticableTreeMixin { + const _$TwoFactorAuthRequiredException({this.session}) : super._(); + + @override + final Session? session; + + @override + String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { + return 'CustomException<$T>.twoFactorAuthRequired(session: $session)'; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties + ..add(DiagnosticsProperty( + 'type', 'CustomException<$T>.twoFactorAuthRequired')) + ..add(DiagnosticsProperty('session', session)); + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$TwoFactorAuthRequiredException && + (identical(other.session, session) || other.session == session)); + } + + @override + int get hashCode => Object.hash(runtimeType, session); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$TwoFactorAuthRequiredExceptionCopyWith> + get copyWith => __$$TwoFactorAuthRequiredExceptionCopyWithImpl>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(T flow) badRequest, + required TResult Function() unauthorized, + required TResult Function(String flowId, String? message) flowExpired, + required TResult Function(Session? session) twoFactorAuthRequired, + required TResult Function(String? message) unknown, + }) { + return twoFactorAuthRequired(session); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(T flow)? badRequest, + TResult? Function()? unauthorized, + TResult? Function(String flowId, String? message)? flowExpired, + TResult? Function(Session? session)? twoFactorAuthRequired, + TResult? Function(String? message)? unknown, + }) { + return twoFactorAuthRequired?.call(session); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(T flow)? badRequest, + TResult Function()? unauthorized, + TResult Function(String flowId, String? message)? flowExpired, + TResult Function(Session? session)? twoFactorAuthRequired, + TResult Function(String? message)? unknown, + required TResult orElse(), + }) { + if (twoFactorAuthRequired != null) { + return twoFactorAuthRequired(session); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(BadRequestException value) badRequest, + required TResult Function(UnauthorizedException value) unauthorized, + required TResult Function(FlowExpiredException value) flowExpired, + required TResult Function(TwoFactorAuthRequiredException value) + twoFactorAuthRequired, + required TResult Function(UnknownException value) unknown, + }) { + return twoFactorAuthRequired(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(BadRequestException value)? badRequest, + TResult? Function(UnauthorizedException value)? unauthorized, + TResult? Function(FlowExpiredException value)? flowExpired, + TResult? Function(TwoFactorAuthRequiredException value)? + twoFactorAuthRequired, + TResult? Function(UnknownException value)? unknown, + }) { + return twoFactorAuthRequired?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(BadRequestException value)? badRequest, + TResult Function(UnauthorizedException value)? unauthorized, + TResult Function(FlowExpiredException value)? flowExpired, + TResult Function(TwoFactorAuthRequiredException value)? + twoFactorAuthRequired, + TResult Function(UnknownException value)? unknown, + required TResult orElse(), + }) { + if (twoFactorAuthRequired != null) { + return twoFactorAuthRequired(this); + } + return orElse(); + } +} + +abstract class TwoFactorAuthRequiredException extends CustomException { + const factory TwoFactorAuthRequiredException({final Session? session}) = + _$TwoFactorAuthRequiredException; + const TwoFactorAuthRequiredException._() : super._(); + + Session? get session; + @JsonKey(ignore: true) + _$$TwoFactorAuthRequiredExceptionCopyWith> + get copyWith => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$$UnknownExceptionCopyWith { + factory _$$UnknownExceptionCopyWith(_$UnknownException value, + $Res Function(_$UnknownException) then) = + __$$UnknownExceptionCopyWithImpl; @useResult $Res call({String? message}); } /// @nodoc -class __$$UnknownExceptionCopyWithImpl<$Res> - extends _$CustomExceptionCopyWithImpl<$Res, _$UnknownException> - implements _$$UnknownExceptionCopyWith<$Res> { +class __$$UnknownExceptionCopyWithImpl + extends _$CustomExceptionCopyWithImpl> + implements _$$UnknownExceptionCopyWith { __$$UnknownExceptionCopyWithImpl( - _$UnknownException _value, $Res Function(_$UnknownException) _then) + _$UnknownException _value, $Res Function(_$UnknownException) _then) : super(_value, _then); @pragma('vm:prefer-inline') @@ -651,7 +767,7 @@ class __$$UnknownExceptionCopyWithImpl<$Res> $Res call({ Object? message = freezed, }) { - return _then(_$UnknownException( + return _then(_$UnknownException( message: freezed == message ? _value.message : message // ignore: cast_nullable_to_non_nullable @@ -662,7 +778,8 @@ class __$$UnknownExceptionCopyWithImpl<$Res> /// @nodoc -class _$UnknownException extends UnknownException with DiagnosticableTreeMixin { +class _$UnknownException extends UnknownException + with DiagnosticableTreeMixin { const _$UnknownException( {this.message = 'An error occured. Please try again later.'}) : super._(); @@ -673,14 +790,14 @@ class _$UnknownException extends UnknownException with DiagnosticableTreeMixin { @override String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { - return 'CustomException.unknown(message: $message)'; + return 'CustomException<$T>.unknown(message: $message)'; } @override void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); properties - ..add(DiagnosticsProperty('type', 'CustomException.unknown')) + ..add(DiagnosticsProperty('type', 'CustomException<$T>.unknown')) ..add(DiagnosticsProperty('message', message)); } @@ -688,7 +805,7 @@ class _$UnknownException extends UnknownException with DiagnosticableTreeMixin { bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$UnknownException && + other is _$UnknownException && (identical(other.message, message) || other.message == message)); } @@ -698,17 +815,17 @@ class _$UnknownException extends UnknownException with DiagnosticableTreeMixin { @JsonKey(ignore: true) @override @pragma('vm:prefer-inline') - _$$UnknownExceptionCopyWith<_$UnknownException> get copyWith => - __$$UnknownExceptionCopyWithImpl<_$UnknownException>(this, _$identity); + _$$UnknownExceptionCopyWith> get copyWith => + __$$UnknownExceptionCopyWithImpl>( + this, _$identity); @override @optionalTypeArgs TResult when({ - required TResult Function(List? messages, int statusCode) - badRequest, - required TResult Function(int statusCode) unauthorized, - required TResult Function(int statusCode, String flowId, String? message) - flowExpired, + required TResult Function(T flow) badRequest, + required TResult Function() unauthorized, + required TResult Function(String flowId, String? message) flowExpired, + required TResult Function(Session? session) twoFactorAuthRequired, required TResult Function(String? message) unknown, }) { return unknown(message); @@ -717,10 +834,10 @@ class _$UnknownException extends UnknownException with DiagnosticableTreeMixin { @override @optionalTypeArgs TResult? whenOrNull({ - TResult? Function(List? messages, int statusCode)? badRequest, - TResult? Function(int statusCode)? unauthorized, - TResult? Function(int statusCode, String flowId, String? message)? - flowExpired, + TResult? Function(T flow)? badRequest, + TResult? Function()? unauthorized, + TResult? Function(String flowId, String? message)? flowExpired, + TResult? Function(Session? session)? twoFactorAuthRequired, TResult? Function(String? message)? unknown, }) { return unknown?.call(message); @@ -729,10 +846,10 @@ class _$UnknownException extends UnknownException with DiagnosticableTreeMixin { @override @optionalTypeArgs TResult maybeWhen({ - TResult Function(List? messages, int statusCode)? badRequest, - TResult Function(int statusCode)? unauthorized, - TResult Function(int statusCode, String flowId, String? message)? - flowExpired, + TResult Function(T flow)? badRequest, + TResult Function()? unauthorized, + TResult Function(String flowId, String? message)? flowExpired, + TResult Function(Session? session)? twoFactorAuthRequired, TResult Function(String? message)? unknown, required TResult orElse(), }) { @@ -745,10 +862,12 @@ class _$UnknownException extends UnknownException with DiagnosticableTreeMixin { @override @optionalTypeArgs TResult map({ - required TResult Function(BadRequestException value) badRequest, - required TResult Function(UnauthorizedException value) unauthorized, - required TResult Function(FlowExpiredException value) flowExpired, - required TResult Function(UnknownException value) unknown, + required TResult Function(BadRequestException value) badRequest, + required TResult Function(UnauthorizedException value) unauthorized, + required TResult Function(FlowExpiredException value) flowExpired, + required TResult Function(TwoFactorAuthRequiredException value) + twoFactorAuthRequired, + required TResult Function(UnknownException value) unknown, }) { return unknown(this); } @@ -756,10 +875,12 @@ class _$UnknownException extends UnknownException with DiagnosticableTreeMixin { @override @optionalTypeArgs TResult? mapOrNull({ - TResult? Function(BadRequestException value)? badRequest, - TResult? Function(UnauthorizedException value)? unauthorized, - TResult? Function(FlowExpiredException value)? flowExpired, - TResult? Function(UnknownException value)? unknown, + TResult? Function(BadRequestException value)? badRequest, + TResult? Function(UnauthorizedException value)? unauthorized, + TResult? Function(FlowExpiredException value)? flowExpired, + TResult? Function(TwoFactorAuthRequiredException value)? + twoFactorAuthRequired, + TResult? Function(UnknownException value)? unknown, }) { return unknown?.call(this); } @@ -767,10 +888,12 @@ class _$UnknownException extends UnknownException with DiagnosticableTreeMixin { @override @optionalTypeArgs TResult maybeMap({ - TResult Function(BadRequestException value)? badRequest, - TResult Function(UnauthorizedException value)? unauthorized, - TResult Function(FlowExpiredException value)? flowExpired, - TResult Function(UnknownException value)? unknown, + TResult Function(BadRequestException value)? badRequest, + TResult Function(UnauthorizedException value)? unauthorized, + TResult Function(FlowExpiredException value)? flowExpired, + TResult Function(TwoFactorAuthRequiredException value)? + twoFactorAuthRequired, + TResult Function(UnknownException value)? unknown, required TResult orElse(), }) { if (unknown != null) { @@ -780,12 +903,13 @@ class _$UnknownException extends UnknownException with DiagnosticableTreeMixin { } } -abstract class UnknownException extends CustomException { - const factory UnknownException({final String? message}) = _$UnknownException; +abstract class UnknownException extends CustomException { + const factory UnknownException({final String? message}) = + _$UnknownException; const UnknownException._() : super._(); String? get message; @JsonKey(ignore: true) - _$$UnknownExceptionCopyWith<_$UnknownException> get copyWith => + _$$UnknownExceptionCopyWith> get copyWith => throw _privateConstructorUsedError; } diff --git a/flutter-ory-network/lib/widgets/helpers.dart b/flutter-ory-network/lib/widgets/helpers.dart new file mode 100644 index 00000000..b565ae70 --- /dev/null +++ b/flutter-ory-network/lib/widgets/helpers.dart @@ -0,0 +1,95 @@ +import 'package:bloc/bloc.dart'; +import 'package:flutter/material.dart'; +import 'package:ory_client/ory_client.dart'; + +import 'nodes/input.dart'; +import 'nodes/input_submit.dart'; +import 'nodes/text.dart'; + +getMessageColor(UiTextTypeEnum type) { + switch (type) { + case UiTextTypeEnum.success: + return Colors.green; + case UiTextTypeEnum.error: + return Colors.red; + case UiTextTypeEnum.info: + return Colors.grey; + } +} + +buildFlowNotCreated(BuildContext context, String? message) { + if (message != null) { + return Center( + child: Text( + message, + style: const TextStyle(color: Colors.red), + )); + } else { + return const Center(child: CircularProgressIndicator()); + } +} + +buildGroup( + BuildContext context, + UiNodeGroupEnum group, + List nodes, + void Function(BuildContext, String, String) onInputChange, + void Function(BuildContext, UiNodeGroupEnum, String, String) + onInputSubmit) { + final formKey = GlobalKey(); + return Padding( + padding: const EdgeInsets.only(bottom: 0), + child: Form( + key: formKey, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + ListView.builder( + physics: const NeverScrollableScrollPhysics(), + shrinkWrap: true, + itemBuilder: ((BuildContext context, index) { + final attributes = nodes[index].attributes.oneOf; + if (attributes.isType(UiNodeInputAttributes)) { + return buildInputNode(context, formKey, nodes[index], + onInputChange, onInputSubmit); + } else if (attributes.isType(UiNodeTextAttributes)) { + return TextNode(node: nodes[index]); + } else { + return Container(); + } + }), + itemCount: nodes.length), + ], + ), + ), + ); +} + +buildInputNode( + BuildContext context, + GlobalKey formKey, + UiNode node, + void Function(BuildContext, String, String) onInputChange, + void Function(BuildContext, UiNodeGroupEnum, String, String) + onInputSubmit) { + final inputNode = node.attributes.oneOf.value as UiNodeInputAttributes; + switch (inputNode.type) { + case UiNodeInputAttributesTypeEnum.submit: + return InputSubmitNode( + node: node, + formKey: formKey, + onChange: onInputChange, + onSubmit: onInputSubmit); + case UiNodeInputAttributesTypeEnum.button: + return InputSubmitNode( + node: node, + formKey: formKey, + onChange: onInputChange, + onSubmit: onInputSubmit); + case UiNodeInputAttributesTypeEnum.hidden: + return const SizedBox.shrink(); + + default: + return InputNode(node: node, onChange: onInputChange); + } +} diff --git a/flutter-ory-network/lib/widgets/nodes/input.dart b/flutter-ory-network/lib/widgets/nodes/input.dart new file mode 100644 index 00000000..3be9b238 --- /dev/null +++ b/flutter-ory-network/lib/widgets/nodes/input.dart @@ -0,0 +1,156 @@ +import 'package:collection/collection.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:ory_client/ory_client.dart'; +import 'package:ory_network_flutter/blocs/login/login_bloc.dart'; +import 'package:ory_network_flutter/blocs/registration/registration_bloc.dart'; + +import '../helpers.dart'; + +class InputNode extends StatefulWidget { + final UiNode node; + final void Function(BuildContext, String, String) onChange; + + const InputNode({super.key, required this.node, required this.onChange}); + @override + State createState() => _InputNodeState(); +} + +class _InputNodeState extends State { + TextEditingController textEditingController = TextEditingController(); + bool? isPasswordHidden; + + @override + void initState() { + super.initState(); + // assign node value to text controller on init + final attributes = + widget.node.attributes.oneOf.value as UiNodeInputAttributes; + // if this is a password field, hide the text + if (attributes.name == 'password') { + setState(() { + isPasswordHidden = true; + }); + } + final fieldValue = attributes.value; + textEditingController.text = fieldValue != null ? fieldValue.asString : ''; + } + +// get text input type of a specific node + _getTextInputType(UiNodeInputAttributesTypeEnum type) { + switch (type) { + case UiNodeInputAttributesTypeEnum.datetimeLocal: + return TextInputType.datetime; + case UiNodeInputAttributesTypeEnum.email: + return TextInputType.emailAddress; + case UiNodeInputAttributesTypeEnum.hidden: + return TextInputType.none; + case UiNodeInputAttributesTypeEnum.number: + return TextInputType.number; + case UiNodeInputAttributesTypeEnum.password: + return TextInputType.text; + case UiNodeInputAttributesTypeEnum.tel: + return TextInputType.phone; + case UiNodeInputAttributesTypeEnum.text: + return TextInputType.text; + case UiNodeInputAttributesTypeEnum.url: + return TextInputType.url; + default: + return null; + } + } + + @override + Widget build(BuildContext context) { + print(widget.node.attributes.oneOf.value); + final attributes = + widget.node.attributes.oneOf.value as UiNodeInputAttributes; + + return BlocListener( + bloc: (context).read(), + listener: (context, state) { + UiNode? node; + // find current node in updated state + if (state is LoginState) { + node = state.loginFlow?.ui.nodes.firstWhereOrNull((element) { + if (element.attributes.oneOf.isType(UiNodeInputAttributes)) { + return (element.attributes.oneOf.value as UiNodeInputAttributes) + .name == + attributes.name; + } else { + return false; + } + }); + } else if (state is RegistrationState) { + node = state.registrationFlow?.ui.nodes.firstWhereOrNull((element) { + if (element.attributes.oneOf.isType(UiNodeInputAttributes)) { + return (element.attributes.oneOf.value as UiNodeInputAttributes) + .name == + attributes.name; + } else { + return false; + } + }); + } + + // assign new value of node to text controller + textEditingController.text = + (node?.attributes.oneOf.value as UiNodeInputAttributes) + .value + ?.asString ?? + ''; + }, + child: Padding( + padding: const EdgeInsets.only(bottom: 20.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + if (widget.node.meta.label?.text != null) + Text( + widget.node.meta.label!.text, + style: const TextStyle(fontWeight: FontWeight.w600), + ), + const SizedBox( + height: 4, + ), + TextFormField( + controller: textEditingController, + enabled: !attributes.disabled, + keyboardType: _getTextInputType(attributes.type), + onChanged: (String value) { + widget.onChange(context, value, attributes.name); + }, + obscureText: isPasswordHidden ?? false, + decoration: isPasswordHidden == null + ? null + : InputDecoration( + suffixIcon: GestureDetector( + onTap: () => setState(() { + isPasswordHidden = !isPasswordHidden!; + }), + child: ImageIcon(isPasswordHidden! + ? const AssetImage('assets/icons/eye.png') + : const AssetImage('assets/icons/eye-off.png')), + )), + validator: (value) { + if (attributes.required_ != null) { + if (attributes.required_! && + (value == null || value.isEmpty)) { + return 'Property is required'; + } + } + return null; + }, + ), + for (var message in widget.node.messages) + Padding( + padding: const EdgeInsets.only(top: 20), + child: Text(message.text, + style: TextStyle(color: getMessageColor(message.type))), + ), + ], + ), + ), + ); + } +} diff --git a/flutter-ory-network/lib/widgets/nodes/input_submit.dart b/flutter-ory-network/lib/widgets/nodes/input_submit.dart new file mode 100644 index 00000000..542c9b61 --- /dev/null +++ b/flutter-ory-network/lib/widgets/nodes/input_submit.dart @@ -0,0 +1,53 @@ +import 'package:flutter/material.dart'; +import 'package:ory_client/ory_client.dart'; + +class InputSubmitNode extends StatelessWidget { + final GlobalKey formKey; + final UiNode node; + final void Function(BuildContext, String, String) onChange; + final void Function(BuildContext, UiNodeGroupEnum, String, String) onSubmit; + + const InputSubmitNode( + {super.key, + required this.formKey, + required this.node, + required this.onChange, + required this.onSubmit}); + + @override + Widget build(BuildContext context) { + return Column( + children: [ + SizedBox( + width: double.infinity, + child: FilledButton( + // validate input fields that belong to this buttons group + onPressed: () { + if (formKey.currentState!.validate()) { + final attributes = + node.attributes.oneOf.value as UiNodeInputAttributes; + final type = attributes.type; + // if attribute type is a button, set its value to true on submit + if (type == UiNodeInputAttributesTypeEnum.button || + type == UiNodeInputAttributesTypeEnum.submit && + attributes.value?.value == 'false') { + final nodeName = attributes.name; + + onChange(context, 'true', nodeName); + } + onSubmit( + context, + node.group, + attributes.name, + attributes.value!.isString + ? attributes.value!.asString + : ''); + } + }, + child: Text(node.meta.label?.text ?? ''), + ), + ), + ], + ); + } +} diff --git a/flutter-ory-network/lib/widgets/nodes/provider.dart b/flutter-ory-network/lib/widgets/nodes/provider.dart new file mode 100644 index 00000000..5c5ccc1b --- /dev/null +++ b/flutter-ory-network/lib/widgets/nodes/provider.dart @@ -0,0 +1,26 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + +import 'package:flutter/material.dart'; +import 'package:ory_client/ory_client.dart'; + +class SocialProviderInput extends StatelessWidget { + final UiNode node; + + const SocialProviderInput({super.key, required this.node}); + @override + Widget build(BuildContext context) { + final provider = node.attributes.oneOf.isType(UiNodeInputAttributes) + ? (node.attributes.oneOf.value as UiNodeInputAttributes).value?.asString + : null; + return SizedBox( + width: double.infinity, + child: OutlinedButton.icon( + icon: Image.asset( + 'assets/images/flows-auth-buttons-social-$provider.png'), + label: Text(node.meta.label?.text ?? ''), + onPressed: () {}, + ), + ); + } +} diff --git a/flutter-ory-network/lib/widgets/nodes/text.dart b/flutter-ory-network/lib/widgets/nodes/text.dart new file mode 100644 index 00000000..26bd54f1 --- /dev/null +++ b/flutter-ory-network/lib/widgets/nodes/text.dart @@ -0,0 +1,25 @@ +import 'package:flutter/material.dart'; +import 'package:ory_client/ory_client.dart'; + +class TextNode extends StatelessWidget { + final UiNode node; + + const TextNode({super.key, required this.node}); + @override + Widget build(BuildContext context) { + final attributes = node.attributes.oneOf.value as UiNodeTextAttributes; + return Padding( + padding: const EdgeInsets.only(bottom: 20.0), + child: Column( + children: [ + // show label test if it is available + if (node.meta.label?.text != null) Text(node.meta.label!.text), + const SizedBox( + height: 10, + ), + Text(attributes.text.text), + ], + ), + ); + } +} diff --git a/flutter-ory-network/pubspec.lock b/flutter-ory-network/pubspec.lock index 642803c1..9ce2d1f5 100644 --- a/flutter-ory-network/pubspec.lock +++ b/flutter-ory-network/pubspec.lock @@ -98,7 +98,7 @@ packages: source: hosted version: "7.2.10" built_collection: - dependency: transitive + dependency: "direct main" description: name: built_collection sha256: "376e3dd27b51ea877c28d525560790aee2e6fbb5f20e2f85d5081027d94e2100" @@ -146,7 +146,7 @@ packages: source: hosted version: "4.5.0" collection: - dependency: transitive + dependency: "direct main" description: name: collection sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687 @@ -185,6 +185,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.3.2" + deep_collection: + dependency: "direct main" + description: + name: deep_collection + sha256: "59abffbfd9add6d47e04d623c50c3e2bcf3ed6a1606513dbe3325a738f77cb0c" + url: "https://pub.dev" + source: hosted + version: "1.0.2" dio: dependency: "direct main" description: @@ -201,6 +209,14 @@ packages: url: "https://pub.dev" source: hosted version: "4.1.0" + effective_dart: + dependency: transitive + description: + name: effective_dart + sha256: "6a69783c808344084b65667e87ff600823531e95810a8a15882cb542fe22de80" + url: "https://pub.dev" + source: hosted + version: "1.3.2" equatable: dependency: "direct main" description: @@ -508,10 +524,10 @@ packages: dependency: "direct main" description: name: ory_client - sha256: a7cdf22fb8f057e773cd6764831aaf4dab7dc8b6cfefc643b5b545b574b214c9 + sha256: "151372511353601d4afd81213523ea0662be0f754b44b4be17c40c91bf1967cc" url: "https://pub.dev" source: hosted - version: "1.1.49" + version: "1.2.10" package_config: dependency: transitive description: diff --git a/flutter-ory-network/pubspec.yaml b/flutter-ory-network/pubspec.yaml index 2484a842..dcc0062a 100644 --- a/flutter-ory-network/pubspec.yaml +++ b/flutter-ory-network/pubspec.yaml @@ -47,6 +47,9 @@ dependencies: dotenv: ^4.1.0 google_fonts: ^5.1.0 built_value: ^8.6.2 + deep_collection: ^1.0.2 + collection: ^1.17.2 + built_collection: ^5.1.1 dev_dependencies: flutter_test: From 6917e92294768dae44c77f6a730a6420676c763a Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Mon, 2 Oct 2023 12:06:40 +0200 Subject: [PATCH 25/57] chore: clean up and format code --- .../lib/blocs/auth/auth_bloc.freezed.dart | 3 ++ .../lib/blocs/auth/auth_event.dart | 2 -- .../lib/blocs/login/login_bloc.dart | 2 ++ .../lib/blocs/login/login_bloc.freezed.dart | 3 ++ .../registration_bloc.freezed.dart | 3 ++ flutter-ory-network/lib/pages/login.dart | 18 ++++++------ .../lib/pages/registration.dart | 13 ++++----- .../lib/repositories/auth.dart | 24 ---------------- flutter-ory-network/lib/services/auth.dart | 28 ++++++------------- .../lib/services/exceptions.freezed.dart | 3 ++ flutter-ory-network/lib/widgets/helpers.dart | 3 ++ .../lib/widgets/nodes/input.dart | 6 ++-- .../lib/widgets/nodes/input_submit.dart | 5 +++- .../lib/widgets/nodes/provider.dart | 4 ++- .../lib/widgets/nodes/text.dart | 3 ++ 15 files changed, 52 insertions(+), 68 deletions(-) diff --git a/flutter-ory-network/lib/blocs/auth/auth_bloc.freezed.dart b/flutter-ory-network/lib/blocs/auth/auth_bloc.freezed.dart index 02acfd8b..c9fb0758 100644 --- a/flutter-ory-network/lib/blocs/auth/auth_bloc.freezed.dart +++ b/flutter-ory-network/lib/blocs/auth/auth_bloc.freezed.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint diff --git a/flutter-ory-network/lib/blocs/auth/auth_event.dart b/flutter-ory-network/lib/blocs/auth/auth_event.dart index 7d9a6364..041a6074 100644 --- a/flutter-ory-network/lib/blocs/auth/auth_event.dart +++ b/flutter-ory-network/lib/blocs/auth/auth_event.dart @@ -17,8 +17,6 @@ final class ChangeAuthStatus extends AuthEvent { List get props => [status]; } -//get current session information final class GetCurrentSessionInformation extends AuthEvent {} -//log out final class LogOut extends AuthEvent {} diff --git a/flutter-ory-network/lib/blocs/login/login_bloc.dart b/flutter-ory-network/lib/blocs/login/login_bloc.dart index fcdcd638..d46ca354 100644 --- a/flutter-ory-network/lib/blocs/login/login_bloc.dart +++ b/flutter-ory-network/lib/blocs/login/login_bloc.dart @@ -79,6 +79,8 @@ class LoginBloc extends Bloc { } on CustomException catch (e) { if (e case BadRequestException _) { emit(state.copyWith(loginFlow: e.flow, isLoading: false)); + } else if (e case UnauthorizedException _) { + authBloc.add(ChangeAuthStatus(status: AuthStatus.unauthenticated)); } else if (e case FlowExpiredException _) { add(GetLoginFlow(flowId: e.flowId)); } else if (e case TwoFactorAuthRequiredException _) { diff --git a/flutter-ory-network/lib/blocs/login/login_bloc.freezed.dart b/flutter-ory-network/lib/blocs/login/login_bloc.freezed.dart index d09b7b6b..805f0938 100644 --- a/flutter-ory-network/lib/blocs/login/login_bloc.freezed.dart +++ b/flutter-ory-network/lib/blocs/login/login_bloc.freezed.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint diff --git a/flutter-ory-network/lib/blocs/registration/registration_bloc.freezed.dart b/flutter-ory-network/lib/blocs/registration/registration_bloc.freezed.dart index d1f90d5e..f31c6b2d 100644 --- a/flutter-ory-network/lib/blocs/registration/registration_bloc.freezed.dart +++ b/flutter-ory-network/lib/blocs/registration/registration_bloc.freezed.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint diff --git a/flutter-ory-network/lib/pages/login.dart b/flutter-ory-network/lib/pages/login.dart index 17dd68f8..03a39018 100644 --- a/flutter-ory-network/lib/pages/login.dart +++ b/flutter-ory-network/lib/pages/login.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:ory_client/ory_client.dart'; @@ -123,20 +126,18 @@ class LoginForm extends StatelessWidget { message.text, style: TextStyle(color: getMessageColor(message.type)), ), - // build progress indicator when state is loading + // show logout button if aal2 requested, otherwise sign up BlocSelector( bloc: (context).read(), selector: (AuthState state) => state.status == AuthStatus.aal2Requested, builder: (BuildContext context, bool booleanState) { - print(booleanState); if (booleanState) { return Row( mainAxisAlignment: MainAxisAlignment.start, children: [ const Text('Something\'s not working?'), TextButton( - // disable button when state is loading onPressed: () => (context).read().add(LogOut()), child: const Text('Logout')) @@ -148,13 +149,10 @@ class LoginForm extends StatelessWidget { children: [ const Text('No account?'), TextButton( - // disable button when state is loading - onPressed: state.isLoading - ? null - : () => Navigator.of(context).pushReplacement( - MaterialPageRoute( - builder: (context) => - const RegistrationPage())), + onPressed: () => Navigator.of(context) + .pushReplacement(MaterialPageRoute( + builder: (context) => + const RegistrationPage())), child: const Text('Sign up')) ], ); diff --git a/flutter-ory-network/lib/pages/registration.dart b/flutter-ory-network/lib/pages/registration.dart index 72c84e59..71726573 100644 --- a/flutter-ory-network/lib/pages/registration.dart +++ b/flutter-ory-network/lib/pages/registration.dart @@ -141,14 +141,11 @@ class RegistrationFormState extends State { children: [ const Text('Already have an account?'), TextButton( - // disable button when state is loading - onPressed: state.isLoading - ? null - : () => Navigator.of(context) - .pushReplacement(MaterialPageRoute( - builder: (context) => const LoginPage( - aal: 'aal1', - ))), + onPressed: () => Navigator.of(context) + .pushReplacement(MaterialPageRoute( + builder: (context) => const LoginPage( + aal: 'aal1', + ))), child: const Text('Sign in')) ], ) diff --git a/flutter-ory-network/lib/repositories/auth.dart b/flutter-ory-network/lib/repositories/auth.dart index 8c92006e..a482b949 100644 --- a/flutter-ory-network/lib/repositories/auth.dart +++ b/flutter-ory-network/lib/repositories/auth.dart @@ -71,7 +71,6 @@ class AuthRepository { final body = _createRequestBody( group: group, name: name, value: value, nodes: nodes); // submit login - print(body); final login = await service.updateLoginFlow( flowId: flowId, group: group, value: body); return login; @@ -119,29 +118,6 @@ class AuthRepository { } } - LoginFlow resetButtonValues({required LoginFlow loginFlow}) { - final submitInputNodes = loginFlow.ui.nodes.where((p0) { - if (p0.attributes.oneOf.isType(UiNodeInputAttributes)) { - final attributes = p0.attributes.oneOf.value as UiNodeInputAttributes; - final type = attributes.type; - if ((type == UiNodeInputAttributesTypeEnum.button || - type == UiNodeInputAttributesTypeEnum.submit) && - attributes.value?.asString == 'true') { - return true; - } - } - return false; - }); - for (var node in submitInputNodes) { - final attributes = node.attributes.oneOf.value as UiNodeInputAttributes; - // reset button value to false - // to prevent submitting values that were not selected - loginFlow = changeLoginNodeValue( - settings: loginFlow, name: attributes.name, value: 'false'); - } - return loginFlow; - } - RegistrationFlow changeRegistrationNodeValue( {required RegistrationFlow settings, required String name, diff --git a/flutter-ory-network/lib/services/auth.dart b/flutter-ory-network/lib/services/auth.dart index 43cffef2..2917ed5a 100644 --- a/flutter-ory-network/lib/services/auth.dart +++ b/flutter-ory-network/lib/services/auth.dart @@ -94,7 +94,8 @@ class AuthService { case UiNodeGroupEnum.lookupSecret: oneOf = OneOf.fromValue1( value: UpdateLoginFlowWithLookupSecretMethod((b) => b - ..method = group.name + // use pre-defined string as enum value doesn't include an underscore + ..method = 'lookup_secret' ..lookupSecret = value['lookup_secret'])); case UiNodeGroupEnum.totp: oneOf = OneOf.fromValue1( @@ -118,8 +119,8 @@ class AuthService { if (response.data!.session.identity != null) { return response.data!; } else { - throw CustomException.twoFactorAuthRequired( - session: response.data!.session); + // identity is null, aal2 is required + throw const CustomException.twoFactorAuthRequired(); } } else { throw const CustomException.unknown(); @@ -137,7 +138,7 @@ class AuthService { throw const CustomException.unknown(); } } else if (e.response?.statusCode == 410) { - // settings flow expired, use new flow id and add error message + // settings flow expired, use new flow id throw CustomException.flowExpired( flowId: e.response?.data['use_flow_id']); } else { @@ -158,12 +159,7 @@ class AuthService { throw const CustomException.unknown(); } } on DioException catch (e) { - if (e.response?.statusCode == 401) { - await storage.deleteToken(); - throw const CustomException.unauthorized(); - } else { - throw _handleUnknownException(e.response?.data); - } + throw _handleUnknownException(e.response?.data); } } @@ -179,12 +175,7 @@ class AuthService { throw const CustomException.unknown(); } } on DioException catch (e) { - if (e.response?.statusCode == 401) { - await storage.deleteToken(); - throw const CustomException.unauthorized(); - } else { - throw _handleUnknownException(e.response?.data); - } + throw _handleUnknownException(e.response?.data); } } @@ -223,10 +214,7 @@ class AuthService { throw const CustomException.unknown(); } } on DioException catch (e) { - if (e.response?.statusCode == 401) { - await storage.deleteToken(); - throw const CustomException.unauthorized(); - } else if (e.response?.statusCode == 400) { + if (e.response?.statusCode == 400) { final registrationFlow = standardSerializers.deserializeWith( RegistrationFlow.serializer, e.response?.data); if (registrationFlow != null) { diff --git a/flutter-ory-network/lib/services/exceptions.freezed.dart b/flutter-ory-network/lib/services/exceptions.freezed.dart index 01e7d71f..f7a7d4b4 100644 --- a/flutter-ory-network/lib/services/exceptions.freezed.dart +++ b/flutter-ory-network/lib/services/exceptions.freezed.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint diff --git a/flutter-ory-network/lib/widgets/helpers.dart b/flutter-ory-network/lib/widgets/helpers.dart index b565ae70..6cb8675f 100644 --- a/flutter-ory-network/lib/widgets/helpers.dart +++ b/flutter-ory-network/lib/widgets/helpers.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + import 'package:bloc/bloc.dart'; import 'package:flutter/material.dart'; import 'package:ory_client/ory_client.dart'; diff --git a/flutter-ory-network/lib/widgets/nodes/input.dart b/flutter-ory-network/lib/widgets/nodes/input.dart index 3be9b238..05731b3b 100644 --- a/flutter-ory-network/lib/widgets/nodes/input.dart +++ b/flutter-ory-network/lib/widgets/nodes/input.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + import 'package:collection/collection.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -23,7 +26,6 @@ class _InputNodeState extends State { @override void initState() { super.initState(); - // assign node value to text controller on init final attributes = widget.node.attributes.oneOf.value as UiNodeInputAttributes; // if this is a password field, hide the text @@ -33,6 +35,7 @@ class _InputNodeState extends State { }); } final fieldValue = attributes.value; + // assign node value to text controller on init textEditingController.text = fieldValue != null ? fieldValue.asString : ''; } @@ -62,7 +65,6 @@ class _InputNodeState extends State { @override Widget build(BuildContext context) { - print(widget.node.attributes.oneOf.value); final attributes = widget.node.attributes.oneOf.value as UiNodeInputAttributes; diff --git a/flutter-ory-network/lib/widgets/nodes/input_submit.dart b/flutter-ory-network/lib/widgets/nodes/input_submit.dart index 542c9b61..c2fed9c8 100644 --- a/flutter-ory-network/lib/widgets/nodes/input_submit.dart +++ b/flutter-ory-network/lib/widgets/nodes/input_submit.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + import 'package:flutter/material.dart'; import 'package:ory_client/ory_client.dart'; @@ -27,7 +30,7 @@ class InputSubmitNode extends StatelessWidget { final attributes = node.attributes.oneOf.value as UiNodeInputAttributes; final type = attributes.type; - // if attribute type is a button, set its value to true on submit + // if attribute type is a button with value 'false', set its value to true on submit if (type == UiNodeInputAttributesTypeEnum.button || type == UiNodeInputAttributesTypeEnum.submit && attributes.value?.value == 'false') { diff --git a/flutter-ory-network/lib/widgets/nodes/provider.dart b/flutter-ory-network/lib/widgets/nodes/provider.dart index 5c5ccc1b..d389084d 100644 --- a/flutter-ory-network/lib/widgets/nodes/provider.dart +++ b/flutter-ory-network/lib/widgets/nodes/provider.dart @@ -19,7 +19,9 @@ class SocialProviderInput extends StatelessWidget { icon: Image.asset( 'assets/images/flows-auth-buttons-social-$provider.png'), label: Text(node.meta.label?.text ?? ''), - onPressed: () {}, + onPressed: () { + //TODO + }, ), ); } diff --git a/flutter-ory-network/lib/widgets/nodes/text.dart b/flutter-ory-network/lib/widgets/nodes/text.dart index 26bd54f1..f8a115b0 100644 --- a/flutter-ory-network/lib/widgets/nodes/text.dart +++ b/flutter-ory-network/lib/widgets/nodes/text.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + import 'package:flutter/material.dart'; import 'package:ory_client/ory_client.dart'; From 8f771f03db9c92b6cc75c3464bad651414a17f79 Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Mon, 2 Oct 2023 13:20:50 +0200 Subject: [PATCH 26/57] fix: aal2 navigation --- .../lib/blocs/login/login_bloc.dart | 2 +- flutter-ory-network/lib/pages/login.dart | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/flutter-ory-network/lib/blocs/login/login_bloc.dart b/flutter-ory-network/lib/blocs/login/login_bloc.dart index d46ca354..e0c9b1a1 100644 --- a/flutter-ory-network/lib/blocs/login/login_bloc.dart +++ b/flutter-ory-network/lib/blocs/login/login_bloc.dart @@ -84,7 +84,7 @@ class LoginBloc extends Bloc { } else if (e case FlowExpiredException _) { add(GetLoginFlow(flowId: e.flowId)); } else if (e case TwoFactorAuthRequiredException _) { - add(CreateLoginFlow(aal: 'aal2')); + authBloc.add(ChangeAuthStatus(status: AuthStatus.aal2Requested)); } else if (e case UnknownException _) { emit(state.copyWith(isLoading: false, message: e.message)); } else { diff --git a/flutter-ory-network/lib/pages/login.dart b/flutter-ory-network/lib/pages/login.dart index 03a39018..99ed0bb2 100644 --- a/flutter-ory-network/lib/pages/login.dart +++ b/flutter-ory-network/lib/pages/login.dart @@ -93,9 +93,21 @@ class LoginForm extends StatelessWidget { const SizedBox( height: 32, ), - const Text('Sign in', - style: TextStyle( - fontWeight: FontWeight.w600, height: 1.5, fontSize: 18)), + // show header depending on auth state + BlocSelector( + bloc: (context).read(), + selector: (AuthState state) => + state.status == AuthStatus.aal2Requested, + builder: (BuildContext context, bool boolState) { + return Text( + boolState ? 'Two-Factor Authentication' : 'Sign in', + style: const TextStyle( + fontWeight: FontWeight.w600, + height: 1.5, + fontSize: 18)); + }, + ), + if (oidcNodes.isNotEmpty) Padding( padding: const EdgeInsets.only(top: 32.0), From c9de1f1d43c2df3de69cbbe149dcfe6f0e947d32 Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Wed, 4 Oct 2023 10:49:34 +0200 Subject: [PATCH 27/57] chore: remove unnecessary code --- flutter-ory-network/lib/blocs/login/login_bloc.dart | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/flutter-ory-network/lib/blocs/login/login_bloc.dart b/flutter-ory-network/lib/blocs/login/login_bloc.dart index e0c9b1a1..d8c1584b 100644 --- a/flutter-ory-network/lib/blocs/login/login_bloc.dart +++ b/flutter-ory-network/lib/blocs/login/login_bloc.dart @@ -29,10 +29,9 @@ class LoginBloc extends Bloc { CreateLoginFlow event, Emitter emit) async { try { emit(state.copyWith(isLoading: true, message: null)); + final loginFlow = await repository.createLoginFlow(aal: event.aal); - if (event.aal == 'aal2') { - authBloc.add(ChangeAuthStatus(status: AuthStatus.aal2Requested)); - } + emit(state.copyWith(loginFlow: loginFlow, isLoading: false)); } on CustomException catch (e) { if (e case UnknownException _) { From b815ba13a485fcf1e6cc0b93b8a5fdb7ae6c4ad8 Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Wed, 11 Oct 2023 13:50:51 +0200 Subject: [PATCH 28/57] feat: sign in/up with google account on iOS --- .../app/FlutterMultiDexApplication.java | 25 ++++++ flutter-ory-network/ios/Podfile.lock | 32 +++++++ .../lib/blocs/login/login_bloc.dart | 2 +- .../blocs/registration/registration_bloc.dart | 2 +- flutter-ory-network/lib/main.dart | 13 ++- flutter-ory-network/lib/pages/login.dart | 47 +++++++--- .../lib/pages/registration.dart | 47 +++++++--- .../lib/repositories/auth.dart | 62 +++++++++++-- flutter-ory-network/lib/services/auth.dart | 34 +++++++- flutter-ory-network/lib/widgets/helpers.dart | 49 +++++------ .../lib/widgets/nodes/input_submit.dart | 86 ++++++++++++------- .../lib/widgets/nodes/provider.dart | 28 ------ .../lib/widgets/ory_theme.dart | 11 +++ .../lib/widgets/social_provider_box.dart | 28 ------ flutter-ory-network/pubspec.lock | 60 ++++++++++--- flutter-ory-network/pubspec.yaml | 6 +- 16 files changed, 364 insertions(+), 168 deletions(-) create mode 100644 flutter-ory-network/android/app/src/main/java/io/flutter/app/FlutterMultiDexApplication.java delete mode 100644 flutter-ory-network/lib/widgets/nodes/provider.dart delete mode 100644 flutter-ory-network/lib/widgets/social_provider_box.dart diff --git a/flutter-ory-network/android/app/src/main/java/io/flutter/app/FlutterMultiDexApplication.java b/flutter-ory-network/android/app/src/main/java/io/flutter/app/FlutterMultiDexApplication.java new file mode 100644 index 00000000..752fc185 --- /dev/null +++ b/flutter-ory-network/android/app/src/main/java/io/flutter/app/FlutterMultiDexApplication.java @@ -0,0 +1,25 @@ +// Generated file. +// +// If you wish to remove Flutter's multidex support, delete this entire file. +// +// Modifications to this file should be done in a copy under a different name +// as this file may be regenerated. + +package io.flutter.app; + +import android.app.Application; +import android.content.Context; +import androidx.annotation.CallSuper; +import androidx.multidex.MultiDex; + +/** + * Extension of {@link android.app.Application}, adding multidex support. + */ +public class FlutterMultiDexApplication extends Application { + @Override + @CallSuper + protected void attachBaseContext(Context base) { + super.attachBaseContext(base); + MultiDex.install(this); + } +} diff --git a/flutter-ory-network/ios/Podfile.lock b/flutter-ory-network/ios/Podfile.lock index 8d113103..72b22c81 100644 --- a/flutter-ory-network/ios/Podfile.lock +++ b/flutter-ory-network/ios/Podfile.lock @@ -1,7 +1,24 @@ PODS: + - AppAuth (1.6.2): + - AppAuth/Core (= 1.6.2) + - AppAuth/ExternalUserAgent (= 1.6.2) + - AppAuth/Core (1.6.2) + - AppAuth/ExternalUserAgent (1.6.2): + - AppAuth/Core - Flutter (1.0.0) - flutter_secure_storage (6.0.0): - Flutter + - google_sign_in_ios (0.0.1): + - Flutter + - GoogleSignIn (~> 6.2) + - GoogleSignIn (6.2.4): + - AppAuth (~> 1.5) + - GTMAppAuth (~> 1.3) + - GTMSessionFetcher/Core (< 3.0, >= 1.1) + - GTMAppAuth (1.3.1): + - AppAuth/Core (~> 1.6) + - GTMSessionFetcher/Core (< 3.0, >= 1.5) + - GTMSessionFetcher/Core (2.3.0) - path_provider_foundation (0.0.1): - Flutter - FlutterMacOS @@ -9,19 +26,34 @@ PODS: DEPENDENCIES: - Flutter (from `Flutter`) - flutter_secure_storage (from `.symlinks/plugins/flutter_secure_storage/ios`) + - google_sign_in_ios (from `.symlinks/plugins/google_sign_in_ios/ios`) - path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`) +SPEC REPOS: + trunk: + - AppAuth + - GoogleSignIn + - GTMAppAuth + - GTMSessionFetcher + EXTERNAL SOURCES: Flutter: :path: Flutter flutter_secure_storage: :path: ".symlinks/plugins/flutter_secure_storage/ios" + google_sign_in_ios: + :path: ".symlinks/plugins/google_sign_in_ios/ios" path_provider_foundation: :path: ".symlinks/plugins/path_provider_foundation/darwin" SPEC CHECKSUMS: + AppAuth: 3bb1d1cd9340bd09f5ed189fb00b1cc28e1e8570 Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854 flutter_secure_storage: 23fc622d89d073675f2eaa109381aefbcf5a49be + google_sign_in_ios: 1256ff9d941db546373826966720b0c24804bcdd + GoogleSignIn: 5651ce3a61e56ca864160e79b484cd9ed3f49b7a + GTMAppAuth: 0ff230db599948a9ad7470ca667337803b3fc4dd + GTMSessionFetcher: 3a63d75eecd6aa32c2fc79f578064e1214dfdec2 path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943 PODFILE CHECKSUM: 70d9d25280d0dd177a5f637cdb0f0b0b12c6a189 diff --git a/flutter-ory-network/lib/blocs/login/login_bloc.dart b/flutter-ory-network/lib/blocs/login/login_bloc.dart index d8c1584b..f2153a7d 100644 --- a/flutter-ory-network/lib/blocs/login/login_bloc.dart +++ b/flutter-ory-network/lib/blocs/login/login_bloc.dart @@ -18,7 +18,7 @@ class LoginBloc extends Bloc { final AuthBloc authBloc; final AuthRepository repository; LoginBloc({required this.authBloc, required this.repository}) - : super(LoginState()) { + : super(const LoginState()) { on(_onCreateLoginFlow); on(_onGetLoginFlow); on(_onChangeNodeValue); diff --git a/flutter-ory-network/lib/blocs/registration/registration_bloc.dart b/flutter-ory-network/lib/blocs/registration/registration_bloc.dart index d4f42249..471a2245 100644 --- a/flutter-ory-network/lib/blocs/registration/registration_bloc.dart +++ b/flutter-ory-network/lib/blocs/registration/registration_bloc.dart @@ -18,7 +18,7 @@ class RegistrationBloc extends Bloc { final AuthBloc authBloc; final AuthRepository repository; RegistrationBloc({required this.authBloc, required this.repository}) - : super(RegistrationState()) { + : super(const RegistrationState()) { on(_onCreateRegistrationFlow); on(_onGetRegistrationFlow); on(_onChangeNodeValue); diff --git a/flutter-ory-network/lib/main.dart b/flutter-ory-network/lib/main.dart index ea93cfc1..29635869 100644 --- a/flutter-ory-network/lib/main.dart +++ b/flutter-ory-network/lib/main.dart @@ -6,7 +6,9 @@ import 'package:dio/io.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; +import 'package:google_sign_in/google_sign_in.dart'; import 'package:ory_network_flutter/widgets/ory_theme.dart'; +import 'dart:io' show Platform; import 'blocs/auth/auth_bloc.dart'; import 'pages/home.dart'; @@ -36,7 +38,16 @@ Future main() async { final dio = DioForNative(options); final authService = AuthService(dio); - final authRepository = AuthRepository(service: authService); + + final googleSignIn = GoogleSignIn( + clientId: Platform.isAndroid ? null : dotenv.get('IOS_CLIENT_ID'), + scopes: [ + 'email', + 'profile', + 'openid', + ]); + final authRepository = + AuthRepository(googleSignIn: googleSignIn, service: authService); runApp(RepositoryProvider.value( value: authRepository, child: BlocProvider( diff --git a/flutter-ory-network/lib/pages/login.dart b/flutter-ory-network/lib/pages/login.dart index 99ed0bb2..ba36590d 100644 --- a/flutter-ory-network/lib/pages/login.dart +++ b/flutter-ory-network/lib/pages/login.dart @@ -1,10 +1,11 @@ // Copyright © 2023 Ory Corp // SPDX-License-Identifier: Apache-2.0 +import 'dart:io'; + import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:ory_client/ory_client.dart'; -import 'package:ory_network_flutter/widgets/nodes/provider.dart'; import '../blocs/auth/auth_bloc.dart'; import '../blocs/login/login_bloc.dart'; @@ -51,8 +52,20 @@ class LoginForm extends StatelessWidget { final nodes = state.loginFlow!.ui.nodes; // get default nodes from all nodes - final defaultNodes = - nodes.where((node) => node.group == UiNodeGroupEnum.default_).toList(); + final defaultNodes = nodes.where((node) { + if (node.group == UiNodeGroupEnum.default_) { + if (node.attributes.oneOf.isType(UiNodeInputAttributes)) { + final attributes = + node.attributes.oneOf.value as UiNodeInputAttributes; + if (attributes.type == UiNodeInputAttributesTypeEnum.hidden) { + return false; + } else { + return true; + } + } + } + return false; + }).toList(); // get password nodes from all nodes final passwordNodes = @@ -68,8 +81,21 @@ class LoginForm extends StatelessWidget { nodes.where((node) => node.group == UiNodeGroupEnum.totp).toList(); // get oidc nodes from all nodes - final oidcNodes = - nodes.where((node) => node.group == UiNodeGroupEnum.oidc).toList(); + final oidcNodes = nodes.where((node) { + if (node.group == UiNodeGroupEnum.oidc) { + if (node.attributes.oneOf.isType(UiNodeInputAttributes)) { + final attributes = + node.attributes.oneOf.value as UiNodeInputAttributes; + final isAndroid = Platform.isAndroid; + if (attributes.value != null && + attributes.value!.asString + .contains(isAndroid ? 'android' : 'ios')) { + return true; + } + } + } + return false; + }).toList(); return Stack(children: [ Padding( @@ -109,14 +135,8 @@ class LoginForm extends StatelessWidget { ), if (oidcNodes.isNotEmpty) - Padding( - padding: const EdgeInsets.only(top: 32.0), - child: Column( - mainAxisSize: MainAxisSize.max, - children: oidcNodes - .map((node) => SocialProviderInput(node: node)) - .toList()), - ), + buildGroup(context, UiNodeGroupEnum.oidc, oidcNodes, + _onInputChange, _onInputSubmit), if (defaultNodes.isNotEmpty) buildGroup(context, UiNodeGroupEnum.default_, defaultNodes, _onInputChange, _onInputSubmit), @@ -129,6 +149,7 @@ class LoginForm extends StatelessWidget { if (totpNodes.isNotEmpty) buildGroup(context, UiNodeGroupEnum.totp, totpNodes, _onInputChange, _onInputSubmit), + const SizedBox( height: 32, ), diff --git a/flutter-ory-network/lib/pages/registration.dart b/flutter-ory-network/lib/pages/registration.dart index 71726573..1139a055 100644 --- a/flutter-ory-network/lib/pages/registration.dart +++ b/flutter-ory-network/lib/pages/registration.dart @@ -1,6 +1,8 @@ // Copyright © 2023 Ory Corp // SPDX-License-Identifier: Apache-2.0 +import 'dart:io' show Platform; + import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:ory_client/ory_client.dart'; @@ -9,7 +11,7 @@ import '../blocs/auth/auth_bloc.dart'; import '../blocs/registration/registration_bloc.dart'; import '../repositories/auth.dart'; import '../widgets/helpers.dart'; -import '../widgets/nodes/provider.dart'; + import 'login.dart'; class RegistrationPage extends StatelessWidget { @@ -57,8 +59,20 @@ class RegistrationFormState extends State { final nodes = state.registrationFlow!.ui.nodes; // get default nodes from all nodes - final defaultNodes = - nodes.where((node) => node.group == UiNodeGroupEnum.default_).toList(); + final defaultNodes = nodes.where((node) { + if (node.group == UiNodeGroupEnum.default_) { + if (node.attributes.oneOf.isType(UiNodeInputAttributes)) { + final attributes = + node.attributes.oneOf.value as UiNodeInputAttributes; + if (attributes.type == UiNodeInputAttributesTypeEnum.hidden) { + return false; + } else { + return true; + } + } + } + return false; + }).toList(); // get password nodes from all nodes final passwordNodes = @@ -74,8 +88,21 @@ class RegistrationFormState extends State { nodes.where((node) => node.group == UiNodeGroupEnum.totp).toList(); // get oidc nodes from all nodes - final oidcNodes = - nodes.where((node) => node.group == UiNodeGroupEnum.oidc).toList(); + final oidcNodes = nodes.where((node) { + if (node.group == UiNodeGroupEnum.oidc) { + if (node.attributes.oneOf.isType(UiNodeInputAttributes)) { + final attributes = + node.attributes.oneOf.value as UiNodeInputAttributes; + final isAndroid = Platform.isAndroid; + if (attributes.value != null && + attributes.value!.asString + .contains(isAndroid ? 'android' : 'ios')) { + return true; + } + } + } + return false; + }).toList(); return Stack(children: [ Padding( @@ -103,14 +130,8 @@ class RegistrationFormState extends State { style: TextStyle( fontWeight: FontWeight.w600, height: 1.5, fontSize: 18)), if (oidcNodes.isNotEmpty) - Padding( - padding: const EdgeInsets.only(top: 32.0), - child: Column( - mainAxisSize: MainAxisSize.max, - children: oidcNodes - .map((node) => SocialProviderInput(node: node)) - .toList()), - ), + buildGroup(context, UiNodeGroupEnum.oidc, + oidcNodes, _onInputChange, _onInputSubmit), if (defaultNodes.isNotEmpty) buildGroup(context, UiNodeGroupEnum.default_, defaultNodes, _onInputChange, _onInputSubmit), diff --git a/flutter-ory-network/lib/repositories/auth.dart b/flutter-ory-network/lib/repositories/auth.dart index a482b949..95229570 100644 --- a/flutter-ory-network/lib/repositories/auth.dart +++ b/flutter-ory-network/lib/repositories/auth.dart @@ -1,12 +1,16 @@ // Copyright © 2023 Ory Corp // SPDX-License-Identifier: Apache-2.0 +import 'dart:convert'; + import 'package:built_collection/built_collection.dart'; import 'package:built_value/json_object.dart'; import 'package:deep_collection/deep_collection.dart'; +import 'package:google_sign_in/google_sign_in.dart'; import 'package:one_of/one_of.dart'; import 'package:ory_client/ory_client.dart'; import 'package:collection/collection.dart'; +import 'package:ory_network_flutter/services/exceptions.dart'; import '../services/auth.dart'; @@ -14,8 +18,9 @@ enum AuthStatus { uninitialized, authenticated, unauthenticated, aal2Requested } class AuthRepository { final AuthService service; + final GoogleSignIn googleSignIn; - AuthRepository({required this.service}); + AuthRepository({required this.googleSignIn, required this.service}); Future getCurrentSessionInformation() async { final session = await service.getCurrentSessionInformation(); @@ -46,19 +51,30 @@ class AuthRepository { await service.logout(); } - Future updateRegistrationFlow( + Future updateRegistrationFlow( {required String flowId, required UiNodeGroupEnum group, required String name, required String value, required List nodes}) async { // create request body - final body = _createRequestBody( + var body = _createRequestBody( group: group, name: name, value: value, nodes: nodes); - // submit registration - final registration = await service.updateRegistrationFlow( + // user used social sign in + if (group == UiNodeGroupEnum.oidc) { + if (value.contains('google')) { + final idToken = await _loginWithGoogle(); + // get nonce value from jwt + final jwtParts = idToken.split('.'); + final jwt = getMapFromJWT(jwtParts[1]); + // add id token and nonce to body + body.addAll({'id_token': idToken, 'nonce': jwt['nonce']}); + } + } + // submit registration and retrieve session + final session = await service.updateRegistrationFlow( flowId: flowId, group: group, value: body); - return registration; + return session; } Future updateLoginFlow( @@ -68,14 +84,46 @@ class AuthRepository { required String value, required List nodes}) async { // create request body - final body = _createRequestBody( + var body = _createRequestBody( group: group, name: name, value: value, nodes: nodes); + // user used social sign in + if (group == UiNodeGroupEnum.oidc) { + if (value.contains('google')) { + final idToken = await _loginWithGoogle(); + // get nonce value from id token + final jwtParts = idToken.split('.'); + final jwt = getMapFromJWT(jwtParts[1]); + // add id token and nonce to body + body.addAll({'id_token': idToken, 'nonce': jwt['nonce']}); + } + } // submit login final login = await service.updateLoginFlow( flowId: flowId, group: group, value: body); return login; } + Map getMapFromJWT(String splittedToken) { + String normalizedSource = base64Url.normalize(splittedToken); + return jsonDecode(utf8.decode(base64Url.decode(normalizedSource))); + } + + Future _loginWithGoogle() async { + try { + final GoogleSignInAccount? account = await googleSignIn.signIn(); + + final GoogleSignInAuthentication? googleAuth = + await account?.authentication; + if (googleAuth?.idToken != null) { + return googleAuth!.idToken!; + } else { + throw const CustomException.unknown(); + } + } catch (e) { + throw const CustomException.unknown(); + } + } + Map _createRequestBody( {required UiNodeGroupEnum group, required String name, diff --git a/flutter-ory-network/lib/services/auth.dart b/flutter-ory-network/lib/services/auth.dart index 2917ed5a..1cbed928 100644 --- a/flutter-ory-network/lib/services/auth.dart +++ b/flutter-ory-network/lib/services/auth.dart @@ -102,6 +102,13 @@ class AuthService { value: UpdateLoginFlowWithTotpMethod((b) => b ..method = group.name ..totpCode = value['totp_code'])); + case UiNodeGroupEnum.oidc: + oneOf = OneOf.fromValue1( + value: UpdateLoginFlowWithOidcMethod((b) => b + ..method = group.name + ..provider = value['provider'] + ..idToken = value['id_token'] + ..idTokenNonce = value['nonce'])); // if method is not implemented, throw exception default: @@ -180,7 +187,7 @@ class AuthService { } /// Update registration flow with [flowId] for [group] with [value] - Future updateRegistrationFlow( + Future updateRegistrationFlow( {required String flowId, required UiNodeGroupEnum group, required Map value}) async { @@ -195,6 +202,13 @@ class AuthService { ..method = group.name ..traits = JsonObject(value['traits']) ..password = value['password'])); + case UiNodeGroupEnum.oidc: + oneOf = OneOf.fromValue1( + value: UpdateRegistrationFlowWithOidcMethod((b) => b + ..method = group.name + ..provider = value['provider'] + ..idToken = value['id_token'] + ..idTokenNonce = value['nonce'])); // if method is not implemented, throw exception default: @@ -209,12 +223,24 @@ class AuthService { if (response.data?.session != null) { // save session token after successful login await storage.persistToken(response.data!.sessionToken!); - return response.data!; + return response.data!.session!; } else { throw const CustomException.unknown(); } + // dio throws exception 200 when logging in with google } on DioException catch (e) { - if (e.response?.statusCode == 400) { + // user tried to register with social sign in using already existing account + if (e.response?.statusCode == 200) { + final successfulLogin = standardSerializers.deserializeWith( + SuccessfulNativeLogin.serializer, e.response?.data); + if (successfulLogin?.session != null) { + // save session token after successful login + await storage.persistToken(successfulLogin!.sessionToken!); + return successfulLogin.session; + } else { + throw const CustomException.unknown(); + } + } else if (e.response?.statusCode == 400) { final registrationFlow = standardSerializers.deserializeWith( RegistrationFlow.serializer, e.response?.data); if (registrationFlow != null) { @@ -230,6 +256,8 @@ class AuthService { } else { throw _handleUnknownException(e.response?.data); } + } catch (e) { + throw CustomException.unknown(); } } diff --git a/flutter-ory-network/lib/widgets/helpers.dart b/flutter-ory-network/lib/widgets/helpers.dart index 6cb8675f..9eba3b7d 100644 --- a/flutter-ory-network/lib/widgets/helpers.dart +++ b/flutter-ory-network/lib/widgets/helpers.dart @@ -40,30 +40,27 @@ buildGroup( void Function(BuildContext, UiNodeGroupEnum, String, String) onInputSubmit) { final formKey = GlobalKey(); - return Padding( - padding: const EdgeInsets.only(bottom: 0), - child: Form( - key: formKey, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ListView.builder( - physics: const NeverScrollableScrollPhysics(), - shrinkWrap: true, - itemBuilder: ((BuildContext context, index) { - final attributes = nodes[index].attributes.oneOf; - if (attributes.isType(UiNodeInputAttributes)) { - return buildInputNode(context, formKey, nodes[index], - onInputChange, onInputSubmit); - } else if (attributes.isType(UiNodeTextAttributes)) { - return TextNode(node: nodes[index]); - } else { - return Container(); - } - }), - itemCount: nodes.length), - ], - ), + return Form( + key: formKey, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + ListView.builder( + physics: const NeverScrollableScrollPhysics(), + shrinkWrap: true, + itemBuilder: ((BuildContext context, index) { + final attributes = nodes[index].attributes.oneOf; + if (attributes.isType(UiNodeInputAttributes)) { + return buildInputNode(context, formKey, nodes[index], + onInputChange, onInputSubmit); + } else if (attributes.isType(UiNodeTextAttributes)) { + return TextNode(node: nodes[index]); + } else { + return Container(); + } + }), + itemCount: nodes.length), + ], ), ); } @@ -76,6 +73,7 @@ buildInputNode( void Function(BuildContext, UiNodeGroupEnum, String, String) onInputSubmit) { final inputNode = node.attributes.oneOf.value as UiNodeInputAttributes; + switch (inputNode.type) { case UiNodeInputAttributesTypeEnum.submit: return InputSubmitNode( @@ -89,9 +87,6 @@ buildInputNode( formKey: formKey, onChange: onInputChange, onSubmit: onInputSubmit); - case UiNodeInputAttributesTypeEnum.hidden: - return const SizedBox.shrink(); - default: return InputNode(node: node, onChange: onInputChange); } diff --git a/flutter-ory-network/lib/widgets/nodes/input_submit.dart b/flutter-ory-network/lib/widgets/nodes/input_submit.dart index c2fed9c8..1cbe71dc 100644 --- a/flutter-ory-network/lib/widgets/nodes/input_submit.dart +++ b/flutter-ory-network/lib/widgets/nodes/input_submit.dart @@ -19,38 +19,60 @@ class InputSubmitNode extends StatelessWidget { @override Widget build(BuildContext context) { - return Column( - children: [ - SizedBox( - width: double.infinity, - child: FilledButton( - // validate input fields that belong to this buttons group - onPressed: () { - if (formKey.currentState!.validate()) { - final attributes = - node.attributes.oneOf.value as UiNodeInputAttributes; - final type = attributes.type; - // if attribute type is a button with value 'false', set its value to true on submit - if (type == UiNodeInputAttributesTypeEnum.button || - type == UiNodeInputAttributesTypeEnum.submit && - attributes.value?.value == 'false') { - final nodeName = attributes.name; - - onChange(context, 'true', nodeName); - } - onSubmit( - context, - node.group, - attributes.name, - attributes.value!.isString - ? attributes.value!.asString - : ''); - } - }, - child: Text(node.meta.label?.text ?? ''), - ), - ), - ], + final value = node.attributes.oneOf.isType(UiNodeInputAttributes) + ? (node.attributes.oneOf.value as UiNodeInputAttributes).value?.asString + : null; + final provider = _getProviderName(value); + return SizedBox( + width: double.infinity, + child: node.group == UiNodeGroupEnum.oidc + ? SizedBox( + width: double.infinity, + child: OutlinedButton.icon( + icon: Image.asset( + 'assets/images/flows-auth-buttons-social-$provider.png'), + label: Text(node.meta.label?.text ?? ''), + onPressed: () => onPressed(context), + ), + ) + : FilledButton( + // validate input fields that belong to this buttons group + onPressed: () => onPressed(context), + child: Text(node.meta.label?.text ?? ''), + ), ); } + + _getProviderName(String? value) { + if (value == null) { + return ''; + } else if (value.contains('google')) { + return 'google'; + } else if (value.contains('apple')) { + return 'apple'; + } else if (value.contains('linkedin')) { + return 'linkedin'; + } else if (value.contains('github')) { + return 'github'; + } else { + return ''; + } + } + + onPressed(BuildContext context) { + if (formKey.currentState!.validate()) { + final attributes = node.attributes.oneOf.value as UiNodeInputAttributes; + final type = attributes.type; + // if attribute type is a button with value 'false', set its value to true on submit + if (type == UiNodeInputAttributesTypeEnum.button || + type == UiNodeInputAttributesTypeEnum.submit && + attributes.value?.value == 'false') { + final nodeName = attributes.name; + + onChange(context, 'true', nodeName); + } + onSubmit(context, node.group, attributes.name, + attributes.value!.isString ? attributes.value!.asString : ''); + } + } } diff --git a/flutter-ory-network/lib/widgets/nodes/provider.dart b/flutter-ory-network/lib/widgets/nodes/provider.dart deleted file mode 100644 index d389084d..00000000 --- a/flutter-ory-network/lib/widgets/nodes/provider.dart +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright © 2023 Ory Corp -// SPDX-License-Identifier: Apache-2.0 - -import 'package:flutter/material.dart'; -import 'package:ory_client/ory_client.dart'; - -class SocialProviderInput extends StatelessWidget { - final UiNode node; - - const SocialProviderInput({super.key, required this.node}); - @override - Widget build(BuildContext context) { - final provider = node.attributes.oneOf.isType(UiNodeInputAttributes) - ? (node.attributes.oneOf.value as UiNodeInputAttributes).value?.asString - : null; - return SizedBox( - width: double.infinity, - child: OutlinedButton.icon( - icon: Image.asset( - 'assets/images/flows-auth-buttons-social-$provider.png'), - label: Text(node.meta.label?.text ?? ''), - onPressed: () { - //TODO - }, - ), - ); - } -} diff --git a/flutter-ory-network/lib/widgets/ory_theme.dart b/flutter-ory-network/lib/widgets/ory_theme.dart index e9bf9778..aad872f5 100644 --- a/flutter-ory-network/lib/widgets/ory_theme.dart +++ b/flutter-ory-network/lib/widgets/ory_theme.dart @@ -71,6 +71,16 @@ class OryTheme { RoundedRectangleBorder( borderRadius: BorderRadius.circular(4.0))))); + static final OutlinedButtonThemeData outlinedButtonThemeData = + OutlinedButtonThemeData( + style: ButtonStyle( + backgroundColor: MaterialStateProperty.all(Colors.white), + padding: MaterialStateProperty.all( + const EdgeInsets.symmetric(vertical: 12, horizontal: 16)), + shape: MaterialStateProperty.all( + RoundedRectangleBorder( + borderRadius: BorderRadius.circular(4.0))))); + static final ThemeData defaultTheme = ThemeData( primarySwatch: primaryColorSwatch, fontFamily: GoogleFonts.getFont('Inter').fontFamily, @@ -78,6 +88,7 @@ class OryTheme { appBarTheme: const AppBarTheme(iconTheme: IconThemeData(color: primaryColor)), filledButtonTheme: filledButtonThemeData, + outlinedButtonTheme: outlinedButtonThemeData, inputDecorationTheme: textFieldTheme, ); } diff --git a/flutter-ory-network/lib/widgets/social_provider_box.dart b/flutter-ory-network/lib/widgets/social_provider_box.dart deleted file mode 100644 index 5c1e7884..00000000 --- a/flutter-ory-network/lib/widgets/social_provider_box.dart +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright © 2023 Ory Corp -// SPDX-License-Identifier: Apache-2.0 - -import 'package:flutter/material.dart'; - -class SocialProviderBox extends StatelessWidget { - final SocialProvider provider; - - const SocialProviderBox({super.key, required this.provider}); - @override - Widget build(BuildContext context) { - return Expanded( - child: AspectRatio( - aspectRatio: 1.6, - child: Container( - padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 16), - decoration: BoxDecoration( - border: Border.all(width: 1, color: const Color(0xFFE2E8F0))), - child: // get icon from assets depending on provider - Image.asset( - 'assets/images/flows-auth-buttons-social-${provider.name}.png'), - ), - ), - ); - } -} - -enum SocialProvider { google, github, apple, linkedin } diff --git a/flutter-ory-network/pubspec.lock b/flutter-ory-network/pubspec.lock index 9ce2d1f5..9b2f5851 100644 --- a/flutter-ory-network/pubspec.lock +++ b/flutter-ory-network/pubspec.lock @@ -169,14 +169,6 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.3" - cupertino_icons: - dependency: "direct main" - description: - name: cupertino_icons - sha256: e35129dc44c9118cee2a5603506d823bab99c68393879edb440e0090d07586be - url: "https://pub.dev" - source: hosted - version: "1.0.5" dart_style: dependency: transitive description: @@ -384,6 +376,54 @@ packages: url: "https://pub.dev" source: hosted version: "5.1.0" + google_identity_services_web: + dependency: transitive + description: + name: google_identity_services_web + sha256: "554748f2478619076128152c58905620d10f9c7fc270ff1d3a9675f9f53838ed" + url: "https://pub.dev" + source: hosted + version: "0.2.1+1" + google_sign_in: + dependency: "direct main" + description: + name: google_sign_in + sha256: f45038d27bcad37498f282295ae97eece23c9349fc16649154067b87b9f1fd03 + url: "https://pub.dev" + source: hosted + version: "6.1.5" + google_sign_in_android: + dependency: transitive + description: + name: google_sign_in_android + sha256: "6031f59074a337fdd81be821aba84cee3a41338c6e958499a5cd34d3e1db80ef" + url: "https://pub.dev" + source: hosted + version: "6.1.20" + google_sign_in_ios: + dependency: transitive + description: + name: google_sign_in_ios + sha256: "8edfde9698b5951f3d02632eceb39cc283865c3cff0b03216bf951089f10345b" + url: "https://pub.dev" + source: hosted + version: "5.6.3" + google_sign_in_platform_interface: + dependency: transitive + description: + name: google_sign_in_platform_interface + sha256: "35ceee5f0eadc1c07b0b4af7553246e315c901facbb7d3dadf734ba2693ceec4" + url: "https://pub.dev" + source: hosted + version: "2.4.2" + google_sign_in_web: + dependency: transitive + description: + name: google_sign_in_web + sha256: "939e9172a378ec4eaeb7f71eeddac9b55ebd0e8546d336daec476a68e5279766" + url: "https://pub.dev" + source: hosted + version: "0.12.0+5" graphs: dependency: transitive description: @@ -814,5 +854,5 @@ packages: source: hosted version: "3.1.2" sdks: - dart: ">=3.1.0-185.0.dev <4.0.0" - flutter: ">=3.3.0" + dart: ">=3.1.0 <4.0.0" + flutter: ">=3.13.0" diff --git a/flutter-ory-network/pubspec.yaml b/flutter-ory-network/pubspec.yaml index dcc0062a..99e576ed 100644 --- a/flutter-ory-network/pubspec.yaml +++ b/flutter-ory-network/pubspec.yaml @@ -30,10 +30,7 @@ environment: dependencies: flutter: sdk: flutter - - # The following adds the Cupertino Icons font to your application. - # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^1.0.2 + bloc: ^8.1.2 flutter_bloc: ^8.1.3 dio: ^5.3.2 @@ -50,6 +47,7 @@ dependencies: deep_collection: ^1.0.2 collection: ^1.17.2 built_collection: ^5.1.1 + google_sign_in: ^6.1.5 dev_dependencies: flutter_test: From 1cfd74edb30efeb40f888831e69a79170994fbad Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Wed, 11 Oct 2023 17:02:02 +0200 Subject: [PATCH 29/57] chore: add ios url scheme and web clientId --- flutter-ory-network/ios/Runner/Info.plist | 12 ++++++++++++ flutter-ory-network/lib/main.dart | 4 +++- flutter-ory-network/lib/services/auth.dart | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/flutter-ory-network/ios/Runner/Info.plist b/flutter-ory-network/ios/Runner/Info.plist index f3fb7dd7..19d1ca6a 100644 --- a/flutter-ory-network/ios/Runner/Info.plist +++ b/flutter-ory-network/ios/Runner/Info.plist @@ -22,6 +22,18 @@ $(FLUTTER_BUILD_NAME) CFBundleSignature ???? + CFBundleURLTypes + + + CFBundleTypeRole + Editor + CFBundleURLSchemes + + + IOS_URL_SCHEME + + + CFBundleVersion $(FLUTTER_BUILD_NUMBER) LSRequiresIPhoneOS diff --git a/flutter-ory-network/lib/main.dart b/flutter-ory-network/lib/main.dart index 29635869..6f40f846 100644 --- a/flutter-ory-network/lib/main.dart +++ b/flutter-ory-network/lib/main.dart @@ -40,7 +40,9 @@ Future main() async { final authService = AuthService(dio); final googleSignIn = GoogleSignIn( - clientId: Platform.isAndroid ? null : dotenv.get('IOS_CLIENT_ID'), + clientId: Platform.isAndroid + ? dotenv.get('WEB_CLIENT_ID') + : dotenv.get('IOS_CLIENT_ID'), scopes: [ 'email', 'profile', diff --git a/flutter-ory-network/lib/services/auth.dart b/flutter-ory-network/lib/services/auth.dart index 1cbed928..b2ccbf9b 100644 --- a/flutter-ory-network/lib/services/auth.dart +++ b/flutter-ory-network/lib/services/auth.dart @@ -257,7 +257,7 @@ class AuthService { throw _handleUnknownException(e.response?.data); } } catch (e) { - throw CustomException.unknown(); + throw const CustomException.unknown(); } } From 1203c2198e8157d3d90ca5ab0cdf8c345a882f7a Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Mon, 16 Oct 2023 16:32:18 +0200 Subject: [PATCH 30/57] chore: fix typo and rename variables --- flutter-ory-network/README.md | 2 +- flutter-ory-network/lib/pages/login.dart | 12 ++++++------ flutter-ory-network/lib/pages/registration.dart | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/flutter-ory-network/README.md b/flutter-ory-network/README.md index 77a624b1..bfe62108 100644 --- a/flutter-ory-network/README.md +++ b/flutter-ory-network/README.md @@ -22,7 +22,7 @@ ORY_BASE_URL=https://{your-project-slug}.projects.oryapis.com ### Run locally -1. Install dependancies from `pubspec.yaml` +1. Install dependencies from `pubspec.yaml` ```console flutter pub get diff --git a/flutter-ory-network/lib/pages/login.dart b/flutter-ory-network/lib/pages/login.dart index 99ed0bb2..6227a3a7 100644 --- a/flutter-ory-network/lib/pages/login.dart +++ b/flutter-ory-network/lib/pages/login.dart @@ -143,8 +143,8 @@ class LoginForm extends StatelessWidget { bloc: (context).read(), selector: (AuthState state) => state.status == AuthStatus.aal2Requested, - builder: (BuildContext context, bool booleanState) { - if (booleanState) { + builder: (BuildContext context, bool isAal2Requested) { + if (isAal2Requested) { return Row( mainAxisAlignment: MainAxisAlignment.start, children: [ @@ -178,8 +178,8 @@ class LoginForm extends StatelessWidget { BlocSelector( bloc: (context).read(), selector: (LoginState state) => state.isLoading, - builder: (BuildContext context, bool booleanState) { - if (booleanState) { + builder: (BuildContext context, bool isLoading) { + if (isLoading) { return const Opacity( opacity: 0.8, child: ModalBarrier(dismissible: false, color: Colors.white30), @@ -191,8 +191,8 @@ class LoginForm extends StatelessWidget { BlocSelector( bloc: (context).read(), selector: (LoginState state) => state.isLoading, - builder: (BuildContext context, bool booleanState) { - if (booleanState) { + builder: (BuildContext context, bool isLoading) { + if (isLoading) { return const Center( child: CircularProgressIndicator(), ); diff --git a/flutter-ory-network/lib/pages/registration.dart b/flutter-ory-network/lib/pages/registration.dart index 71726573..adedae70 100644 --- a/flutter-ory-network/lib/pages/registration.dart +++ b/flutter-ory-network/lib/pages/registration.dart @@ -157,8 +157,8 @@ class RegistrationFormState extends State { BlocSelector( bloc: (context).read(), selector: (RegistrationState state) => state.isLoading, - builder: (BuildContext context, bool booleanState) { - if (booleanState) { + builder: (BuildContext context, bool isLoading) { + if (isLoading) { return const Opacity( opacity: 0.8, child: ModalBarrier(dismissible: false, color: Colors.white30), @@ -170,8 +170,8 @@ class RegistrationFormState extends State { BlocSelector( bloc: (context).read(), selector: (RegistrationState state) => state.isLoading, - builder: (BuildContext context, bool booleanState) { - if (booleanState) { + builder: (BuildContext context, bool isLoading) { + if (isLoading) { return const Center( child: CircularProgressIndicator(), ); From ce12100a7ddaa455f1ad00b4c72b0dbd8fcc2e7f Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Mon, 16 Oct 2023 16:41:39 +0200 Subject: [PATCH 31/57] chore: separate exception handlings --- .../lib/blocs/auth/auth_bloc.dart | 42 +++++++--------- .../lib/blocs/login/login_bloc.dart | 48 ++++++++----------- .../blocs/registration/registration_bloc.dart | 40 +++++++--------- 3 files changed, 55 insertions(+), 75 deletions(-) diff --git a/flutter-ory-network/lib/blocs/auth/auth_bloc.dart b/flutter-ory-network/lib/blocs/auth/auth_bloc.dart index 2fcdd21c..6d49f030 100644 --- a/flutter-ory-network/lib/blocs/auth/auth_bloc.dart +++ b/flutter-ory-network/lib/blocs/auth/auth_bloc.dart @@ -37,20 +37,16 @@ class AuthBloc extends Bloc { isLoading: false, status: AuthStatus.authenticated, session: session)); - } on CustomException catch (e) { - if (e case UnauthorizedException _) { - emit(state.copyWith( - status: AuthStatus.unauthenticated, - session: null, - isLoading: false)); - } else if (e case TwoFactorAuthRequiredException _) { - emit(state.copyWith( - isLoading: false, session: null, status: AuthStatus.aal2Requested)); - } else if (e case UnknownException _) { - emit(state.copyWith(isLoading: false, errorMessage: e.message)); - } else { - emit(state.copyWith(isLoading: false)); - } + } on UnauthorizedException catch (_) { + emit(state.copyWith( + status: AuthStatus.unauthenticated, session: null, isLoading: false)); + } on TwoFactorAuthRequiredException catch (_) { + emit(state.copyWith( + isLoading: false, session: null, status: AuthStatus.aal2Requested)); + } on UnknownException catch (e) { + emit(state.copyWith(isLoading: false, errorMessage: e.message)); + } catch (_) { + emit(state.copyWith(isLoading: false)); } } @@ -62,17 +58,13 @@ class AuthBloc extends Bloc { emit(state.copyWith( isLoading: false, status: AuthStatus.unauthenticated, session: null)); - } on CustomException catch (e) { - if (e case UnauthorizedException _) { - emit(state.copyWith( - isLoading: false, - status: AuthStatus.unauthenticated, - session: null)); - } else if (e case UnknownException _) { - emit(state.copyWith(isLoading: false, errorMessage: e.message)); - } else { - emit(state.copyWith(isLoading: false)); - } + } on UnauthorizedException catch (_) { + emit(state.copyWith( + status: AuthStatus.unauthenticated, session: null, isLoading: false)); + } on UnknownException catch (e) { + emit(state.copyWith(isLoading: false, errorMessage: e.message)); + } catch (_) { + emit(state.copyWith(isLoading: false)); } } } diff --git a/flutter-ory-network/lib/blocs/login/login_bloc.dart b/flutter-ory-network/lib/blocs/login/login_bloc.dart index d8c1584b..103b5744 100644 --- a/flutter-ory-network/lib/blocs/login/login_bloc.dart +++ b/flutter-ory-network/lib/blocs/login/login_bloc.dart @@ -18,7 +18,7 @@ class LoginBloc extends Bloc { final AuthBloc authBloc; final AuthRepository repository; LoginBloc({required this.authBloc, required this.repository}) - : super(LoginState()) { + : super(const LoginState()) { on(_onCreateLoginFlow); on(_onGetLoginFlow); on(_onChangeNodeValue); @@ -33,12 +33,10 @@ class LoginBloc extends Bloc { final loginFlow = await repository.createLoginFlow(aal: event.aal); emit(state.copyWith(loginFlow: loginFlow, isLoading: false)); - } on CustomException catch (e) { - if (e case UnknownException _) { - emit(state.copyWith(isLoading: false, message: e.message)); - } else { - emit(state.copyWith(isLoading: false)); - } + } on UnknownException catch (e) { + emit(state.copyWith(isLoading: false, message: e.message)); + } catch (_) { + emit(state.copyWith(isLoading: false)); } } @@ -48,12 +46,10 @@ class LoginBloc extends Bloc { emit(state.copyWith(isLoading: true, message: null)); final loginFlow = await repository.getLoginFlow(flowId: event.flowId); emit(state.copyWith(loginFlow: loginFlow, isLoading: false)); - } on CustomException catch (e) { - if (e case UnknownException _) { - emit(state.copyWith(isLoading: false, message: e.message)); - } else { - emit(state.copyWith(isLoading: false)); - } + } on UnknownException catch (e) { + emit(state.copyWith(isLoading: false, message: e.message)); + } catch (_) { + emit(state.copyWith(isLoading: false)); } } @@ -75,20 +71,18 @@ class LoginBloc extends Bloc { value: event.value, nodes: state.loginFlow!.ui.nodes.toList()); authBloc.add(ChangeAuthStatus(status: AuthStatus.authenticated)); - } on CustomException catch (e) { - if (e case BadRequestException _) { - emit(state.copyWith(loginFlow: e.flow, isLoading: false)); - } else if (e case UnauthorizedException _) { - authBloc.add(ChangeAuthStatus(status: AuthStatus.unauthenticated)); - } else if (e case FlowExpiredException _) { - add(GetLoginFlow(flowId: e.flowId)); - } else if (e case TwoFactorAuthRequiredException _) { - authBloc.add(ChangeAuthStatus(status: AuthStatus.aal2Requested)); - } else if (e case UnknownException _) { - emit(state.copyWith(isLoading: false, message: e.message)); - } else { - emit(state.copyWith(isLoading: false)); - } + } on BadRequestException catch (e) { + emit(state.copyWith(loginFlow: e.flow, isLoading: false)); + } on UnauthorizedException catch (_) { + authBloc.add(ChangeAuthStatus(status: AuthStatus.unauthenticated)); + } on FlowExpiredException catch (e) { + add(GetLoginFlow(flowId: e.flowId)); + } on TwoFactorAuthRequiredException catch (_) { + authBloc.add(ChangeAuthStatus(status: AuthStatus.aal2Requested)); + } on UnknownException catch (e) { + emit(state.copyWith(isLoading: false, message: e.message)); + } catch (_) { + emit(state.copyWith(isLoading: false)); } } } diff --git a/flutter-ory-network/lib/blocs/registration/registration_bloc.dart b/flutter-ory-network/lib/blocs/registration/registration_bloc.dart index d4f42249..cc861f0f 100644 --- a/flutter-ory-network/lib/blocs/registration/registration_bloc.dart +++ b/flutter-ory-network/lib/blocs/registration/registration_bloc.dart @@ -18,7 +18,7 @@ class RegistrationBloc extends Bloc { final AuthBloc authBloc; final AuthRepository repository; RegistrationBloc({required this.authBloc, required this.repository}) - : super(RegistrationState()) { + : super(const RegistrationState()) { on(_onCreateRegistrationFlow); on(_onGetRegistrationFlow); on(_onChangeNodeValue); @@ -31,12 +31,10 @@ class RegistrationBloc extends Bloc { emit(state.copyWith(isLoading: true, message: null)); final flow = await repository.createRegistrationFlow(); emit(state.copyWith(registrationFlow: flow, isLoading: false)); - } on CustomException catch (e) { - if (e case UnknownException _) { - emit(state.copyWith(isLoading: false, message: e.message)); - } else { - emit(state.copyWith(isLoading: false)); - } + } on UnknownException catch (e) { + emit(state.copyWith(isLoading: false, message: e.message)); + } catch (_) { + emit(state.copyWith(isLoading: false)); } } @@ -46,12 +44,10 @@ class RegistrationBloc extends Bloc { emit(state.copyWith(isLoading: true, message: null)); final flow = await repository.getRegistrationFlow(flowId: event.flowId); emit(state.copyWith(registrationFlow: flow, isLoading: false)); - } on CustomException catch (e) { - if (e case UnknownException _) { - emit(state.copyWith(isLoading: false, message: e.message)); - } else { - emit(state.copyWith(isLoading: false)); - } + } on UnknownException catch (e) { + emit(state.copyWith(isLoading: false, message: e.message)); + } catch (_) { + emit(state.copyWith(isLoading: false)); } } @@ -79,16 +75,14 @@ class RegistrationBloc extends Bloc { nodes: state.registrationFlow!.ui.nodes.toList()); authBloc.add(ChangeAuthStatus(status: AuthStatus.authenticated)); } - } on CustomException catch (e) { - if (e case BadRequestException _) { - emit(state.copyWith(registrationFlow: e.flow, isLoading: false)); - } else if (e case FlowExpiredException _) { - add(GetRegistrationFlow(flowId: e.flowId)); - } else if (e case UnknownException _) { - emit(state.copyWith(isLoading: false, message: e.message)); - } else { - emit(state.copyWith(isLoading: false)); - } + } on BadRequestException catch (e) { + emit(state.copyWith(registrationFlow: e.flow, isLoading: false)); + } on FlowExpiredException catch (e) { + add(GetRegistrationFlow(flowId: e.flowId)); + } on UnknownException catch (e) { + emit(state.copyWith(isLoading: false, message: e.message)); + } catch (_) { + emit(state.copyWith(isLoading: false)); } } } From 3719abdeb78962faac5a838b418dde402299b619 Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Mon, 16 Oct 2023 17:00:39 +0200 Subject: [PATCH 32/57] fix: prevent null exception --- flutter-ory-network/lib/main.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flutter-ory-network/lib/main.dart b/flutter-ory-network/lib/main.dart index ea93cfc1..2ece2dfd 100644 --- a/flutter-ory-network/lib/main.dart +++ b/flutter-ory-network/lib/main.dart @@ -29,8 +29,8 @@ Future main() async { 'Accept': 'application/json', }, validateStatus: (status) { - // here we prevent the request from throwing an error when the status code is less than 500 (internal server error) - return status! < 500; + // prevent the request from throwing null exception + return status != null && status < 500 ? true : false; }, ); final dio = DioForNative(options); From 78bc88e62d946518c0b0fc748b9762a2dbb44af5 Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Wed, 18 Oct 2023 15:03:06 +0200 Subject: [PATCH 33/57] chore: delete unused assets & widgets --- .../assets/images/1.5x/github.png | Bin 929 -> 0 bytes .../assets/images/1.5x/linkedin.png | Bin 851 -> 0 bytes .../assets/images/2.0x/github.png | Bin 1240 -> 0 bytes .../assets/images/2.0x/linkedin.png | Bin 1026 -> 0 bytes .../assets/images/3.0x/github.png | Bin 1715 -> 0 bytes .../assets/images/3.0x/linkedin.png | Bin 1409 -> 0 bytes .../assets/images/4.0x/github.png | Bin 2371 -> 0 bytes .../assets/images/4.0x/linkedin.png | Bin 1744 -> 0 bytes flutter-ory-network/assets/images/github.png | Bin 635 -> 0 bytes .../assets/images/linkedin.png | Bin 610 -> 0 bytes .../lib/widgets/social_provider_box.dart | 27 ------------------ 11 files changed, 27 deletions(-) delete mode 100644 flutter-ory-network/assets/images/1.5x/github.png delete mode 100644 flutter-ory-network/assets/images/1.5x/linkedin.png delete mode 100644 flutter-ory-network/assets/images/2.0x/github.png delete mode 100644 flutter-ory-network/assets/images/2.0x/linkedin.png delete mode 100644 flutter-ory-network/assets/images/3.0x/github.png delete mode 100644 flutter-ory-network/assets/images/3.0x/linkedin.png delete mode 100644 flutter-ory-network/assets/images/4.0x/github.png delete mode 100644 flutter-ory-network/assets/images/4.0x/linkedin.png delete mode 100644 flutter-ory-network/assets/images/github.png delete mode 100644 flutter-ory-network/assets/images/linkedin.png delete mode 100644 flutter-ory-network/lib/widgets/social_provider_box.dart diff --git a/flutter-ory-network/assets/images/1.5x/github.png b/flutter-ory-network/assets/images/1.5x/github.png deleted file mode 100644 index d627e36cca70e6c2c168789db93803b156d5c44c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 929 zcmV;S177@zP)ZU3xRe1<`Ga)I-4b~fw6M!d(o#| z2|wHE*##WfAud8y@>TJ(J-z*P&rJUS{6pY0%64ue4`h`BqD@510}y{evKh&S>OjE- zJX&<6SC>ibB_g+TZyX}pV=^a+J`vW0NLQs__u!%AcCMHw>KrE}jX42$D6;Itgq@g3 zzO=eg7Q#AY6E@5S4{>43vgJQ87g#!fI(Pg*SO}uk1N;L?; zg~vZU>3MP}hg4prp7a~FJN-h1v*dU@80mjDem|VPYfV_jjfL*&RHmVhX?0?`bidWb&%nAf{>{ zTKmw;aK3g}+)FeT$L#W8q4#=)Sb3GQE_rfM{nm>dXrBjxwFg#5ov8zsHFfdfh)?8o zb7x#`tnE=ZQVyW29N=>gClWr>1L(n2{hd#X=l4d%v^KG^CN&+Qdf&-+oI7lLclhN1?4w_i)=mbtOkN}AgCdGk-v?i7fC+K8!d9@lH z7_3n?jU6!2!KQ(PnAmDtwKOSr=XbBZw(s?*?X%VRTkhWX?%x0IyYIet2k;Le;1Kts z?#dLpT(X{7zK{e5G%PN~a^L9$A#hoM7(MaVU#qtDc6Gw!*%7#UY6zTw0qPl;kKVQ0JM4xc zqqnfRyV|zoJAuN(<>&jacc59g5HlD<;m<*T+_YI{E@zFSoUnJ4GdCGM+6zwMKrOSk z1YG}IbWJ5b+;gSRMryW+vwb%>WEJCJG z`;)SOHlqQFRO(j3&}JBAF|%$-GMeBKPPA!zhs{I^gS5o2TQl-2 zko8|4Eh_svCh0^$m^0Z#d`YVn$_CMc69kJhif;J2%VCCZb`zzyAl?tcy~0=HKz z9rStac4d-D-SNi=@N3W-;;ftbK{=>8xbSDA5j;Q&X9q}}z)CvkpE>A#-SnElQwP_$ z7c;{OG$l%6xO2SqgiGxj#D%9E%D@9a$CZ}`0!j4HBe`AWvNiHe$JZqnUM6r)l&(u5 dYZU(%`~=AD7Lyx9QSJZ$002ovPDHLkV1geziNgQ@ diff --git a/flutter-ory-network/assets/images/2.0x/github.png b/flutter-ory-network/assets/images/2.0x/github.png deleted file mode 100644 index 33e2fce264f9624a7c7c4805ddb3183912928cca..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1240 zcmV;}1Sk86P)<_U0~Ae$#h`~-m`r!`No$&nM@+umXdOt?iH zs8R@3On^Y*A2mIe?Z}cwQWBY}d{wrjnV!)%Jw2`N2Dk!1$N{Ehn{d*%0muqX?|?y4 zzVEc*61Xr)v-C#=h#nA7jUTNPafb+70=ymhVQ(AGiF1=QOXWHdJYua?;9_tPu_4_~ zGwXoNB+WavO`^AT336d%CTlP*cI&B%(nMm>{5gbEHROm(&7ne7FB0&Y4zW4r(>xi|o((e|K z*djK5e*x?ZmGdT&qZOG*V6q>zM??5Di&g2qZk^3>ugU)NQDh-=xDxyT%!LKKZ{0P1 zp%obj^e*@;-M0>39-4Q`HvDqzNXLmadY=sMOyO%gB152vL`YH}*wsNbmZVv-EuwBc z?nNHLr?_@`$SXdCLtdI7fB61D%YB_N2Nw>^2uhov-Eu#Oo{(hL`hzhT zXno*}VW~d>R{+^a8bblkF#N3Q;i$iWCehJJ5{L&dD;SXA zn|)3JKWQYSo$6bvoPGWvqK$;km+EpxvTL*;akAb&kTXC5h6-ptyKh#<&k<)X-8Y*M++vk6 z(rJyOB$Myg!}7e!owNvv&FC3q21>3OHG(a3v0@&ql7QXuGi!4LZ(O^pDrZQ8b;6O~ zR7sbI4M>A0S|A9rfEUyVFFH1*J^6O%s??H){55JSP~R(Xw)nL0>ur}cy2HOCMB_P! zc<#y9kBI?Dq4*o8t(cm_^R7IR2YZ__?RrG)ldvhoJg>Cvz&W7OUm~%eB%|_hE?(7R z`yllN(?mzZSaT}B=G+=#J*_g9Mly+@LTVJG4ib{_5T*jtVNzygPR<7UC`uj1B!Zbp zD##D7wpAj=&OCZb$xA0{L<4HpUW+RlRkp#$X~Q!Iz3RkCcdw2fuEdf}!hmFioZG2t ziv}TFqGryuAaCA=8(&&UC62TdR^H2z5_*gAkoy?5U4=qo(l-UefB}m_d7$9I^<-=!XotWeoBLDYJXK%rL)@N$$waM62Y-#kb^mt* zaH2PLnSzqy#W2W4SHXy{CF7oJ)>mXf;0*Y$yK>2Lp|`w*dWx)oKod`)id!#SgM}$R zXn{xw$HFn49=eL;n`8hS*5H}rbuit19oC=4V78}K)FmM{CIl7P*qci5U7T=w*4K6c zZk%fp<;bZ980v_CEYNc_JxWC(h)4#?0JzX_wANCuud4x>FrwPVwuuxciHEBheg6$s zH#S8%x0Q#d(_cU)PS&)UfuAN1z=Ne9If#zUimAqO?r$Ds!-#T^|7qYV(&t3MjnY!s zEGRVndlOdq50?SfP5y8zFaFGl_V!4#=!5UhFRzRDJw*bbp?b`^#ZMOe;)2%)`r0nS zWBxOF_-X;BKBmQH!d-8IZD{GCn0;f7&n?3fpJigGN6uzPZtGaKtVzRA!ypN?o|8bN z`{sG*yw>8`U#0n|S+KHI&GXus5XpfyQ?;l3Nv0q zl~EYA7|M2bXP(Ek#@=bo?F^q^&cNud`r`L(H-qQ$=)14Q_N86!$7KA&3N#$61yA@? zXOeNv+T;L+N(K?RO~v7OV diff --git a/flutter-ory-network/assets/images/3.0x/github.png b/flutter-ory-network/assets/images/3.0x/github.png deleted file mode 100644 index 88a204303b909301a076ea3e5623f4a4ce1160d2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1715 zcmV;k22A;hP)fLYcdz&ELJs66ZP|_$d~Du9pj%KJJj9vRtWqyQ4p>W$P0gbx{KVFv zSnyJ6topvz^u$Rx3L!o_ck!Tc`1V=i7%;$v#Vh~7c($r%>6jkM zwi@?cs-&&?3a?{&o;C(crR)Cxe?98CPW*1bP4=E{!0_;p=(hj*Rqq^@W6_x-(ZEC- zLx5ZF_IGbb&!>_$QR_4{5_9YOq|H=DJhAS*wkWW+nP*RqTCTkHkQNUNQaqe)s1n|X2|(z0 zpjiSTXla4=N*a|7X7H1|up+=~+bDSu0Q@BH5z@!D$;GTv6GK?T@P3dmM$&+`$;APX z2NMOUjF^C83>i*tR%Ap-vff`c@{?A8HcS+_D3}4gqzR2Gh3vrFFi|kRA5Z>7)-;%w zN9{tRt0)M5H5(WTHEO**FhzmURTNwfc1^}%Td2LHC6!}5Q&4nCN28q}Fw;7s7xLCi zx;gEEA^7RumB;Kqzen0V%rNpDE_z?%<8 z*plUO73Na+iR6HzF~do>KDX4?>h)pP1vvJY^bS9@foUVDHkvlW$hL_%x`bm~4o#&_ z4iuYo6N{}|J%VYc?Yer9ieLvaAlzDpFZr@SYTatxL24(0RP)Po3oi5N7qTJLs4 zW!>naInaGc56eqFL;3JJtPUEKxr-o4;@uO69-CxV(dH=V(YyLy<}E0Pq&4BBR*h~~*cjk>@@80P>*KyHAIb z#SPJ}Xd_)#oJtQ^*fCgg!z6r=yLcbQ=JFe=I_m$}`HpV^p8-)rpKx!55kLR{002ov JPDHLkV1fpiE_na| diff --git a/flutter-ory-network/assets/images/3.0x/linkedin.png b/flutter-ory-network/assets/images/3.0x/linkedin.png deleted file mode 100644 index 5c377f759501798d6f0586d42d7cd055dac982aa..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1409 zcmV-{1%CR8P)>`(=!FhmMb14@-4FeIX-Qpwg# zB~zpeyVmckyw-3Z)*h!c+q9}Sx^D|AG9?=m3RTV7+KG}}-gR)`9(9gj7 zxjF9e6`g=A5rQQK{QT-6BU_DzsEX*$bBifvunQhUy22Y_fvDu_#_aJdDnvy^AD&E) z0_q7aHigQg@dlWAFgLV-GO37Yi)T})K3cO%kKLag(GU;?WzsQ~`HmX&c1VH+iD!oL zPsh~a1q39pr@PLj#gC`?$9~j~Kwb|d`nllS{9^*O$G33bq9Z2Q#Fubiq9ZEU#ItbE zq9ZQYL~CuK@40noJZJB`p^9voK(t9b&Z$4RRr2I%(dl4NTu=7S>utC=)Q5rIPOLu6 z;nvDJ&SzE-I)t3r{AOt0_Ap%V8rI$IhmbvU6m18Z_Smo8S;eXAO9&aAhk1`(n7f9z z*RVeMQE!Q0!RPOHb9)RS6MvFZZ96ZHqJ@`vPiqt&kO_Wq>|is(hB7uGMtQPhj-sD? z*%R09tV!*wo4LaET?@8y%7o1BDB4ed`nP)<`1+^6_t=Es;VZwRW-y$VdD}LTdCl0x zh=i8pS^Uw{e4!y~4Ihq<6%R)pGK@Mbn#wOClxr2vGPr`H{B6N%i`iH9H&kpp*o48p zt`hs&=2QG?@%Uih5ni|SXU&`-65?R83&|sGg>wqbsJXRrAO2yV@s}~HMH=3(O{V(| zD0krl5!QFV`nbd{#GJbR@>HUZs9Vh8sSL(H?8Ve4Z`tgx@)&v3T9kg1@JcK|<}R1-f4NskR^r+fAw15zwzA|Xyxra2 zg1^=uc{(rG(rzt>-YK?2B)s#B%P-1nT)4>Cneh(_qqbs_Z?t+At$?)cEk}ea+{-e4 zT$bOaS{)Le8+M{YSyQrN=e4cvywq;q!-F8t-h_FJn>vAKC(T;6^R$LWg0O$BMMYkR zYG@$DN~pCg6>X@)DxvF_M%+DJfZ!$?0I|4VY_k>3uj?!# zz$zb_mILpY+$go#VB{ex*LR2$XtG6oThaPFpED-7jCzKVtjz2<*&m-s$CW1KAv_>@ zNMg35n6;wmBUwLMU^k!U^}I5uN_%w4f}ZONN5_{p=XpGwM%_UcHs^-MWJg>F9MquG zsJCmIU&~ZAX6z2TiY{E+jLx8r;PU}9y2CoP=k@9K$xNE;&MZb8`>;0gJf3EGV@!k% zqKr#en|Ky2!kjAfSY(9@!TkT}mE3+|66Y(K3gzq7EJBlqJ_PSp4?v`Z`xGn)G)E?W zAR?i@^66DW_}o&IHdwwS6u&JdqY$JNJ3F-1x7KmV@R z#~FCNKNUuA?7V^{y@~0drDELIAGL9O(c600d`2O+f$vv5yPgwI`BKK==f}krT-$06qccMo)xO+Y{!-4KXEw zLuU{(wBrzF`a(%?oLH~Bk`)qLf1l-84*AW*Qe;Vf{(1N9pSLT36P(}##{>u&fo_y_ z*xsoCY6kuLy#z^H)WO*v1X}zmrL;5+-hwSn7||^8_o@j4!oWy$NNensiH$2n*gPFF zpeLZ97n8owW5AIWQ8z6(A{;r1dg+IXl=gM{=nBb`4*i3Pi1z?SYW*hkNJwOSU?0LvG zEYc7naB%Ym^y^kmtVYs18WKSfz^WW|xQr`+34+uPkb4jBgWfENin@?!B495$JiPS(5 z_V(@_IDP~&bh#&==;vo+e>Wu(T_ZB|b6^;l$VYmqY{WS^u{xifoW72Lcj4=Ri3Kt? zmMOwcO5`WHzl{BR%+q;Jc?O7e$Vk*eE|^7|8vVVdzY_iBBQ7b)Jv$%eM<$ZQbCWY~ zASNM*_LQi((EE7cJD(x2vX~*AhnJ~BCD~K%{LGebkloc zeeFj0JulEbHFlAV!`Gr|qck-sH%Xj@m&x9Tq;L(TZd3M~&Nb-&^5G0oTk`VTcZFq% zh|iDxog~?TkL#;9{oad3;U?|WrRYXEoI8)VmG?Ya50+qP9bA>LeNIp(7Mz=eUg-fC>)hwvA2fh># z6AI%bY2=m40|+G1vB-*{osD=AG7i1y#KvkrcB6U7^9Yf|-3llI)08s(yIk(&<`3I&HoJ6d9_5VM5xB~5eEq&Oo28ofHJ;FvcDvr zZdE`DC^WFMFNJNebI;KgD1gG&%ig{}iKs>*8KRZA(L!dhb9#wh75v&SR@#?DiW8Nr z>o7^72S=>|9)JqCAPWKwOY-@UGA6a5lR^)usfDPrPAMfmh<$@! zyCpG)Y7VHD8(5KLuV9r1HFwA07aw(2jC+SB=@5jZ$q2`Ge9zl%5|!iLJqv~yw4Cu4 z5<>=9XH-<@VTZ(XkQ~7-juLXYp(bB~lJKNVV(TlFU`Uh1p-IFBL23MsG4&xaxs~c+ z5Lto&$q_`NBINKEH~Fob!~sQV7H_*rY=M%~ECDXVu%aElCBKf=#=(!o-4P4apsW6( zgN6j{3aG*2mo5_9A&^@1Av51G&;_?hOR>^7m#gt6U`|9;mA=}!5|(w?c2m732yKfu zz9b?lXJquwm9Q*>r4SJoK@GwyNe+-itpUzP9?4=;qf{ zvogAr%_mt`Yp(c}y_HPwXTyC-bd8JJyx4}podsDX@=Wo<)!s{{TQzSl(Ah?*DXoGX zK$(bqo;B5G3Dh*L3O%56DI_>zX*%Y+*F>w~s5aLi4jBAna-C&LMf-;qwgL;^8;yFS zaHd$G-HQJiC}^SnAt0EVTjp2_xRuk0m>(}L7S2p;Ha=|}=`sQb0QqltvZd*2P?0*3vGno%+Oku2lHZ-@B6GbovqZ;lLws1AIYMsPz}7vL zWmkQ2`i3p>BKdq3=ySVAXIBIxMixgd1>X>s&P~odhdk&mfz#D?DlN%6uHi@v%1z~U zYm_TAmK2_75)P-%$Y+d^%|NXCh4JFIv>Vh2PIF)i<{0NC2m58T*nKDHeb0aNy_T!a#iG}UCIO9}$E>2_X z!?Q4>!A|e!SP^!%HoB6#jqQzkLx=|S0r~L>UT{idiNd0J@E7s!uUN)T`Qbto1J|O6 z^y20G_<7OzRQLTwIZSJadMc!*L?RP7m&EZ;WLP@E^96-@5EAAYu6i}O8PPgi7{C=( z$azO5cM7tB!~`;WB9Y+`IXNxD=EydT?kWk#lJ?C(P6BqdAiuSsGFPWk0l_{bS#9pL zw_ph2TH)0>Rb!W08Hv*q;yR^Ck`Dt03g`I_5l;z-LW)&ktlF=g@Q6F_A>&fX>WkRA z6!w6OxJZ>m4~}}1RMPsjT7O7?VY!bXSe;9&Wuz}8GI)TZ{%VnvnAsqcAFu(-q$yK= z&vEDleIwCB6q#OmS~}>ym#emT4GUXSaY8tyPlY3f`&^t{h3j_6!Q@4sn`w4pIUy-( pS5Vq70COv8OWg@haDrov{{bV<>Bygv5c&WB002ovPDHLkV1nRkWmf1~2)EP)@~0drDELIAGL9O(c600d`2O+f$vv5yPFn-oBmbeEWOv z_j|wh2S`atNl8fw5r&ws;*)b3&W#M?*dzc=KxE7>1hjb-8H%z@XJ9&GC~%IO>SA^L z-m#qpG>C?Ys14*>A3Rihq!8U@!CDavDJmP60*|(+#`xVYaz)gMx{KIxzicltOOzD`a31 zn?S%hd{FFF*1vVq4$XS4f@{aYN=IMHn9N)tt*i zxKn6m7&|yUm>qUi6&@+~gIC}&klwnc1BZ9KfeovcVc82Uxb)Y3oc?{%e8m)9_K%%z z`o~4^h#bmEQx~2DJp9%=^vT!rkf`)pz5FG7`SYKMA+0oQmG9e~DthV@pEhIBi>7cob( z>l@u!qJljL!2TZ#I6qM-)I}+7_qUgk1O%%cfIG&C<+$($LV!Y=jjt{>KVQB5z}7tB&! zO!Zrp9?w)b77D(%u5GV*z4H@yPhOc*b*1TT!>TN#q0QV>>7f?TX?5_EH`h-ifwZ?gxZCe^3CoHKFe-!B_OeH+ggn6 z+k&8|Girr3+V_b}Xow-lvg`5g=GE{DMF(WP!4Td=lykG25JM=P<`=tUh#Pp7L5Hn~ z!eh!S36SF^bMp8{cg39*)WWQ*3LwV>K7Ks$`v_tSbai?T9 z^?H#=5wAMrALm9ZwFrAU!b!v;V#uV6A>3pL!@L?4tp$m+#M0wgGz^A{RG3q+-LP#9 zafJ!yO+*=N-$aT9@rSjWoh74hDXnK#psGKX%> zB@&L_Idv}oBYk;ZKAfYCGvip`$fi81 z*I29QYQ(~XaTE(2g|U&E-@yg|NmJ+0Yp z>l?jMahyQ2Bdu_Hu={npDxR`93g>&Vz>oVj5MHj+QQ0J<ePkhsfJEr$;N8aXT^wpRdzxAc zejKWtBc~}|{<1L=)Z==gVIo>-?agNt+I+->Mq5A3oeN9~TkT+8(0n*6NbzsddLcu` mdiqc0)+jEP)200009a7bBm000XU z000XU0RWnu7ytkO0drDELIAGL9O(c600d`2O+f$vv5yPHiC`2gH92{2?!@(dV)?*0Gyz30?G-JoPgdS=?OX&3Sx&@fYO}> zi$-n7ug~+BnQ4ybSBMnAuOw!vQoCC7-?w%-`?Fsr%il04i}r-3T-9I_rz_qS(H7 zV+tkmOGovxQmKnEk>OB%U1(BH0wus#g^d7bu#VVPxtyenvw#PX1d3>X=L!ON1M3LJ z{qoW!H;XA$UD$llq?^)a0eDyXLR44^R!mA8h7bp`=Y=bQPduNS#nq-NZUUX8VZ2d-*L~!3RRxXSL=e9{)R^eq30$+b6PLcxh` diff --git a/flutter-ory-network/assets/images/linkedin.png b/flutter-ory-network/assets/images/linkedin.png deleted file mode 100644 index 1bac417e150462538473dec9f00c4ec0e68101d3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 610 zcmV-o0-gPdP)200009a7bBm000XU z000XU0RWnu7ytkO0drDELIAGL9O(c600d`2O+f$vv5yPP4`@-rdn5EL-CKKVyce27Z7n@Co?5CdRPYis;6*_N zy$MFl#e=das0X9FC@RsN=e*Ud*%;$S@dNwbydU#r-Y`4BJs_?-h@~=-{bT)&Ahb(f zLL$PqEuP03b!TS#r(xD5+R~T(2vCa6$aRjI5W~$OXTVGu){UakFXJPUWCFo3n{?`~ zj9M#Sw0s`_U5B6|R&=y!m8z6JHKW7go~sl zcuIMqL=-Q-pq@XQjANZeI)6+d$Ei>(Z`yeI{9N?^!a6>T<~$!M(SeHR#}I(|)dGG^ zuDJHQt~O3lgLlSd)QQoxs`$B9M{p}ddUvp=*B7ax zFleNOq<^Rv0h4rRz`s>N^iw7+h4vmn1vTonYBdx^VaP}bP_J^RA!qTOKNO-)t4d!L wH5^NM?%;B93!9s@$-@#gJ87#*AH7%30F++55#!XMfB*mh07*qoM6N<$g1cxB3jhEB diff --git a/flutter-ory-network/lib/widgets/social_provider_box.dart b/flutter-ory-network/lib/widgets/social_provider_box.dart deleted file mode 100644 index 1e48428a..00000000 --- a/flutter-ory-network/lib/widgets/social_provider_box.dart +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright © 2023 Ory Corp -// SPDX-License-Identifier: Apache-2.0 - -import 'package:flutter/material.dart'; - -class SocialProviderBox extends StatelessWidget { - final SocialProvider provider; - - const SocialProviderBox({super.key, required this.provider}); - @override - Widget build(BuildContext context) { - return Expanded( - child: AspectRatio( - aspectRatio: 1.6, - child: Container( - padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 16), - decoration: BoxDecoration( - border: Border.all(width: 1, color: const Color(0xFFE2E8F0))), - child: // get icon from assets depending on provider - Image.asset('assets/images/${provider.name}.png'), - ), - ), - ); - } -} - -enum SocialProvider { google, github, apple, linkedin } From 84afc46b7480af6f7186470fbe7c5c0c0cf65207 Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Wed, 18 Oct 2023 15:38:58 +0200 Subject: [PATCH 34/57] fix: remove pop & show provider buttons correctly --- .../lib/blocs/login/login_bloc.dart | 3 - flutter-ory-network/lib/pages/home.dart | 18 -- flutter-ory-network/lib/pages/login.dart | 261 +++++++++--------- .../lib/pages/registration.dart | 14 - .../lib/widgets/nodes/provider.dart | 15 +- 5 files changed, 138 insertions(+), 173 deletions(-) diff --git a/flutter-ory-network/lib/blocs/login/login_bloc.dart b/flutter-ory-network/lib/blocs/login/login_bloc.dart index fc0b3995..437d1e2f 100644 --- a/flutter-ory-network/lib/blocs/login/login_bloc.dart +++ b/flutter-ory-network/lib/blocs/login/login_bloc.dart @@ -31,9 +31,6 @@ class LoginBloc extends Bloc { emit(state.copyWith(isLoading: true, message: null)); final loginFlow = await repository.createLoginFlow( aal: event.aal, refresh: event.refresh); - if (event.aal == 'aal2') { - authBloc.add(ChangeAuthStatus(status: AuthStatus.aal2Requested)); - } emit(state.copyWith(loginFlow: loginFlow, isLoading: false)); } on UnknownException catch (e) { emit(state.copyWith(isLoading: false, message: e.message)); diff --git a/flutter-ory-network/lib/pages/home.dart b/flutter-ory-network/lib/pages/home.dart index 99b5fd63..b21bda33 100644 --- a/flutter-ory-network/lib/pages/home.dart +++ b/flutter-ory-network/lib/pages/home.dart @@ -106,24 +106,6 @@ class _HomePageState extends State { fontWeight: FontWeight.w500, color: Colors.white)), ), ), - const Padding( - padding: EdgeInsets.only(top: 15.0), - child: - Text('You are signed in using an ORY Kratos Session Token:'), - ), - Padding( - padding: const EdgeInsets.only(top: 15.0), - child: Container( - padding: const EdgeInsets.all(35), - width: double.infinity, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(8), - color: Colors.grey[600]), - child: Text(session.id, - style: const TextStyle( - fontWeight: FontWeight.w500, color: Colors.white)), - ), - ), const Padding( padding: EdgeInsets.only(top: 15.0), child: Text( diff --git a/flutter-ory-network/lib/pages/login.dart b/flutter-ory-network/lib/pages/login.dart index 7430be7f..e0db3f53 100644 --- a/flutter-ory-network/lib/pages/login.dart +++ b/flutter-ory-network/lib/pages/login.dart @@ -104,150 +104,137 @@ class LoginForm extends StatelessWidget { final oidcNodes = nodes.where((node) => node.group == UiNodeGroupEnum.oidc).toList(); - return BlocListener( - bloc: (context).read(), - // listen when the user was already authenticated and session was updated - listenWhen: (previous, current) => - previous.session != null && - current.session != null && - previous.session != current.session, - listener: (context, state) { - // pop with true to trigger change password flow - Navigator.of(context).pop(true); - }, - child: Stack(children: [ - Padding( - padding: const EdgeInsets.symmetric(horizontal: 32), - child: SingleChildScrollView( - // do not show scrolling indicator - physics: const BouncingScrollPhysics(), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - if (!isSessionRefresh) - Padding( - padding: EdgeInsets.only( - //status bar height + padding - top: MediaQuery.of(context).viewPadding.top + 48), - child: Image.asset( - 'assets/images/ory_logo.png', - width: 70, - ), + return Stack(children: [ + Padding( + padding: const EdgeInsets.symmetric(horizontal: 32), + child: SingleChildScrollView( + // do not show scrolling indicator + physics: const BouncingScrollPhysics(), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + if (!isSessionRefresh) + Padding( + padding: EdgeInsets.only( + //status bar height + padding + top: MediaQuery.of(context).viewPadding.top + 48), + child: Image.asset( + 'assets/images/ory_logo.png', + width: 70, ), - const SizedBox( - height: 32, ), - // show header depending on auth state - BlocSelector( + const SizedBox( + height: 32, + ), + // show header depending on auth state + BlocSelector( + bloc: (context).read(), + selector: (AuthState state) => + state.status == AuthStatus.aal2Requested, + builder: (BuildContext context, bool boolState) { + return Text( + boolState ? 'Two-Factor Authentication' : 'Sign in', + style: const TextStyle( + fontWeight: FontWeight.w600, + height: 1.5, + fontSize: 18)); + }, + ), + + if (oidcNodes.isNotEmpty) + Padding( + padding: const EdgeInsets.only(top: 32.0, bottom: 32), + child: Column( + mainAxisSize: MainAxisSize.max, + children: oidcNodes + .map((node) => SocialProviderInput(node: node)) + .toList()), + ), + if (defaultNodes.isNotEmpty) + buildGroup(context, UiNodeGroupEnum.default_, + defaultNodes, _onInputChange, _onInputSubmit), + if (passwordNodes.isNotEmpty) + buildGroup(context, UiNodeGroupEnum.password, + passwordNodes, _onInputChange, _onInputSubmit), + if (lookupSecretNodes.isNotEmpty) + buildGroup(context, UiNodeGroupEnum.lookupSecret, + lookupSecretNodes, _onInputChange, _onInputSubmit), + if (totpNodes.isNotEmpty) + buildGroup(context, UiNodeGroupEnum.totp, totpNodes, + _onInputChange, _onInputSubmit), + const SizedBox( + height: 32, + ), + if (state.loginFlow?.ui.messages != null) + for (var message in state.loginFlow!.ui.messages!) + Text( + message.text, + style: TextStyle(color: getMessageColor(message.type)), + ), + // show logout button if aal2 requested, otherwise sign up + BlocSelector( bloc: (context).read(), selector: (AuthState state) => state.status == AuthStatus.aal2Requested, - builder: (BuildContext context, bool boolState) { - return Text( - boolState ? 'Two-Factor Authentication' : 'Sign in', - style: const TextStyle( - fontWeight: FontWeight.w600, - height: 1.5, - fontSize: 18)); - }, - ), - - if (oidcNodes.isNotEmpty) - Padding( - padding: const EdgeInsets.only(top: 32.0, bottom: 32), - child: Column( - mainAxisSize: MainAxisSize.max, - children: oidcNodes - .map((node) => SocialProviderInput(node: node)) - .toList()), - ), - if (defaultNodes.isNotEmpty) - buildGroup(context, UiNodeGroupEnum.default_, - defaultNodes, _onInputChange, _onInputSubmit), - if (passwordNodes.isNotEmpty) - buildGroup(context, UiNodeGroupEnum.password, - passwordNodes, _onInputChange, _onInputSubmit), - if (lookupSecretNodes.isNotEmpty) - buildGroup(context, UiNodeGroupEnum.lookupSecret, - lookupSecretNodes, _onInputChange, _onInputSubmit), - if (totpNodes.isNotEmpty) - buildGroup(context, UiNodeGroupEnum.totp, - totpNodes, _onInputChange, _onInputSubmit), - const SizedBox( - height: 32, - ), - if (state.loginFlow?.ui.messages != null) - for (var message in state.loginFlow!.ui.messages!) - Text( - message.text, - style: TextStyle(color: getMessageColor(message.type)), - ), - // show logout button if aal2 requested, otherwise sign up - BlocSelector( - bloc: (context).read(), - selector: (AuthState state) => - state.status == AuthStatus.aal2Requested, - builder: (BuildContext context, bool booleanState) { - if (booleanState) { - return Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - const Text('Something\'s not working?'), - TextButton( - onPressed: () => - (context).read().add(LogOut()), - child: const Text('Logout')) - ], - ); - } else { - return Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - const Text('No account?'), - TextButton( - onPressed: () => Navigator.of(context) - .pushReplacement(MaterialPageRoute( - builder: (context) => - const RegistrationPage())), - child: const Text('Sign up')) - ], - ); - } - }), - ], - ), + builder: (BuildContext context, bool booleanState) { + if (booleanState) { + return Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + const Text('Something\'s not working?'), + TextButton( + onPressed: () => + (context).read().add(LogOut()), + child: const Text('Logout')) + ], + ); + } else { + return Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + const Text('No account?'), + TextButton( + onPressed: () => Navigator.of(context) + .pushReplacement(MaterialPageRoute( + builder: (context) => + const RegistrationPage())), + child: const Text('Sign up')) + ], + ); + } + }), + ], ), ), - // build progress indicator when state is loading - BlocSelector( - bloc: (context).read(), - selector: (LoginState state) => state.isLoading, - builder: (BuildContext context, bool booleanState) { - if (booleanState) { - return const Opacity( - opacity: 0.8, - child: - ModalBarrier(dismissible: false, color: Colors.white30), - ); - } else { - return Container(); - } - }), - BlocSelector( - bloc: (context).read(), - selector: (LoginState state) => state.isLoading, - builder: (BuildContext context, bool booleanState) { - if (booleanState) { - return const Center( - child: CircularProgressIndicator(), - ); - } else { - return Container(); - } - }) - ]), - ); + ), + // build progress indicator when state is loading + BlocSelector( + bloc: (context).read(), + selector: (LoginState state) => state.isLoading, + builder: (BuildContext context, bool booleanState) { + if (booleanState) { + return const Opacity( + opacity: 0.8, + child: ModalBarrier(dismissible: false, color: Colors.white30), + ); + } else { + return Container(); + } + }), + BlocSelector( + bloc: (context).read(), + selector: (LoginState state) => state.isLoading, + builder: (BuildContext context, bool booleanState) { + if (booleanState) { + return const Center( + child: CircularProgressIndicator(), + ); + } else { + return Container(); + } + }) + ]); } _onInputChange(BuildContext context, String value, String name) { diff --git a/flutter-ory-network/lib/pages/registration.dart b/flutter-ory-network/lib/pages/registration.dart index adedae70..83d60a0f 100644 --- a/flutter-ory-network/lib/pages/registration.dart +++ b/flutter-ory-network/lib/pages/registration.dart @@ -9,7 +9,6 @@ import '../blocs/auth/auth_bloc.dart'; import '../blocs/registration/registration_bloc.dart'; import '../repositories/auth.dart'; import '../widgets/helpers.dart'; -import '../widgets/nodes/provider.dart'; import 'login.dart'; class RegistrationPage extends StatelessWidget { @@ -73,10 +72,6 @@ class RegistrationFormState extends State { final totpNodes = nodes.where((node) => node.group == UiNodeGroupEnum.totp).toList(); - // get oidc nodes from all nodes - final oidcNodes = - nodes.where((node) => node.group == UiNodeGroupEnum.oidc).toList(); - return Stack(children: [ Padding( padding: const EdgeInsets.symmetric(horizontal: 32), @@ -102,15 +97,6 @@ class RegistrationFormState extends State { const Text('Sign up', style: TextStyle( fontWeight: FontWeight.w600, height: 1.5, fontSize: 18)), - if (oidcNodes.isNotEmpty) - Padding( - padding: const EdgeInsets.only(top: 32.0), - child: Column( - mainAxisSize: MainAxisSize.max, - children: oidcNodes - .map((node) => SocialProviderInput(node: node)) - .toList()), - ), if (defaultNodes.isNotEmpty) buildGroup(context, UiNodeGroupEnum.default_, defaultNodes, _onInputChange, _onInputSubmit), diff --git a/flutter-ory-network/lib/widgets/nodes/provider.dart b/flutter-ory-network/lib/widgets/nodes/provider.dart index c9f81e3b..2ea0fbca 100644 --- a/flutter-ory-network/lib/widgets/nodes/provider.dart +++ b/flutter-ory-network/lib/widgets/nodes/provider.dart @@ -13,10 +13,11 @@ class SocialProviderInput extends StatelessWidget { final provider = node.attributes.oneOf.isType(UiNodeInputAttributes) ? (node.attributes.oneOf.value as UiNodeInputAttributes).value?.asString : null; + final providerName = _getProviderName(provider); return SizedBox( width: double.infinity, child: OutlinedButton.icon( - icon: Image.asset('assets/images/$provider.png'), + icon: Image.asset('assets/images/$providerName.png'), label: Text(node.meta.label?.text ?? ''), onPressed: () { //TODO @@ -24,4 +25,16 @@ class SocialProviderInput extends StatelessWidget { ), ); } + + _getProviderName(String? value) { + if (value == null) { + return ''; + } else if (value.contains('google')) { + return 'google'; + } else if (value.contains('apple')) { + return 'apple'; + } else { + return ''; + } + } } From 8e3b2ecace9126abc890f154646f92bf174c6405 Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Wed, 18 Oct 2023 15:57:37 +0200 Subject: [PATCH 35/57] chore: separate exception handlings --- .../lib/blocs/login/login_bloc.dart | 26 ++++---- .../lib/blocs/settings/settings_bloc.dart | 64 +++++++++---------- 2 files changed, 41 insertions(+), 49 deletions(-) diff --git a/flutter-ory-network/lib/blocs/login/login_bloc.dart b/flutter-ory-network/lib/blocs/login/login_bloc.dart index 437d1e2f..1a9158a4 100644 --- a/flutter-ory-network/lib/blocs/login/login_bloc.dart +++ b/flutter-ory-network/lib/blocs/login/login_bloc.dart @@ -72,20 +72,18 @@ class LoginBloc extends Bloc { authBloc.add( ChangeAuthStatus(status: AuthStatus.authenticated, session: session)); emit(state.copyWith(isLoading: false)); - } on CustomException catch (e) { - if (e case BadRequestException _) { - emit(state.copyWith(loginFlow: e.flow, isLoading: false)); - } else if (e case UnauthorizedException _) { - authBloc.add(ChangeAuthStatus(status: AuthStatus.unauthenticated)); - } else if (e case FlowExpiredException _) { - add(GetLoginFlow(flowId: e.flowId)); - } else if (e case TwoFactorAuthRequiredException _) { - authBloc.add(ChangeAuthStatus(status: AuthStatus.aal2Requested)); - } else if (e case UnknownException _) { - emit(state.copyWith(isLoading: false, message: e.message)); - } else { - emit(state.copyWith(isLoading: false)); - } + } on BadRequestException catch (e) { + emit(state.copyWith(loginFlow: e.flow, isLoading: false)); + } on UnauthorizedException catch (_) { + authBloc.add(ChangeAuthStatus(status: AuthStatus.unauthenticated)); + } on FlowExpiredException catch (e) { + add(GetLoginFlow(flowId: e.flowId)); + } on TwoFactorAuthRequiredException catch (_) { + authBloc.add(ChangeAuthStatus(status: AuthStatus.aal2Requested)); + } on UnknownException catch (e) { + emit(state.copyWith(isLoading: false, message: e.message)); + } catch (_) { + emit(state.copyWith(isLoading: false)); } } } diff --git a/flutter-ory-network/lib/blocs/settings/settings_bloc.dart b/flutter-ory-network/lib/blocs/settings/settings_bloc.dart index b377ad63..f35a421b 100644 --- a/flutter-ory-network/lib/blocs/settings/settings_bloc.dart +++ b/flutter-ory-network/lib/blocs/settings/settings_bloc.dart @@ -22,7 +22,7 @@ class SettingsBloc extends Bloc { final SettingsRepository repository; late SettingsEvent? _previousEvent; SettingsBloc({required this.authBloc, required this.repository}) - : super(SettingsState()) { + : super(const SettingsState()) { on(_onCreateSettingsFlow); on(_onGetSettingsFlow); on(_onChangeNodeValue, transformer: sequential()); @@ -32,8 +32,8 @@ class SettingsBloc extends Bloc { @override void onEvent(SettingsEvent event) { - _previousEvent = event; super.onEvent(event); + _previousEvent = event; } void retry() { @@ -71,21 +71,19 @@ class SettingsBloc extends Bloc { nodes: state.settingsFlow!.ui.nodes.toList()); emit(state.copyWith(isLoading: false, settingsFlow: settings)); } - } on CustomException catch (e) { - if (e case UnauthorizedException _) { - // change auth status as the user is not authenticated - authBloc.add(ChangeAuthStatus(status: AuthStatus.unauthenticated)); - } else if (e case FlowExpiredException _) { - // create new settings flow - add(GetSettingsFlow(flowId: e.flowId)); - } else if (e case SessionRefreshRequiredException _) { - // set session required flag to navigate to login page - emit(state.copyWith(isSessionRefreshRequired: true, isLoading: false)); - } else if (e case UnknownException _) { - emit(state.copyWith(isLoading: false, message: e.message)); - } else { - emit(state.copyWith(isLoading: false)); - } + } on UnauthorizedException catch (_) { + // change auth status as the user is not authenticated + authBloc.add(ChangeAuthStatus(status: AuthStatus.unauthenticated)); + } on FlowExpiredException catch (e) { + // get new settings flow + add(GetSettingsFlow(flowId: e.flowId)); + } on SessionRefreshRequiredException catch (_) { + // set session refresh required flag to navigate to login page + emit(state.copyWith(isSessionRefreshRequired: true, isLoading: false)); + } on UnknownException catch (e) { + emit(state.copyWith(isLoading: false, message: e.message)); + } catch (_) { + emit(state.copyWith(isLoading: false)); } } @@ -97,15 +95,13 @@ class SettingsBloc extends Bloc { final settingsFlow = await repository.createSettingsFlow(); emit(state.copyWith(isLoading: false, settingsFlow: settingsFlow)); - } on CustomException catch (e) { - if (e case UnauthorizedException _) { - // change auth status as the user is not authenticated - authBloc.add(ChangeAuthStatus(status: AuthStatus.unauthenticated)); - } else if (e case UnknownException _) { - emit(state.copyWith(isLoading: false, message: e.message)); - } else { - emit(state.copyWith(isLoading: false)); - } + } on UnauthorizedException catch (_) { + // change auth status as the user is not authenticated + authBloc.add(ChangeAuthStatus(status: AuthStatus.unauthenticated)); + } on UnknownException catch (e) { + emit(state.copyWith(isLoading: false, message: e.message)); + } catch (_) { + emit(state.copyWith(isLoading: false)); } } @@ -116,15 +112,13 @@ class SettingsBloc extends Bloc { final settingsFlow = await repository.getSettingsFlow(flowId: event.flowId); emit(state.copyWith(isLoading: false, settingsFlow: settingsFlow)); - } on CustomException catch (e) { - if (e case UnauthorizedException _) { - // change auth status as the user is not authenticated - authBloc.add(ChangeAuthStatus(status: AuthStatus.unauthenticated)); - } else if (e case UnknownException _) { - emit(state.copyWith(isLoading: false, message: e.message)); - } else { - emit(state.copyWith(isLoading: false)); - } + } on UnauthorizedException catch (_) { + // change auth status as the user is not authenticated + authBloc.add(ChangeAuthStatus(status: AuthStatus.unauthenticated)); + } on UnknownException catch (e) { + emit(state.copyWith(isLoading: false, message: e.message)); + } catch (_) { + emit(state.copyWith(isLoading: false)); } } } From 3d10cc0cb30dd0cfdc5c4188ef34c0e1e34909c4 Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Wed, 18 Oct 2023 15:58:28 +0200 Subject: [PATCH 36/57] chore: format code --- flutter-ory-network/lib/blocs/auth/auth_bloc.freezed.dart | 3 +++ flutter-ory-network/lib/blocs/login/login_bloc.freezed.dart | 3 +++ .../lib/blocs/registration/registration_bloc.freezed.dart | 3 +++ .../lib/blocs/settings/settings_bloc.freezed.dart | 3 +++ flutter-ory-network/lib/services/exceptions.freezed.dart | 3 +++ 5 files changed, 15 insertions(+) diff --git a/flutter-ory-network/lib/blocs/auth/auth_bloc.freezed.dart b/flutter-ory-network/lib/blocs/auth/auth_bloc.freezed.dart index 02acfd8b..c9fb0758 100644 --- a/flutter-ory-network/lib/blocs/auth/auth_bloc.freezed.dart +++ b/flutter-ory-network/lib/blocs/auth/auth_bloc.freezed.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint diff --git a/flutter-ory-network/lib/blocs/login/login_bloc.freezed.dart b/flutter-ory-network/lib/blocs/login/login_bloc.freezed.dart index d09b7b6b..805f0938 100644 --- a/flutter-ory-network/lib/blocs/login/login_bloc.freezed.dart +++ b/flutter-ory-network/lib/blocs/login/login_bloc.freezed.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint diff --git a/flutter-ory-network/lib/blocs/registration/registration_bloc.freezed.dart b/flutter-ory-network/lib/blocs/registration/registration_bloc.freezed.dart index d1f90d5e..f31c6b2d 100644 --- a/flutter-ory-network/lib/blocs/registration/registration_bloc.freezed.dart +++ b/flutter-ory-network/lib/blocs/registration/registration_bloc.freezed.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint diff --git a/flutter-ory-network/lib/blocs/settings/settings_bloc.freezed.dart b/flutter-ory-network/lib/blocs/settings/settings_bloc.freezed.dart index 975beb95..c5a91145 100644 --- a/flutter-ory-network/lib/blocs/settings/settings_bloc.freezed.dart +++ b/flutter-ory-network/lib/blocs/settings/settings_bloc.freezed.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint diff --git a/flutter-ory-network/lib/services/exceptions.freezed.dart b/flutter-ory-network/lib/services/exceptions.freezed.dart index 38a0b791..bfea1eaf 100644 --- a/flutter-ory-network/lib/services/exceptions.freezed.dart +++ b/flutter-ory-network/lib/services/exceptions.freezed.dart @@ -1,3 +1,6 @@ +// Copyright © 2023 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint From 7439b5c77802c66ac84d9ec9430776ba6f0acb54 Mon Sep 17 00:00:00 2001 From: Alexandra Talalaieva <25621530+sashatalalasha@users.noreply.github.com> Date: Fri, 20 Oct 2023 17:05:51 +0200 Subject: [PATCH 37/57] chore: change package name and add auth packages --- flutter-ory-network/android/app/build.gradle | 6 +-- .../android/app/src/main/AndroidManifest.xml | 41 ++++++++++++++++--- .../flutter_ory_network}/MainActivity.kt | 2 +- flutter-ory-network/ios/Podfile.lock | 18 ++++++++ .../ios/Runner.xcodeproj/project.pbxproj | 15 +++++-- flutter-ory-network/ios/Runner/Info.plist | 2 +- .../ios/Runner/Runner.entitlements | 10 +++++ flutter-ory-network/pubspec.lock | 34 ++++++++++++++- flutter-ory-network/pubspec.yaml | 3 ++ 9 files changed, 115 insertions(+), 16 deletions(-) rename flutter-ory-network/android/app/src/main/kotlin/com/{example/kratos_flutter => ory/flutter_ory_network}/MainActivity.kt (70%) create mode 100644 flutter-ory-network/ios/Runner/Runner.entitlements diff --git a/flutter-ory-network/android/app/build.gradle b/flutter-ory-network/android/app/build.gradle index 94108385..262d5d3a 100644 --- a/flutter-ory-network/android/app/build.gradle +++ b/flutter-ory-network/android/app/build.gradle @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - namespace "com.example.ory_network_flutter" + namespace "com.ory.flutter_ory_network" compileSdkVersion flutter.compileSdkVersion ndkVersion flutter.ndkVersion @@ -45,10 +45,10 @@ android { defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). - applicationId "com.example.ory_network_flutter" + applicationId "com.ory.flutter_ory_network" // You can update the following values to match your application needs. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. - minSdkVersion 18 + minSdkVersion 19 targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName diff --git a/flutter-ory-network/android/app/src/main/AndroidManifest.xml b/flutter-ory-network/android/app/src/main/AndroidManifest.xml index 097b25fe..aff483cc 100644 --- a/flutter-ory-network/android/app/src/main/AndroidManifest.xml +++ b/flutter-ory-network/android/app/src/main/AndroidManifest.xml @@ -1,8 +1,10 @@ + + android:icon="@mipmap/ic_launcher" + android:usesCleartextTraffic="true"> + android:name="io.flutter.embedding.android.NormalTheme" + android:resource="@style/NormalTheme" /> + - - + + + + + + + + + + + + + + + + + + + + + + + + +