Skip to content

Commit

Permalink
Add user sign up flow
Browse files Browse the repository at this point in the history
  • Loading branch information
anhappdev committed Aug 8, 2023
1 parent 549f67e commit 507f1b7
Show file tree
Hide file tree
Showing 16 changed files with 566 additions and 200 deletions.
6 changes: 3 additions & 3 deletions flutter/flutter.mk
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ output/flutter/pub/%.stamp: %/pubspec.yaml

.PHONY: flutter/test/unit
flutter/test/unit:
cd flutter && ${_start_args} flutter --no-version-check test test -r expanded
cd flutter_common && ${_start_args} flutter --no-version-check test test -r expanded
cd flutter && ${_start_args} flutter --no-version-check test --no-pub test -r expanded
cd flutter_common && ${_start_args} flutter --no-version-check test --no-pub test -r expanded

ifneq (${FLUTTER_TEST_DEVICE},)
flutter_test_device_arg=--device-id "${FLUTTER_TEST_DEVICE}"
Expand All @@ -186,7 +186,7 @@ flutter_perf_test_arg=--dart-define=enable-perf-test=${PERF_TEST}
.PHONY: flutter/test/integration
flutter/test/integration:
cd flutter && ${_start_args} \
flutter --no-version-check test \
flutter --no-version-check test --no-pub \
integration_test \
${flutter_test_device_arg} \
${flutter_official_build_arg} \
Expand Down
100 changes: 61 additions & 39 deletions flutter/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,63 +1,75 @@
PODS:
- desktop_webview_auth (0.0.1):
- Flutter
- device_info_plus (0.0.1):
- Flutter
- file_picker (0.0.1):
- Flutter
- Firebase/Auth (10.7.0):
- Firebase/Auth (10.12.0):
- Firebase/CoreOnly
- FirebaseAuth (~> 10.12.0)
- Firebase/CoreOnly (10.12.0):
- FirebaseCore (= 10.12.0)
- Firebase/DynamicLinks (10.12.0):
- Firebase/CoreOnly
- FirebaseAuth (~> 10.7.0)
- Firebase/CoreOnly (10.7.0):
- FirebaseCore (= 10.7.0)
- Firebase/Storage (10.7.0):
- FirebaseDynamicLinks (~> 10.12.0)
- Firebase/Storage (10.12.0):
- Firebase/CoreOnly
- FirebaseStorage (~> 10.7.0)
- firebase_auth (4.4.2):
- Firebase/Auth (= 10.7.0)
- FirebaseStorage (~> 10.12.0)
- firebase_auth (4.7.2):
- Firebase/Auth (= 10.12.0)
- firebase_core
- Flutter
- firebase_core (2.10.0):
- Firebase/CoreOnly (= 10.7.0)
- firebase_core (2.15.0):
- Firebase/CoreOnly (= 10.12.0)
- Flutter
- firebase_dynamic_links (5.3.4):
- Firebase/DynamicLinks (= 10.12.0)
- firebase_core
- Flutter
- firebase_storage (11.1.1):
- Firebase/Storage (= 10.7.0)
- firebase_storage (11.2.5):
- Firebase/Storage (= 10.12.0)
- firebase_core
- Flutter
- FirebaseAppCheckInterop (10.9.0)
- FirebaseAuth (10.7.0):
- FirebaseAppCheckInterop (10.13.0)
- FirebaseAuth (10.12.0):
- FirebaseAppCheckInterop (~> 10.0)
- FirebaseCore (~> 10.0)
- GoogleUtilities/AppDelegateSwizzler (~> 7.8)
- GoogleUtilities/Environment (~> 7.8)
- GTMSessionFetcher/Core (< 4.0, >= 2.1)
- FirebaseAuthInterop (10.9.0)
- FirebaseCore (10.7.0):
- FirebaseAuthInterop (10.13.0)
- FirebaseCore (10.12.0):
- FirebaseCoreInternal (~> 10.0)
- GoogleUtilities/Environment (~> 7.8)
- GoogleUtilities/Logger (~> 7.8)
- FirebaseCoreExtension (10.9.0):
- FirebaseCoreExtension (10.13.0):
- FirebaseCore (~> 10.0)
- FirebaseCoreInternal (10.9.0):
- FirebaseCoreInternal (10.13.0):
- "GoogleUtilities/NSData+zlib (~> 7.8)"
- FirebaseStorage (10.7.0):
- FirebaseDynamicLinks (10.12.0):
- FirebaseCore (~> 10.0)
- FirebaseStorage (10.12.0):
- FirebaseAppCheckInterop (~> 10.0)
- FirebaseAuthInterop (~> 10.0)
- FirebaseCore (~> 10.0)
- FirebaseCoreExtension (~> 10.0)
- GTMSessionFetcher/Core (< 4.0, >= 2.1)
- Flutter (1.0.0)
- GoogleUtilities/AppDelegateSwizzler (7.11.1):
- GoogleUtilities/AppDelegateSwizzler (7.11.5):
- GoogleUtilities/Environment
- GoogleUtilities/Logger
- GoogleUtilities/Network
- GoogleUtilities/Environment (7.11.1):
- GoogleUtilities/Environment (7.11.5):
- PromisesObjC (< 3.0, >= 1.2)
- GoogleUtilities/Logger (7.11.1):
- GoogleUtilities/Logger (7.11.5):
- GoogleUtilities/Environment
- GoogleUtilities/Network (7.11.1):
- GoogleUtilities/Network (7.11.5):
- GoogleUtilities/Logger
- "GoogleUtilities/NSData+zlib"
- GoogleUtilities/Reachability
- "GoogleUtilities/NSData+zlib (7.11.1)"
- GoogleUtilities/Reachability (7.11.1):
- "GoogleUtilities/NSData+zlib (7.11.5)"
- GoogleUtilities/Reachability (7.11.5):
- GoogleUtilities/Logger
- GTMSessionFetcher/Core (3.1.1)
- integration_test (0.0.1):
Expand All @@ -69,7 +81,7 @@ PODS:
- FlutterMacOS
- permission_handler_apple (9.1.1):
- Flutter
- PromisesObjC (2.2.0)
- PromisesObjC (2.3.1)
- share (0.0.1):
- Flutter
- share_plus (0.0.1):
Expand All @@ -83,10 +95,12 @@ PODS:
- Flutter

DEPENDENCIES:
- desktop_webview_auth (from `.symlinks/plugins/desktop_webview_auth/ios`)
- device_info_plus (from `.symlinks/plugins/device_info_plus/ios`)
- file_picker (from `.symlinks/plugins/file_picker/ios`)
- firebase_auth (from `.symlinks/plugins/firebase_auth/ios`)
- firebase_core (from `.symlinks/plugins/firebase_core/ios`)
- firebase_dynamic_links (from `.symlinks/plugins/firebase_dynamic_links/ios`)
- firebase_storage (from `.symlinks/plugins/firebase_storage/ios`)
- Flutter (from `Flutter`)
- integration_test (from `.symlinks/plugins/integration_test/ios`)
Expand All @@ -108,12 +122,15 @@ SPEC REPOS:
- FirebaseCore
- FirebaseCoreExtension
- FirebaseCoreInternal
- FirebaseDynamicLinks
- FirebaseStorage
- GoogleUtilities
- GTMSessionFetcher
- PromisesObjC

EXTERNAL SOURCES:
desktop_webview_auth:
:path: ".symlinks/plugins/desktop_webview_auth/ios"
device_info_plus:
:path: ".symlinks/plugins/device_info_plus/ios"
file_picker:
Expand All @@ -122,6 +139,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/firebase_auth/ios"
firebase_core:
:path: ".symlinks/plugins/firebase_core/ios"
firebase_dynamic_links:
:path: ".symlinks/plugins/firebase_dynamic_links/ios"
firebase_storage:
:path: ".symlinks/plugins/firebase_storage/ios"
Flutter:
Expand All @@ -146,27 +165,30 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/wakelock/ios"

SPEC CHECKSUMS:
desktop_webview_auth: d645139460ef203d50bd0cdb33356785dd939cce
device_info_plus: e5c5da33f982a436e103237c0c85f9031142abed
file_picker: ec55172937ec2d774460eb4538bad01df0171d81
Firebase: 0219acf760880eeec8ce479895bd7767466d9f81
firebase_auth: 98778cde4127b34d2d006f8bd049d3a8131f37bd
firebase_core: 18d44f087248303a4a8f05d0099a000c46e3c77a
firebase_storage: caf39437ad5db21ea75fd3dca77a21cd9178d158
FirebaseAppCheckInterop: e69dde5cd51b88ee1b4339d6766b691272256f9b
FirebaseAuth: dd64c01631df724b09f33e584625775c52f7d71f
FirebaseAuthInterop: e53c08e60a02de17d1ab77c5032db8ae22d3a799
FirebaseCore: e317665b9d744727a97e623edbbed009320afdd7
FirebaseCoreExtension: d3e9bba2930a8033042112397cd9f006a1bb203d
FirebaseCoreInternal: d2b4acb827908e72eca47a9fd896767c3053921e
FirebaseStorage: 4841efa304543e1f9e4ca116c559c7a1ea2a9d0f
Firebase: 07150e75d142fb9399f6777fa56a187b17f833a0
firebase_auth: 3f7820b22557dd4a1b024f4d86947d1a0ff8a10f
firebase_core: e477125798fc37cd4ab43ca6a8536bf7e0929c00
firebase_dynamic_links: d85cf455646322fd101c8a5a5942c3d47132fe80
firebase_storage: d5c1b95383db1230d9fed88c76cb257d8d1ec1d6
FirebaseAppCheckInterop: 5e12dc623d443dedffcde9c6f3ed41510125d8ef
FirebaseAuth: a66c1e14ec58f41d154a4b41ce1a23ea00ad4805
FirebaseAuthInterop: 74875bde5d15636522a8fe98beb561df7a54db58
FirebaseCore: f86a1394906b97ac445ae49c92552a9425831bed
FirebaseCoreExtension: ce60f9db46d83944cf444664d6d587474128eeca
FirebaseCoreInternal: b342e37cd4f5b4454ec34308f073420e7920858e
FirebaseDynamicLinks: 1a387da899779e5ef34f4d6f8bdba882f90d0e67
FirebaseStorage: 1d7ca8c8953fc61ccacaa7c612696b5402968a0d
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
GoogleUtilities: 9aa0ad5a7bc171f8bae016300bfcfa3fb8425749
GoogleUtilities: 13e2c67ede716b8741c7989e26893d151b2b2084
GTMSessionFetcher: e8647203b65cee28c5f73d0f473d096653945e72
integration_test: a1e7d09bd98eca2fc37aefd79d4f41ad37bdbbe5
package_info_plus: 6c92f08e1f853dc01228d6f553146438dafcd14e
path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943
permission_handler_apple: e76247795d700c14ea09e3a2d8855d41ee80a2e6
PromisesObjC: 09985d6d70fbe7878040aa746d78236e6946d2ef
PromisesObjC: c50d2056b5253dadbd6c2bea79b0674bd5a52fa4
share: 0b2c3e82132f5888bccca3351c504d0003b3b410
share_plus: 056a1e8ac890df3e33cb503afffaf1e9b4fbae68
shared_preferences_foundation: 5b919d13b803cadd15ed2dc053125c68730e5126
Expand Down
14 changes: 0 additions & 14 deletions flutter/lib/benchmark/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import 'package:mlperfbench/backend/list.dart';
import 'package:mlperfbench/benchmark/benchmark.dart';
import 'package:mlperfbench/board_decoder.dart';
import 'package:mlperfbench/build_info.dart';
import 'package:mlperfbench/firebase/firebase_manager.dart';
import 'package:mlperfbench/resources/config_manager.dart';
import 'package:mlperfbench/resources/resource_manager.dart';
import 'package:mlperfbench/resources/validation_helper.dart';
Expand Down Expand Up @@ -99,10 +98,6 @@ class BenchmarkState extends ChangeNotifier {
);
}

Future<void> uploadLastResult() async {
// TODO: implement uploadLastResult
}

Future<void> clearCache() async {
await resourceManager.cacheManager.deleteLoadedResources([], 0);
notifyListeners();
Expand Down Expand Up @@ -149,15 +144,6 @@ class BenchmarkState extends ChangeNotifier {
),
needToPurgeCache,
);
if (FirebaseManager.enabled) {
await FirebaseManager.instance.initialize();
final excluded = resourceManager.resultManager.results
.map((e) => e.meta.uuid)
.toList();
final onlineResults =
await FirebaseManager.instance.downloadResults(excluded);
resourceManager.resultManager.results.addAll(onlineResults);
}
print('finished loading resources');
error = null;
stackTrace = null;
Expand Down
50 changes: 41 additions & 9 deletions flutter/lib/firebase/firebase_auth_service.dart
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_auth/firebase_auth.dart' hide EmailAuthProvider;
import 'package:firebase_ui_auth/firebase_ui_auth.dart';

class FirebaseAuthService {
static final List<AuthProvider> providers = [
EmailAuthProvider(),
];

late final FirebaseAuth firebaseAuth;

late final User user;
User get currentUser {
final user = FirebaseAuth.instance.currentUser;
if (user == null) {
throw 'FirebaseAuth.instance.currentUser is null';
}
print('currentUser: $user');
return user;
}

signInAnonymously() async {
Future<User> signInAnonymously() async {
final userCredential = await firebaseAuth.signInAnonymously();
user = await _getUserFromCredential(userCredential);
return _getUserFromCredential(userCredential);
}

signIn({required String email, required String password}) async {
Future<User> signIn({required String email, required String password}) async {
try {
UserCredential userCredential =
await firebaseAuth.signInWithEmailAndPassword(
final userCredential = await firebaseAuth.signInWithEmailAndPassword(
email: email,
password: password,
);
user = await _getUserFromCredential(userCredential);
return _getUserFromCredential(userCredential);
} on FirebaseAuthException catch (e) {
if (e.code == 'user-not-found') {
print('No user found for email $email');
Expand All @@ -28,10 +39,31 @@ class FirebaseAuthService {
}
}

Future<User> link(AuthCredential authCred) async {
try {
final userCredential = await currentUser.linkWithCredential(authCred);
print('userCredential: $userCredential');
return _getUserFromCredential(userCredential);
} on FirebaseAuthException catch (e) {
switch (e.code) {
case 'provider-already-linked':
throw ('The provider has already been linked to the user.');
case 'invalid-credential':
throw ("The provider's credential is not valid.");
case 'credential-already-in-use':
throw ('The account corresponding to the credential already exists, '
'or is already linked to a Firebase User.');
// See the API reference for the full list of error codes.
default:
rethrow;
}
}
}

Future<User> _getUserFromCredential(UserCredential? credential) async {
final user = credential?.user;
if (user == null) {
throw Exception('User is not signed in');
throw 'User is not signed in';
}
return user;
}
Expand Down
Loading

0 comments on commit 507f1b7

Please sign in to comment.