v1.1.26+110 android release

This commit is contained in:
Tibor Bossanyi (Freelancer)
2022-11-13 21:26:27 +01:00
parent 6ef311286c
commit cbaa1a5b81
9 changed files with 77 additions and 118 deletions
+32 -69
View File
@@ -3,6 +3,7 @@ import 'dart:convert';
import 'package:crypto/crypto.dart';
import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/service/logging.dart' as logging;
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:sign_in_with_apple/sign_in_with_apple.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
@@ -36,26 +37,7 @@ class FirebaseApi with logging.Logging {
await Firebase.initializeApp();
this.appleSignInAvailable = await SignInWithApple.isAvailable();
/* AwesomeNotifications().initialize(
// set the icon to null if you want to use the default app icon
null,
[
NotificationChannel(
channelKey: 'basic_channel',
channelName: 'Basic notifications',
channelDescription: 'Notification channel for basic tests',
defaultColor: Color(0xFF9D50DD),
ledColor: Colors.white)
]);
AwesomeNotifications().isNotificationAllowed().then((isAllowed) {
if (!isAllowed) {
// Insert here your friendly dialog box before call the request method
// This is very important to not harm the user experience
AwesomeNotifications().requestPermissionToSendNotifications();
}
}); */
await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(
alert: true, // Required to display a heads up notification
@@ -77,6 +59,7 @@ class FirebaseApi with logging.Logging {
});
} catch (e) {
// Set `_error` state to true if Firebase initialization fails
Sentry.captureException(e);
log("Error initializing Firebase");
}
}
@@ -93,6 +76,7 @@ class FirebaseApi with logging.Logging {
userCredential = await FirebaseAuth.instance.signInWithEmailAndPassword(email: email, password: password);
Cache().firebaseUid = userCredential.user!.uid;
} on FirebaseAuthException catch (e) {
Sentry.captureException(e);
if (e.code == 'user-not-found') {
log('No user found for that email.');
rc = SIGN_IN_NOT_FOUND;
@@ -112,6 +96,7 @@ class FirebaseApi with logging.Logging {
userCredential = await FirebaseAuth.instance.createUserWithEmailAndPassword(email: email, password: password);
Cache().firebaseUid = userCredential.user!.uid;
} on FirebaseAuthException catch (e) {
Sentry.captureException(e);
if (e.code == 'weak-password') {
log('The password provided is too weak.');
rc = REGISTER_WEAK_PWD;
@@ -123,6 +108,7 @@ class FirebaseApi with logging.Logging {
}
} catch (e) {
log(e.toString());
Sentry.captureException(e);
throw Exception(e.toString());
}
return rc;
@@ -143,27 +129,7 @@ class FirebaseApi with logging.Logging {
Future<Map<String, dynamic>> signInWithApple() async {
Map<String, dynamic> userData = Map();
/* final apple.AuthorizationResult result = await SignInWithApple.performRequests([
apple.AppleIdRequest(requestedScopes: [apple.Scope.email, apple.Scope.fullName])
]);
switch (result.status) {
case apple.AuthorizationStatus.authorized:
print('User authorized');
break;
case apple.AuthorizationStatus.error:
print('User error');
throw Exception("Apple Sign-In failed");
case apple.AuthorizationStatus.cancelled:
print('User cancelled');
throw Exception("Apple Sign-In cancelled");
}
// Create an `OAuthCredential` from the credential returned by Apple.
final oauthCredential = OAuthProvider("apple.com").credential(
idToken: String.fromCharCodes(result.credential.identityToken),
accessToken: String.fromCharCodes(result.credential.authorizationCode!));
*/
// To prevent replay attacks with the credential returned from Apple, we
// include a nonce in the credential request. When signing in with
// Firebase, the nonce in the id token returned by Apple, is expected to
@@ -185,9 +151,15 @@ class FirebaseApi with logging.Logging {
idToken: appleCredential.identityToken,
rawNonce: rawNonce,
);
// Sign in the user with Firebase. If the nonce we generated earlier does
// not match the nonce in `appleCredential.identityToken`, sign in will fail.
UserCredential userCredential = await FirebaseAuth.instance.signInWithCredential(oauthCredential);
UserCredential? userCredential;
try {
// Sign in the user with Firebase. If the nonce we generated earlier does
// not match the nonce in `appleCredential.identityToken`, sign in will fail.
userCredential = await FirebaseAuth.instance.signInWithCredential(oauthCredential);
} on FirebaseAuthException catch(e) {
Sentry.captureException(e);
throw Exception(e);
}
Cache().firebaseUid = userCredential.user!.uid;
log("userCredential: " + userCredential.toString());
@@ -199,21 +171,7 @@ class FirebaseApi with logging.Logging {
Future<Map<String, dynamic>> registerWithApple() async {
Map<String, dynamic> userData = Map();
/* final apple.AuthorizationResult result = await apple.TheAppleSignIn.performRequests([
apple.AppleIdRequest(requestedScopes: [apple.Scope.email, apple.Scope.fullName])
]);
switch (result.status) {
case apple.AuthorizationStatus.authorized:
print('Apple User authorized');
break;
case apple.AuthorizationStatus.error:
print('Apple User error');
throw Exception("Apple Sign-In failed");
case apple.AuthorizationStatus.cancelled:
print('User cancelled');
throw Exception("Apple Sign-In cancelled");
}
*/
final rawNonce = generateNonce();
final nonce = sha256ofString(rawNonce);
@@ -231,18 +189,19 @@ class FirebaseApi with logging.Logging {
rawNonce: rawNonce,
);
/* // Create an `OAuthCredential` from the credential returned by Apple.
final oauthCredential = OAuthProvider("apple.com").credential(
idToken: String.fromCharCodes(result.credential.identityToken),
accessToken: String.fromCharCodes(result.credential.authorizationCode));
*/
// Sign in the user with Firebase. If the nonce we generated earlier does
// not match the nonce in `appleCredential.identityToken`, sign in will fail.
UserCredential userCredential = await FirebaseAuth.instance.signInWithCredential(oauthCredential);
UserCredential? userCredential;
try {
// Sign in the user with Firebase. If the nonce we generated earlier does
// not match the nonce in `appleCredential.identityToken`, sign in will fail.
userCredential = await FirebaseAuth.instance.signInWithCredential(oauthCredential);
} on FirebaseAuthException catch(e) {
Sentry.captureException(e);
throw Exception(e);
}
Cache().firebaseUid = userCredential.user!.uid;
Cache().firebaseUid = userCredential!.user!.uid;
userData['email'] = userCredential.user!.email;
userData['email'] = userCredential!.user!.email;
return userData;
}
@@ -260,6 +219,7 @@ class FirebaseApi with logging.Logging {
final GoogleSignInAccount? googleUser = await _googleSignIn.signIn();
if (googleUser == null) {
Sentry.captureException(new Exception("Google Sign In failed"));
throw Exception("Google Sign In failed");
}
@@ -296,6 +256,7 @@ class FirebaseApi with logging.Logging {
final GoogleSignInAccount? googleUser = await _googleSignIn.signIn();
if (googleUser == null) {
Sentry.captureException(new Exception("Google Sign In failed"));
throw Exception("Google Sign In failed");
}
@@ -332,6 +293,7 @@ class FirebaseApi with logging.Logging {
Cache().firebaseUid = userData['id'];
log(userData.toString());
} else {
Sentry.captureException(new Exception(result.message));
throw Exception("Facebook login was not successful");
}
@@ -359,6 +321,7 @@ class FirebaseApi with logging.Logging {
Cache().firebaseUid = userCredential.user!.uid;
} else {
Sentry.captureException(new Exception(result.message));
throw Exception("Facebook login was not successful");
}