Search in sources :

Example 1 with FirebaseTooManyRequestsException

use of com.google.firebase.FirebaseTooManyRequestsException in project Skool by NhatTruongK15.

the class SignUpActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    final String TAG = "mCallBack";
    super.onCreate(savedInstanceState);
    binding = ActivitySignUpBinding.inflate(getLayoutInflater());
    setContentView(binding.getRoot());
    preferenceManager = new PreferenceManager(getApplicationContext());
    mAuth = FirebaseAuth.getInstance();
    // set up mCallback
    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);
        }

        @Override
        public void onVerificationFailed(FirebaseException e) {
            // This callback is invoked in an invalid request for verification is made,
            // for instance if the the phone number format is not valid.
            Log.w(TAG, "onVerificationFailed", e);
            if (e instanceof FirebaseAuthInvalidCredentialsException) {
            // Invalid request
            } else if (e instanceof FirebaseTooManyRequestsException) {
            // The SMS quota for the project has been exceeded
            }
        // Show a message and update the UI
        }

        @Override
        public void onCodeSent(@NonNull String verificationId, @NonNull PhoneAuthProvider.ForceResendingToken token) {
            // The SMS verification code has been sent to the provided phone number, we
            // now need to ask the user to enter the code and then construct a credential
            // by combining the code with a verification ID.
            Log.d(TAG, "onCodeSent:" + verificationId);
            // Save verification ID and resending token so we can use them later
            mVerificationId = verificationId;
            mResendToken = token;
            pd.dismiss();
            binding.verificationLayout.setVisibility(View.VISIBLE);
            binding.userInfoLayout.setVisibility(View.GONE);
            binding.resendContent.setText("didn't see smsCode?");
            binding.verificationCodeEditText.setHint("Please enter your smsCode we sent \n +84" + binding.inputPhoneNumb.getText().subSequence(1, binding.inputPhoneNumb.getText().length()));
        }
    };
    // set up progressdialog
    pd = new ProgressDialog(this);
    pd.setTitle("Please wait...");
    pd.setCanceledOnTouchOutside(false);
    // setup view
    binding.verificationLayout.setVisibility(View.GONE);
    binding.userInfoLayout.setVisibility(View.VISIBLE);
    // listener
    setListener();
}
Also used : FirebaseException(com.google.firebase.FirebaseException) FirebaseTooManyRequestsException(com.google.firebase.FirebaseTooManyRequestsException) FirebaseAuthInvalidCredentialsException(com.google.firebase.auth.FirebaseAuthInvalidCredentialsException) PhoneAuthCredential(com.google.firebase.auth.PhoneAuthCredential) PhoneAuthProvider(com.google.firebase.auth.PhoneAuthProvider) ProgressDialog(android.app.ProgressDialog) PreferenceManager(com.example.clown.utilities.PreferenceManager)

Example 2 with FirebaseTooManyRequestsException

use of com.google.firebase.FirebaseTooManyRequestsException in project vmess by zidquocviet1.

the class GenerateOtpActivity method setupEvent.

private void setupEvent() {
    mBinding.editTextPhone.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            var isCorrect = isPhoneFormatCorrect(s.toString().trim());
            if (!isCorrect) {
                mBinding.editTextPhone.setError(getString(R.string.invalid_phone_format));
            }
            mBinding.buttonSend.setEnabled(isCorrect);
        }
    });
    mBinding.buttonSend.setOnClickListener(v -> {
        var phoneText = mBinding.editTextPhone.getText().toString().trim();
        /*
            * If the app is published for all the country in the world.
            * Change the prefix by their region
            * Maybe modify the UI again*/
        var reformat = "+84" + phoneText.substring(1);
        var phoneOptions = PhoneAuthOptions.newBuilder(mAuth).setPhoneNumber(reformat).setTimeout(Const.PHONE_AUTH_TIME_OUT, TimeUnit.SECONDS).setActivity(this).setCallbacks(new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {

            @Override
            public void onVerificationCompleted(@NonNull PhoneAuthCredential phoneAuthCredential) {
            }

            @Override
            public void onVerificationFailed(@NonNull FirebaseException e) {
                new Handler(Looper.getMainLooper()).postDelayed(() -> {
                    mBinding.buttonSend.setEnabled(true);
                    mBinding.progressBarLoading.setVisibility(View.GONE);
                    if (e instanceof FirebaseTooManyRequestsException) {
                        Toast.makeText(getApplicationContext(), R.string.error_phone_verification_limit_sms_per_day, Toast.LENGTH_SHORT).show();
                    } else {
                        Toast.makeText(getApplicationContext(), R.string.error_phone_verification, Toast.LENGTH_SHORT).show();
                    }
                }, 1500);
            }

            @Override
            public void onCodeSent(@NonNull String s, @NonNull PhoneAuthProvider.ForceResendingToken forceResendingToken) {
                super.onCodeSent(s, forceResendingToken);
                var intent = new Intent(GenerateOtpActivity.this, VerifyOtpActivity.class);
                intent.putExtra(Const.EXTRA_VERIFICATION_ID, s);
                intent.putExtra(Const.EXTRA_RESEND_TOKEN, forceResendingToken);
                intent.putExtra(Const.EXTRA_RESEND_PHONE_NUMBER, reformat);
                startActivity(intent);
                finish();
            }
        }).build();
        PhoneAuthProvider.verifyPhoneNumber(phoneOptions);
        mBinding.progressBarLoading.setVisibility(View.VISIBLE);
        mBinding.buttonSend.setEnabled(false);
    });
}
Also used : FirebaseException(com.google.firebase.FirebaseException) Handler(android.os.Handler) Intent(android.content.Intent) AndroidEntryPoint(dagger.hilt.android.AndroidEntryPoint) FirebaseTooManyRequestsException(com.google.firebase.FirebaseTooManyRequestsException) NonNull(androidx.annotation.NonNull) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) PhoneAuthCredential(com.google.firebase.auth.PhoneAuthCredential)

Example 3 with FirebaseTooManyRequestsException

use of com.google.firebase.FirebaseTooManyRequestsException in project Skool by NhatTruongK15.

the class ResetPasswordActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    binding = ActivityResetPasswordBinding.inflate(getLayoutInflater());
    preferenceManager = new PreferenceManager(getApplicationContext());
    // set up progressdialog
    pd = new ProgressDialog(this);
    pd.setTitle("Please wait...");
    pd.setCanceledOnTouchOutside(false);
    final String TAG = "onCodeSent";
    // set up ui
    binding.waitForEnteringPhoneNumberLayout.setVisibility(View.VISIBLE);
    binding.verificationLayout.setVisibility(View.GONE);
    setContentView(binding.getRoot());
    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);
            ResetPhoneAuthCredential(credential);
        }

        @Override
        public void onVerificationFailed(FirebaseException e) {
            // This callback is invoked in an invalid request for verification is made,
            // for instance if the the phone number format is not valid.
            Log.w(TAG, "onVerificationFailed", e);
            if (e instanceof FirebaseAuthInvalidCredentialsException) {
            // Invalid request
            } else if (e instanceof FirebaseTooManyRequestsException) {
            // The SMS quota for the project has been exceeded
            }
        // Show a message and update the UI
        }

        @Override
        public void onCodeSent(@NonNull String verificationId, @NonNull PhoneAuthProvider.ForceResendingToken token) {
            // The SMS verification code has been sent to the provided phone number, we
            // now need to ask the user to enter the code and then construct a credential
            // by combining the code with a verification ID.
            Log.d(TAG, "onCodeSent:" + verificationId);
            // Save verification ID and resending token so we can use them later
            mVerificationId = verificationId;
            mResendToken = token;
            pd.dismiss();
            binding.verificationLayout.setVisibility(View.VISIBLE);
            binding.waitForEnteringPhoneNumberLayout.setVisibility(View.GONE);
        }
    };
    setListener();
}
Also used : FirebaseException(com.google.firebase.FirebaseException) FirebaseTooManyRequestsException(com.google.firebase.FirebaseTooManyRequestsException) FirebaseAuthInvalidCredentialsException(com.google.firebase.auth.FirebaseAuthInvalidCredentialsException) PhoneAuthCredential(com.google.firebase.auth.PhoneAuthCredential) PhoneAuthProvider(com.google.firebase.auth.PhoneAuthProvider) ProgressDialog(android.app.ProgressDialog) PreferenceManager(com.example.clown.utilities.PreferenceManager)

Aggregations

FirebaseException (com.google.firebase.FirebaseException)3 FirebaseTooManyRequestsException (com.google.firebase.FirebaseTooManyRequestsException)3 PhoneAuthCredential (com.google.firebase.auth.PhoneAuthCredential)3 ProgressDialog (android.app.ProgressDialog)2 PreferenceManager (com.example.clown.utilities.PreferenceManager)2 FirebaseAuthInvalidCredentialsException (com.google.firebase.auth.FirebaseAuthInvalidCredentialsException)2 PhoneAuthProvider (com.google.firebase.auth.PhoneAuthProvider)2 Intent (android.content.Intent)1 Handler (android.os.Handler)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 NonNull (androidx.annotation.NonNull)1 AndroidEntryPoint (dagger.hilt.android.AndroidEntryPoint)1