fix: rework core and entities

This commit is contained in:
Hugo Pointcheval 2022-11-09 01:47:37 -05:00
parent 2f572db4a4
commit d2d8acdafb
Signed by: hugo
GPG Key ID: A9E8E9615379254F
11 changed files with 224 additions and 190 deletions

View File

@ -0,0 +1,19 @@
// Copyright (C) 2022 WYATT GROUP
// Please see the AUTHORS file for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
export 'enums/enums.dart';
export 'exceptions/exceptions.dart';
export 'utils/utils.dart';

View File

@ -0,0 +1,21 @@
// Copyright (C) 2022 WYATT GROUP
// Please see the AUTHORS file for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
enum AuthenticationStatus {
unknown,
authenticated,
unauthenticated,
}

View File

@ -1,20 +1,17 @@
// Copyright (C) 2022 WYATT GROUP // Copyright (C) 2022 WYATT GROUP
// Please see the AUTHORS file for details. // Please see the AUTHORS file for details.
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// any later version. // any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
enum AuthCubitStatus { export 'authentication_status.dart';
started,
stoped,
}

View File

@ -14,13 +14,18 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
abstract class AuthenticationFailureInterface implements Exception { import 'package:wyatt_architecture/wyatt_architecture.dart';
String code;
String message;
AuthenticationFailureInterface(this.code, this.message); part 'exceptions_firebase.dart';
abstract class AuthenticationFailureInterface extends AppException
implements Exception {
String code;
String msg;
AuthenticationFailureInterface(this.code, this.msg);
AuthenticationFailureInterface.fromCode(this.code) AuthenticationFailureInterface.fromCode(this.code)
: message = 'An unknown error occurred.'; : msg = 'An unknown error occurred.';
} }
/// {@template apply_action_code_failure} /// {@template apply_action_code_failure}
@ -29,7 +34,7 @@ abstract class AuthenticationFailureInterface implements Exception {
abstract class ApplyActionCodeFailureInterface abstract class ApplyActionCodeFailureInterface
extends AuthenticationFailureInterface { extends AuthenticationFailureInterface {
/// {@macro apply_action_code_failure} /// {@macro apply_action_code_failure}
ApplyActionCodeFailureInterface(super.code, super.message); ApplyActionCodeFailureInterface(super.code, super.msg);
/// {@macro apply_action_code_failure} /// {@macro apply_action_code_failure}
ApplyActionCodeFailureInterface.fromCode(super.code) : super.fromCode(); ApplyActionCodeFailureInterface.fromCode(super.code) : super.fromCode();
@ -41,7 +46,7 @@ abstract class ApplyActionCodeFailureInterface
abstract class SignUpWithEmailAndPasswordFailureInterface abstract class SignUpWithEmailAndPasswordFailureInterface
extends AuthenticationFailureInterface { extends AuthenticationFailureInterface {
/// {@macro sign_up_with_email_and_password_failure} /// {@macro sign_up_with_email_and_password_failure}
SignUpWithEmailAndPasswordFailureInterface(super.code, super.message); SignUpWithEmailAndPasswordFailureInterface(super.code, super.msg);
/// {@macro sign_up_with_email_and_password_failure} /// {@macro sign_up_with_email_and_password_failure}
SignUpWithEmailAndPasswordFailureInterface.fromCode(super.code) SignUpWithEmailAndPasswordFailureInterface.fromCode(super.code)
@ -54,7 +59,7 @@ abstract class SignUpWithEmailAndPasswordFailureInterface
abstract class FetchSignInMethodsForEmailFailureInterface abstract class FetchSignInMethodsForEmailFailureInterface
extends AuthenticationFailureInterface { extends AuthenticationFailureInterface {
/// {@macro fetch_sign_in_methods_failure} /// {@macro fetch_sign_in_methods_failure}
FetchSignInMethodsForEmailFailureInterface(super.code, super.message); FetchSignInMethodsForEmailFailureInterface(super.code, super.msg);
/// {@macro fetch_sign_in_methods_failure} /// {@macro fetch_sign_in_methods_failure}
FetchSignInMethodsForEmailFailureInterface.fromCode(super.code) FetchSignInMethodsForEmailFailureInterface.fromCode(super.code)
@ -67,7 +72,7 @@ abstract class FetchSignInMethodsForEmailFailureInterface
abstract class SignInWithCredentialFailureInterface abstract class SignInWithCredentialFailureInterface
extends AuthenticationFailureInterface { extends AuthenticationFailureInterface {
/// {@macro sign_in_with_credential_failure} /// {@macro sign_in_with_credential_failure}
SignInWithCredentialFailureInterface(super.code, super.message); SignInWithCredentialFailureInterface(super.code, super.msg);
/// {@macro sign_in_with_credential_failure} /// {@macro sign_in_with_credential_failure}
SignInWithCredentialFailureInterface.fromCode(super.code) : super.fromCode(); SignInWithCredentialFailureInterface.fromCode(super.code) : super.fromCode();
@ -79,7 +84,7 @@ abstract class SignInWithCredentialFailureInterface
abstract class SignInAnonymouslyFailureInterface abstract class SignInAnonymouslyFailureInterface
extends AuthenticationFailureInterface { extends AuthenticationFailureInterface {
/// {@macro sign_in_anonymously_failure} /// {@macro sign_in_anonymously_failure}
SignInAnonymouslyFailureInterface(super.code, super.message); SignInAnonymouslyFailureInterface(super.code, super.msg);
/// {@macro sign_in_anonymously_failure} /// {@macro sign_in_anonymously_failure}
SignInAnonymouslyFailureInterface.fromCode(super.code) : super.fromCode(); SignInAnonymouslyFailureInterface.fromCode(super.code) : super.fromCode();
@ -91,7 +96,7 @@ abstract class SignInAnonymouslyFailureInterface
abstract class SignInWithGoogleFailureInterface abstract class SignInWithGoogleFailureInterface
extends AuthenticationFailureInterface { extends AuthenticationFailureInterface {
/// {@macro sign_in_with_google_failure} /// {@macro sign_in_with_google_failure}
SignInWithGoogleFailureInterface(super.code, super.message); SignInWithGoogleFailureInterface(super.code, super.msg);
/// {@macro sign_in_with_google_failure} /// {@macro sign_in_with_google_failure}
SignInWithGoogleFailureInterface.fromCode(super.code) : super.fromCode(); SignInWithGoogleFailureInterface.fromCode(super.code) : super.fromCode();
@ -103,7 +108,7 @@ abstract class SignInWithGoogleFailureInterface
abstract class SignInWithFacebookFailureInterface abstract class SignInWithFacebookFailureInterface
extends AuthenticationFailureInterface { extends AuthenticationFailureInterface {
/// {@macro sign_in_with_facebook_failure} /// {@macro sign_in_with_facebook_failure}
SignInWithFacebookFailureInterface(super.code, super.message); SignInWithFacebookFailureInterface(super.code, super.msg);
/// {@macro sign_in_with_facebook_failure} /// {@macro sign_in_with_facebook_failure}
SignInWithFacebookFailureInterface.fromCode(super.code) : super.fromCode(); SignInWithFacebookFailureInterface.fromCode(super.code) : super.fromCode();
@ -115,7 +120,7 @@ abstract class SignInWithFacebookFailureInterface
abstract class SignInWithAppleFailureInterface abstract class SignInWithAppleFailureInterface
extends AuthenticationFailureInterface { extends AuthenticationFailureInterface {
/// {@macro sign_in_with_apple_failure} /// {@macro sign_in_with_apple_failure}
SignInWithAppleFailureInterface(super.code, super.message); SignInWithAppleFailureInterface(super.code, super.msg);
/// {@macro sign_in_with_apple_failure} /// {@macro sign_in_with_apple_failure}
SignInWithAppleFailureInterface.fromCode(super.code) : super.fromCode(); SignInWithAppleFailureInterface.fromCode(super.code) : super.fromCode();
@ -127,7 +132,7 @@ abstract class SignInWithAppleFailureInterface
abstract class SignInWithTwitterFailureInterface abstract class SignInWithTwitterFailureInterface
extends AuthenticationFailureInterface { extends AuthenticationFailureInterface {
/// {@macro sign_in_with_twitter_failure} /// {@macro sign_in_with_twitter_failure}
SignInWithTwitterFailureInterface(super.code, super.message); SignInWithTwitterFailureInterface(super.code, super.msg);
/// {@macro sign_in_with_twitter_failure} /// {@macro sign_in_with_twitter_failure}
SignInWithTwitterFailureInterface.fromCode(super.code) : super.fromCode(); SignInWithTwitterFailureInterface.fromCode(super.code) : super.fromCode();
@ -139,7 +144,7 @@ abstract class SignInWithTwitterFailureInterface
abstract class SignInWithEmailLinkFailureInterface abstract class SignInWithEmailLinkFailureInterface
extends AuthenticationFailureInterface { extends AuthenticationFailureInterface {
/// {@macro sign_in_with_email_link_failure} /// {@macro sign_in_with_email_link_failure}
SignInWithEmailLinkFailureInterface(super.code, super.message); SignInWithEmailLinkFailureInterface(super.code, super.msg);
/// {@macro sign_in_with_email_link_failure} /// {@macro sign_in_with_email_link_failure}
SignInWithEmailLinkFailureInterface.fromCode(super.code) : super.fromCode(); SignInWithEmailLinkFailureInterface.fromCode(super.code) : super.fromCode();
@ -151,7 +156,7 @@ abstract class SignInWithEmailLinkFailureInterface
abstract class SignInWithEmailAndPasswordFailureInterface abstract class SignInWithEmailAndPasswordFailureInterface
extends AuthenticationFailureInterface { extends AuthenticationFailureInterface {
/// {@macro sign_in_with_email_and_password_failure} /// {@macro sign_in_with_email_and_password_failure}
SignInWithEmailAndPasswordFailureInterface(super.code, super.message); SignInWithEmailAndPasswordFailureInterface(super.code, super.msg);
/// {@macro sign_in_with_email_and_password_failure} /// {@macro sign_in_with_email_and_password_failure}
SignInWithEmailAndPasswordFailureInterface.fromCode(super.code) SignInWithEmailAndPasswordFailureInterface.fromCode(super.code)
@ -164,7 +169,7 @@ abstract class SignInWithEmailAndPasswordFailureInterface
abstract class SendEmailVerificationFailureInterface abstract class SendEmailVerificationFailureInterface
extends AuthenticationFailureInterface { extends AuthenticationFailureInterface {
/// {@macro send_email_verification_failure} /// {@macro send_email_verification_failure}
SendEmailVerificationFailureInterface(super.code, super.message); SendEmailVerificationFailureInterface(super.code, super.msg);
/// {@macro send_email_verification_failure} /// {@macro send_email_verification_failure}
SendEmailVerificationFailureInterface.fromCode(super.code) : super.fromCode(); SendEmailVerificationFailureInterface.fromCode(super.code) : super.fromCode();
@ -176,7 +181,7 @@ abstract class SendEmailVerificationFailureInterface
abstract class SendPasswordResetEmailFailureInterface abstract class SendPasswordResetEmailFailureInterface
extends AuthenticationFailureInterface { extends AuthenticationFailureInterface {
/// {@macro send_password_reset_email_failure} /// {@macro send_password_reset_email_failure}
SendPasswordResetEmailFailureInterface(super.code, super.message); SendPasswordResetEmailFailureInterface(super.code, super.msg);
/// {@macro send_password_reset_email_failure} /// {@macro send_password_reset_email_failure}
SendPasswordResetEmailFailureInterface.fromCode(super.code) SendPasswordResetEmailFailureInterface.fromCode(super.code)
@ -189,7 +194,7 @@ abstract class SendPasswordResetEmailFailureInterface
abstract class SendSignInLinkEmailFailureInterface abstract class SendSignInLinkEmailFailureInterface
extends AuthenticationFailureInterface { extends AuthenticationFailureInterface {
/// {@macro send_sign_in_link_email_failure} /// {@macro send_sign_in_link_email_failure}
SendSignInLinkEmailFailureInterface(super.code, super.message); SendSignInLinkEmailFailureInterface(super.code, super.msg);
/// {@macro send_sign_in_link_email_failure} /// {@macro send_sign_in_link_email_failure}
SendSignInLinkEmailFailureInterface.fromCode(super.code) : super.fromCode(); SendSignInLinkEmailFailureInterface.fromCode(super.code) : super.fromCode();
@ -201,7 +206,7 @@ abstract class SendSignInLinkEmailFailureInterface
abstract class ConfirmPasswordResetFailureInterface abstract class ConfirmPasswordResetFailureInterface
extends AuthenticationFailureInterface { extends AuthenticationFailureInterface {
/// {@macro confirm_password_reset_failure} /// {@macro confirm_password_reset_failure}
ConfirmPasswordResetFailureInterface(super.code, super.message); ConfirmPasswordResetFailureInterface(super.code, super.msg);
/// {@macro confirm_password_reset_failure} /// {@macro confirm_password_reset_failure}
ConfirmPasswordResetFailureInterface.fromCode(super.code) : super.fromCode(); ConfirmPasswordResetFailureInterface.fromCode(super.code) : super.fromCode();
@ -213,7 +218,7 @@ abstract class ConfirmPasswordResetFailureInterface
abstract class VerifyPasswordResetCodeFailureInterface abstract class VerifyPasswordResetCodeFailureInterface
extends AuthenticationFailureInterface { extends AuthenticationFailureInterface {
/// {@macro verify_password_reset_code_failure} /// {@macro verify_password_reset_code_failure}
VerifyPasswordResetCodeFailureInterface(super.code, super.message); VerifyPasswordResetCodeFailureInterface(super.code, super.msg);
/// {@macro verify_password_reset_code_failure} /// {@macro verify_password_reset_code_failure}
VerifyPasswordResetCodeFailureInterface.fromCode(super.code) VerifyPasswordResetCodeFailureInterface.fromCode(super.code)
@ -225,7 +230,7 @@ abstract class VerifyPasswordResetCodeFailureInterface
/// {@endtemplate} /// {@endtemplate}
abstract class RefreshFailureInterface extends AuthenticationFailureInterface { abstract class RefreshFailureInterface extends AuthenticationFailureInterface {
/// {@macro refresh_failure} /// {@macro refresh_failure}
RefreshFailureInterface(super.code, super.message); RefreshFailureInterface(super.code, super.msg);
/// {@macro refresh_failure} /// {@macro refresh_failure}
RefreshFailureInterface.fromCode(super.code) : super.fromCode(); RefreshFailureInterface.fromCode(super.code) : super.fromCode();
@ -236,7 +241,7 @@ abstract class RefreshFailureInterface extends AuthenticationFailureInterface {
/// {@endtemplate} /// {@endtemplate}
abstract class SignOutFailureInterface extends AuthenticationFailureInterface { abstract class SignOutFailureInterface extends AuthenticationFailureInterface {
/// {@macro sign_out_failure} /// {@macro sign_out_failure}
SignOutFailureInterface(super.code, super.message); SignOutFailureInterface(super.code, super.msg);
/// {@macro sign_out_failure} /// {@macro sign_out_failure}
SignOutFailureInterface.fromCode(super.code) : super.fromCode(); SignOutFailureInterface.fromCode(super.code) : super.fromCode();

View File

@ -14,133 +14,130 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
import 'package:wyatt_authentication_bloc/src/core/exceptions/exceptions.dart'; part of 'exceptions.dart';
class ApplyActionCodeFailureFirebase extends ApplyActionCodeFailureInterface { class ApplyActionCodeFailureFirebase extends ApplyActionCodeFailureInterface {
ApplyActionCodeFailureFirebase([String? code, String? message]) ApplyActionCodeFailureFirebase([String? code, String? msg])
: super(code ?? 'unknown', message ?? 'An unknown error occurred.'); : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');
ApplyActionCodeFailureFirebase.fromCode(String code) : super.fromCode(code) { ApplyActionCodeFailureFirebase.fromCode(String code) : super.fromCode(code) {
switch (code) { switch (code) {
case 'expired-action-code': case 'expired-action-code':
message = 'Action code has expired.'; msg = 'Action code has expired.';
break; break;
case 'invalid-action-code': case 'invalid-action-code':
message = 'Action code is invalid.'; msg = 'Action code is invalid.';
break; break;
case 'user-disabled': case 'user-disabled':
message = msg = 'This user has been disabled. Please contact support for help.';
'This user has been disabled. Please contact support for help.';
break; break;
case 'user-not-found': case 'user-not-found':
message = 'Email is not found, please create an account.'; msg = 'Email is not found, please create an account.';
break; break;
default: default:
this.code = 'unknown'; this.code = 'unknown';
message = 'An unknown error occurred.'; msg = 'An unknown error occurred.';
} }
} }
} }
class SignUpWithEmailAndPasswordFailureFirebase class SignUpWithEmailAndPasswordFailureFirebase
extends SignUpWithEmailAndPasswordFailureInterface { extends SignUpWithEmailAndPasswordFailureInterface {
SignUpWithEmailAndPasswordFailureFirebase([String? code, String? message]) SignUpWithEmailAndPasswordFailureFirebase([String? code, String? msg])
: super(code ?? 'unknown', message ?? 'An unknown error occurred.'); : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');
SignUpWithEmailAndPasswordFailureFirebase.fromCode(String code) SignUpWithEmailAndPasswordFailureFirebase.fromCode(String code)
: super.fromCode(code) { : super.fromCode(code) {
switch (code) { switch (code) {
case 'invalid-email': case 'invalid-email':
message = 'The email address is badly formatted.'; msg = 'The email address is badly formatted.';
break; break;
case 'user-disabled': case 'user-disabled':
message = msg = 'This user has been disabled. Please contact support for help.';
'This user has been disabled. Please contact support for help.';
break; break;
case 'email-already-in-use': case 'email-already-in-use':
message = 'An account already exists for that email.'; msg = 'An account already exists for that email.';
break; break;
case 'operation-not-allowed': case 'operation-not-allowed':
message = 'Operation is not allowed. Please contact support.'; msg = 'Operation is not allowed. Please contact support.';
break; break;
case 'weak-password': case 'weak-password':
message = 'Please enter a stronger password.'; msg = 'Please enter a stronger password.';
break; break;
default: default:
this.code = 'unknown'; this.code = 'unknown';
message = 'An unknown error occurred.'; msg = 'An unknown error occurred.';
} }
} }
} }
class FetchSignInMethodsForEmailFailureFirebase class FetchSignInMethodsForEmailFailureFirebase
extends FetchSignInMethodsForEmailFailureInterface { extends FetchSignInMethodsForEmailFailureInterface {
FetchSignInMethodsForEmailFailureFirebase([String? code, String? message]) FetchSignInMethodsForEmailFailureFirebase([String? code, String? msg])
: super(code ?? 'unknown', message ?? 'An unknown error occurred.'); : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');
FetchSignInMethodsForEmailFailureFirebase.fromCode(String code) FetchSignInMethodsForEmailFailureFirebase.fromCode(String code)
: super.fromCode(code) { : super.fromCode(code) {
switch (code) { switch (code) {
case 'invalid-email': case 'invalid-email':
message = 'The email address is badly formatted.'; msg = 'The email address is badly formatted.';
break; break;
default: default:
this.code = 'unknown'; this.code = 'unknown';
message = 'An unknown error occurred.'; msg = 'An unknown error occurred.';
} }
} }
} }
class SignInAnonymouslyFailureFirebase class SignInAnonymouslyFailureFirebase
extends SignInAnonymouslyFailureInterface { extends SignInAnonymouslyFailureInterface {
SignInAnonymouslyFailureFirebase([String? code, String? message]) SignInAnonymouslyFailureFirebase([String? code, String? msg])
: super(code ?? 'unknown', message ?? 'An unknown error occurred.'); : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');
SignInAnonymouslyFailureFirebase.fromCode(String code) SignInAnonymouslyFailureFirebase.fromCode(String code)
: super.fromCode(code) { : super.fromCode(code) {
switch (code) { switch (code) {
case 'operation-not-allowed': case 'operation-not-allowed':
message = 'Operation is not allowed. Please contact support.'; msg = 'Operation is not allowed. Please contact support.';
break; break;
default: default:
this.code = 'unknown'; this.code = 'unknown';
message = 'An unknown error occurred.'; msg = 'An unknown error occurred.';
} }
} }
} }
class SignInWithCredentialFailureFirebase class SignInWithCredentialFailureFirebase
extends SignInWithCredentialFailureInterface { extends SignInWithCredentialFailureInterface {
SignInWithCredentialFailureFirebase([String? code, String? message]) SignInWithCredentialFailureFirebase([String? code, String? msg])
: super(code ?? 'unknown', message ?? 'An unknown error occurred.'); : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');
SignInWithCredentialFailureFirebase.fromCode(String code) SignInWithCredentialFailureFirebase.fromCode(String code)
: super.fromCode(code) { : super.fromCode(code) {
switch (code) { switch (code) {
case 'account-exists-with-different-credential': case 'account-exists-with-different-credential':
message = 'Account exists with different credentials.'; msg = 'Account exists with different credentials.';
break; break;
case 'invalid-credential': case 'invalid-credential':
message = 'The credential received is malformed or has expired.'; msg = 'The credential received is malformed or has expired.';
break; break;
case 'operation-not-allowed': case 'operation-not-allowed':
message = 'Operation is not allowed. Please contact support.'; msg = 'Operation is not allowed. Please contact support.';
break; break;
case 'user-disabled': case 'user-disabled':
message = msg = 'This user has been disabled. Please contact support for help.';
'This user has been disabled. Please contact support for help.';
break; break;
case 'user-not-found': case 'user-not-found':
message = 'Email is not found, please create an account.'; msg = 'Email is not found, please create an account.';
break; break;
case 'wrong-password': case 'wrong-password':
message = 'Incorrect password, please try again.'; msg = 'Incorrect password, please try again.';
break; break;
case 'invalid-verification-code': case 'invalid-verification-code':
message = 'The credential verification code received is invalid.'; msg = 'The credential verification code received is invalid.';
break; break;
case 'invalid-verification-id': case 'invalid-verification-id':
message = 'The credential verification ID received is invalid.'; msg = 'The credential verification ID received is invalid.';
break; break;
default: default:
this.code = 'unknown'; this.code = 'unknown';
message = 'An unknown error occurred.'; msg = 'An unknown error occurred.';
} }
} }
} }
@ -148,130 +145,128 @@ class SignInWithCredentialFailureFirebase
class SignInWithGoogleFailureFirebase class SignInWithGoogleFailureFirebase
extends SignInWithCredentialFailureFirebase extends SignInWithCredentialFailureFirebase
implements SignInWithGoogleFailureInterface { implements SignInWithGoogleFailureInterface {
SignInWithGoogleFailureFirebase([super.code, super.message]); SignInWithGoogleFailureFirebase([super.code, super.msg]);
SignInWithGoogleFailureFirebase.fromCode(super.code) : super.fromCode(); SignInWithGoogleFailureFirebase.fromCode(super.code) : super.fromCode();
} }
class SignInWithFacebookFailureFirebase class SignInWithFacebookFailureFirebase
extends SignInWithCredentialFailureFirebase extends SignInWithCredentialFailureFirebase
implements SignInWithFacebookFailureInterface { implements SignInWithFacebookFailureInterface {
SignInWithFacebookFailureFirebase([super.code, super.message]); SignInWithFacebookFailureFirebase([super.code, super.msg]);
SignInWithFacebookFailureFirebase.fromCode(super.code) : super.fromCode(); SignInWithFacebookFailureFirebase.fromCode(super.code) : super.fromCode();
} }
class SignInWithAppleFailureFirebase extends SignInWithCredentialFailureFirebase class SignInWithAppleFailureFirebase extends SignInWithCredentialFailureFirebase
implements SignInWithAppleFailureInterface { implements SignInWithAppleFailureInterface {
SignInWithAppleFailureFirebase([super.code, super.message]); SignInWithAppleFailureFirebase([super.code, super.msg]);
SignInWithAppleFailureFirebase.fromCode(super.code) : super.fromCode(); SignInWithAppleFailureFirebase.fromCode(super.code) : super.fromCode();
} }
class SignInWithTwitterFailureFirebase class SignInWithTwitterFailureFirebase
extends SignInWithCredentialFailureFirebase extends SignInWithCredentialFailureFirebase
implements SignInWithAppleFailureInterface { implements SignInWithAppleFailureInterface {
SignInWithTwitterFailureFirebase([super.code, super.message]); SignInWithTwitterFailureFirebase([super.code, super.msg]);
SignInWithTwitterFailureFirebase.fromCode(super.code) : super.fromCode(); SignInWithTwitterFailureFirebase.fromCode(super.code) : super.fromCode();
} }
class SignInWithEmailLinkFailureFirebase class SignInWithEmailLinkFailureFirebase
extends SignInWithEmailLinkFailureInterface { extends SignInWithEmailLinkFailureInterface {
SignInWithEmailLinkFailureFirebase([String? code, String? message]) SignInWithEmailLinkFailureFirebase([String? code, String? msg])
: super(code ?? 'unknown', message ?? 'An unknown error occurred.'); : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');
SignInWithEmailLinkFailureFirebase.fromCode(String code) SignInWithEmailLinkFailureFirebase.fromCode(String code)
: super.fromCode(code) { : super.fromCode(code) {
switch (code) { switch (code) {
case 'expired-action-code': case 'expired-action-code':
message = 'Action code has expired.'; msg = 'Action code has expired.';
break; break;
case 'invalid-email': case 'invalid-email':
message = 'Email is not valid or badly formatted.'; msg = 'Email is not valid or badly formatted.';
break; break;
case 'user-disabled': case 'user-disabled':
message = msg = 'This user has been disabled. Please contact support for help.';
'This user has been disabled. Please contact support for help.';
break; break;
default: default:
this.code = 'unknown'; this.code = 'unknown';
message = 'An unknown error occurred.'; msg = 'An unknown error occurred.';
} }
} }
} }
class SignInWithEmailAndPasswordFailureFirebase class SignInWithEmailAndPasswordFailureFirebase
extends SignInWithEmailAndPasswordFailureInterface { extends SignInWithEmailAndPasswordFailureInterface {
SignInWithEmailAndPasswordFailureFirebase([String? code, String? message]) SignInWithEmailAndPasswordFailureFirebase([String? code, String? msg])
: super(code ?? 'unknown', message ?? 'An unknown error occurred.'); : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');
SignInWithEmailAndPasswordFailureFirebase.fromCode(String code) SignInWithEmailAndPasswordFailureFirebase.fromCode(String code)
: super.fromCode(code) { : super.fromCode(code) {
switch (code) { switch (code) {
case 'invalid-email': case 'invalid-email':
message = 'Email is not valid or badly formatted.'; msg = 'Email is not valid or badly formatted.';
break; break;
case 'user-disabled': case 'user-disabled':
message = msg = 'This user has been disabled. Please contact support for help.';
'This user has been disabled. Please contact support for help.';
break; break;
case 'user-not-found': case 'user-not-found':
message = 'Email is not found, please create an account.'; msg = 'Email is not found, please create an account.';
break; break;
case 'wrong-password': case 'wrong-password':
message = 'Incorrect password, please try again.'; msg = 'Incorrect password, please try again.';
break; break;
default: default:
this.code = 'unknown'; this.code = 'unknown';
message = 'An unknown error occurred.'; msg = 'An unknown error occurred.';
} }
} }
} }
class SendEmailVerificationFailureFirebase class SendEmailVerificationFailureFirebase
extends SendEmailVerificationFailureInterface { extends SendEmailVerificationFailureInterface {
SendEmailVerificationFailureFirebase([String? code, String? message]) SendEmailVerificationFailureFirebase([String? code, String? msg])
: super(code ?? 'unknown', message ?? 'An unknown error occurred.'); : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');
SendEmailVerificationFailureFirebase.fromCode(super.code) : super.fromCode(); SendEmailVerificationFailureFirebase.fromCode(super.code) : super.fromCode();
} }
class SendPasswordResetEmailFailureFirebase class SendPasswordResetEmailFailureFirebase
extends SendPasswordResetEmailFailureInterface { extends SendPasswordResetEmailFailureInterface {
SendPasswordResetEmailFailureFirebase([String? code, String? message]) SendPasswordResetEmailFailureFirebase([String? code, String? msg])
: super(code ?? 'unknown', message ?? 'An unknown error occurred.'); : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');
SendPasswordResetEmailFailureFirebase.fromCode(super.code) : super.fromCode(); SendPasswordResetEmailFailureFirebase.fromCode(super.code) : super.fromCode();
} }
class SendSignInLinkEmailFailureFirebase class SendSignInLinkEmailFailureFirebase
extends SendSignInLinkEmailFailureInterface { extends SendSignInLinkEmailFailureInterface {
SendSignInLinkEmailFailureFirebase([String? code, String? message]) SendSignInLinkEmailFailureFirebase([String? code, String? msg])
: super(code ?? 'unknown', message ?? 'An unknown error occurred.'); : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');
SendSignInLinkEmailFailureFirebase.fromCode(super.code) : super.fromCode(); SendSignInLinkEmailFailureFirebase.fromCode(super.code) : super.fromCode();
} }
class ConfirmPasswordResetFailureFirebase class ConfirmPasswordResetFailureFirebase
extends ConfirmPasswordResetFailureInterface { extends ConfirmPasswordResetFailureInterface {
ConfirmPasswordResetFailureFirebase([String? code, String? message]) ConfirmPasswordResetFailureFirebase([String? code, String? msg])
: super(code ?? 'unknown', message ?? 'An unknown error occurred.'); : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');
ConfirmPasswordResetFailureFirebase.fromCode(super.code) : super.fromCode(); ConfirmPasswordResetFailureFirebase.fromCode(super.code) : super.fromCode();
} }
class VerifyPasswordResetCodeFailureFirebase class VerifyPasswordResetCodeFailureFirebase
extends VerifyPasswordResetCodeFailureInterface { extends VerifyPasswordResetCodeFailureInterface {
VerifyPasswordResetCodeFailureFirebase([String? code, String? message]) VerifyPasswordResetCodeFailureFirebase([String? code, String? msg])
: super(code ?? 'unknown', message ?? 'An unknown error occurred.'); : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');
VerifyPasswordResetCodeFailureFirebase.fromCode(super.code) VerifyPasswordResetCodeFailureFirebase.fromCode(super.code)
: super.fromCode(); : super.fromCode();
} }
class RefreshFailureFirebase extends RefreshFailureInterface { class RefreshFailureFirebase extends RefreshFailureInterface {
RefreshFailureFirebase([String? code, String? message]) RefreshFailureFirebase([String? code, String? msg])
: super(code ?? 'unknown', message ?? 'An unknown error occurred.'); : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');
RefreshFailureFirebase.fromCode(super.code) : super.fromCode(); RefreshFailureFirebase.fromCode(super.code) : super.fromCode();
} }
class SignOutFailureFirebase extends SignOutFailureInterface { class SignOutFailureFirebase extends SignOutFailureInterface {
SignOutFailureFirebase([String? code, String? message]) SignOutFailureFirebase([String? code, String? msg])
: super(code ?? 'unknown', message ?? 'An unknown error occurred.'); : super(code ?? 'unknown', msg ?? 'An unknown error occurred.');
SignOutFailureFirebase.fromCode(super.code) : super.fromCode(); SignOutFailureFirebase.fromCode(super.code) : super.fromCode();
} }

View File

@ -0,0 +1,17 @@
// Copyright (C) 2022 WYATT GROUP
// Please see the AUTHORS file for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
export 'cryptography.dart';

View File

@ -0,0 +1,19 @@
// Copyright (C) 2022 WYATT GROUP
// Please see the AUTHORS file for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
export 'data_sources/data_sources.dart';
export 'entities/entities.dart';
export 'repositories/repositories.dart';

View File

@ -0,0 +1,27 @@
// Copyright (C) 2022 WYATT GROUP
// Please see the AUTHORS file for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
import 'package:wyatt_architecture/wyatt_architecture.dart';
abstract class Account extends Entity {
/// The user's unique ID.
String get uid;
/// The users email address.
///
/// Will be `null` if signing in anonymously.
String? get email;
}

View File

@ -14,9 +14,10 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
import 'package:firebase_auth/firebase_auth.dart'; import 'package:wyatt_architecture/wyatt_architecture.dart';
import 'package:wyatt_authentication_bloc/src/data/models/user_firebase.dart'; import 'package:wyatt_authentication_bloc/src/domain/entities/account.dart';
extension FirebaseAuthUserX on User { abstract class AccountWrapper<T> extends Entity {
UserFirebase get model => UserFirebase(this); Account? get account;
T? get data;
} }

View File

@ -0,0 +1,18 @@
// Copyright (C) 2022 WYATT GROUP
// Please see the AUTHORS file for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
export 'account.dart';
export 'account_wrapper.dart';

View File

@ -1,85 +0,0 @@
// Copyright (C) 2022 WYATT GROUP
// Please see the AUTHORS file for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
abstract class User {
/// The empty user constructor.
const User.empty();
/// The users display name.
///
/// Will be `null` if signing in anonymously or via password authentication.
String? get displayName;
/// The users email address.
///
/// Will be `null` if signing in anonymously.
String? get email;
/// Returns whether the users email address has been verified.
///
/// To send a verification email, see `SendEmailVerification`.
///
/// Once verified, call `reload` to ensure the latest user information is
/// retrieved from Firebase.
bool get emailVerified;
/// Returns whether the user is a anonymous.
bool get isAnonymous;
/// Returns the users account creation time.
///
/// When this account was created as dictated by the server clock.
DateTime? get creationTime;
/// When the user last signed in as dictated by the server clock.
///
/// This is only accurate up to a granularity of 2 minutes for consecutive
/// sign-in attempts.
DateTime? get lastSignInTime;
/// Returns the users phone number.
///
/// This property will be `null` if the user has not signed in or been has
/// their phone number linked.
String? get phoneNumber;
/// Returns a photo URL for the user.
///
/// This property will be populated if the user has signed in or been linked
/// with a 3rd party OAuth provider (such as Google).
String? get photoURL;
/// Returns a JWT refresh token for the user.
///
/// This property maybe `null` or empty if the underlying platform does not
/// support providing refresh tokens.
String? get refreshToken;
/// The user's unique ID.
String get uid;
/// The provider ID for the user.
String? get providerId;
/// Whether the user account has been recently created.
bool? get isNewUser;
/// Convenience getter to determine whether the current user is empty.
bool get isEmpty;
/// Convenience getter to determine whether the current user is not empty.
bool get isNotEmpty;
}