-
StackOverflow 文件
-
Android 教程
-
Firebase
-
更改密碼
public class ChangePasswordActivity extends BaseAppCompatActivity implements ReAuthenticateDialogFragment.OnReauthenticateSuccessListener {
@BindView(R.id.et_change_password)
EditText mEditText;
private FirebaseUser mFirebaseUser;
@OnClick(R.id.btn_change_password)
void onChangePasswordClick() {
FormValidationUtils.clearErrors(mEditText);
if (FormValidationUtils.isBlank(mEditText)) {
FormValidationUtils.setError(null, mEditText, "Please enter password");
return;
}
changePassword(mEditText.getText().toString());
}
private void changePassword(String password) {
DialogUtils.showProgressDialog(this, "Changing Password", "Please wait...", false);
mFirebaseUser.updatePassword(password)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
DialogUtils.dismissProgressDialog();
if (task.isSuccessful()) {
showToast("Password updated successfully.");
return;
}
if (task.getException() instanceof FirebaseAuthRecentLoginRequiredException) {
FragmentManager fm = getSupportFragmentManager();
ReAuthenticateDialogFragment reAuthenticateDialogFragment = new ReAuthenticateDialogFragment();
reAuthenticateDialogFragment.show(fm, reAuthenticateDialogFragment.getClass().getSimpleName());
}
}
});
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mFirebaseUser = mFirebaseAuth.getCurrentUser();
}
@Override
protected int getLayoutResourceId() {
return R.layout.activity_change_password;
}
@Override
public void onReauthenticateSuccess() {
changePassword(mEditText.getText().toString());
}
}