我想制作一个使用Firebase接收用户的电子邮件ID和联系电话(其他字段除外)的应用程序。之后,我想通过发送OTP到用户的联系号和验证电子邮件到用户的电子邮件ID来验证用户的电子邮件ID和联系电话。可以在Firebase中完成吗?如果是这样,请指导我。我正在使用Android Studio。
答案 0 :(得分:1)
我相信这是可能的,尽管这会有些棘手。您将必须同时实现email和phone number,并在回调上添加一个检查,以查看二者是否都已完成,然后再登录用户。我认为鉴于电子邮件似乎必须登录用户,您将必须先实施电话验证,然后再发送电子邮件,并在检查电子邮件和登录之前添加电话已通过验证的检查。在文档中显示:
按照文档中的说明以及回叫设置电话验证
mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(PhoneAuthCredential credential) {
// This callback will be invoked in two situations:
// 1 - Instant verification. In some cases the phone number can be instantly
// verified without needing to send or enter a verification code.
// 2 - Auto-retrieval. On some devices Google Play services can automatically
// detect the incoming verification SMS and perform verification without
// user action.
Log.d(TAG, "onVerificationCompleted:" + credential);
//signInWithPhoneAuthCredential(credential); //send email for email verification here instead/ sign in with email method
}
也许像这样确认电话号码后发送电子邮件验证
//Save the user email address beforehand for this
FirebaseAuth auth = FirebaseAuth.getInstance();
auth.sendSignInLinkToEmail(email, actionCodeSettings)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.d(TAG, "Email sent.");
}
}
});
实施此https://firebase.google.com/docs/auth/android/email-link-auth#completing_sign-in_in_an_android_app以设置动态链接以完成应用内的登录 并使用电子邮件登录方法使用类似的方法。
FirebaseAuth auth = FirebaseAuth.getInstance();
Intent intent = getIntent();
String emailLink = intent.getData().toString();
// Confirm the link is a sign-in with email link.
if (auth.isSignInWithEmailLink(emailLink)) {
// Retrieve this from wherever you stored it
String email = "someemail@domain.com";
// The client SDK will parse the code from the link for you.
auth.signInWithEmailLink(email, emailLink)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Log.d(TAG, "Successfully signed in with email link!");
AuthResult result = task.getResult();
// You can access the new user via result.getUser()
// Additional user info profile *not* available via:
// result.getAdditionalUserInfo().getProfile() == null
// You can check if the user is new or existing:
// result.getAdditionalUserInfo().isNewUser()
} else {
Log.e(TAG, "Error signing in with email link", task.getException());
}
}
});
}
我认为有更好的方法来解决此问题。也许控制台中有某种云功能,但这是我目前可以找到的唯一方法。