This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EmailPasswordSignInModel with EmailAndPasswordValidators, ChangeNotifier { | |
EmailPasswordSignInModel({ | |
@required this.firebaseAuth, | |
this.email = '', | |
this.password = '', | |
this.formType = EmailPasswordSignInFormType.signIn, | |
this.isLoading = false, | |
this.submitted = false, | |
}); | |
final FirebaseAuth firebaseAuth; | |
String email; | |
String password; | |
EmailPasswordSignInFormType formType; | |
bool isLoading; | |
bool submitted; | |
Future<bool> submit() async { | |
try { | |
updateWith(submitted: true); | |
if (!canSubmit) { | |
return false; | |
} | |
updateWith(isLoading: true); | |
switch (formType) { | |
case EmailPasswordSignInFormType.signIn: | |
await firebaseAuth.signInWithCredential( | |
EmailAuthProvider.credential(email: email, password: password) | |
); | |
break; | |
case EmailPasswordSignInFormType.register: | |
UserCredential userCredential = await firebaseAuth.createUserWithEmailAndPassword( | |
email: email, password: password | |
); | |
await FirestoreService.createUser(userCredential); | |
break; | |
case EmailPasswordSignInFormType.forgotPassword: | |
await firebaseAuth.sendPasswordResetEmail(email: email); | |
updateWith(isLoading: false); | |
break; | |
} | |
return true; | |
} catch (e) { | |
updateWith(isLoading: false); | |
rethrow; | |
} | |
} | |
// ...略 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment