本文整理汇总了Java中com.google.firebase.auth.EmailAuthProvider.getCredential方法的典型用法代码示例。如果您正苦于以下问题:Java EmailAuthProvider.getCredential方法的具体用法?Java EmailAuthProvider.getCredential怎么用?Java EmailAuthProvider.getCredential使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.firebase.auth.EmailAuthProvider
的用法示例。
在下文中一共展示了EmailAuthProvider.getCredential方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: reauthenticate
import com.google.firebase.auth.EmailAuthProvider; //导入方法依赖的package包/类
private void reauthenticate() {
// [START reauthenticate]
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
// Get auth credentials from the user for re-authentication. The example below shows
// email and password credentials but there are multiple possible providers,
// such as GoogleAuthProvider or FacebookAuthProvider.
AuthCredential credential = EmailAuthProvider
.getCredential("[email protected]", "password1234");
// Prompt the user to re-provide their sign-in credentials
user.reauthenticate(credential)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
Log.d(TAG, "User re-authenticated.");
}
});
// [END reauthenticate]
}
示例2: validate
import com.google.firebase.auth.EmailAuthProvider; //导入方法依赖的package包/类
private void validate() {
String passwordText = passwordEntry.getText().toString();
if (TextUtils.isEmpty(passwordText)) {
passwordEntry.setError(getString(R.string.error_field_required));
return;
}
if (user.getEmail() != null) {
AuthCredential credential = EmailAuthProvider.getCredential(user.getEmail(), passwordText);
user.reauthenticate(credential).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
System.out.println("Re-authenticated");
user.delete();
dismiss();
}
});
}
}
示例3: validate
import com.google.firebase.auth.EmailAuthProvider; //导入方法依赖的package包/类
private void validate() {
final String oldPasswordText = oldPasswordEntry.getText().toString();
final String newPasswordText = newPasswordEntry.getText().toString();
final String confirmPasswordText = confirmPasswordEntry.getText().toString();
if (TextUtils.isEmpty(oldPasswordText)) {
oldPasswordEntry.setError(getString(R.string.error_field_required));
return;
}
if (TextUtils.isEmpty(newPasswordText)) {
newPasswordEntry.setError(getString(R.string.error_field_required));
return;
}
if (TextUtils.isEmpty(confirmPasswordText)) {
confirmPasswordEntry.setError(getString(R.string.error_field_required));
return;
}
if (!newPasswordText.equals(confirmPasswordText)) {
confirmPasswordEntry.setError(getString(R.string.error_field_required));
return;
}
if (user.getEmail() != null) {
AuthCredential credential = EmailAuthProvider.getCredential(user.getEmail(), oldPasswordText);
user.reauthenticate(credential).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
System.out.println("Re-authenticated");
updatePassword(newPasswordText);
}
});
}
}
示例4: linkAccount
import com.google.firebase.auth.EmailAuthProvider; //导入方法依赖的package包/类
private void linkAccount() {
// Make sure form is valid
if (!validateLinkForm()) {
return;
}
// Get email and password from form
String email = mEmailField.getText().toString();
String password = mPasswordField.getText().toString();
// Create EmailAuthCredential with email and password
AuthCredential credential = EmailAuthProvider.getCredential(email, password);
// Link the anonymous user to the email credential
showProgressDialog();
// [START link_credential]
mAuth.getCurrentUser().linkWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Log.d(TAG, "linkWithCredential:success");
FirebaseUser user = task.getResult().getUser();
updateUI(user);
} else {
Log.w(TAG, "linkWithCredential:failure", task.getException());
Toast.makeText(AnonymousAuthActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
updateUI(null);
}
// [START_EXCLUDE]
hideProgressDialog();
// [END_EXCLUDE]
}
});
// [END link_credential]
}
示例5: linkAccount
import com.google.firebase.auth.EmailAuthProvider; //导入方法依赖的package包/类
private void linkAccount() {
// Make sure form is valid
if (!validateLinkForm()) {
return;
}
// Get email and password from form
String email = mEmailField.getText().toString();
String password = mPasswordField.getText().toString();
// Create EmailAuthCredential with email and password
AuthCredential credential = EmailAuthProvider.getCredential(email, password);
// Link the anonymous user to the email credential
showProgressDialog();
// [START link_credential]
mAuth.getCurrentUser().linkWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d(TAG, "linkWithCredential:onComplete:" + task.isSuccessful());
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
Toast.makeText(AnonymousAuthActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
}
// [START_EXCLUDE]
hideProgressDialog();
// [END_EXCLUDE]
}
});
// [END link_credential]
}
示例6: linkCredentials
import com.google.firebase.auth.EmailAuthProvider; //导入方法依赖的package包/类
@Override
public Observable<User> linkCredentials(Credentials credentials) {
AuthCredential emailCredentials = EmailAuthProvider.getCredential(credentials.getEmail(), credentials.getPassword());
return firebaseWrapper.linkAccount(emailCredentials)
.map(authResult -> authResult.getUser())
.map(firebaseUser -> UserAdapter.fromFirebaseUser(firebaseUser));
}
示例7: getEmailAuthCredential
import com.google.firebase.auth.EmailAuthProvider; //导入方法依赖的package包/类
private static AuthCredential getEmailAuthCredential(final JSONObject credential) throws Exception {
final String email = credential.getString("email");
final String password = credential.getString("password");
return EmailAuthProvider.getCredential(email, password);
}
示例8: busAction
import com.google.firebase.auth.EmailAuthProvider; //导入方法依赖的package包/类
@Subscribe(threadMode = ThreadMode.MAIN)
public void busAction(BusEvent busEvent) {
//这里更新视图或者后台操作,从busAction获取传递参数.
if (busEvent != null) {
switch (busEvent.getFlag()) {
case BUS_FLAG_CAMERA:
onCameraClick(mView, true);
break;
case BUS_FLAG_ALBUM:
onAlbumClick(mView, true);
break;
case BUS_FLAG_USERNAME:
if (busEvent.getMessage() != null) {
mNickname.setText(busEvent.getMessage());
mUser.setNickname(busEvent.getMessage());
UserUtils.saveUserToCache(mActivity.getApplicationContext(), mUser);
updateProfile(busEvent.getMessage(), null);
}
break;
case BUS_FLAG_EMAIL:
if (busEvent.getMessage().contains("@")) {
AuthUtils.sendRPEmail(mActivity, mView, busEvent.getMessage());
}
break;
case BUS_FLAG_DELETE_ACCOUNT:
if (busEvent.getMessage() != null) {
final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
AuthCredential credential =
EmailAuthProvider.getCredential(user.getEmail(), busEvent.getMessage());
FDatabaseUtils.emptyNote(user.getUid());
FDatabaseUtils.emptyTrash(user.getUid());
user.reauthenticate(credential)
.addOnCompleteListener(task -> user.delete().addOnCompleteListener(task1 -> {
if (task1.isSuccessful()) {
if (BuildConfig.DEBUG) { Log.d(TAG, "busAction: User account deleted."); }
startActivity(new Intent(mActivity, LoginActivity.class));
}
}).addOnFailureListener(e -> {
if (BuildConfig.DEBUG) { Log.d(TAG, e.toString()); }
}));
}
break;
}
}
}