Example #1
0
        private void PhoneImageViewBtn_Click(object sender, EventArgs e)
        {
            var phoneNumberDialogHandler = new EventHandler <DialogClickEventArgs>((alertDialog, clicked) =>
            {
                var phoneNumberAlertDialog = alertDialog as AlertDialog;
                Button btnClicked          = phoneNumberAlertDialog?.GetButton(clicked.Which);

                if (btnClicked?.Text != GetString(Resource.String.send_code))
                {
                    return;
                }

                var phoneNumber = phoneNumberAlertDialog?.FindViewById <EditText>(Resource.Id.phoneNumber);
                var mCallBacks  = new PhoneAuthVerificationCallbacks();

                mCallBacks.CodeSent += MCallBacks_CodeSent;
                mCallBacks.VerificationCompleted += MCallBacks_VerificationCompleted;
                PhoneAuthProvider.GetInstance(FirebaseAuth).VerifyPhoneNumber(phoneNumber?.Text, VERIFICATION_TIMEOUT, TimeUnit.Seconds, this, mCallBacks);
            });

            AlertDialog phoneNumberAlert = new AlertDialog.Builder(this)
                                           .SetTitle(GetString(Resource.String.input_phone_number))
                                           .SetPositiveButton(GetString(Resource.String.send_code), phoneNumberDialogHandler)
                                           .SetView(LayoutInflater.Inflate(Resource.Layout.PhoneNumberDialog, null))
                                           .Show();

            EditText phoneNumberInput = phoneNumberAlert.FindViewById <EditText>(Resource.Id.phoneNumber);

            //phoneNumberInput.AddTextChangedListener(new PhoneNumberFormattingTextWatcher("NG"));
            phoneNumberInput.AddTextChangedListener(new PhoneTextWatcher(phoneNumberInput));
        }
Example #2
0
        // Begin authentication with the phone number.
        protected void VerifyPhoneNumber()
        {
            PhoneAuthProvider phoneAuthProvider = PhoneAuthProvider.GetInstance(auth);

            phoneAuthProvider.VerifyPhoneNumber(phoneNumber, phoneAuthTimeoutMs, null,
                                                cred =>
            {
                DebugLog("Phone Auth, auto-verification completed");
                if (signInAndFetchProfile)
                {
                    auth.SignInAndRetrieveDataWithCredentialAsync(cred).ContinueWith(
                        HandleSignInWithSignInResult);
                }
                else
                {
                    auth.SignInWithCredentialAsync(cred).ContinueWith(HandleSignInWithUser);
                }
            },
                                                error => { DebugLog("Phone Auth, verification failed: " + error); },
                                                (id, token) =>
            {
                phoneAuthVerificationId = id;
                DebugLog("Phone Auth, code sent");
            },
                                                id => { DebugLog("Phone Auth, auto-verification timed out"); });
        }
Example #3
0
    public void GetOTP()                                                                 //Function to send otp to the valid user mobile number
    {
        Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;    //Firebase auth instance creation to start authorization activity


        uint phoneAuthTimeoutMs    = 10000;                                              //
        PhoneAuthProvider provider = PhoneAuthProvider.GetInstance(auth);

        provider.VerifyPhoneNumber("+91" + mobile.text, phoneAuthTimeoutMs, null,
                                   verificationCompleted: (credential) =>
        {
            Debug.Log("1");

            //OnVerifyOTP(credential);
        },
                                   verificationFailed: (error) =>
        {
            Debug.Log("Verification failed");
        },
                                   codeSent: (id, token) =>
        {
            phoneVerificationId = id;
            Debug.Log("+91" + mobile.text);
            Debug.Log("SMS Has been sent and the verification Id is  " + id);
        },
                                   codeAutoRetrievalTimeOut: (id) =>
        {
            Debug.Log("Code Retrieval Time out");
        });
    }
Example #4
0
    public void SignInPhone()
    {
        PhoneAuthProvider provider   = PhoneAuthProvider.GetInstance(auth);
        Credential        credential = provider.GetCredential(phoneVerificationId, otp.text);

        auth.SignInWithCredentialAsync(credential).ContinueWith(task => {
            if (task.IsFaulted)
            {
                Debug.Log("SignInWithCredentialAsync encountered an error: " + task.Exception);
                OTPTimerText.text = "Otp entered is invalid";
                return;
            }

            Debug.Log("Phone Sign In successed.");
            Firebase.Auth.FirebaseUser newUser = task.Result;

            Debug.LogFormat("User signed in successfully: {0} ({1})",
                            newUser.DisplayName, newUser.UserId);

            userUID = newUser.UserId;


            GetUserName();
        });
    }
Example #5
0
    void GetOTP()
    {
        Debug.Log("Getting OTP");
        PhoneAuthProvider provider = PhoneAuthProvider.GetInstance(auth);

        provider.VerifyPhoneNumber("+917907136126", phoneAuthTimeoutMs, null,
                                   verificationCompleted: (credential) =>
        {
            // Auto-sms-retrieval or instant validation has succeeded (Android only).
            // There is no need to input the verification code.
            // `credential` can be used instead of calling GetCredential().
        },
                                   verificationFailed: (error) =>
        {
            // The verification code was not sent.
            // `error` contains a human readable explanation of the problem.
        },
                                   codeSent: (id, token) =>
        {
            // Verification code was successfully sent via SMS.
            // `id` contains the verification id that will need to passed in with
            // the code from the user when calling GetCredential().
            // `token` can be used if the user requests the code be sent again, to
            // tie the two requests together.
        },
                                   codeAutoRetrievalTimeOut: (id) =>
        {
            // Called when the auto-sms-retrieval has timed out, based on the given
            // timeout parameter.
            // `id` contains the verification id of the request that timed out.
        });
    }
Example #6
0
        public void VerifyPhoneNumber(string phoneNumber)
        {
            _phoneNumber = phoneNumber;

            _provider = PhoneAuthProvider.GetInstance(Auth);
            _provider.VerifyPhoneNumber(_phoneNumber, PhoneAuthTimeout, null,
                                        verificationCompleted: (credential) =>
            {
                print("verification completed");
            },
                                        verificationFailed: (error) =>
            {
                print("verification failed");
            },
                                        codeSent: (id, token) =>
            {
                print("code sent");

                _verificationId = id;

                OnCodeSent?.Invoke();
            },
                                        codeAutoRetrievalTimeOut: (id) =>
            {
                print("code auto retrieval timed Out");
            });
        }
 public static void Register(string phoneNumber, UnityAction <RequestData> onRegister = null)
 {
     provider = PhoneAuthProvider.GetInstance(auth);
     provider.VerifyPhoneNumber(phoneNumber, 1000, null, OnVerificationCompleted,
                                OnVerificationFailed, OnCodeSent, OnCodeAutoRetrievalTimeout);
     _onRegister = onRegister;
 }
Example #8
0
    public void NewSignIn()
    {
        auth = FirebaseAuth.DefaultInstance;
        string            phoneNumber        = "+79244225416";
        uint              phoneAuthTimeoutMs = 100000;
        PhoneAuthProvider provider           = PhoneAuthProvider.GetInstance(auth);

        provider.VerifyPhoneNumber(phoneNumber, phoneAuthTimeoutMs, null,
                                   verificationCompleted: (credential) =>
        {
            Debug.Log("Completed");
        },
                                   verificationFailed: (error) =>
        {
            Debug.Log("error");
        },
                                   codeSent: (id, token) =>
        {
            Debug.Log(id);
        },
                                   codeAutoRetrievalTimeOut: (id) =>
        {
            Debug.Log("Phone Auth, auto-verification timed out");
        });
    }
Example #9
0
        private void OnEnable()
        {
            bool isEditor = false;

#if UNITY_EDITOR
            isEditor = true;
#endif

            if (isEditor)
            {
                FirebaseApp firebaseApp = FirebaseApp.Create(
                    FirebaseApp.DefaultInstance.Options,
                    "FIREBASE_EDITOR");

                firebaseApp.SetEditorDatabaseUrl("https://artie-data.firebaseio.com/");

                FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task =>
                {
                    if (task.Result == DependencyStatus.Available)
                    {
                        _dbReference   = FirebaseDatabase.GetInstance(firebaseApp).RootReference;
                        _storage       = FirebaseStorage.GetInstance(firebaseApp);
                        _auth          = FirebaseAuth.GetAuth(firebaseApp);
                        _phoneProvider = PhoneAuthProvider.GetInstance(_auth);
                        _functions     = FirebaseFunctions.DefaultInstance;
                        if (localServices.Value)
                        {
                            _functions.UseFunctionsEmulator("http://localhost:5001");
                        }

                        // Listener for authentications changes
                        _auth.StateChanged += this.AuthStateChanged;
                        AuthStateChanged(this, null);
                    }
                    else
                    {
                        Debug.LogError("Could not resolve all Firebase dependencies: " + task.Result);
                        Console.WriteLine("Could not resolve all Firebase dependencies: " + task.Result);

                        // Listener for authentications changes
                        _auth.StateChanged += this.AuthStateChanged;
                        AuthStateChanged(this, null);
                    }
                });
            }
            else
            {
                FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://artie-data.firebaseio.com/");
                _dbReference   = FirebaseDatabase.DefaultInstance.RootReference;
                _storage       = FirebaseStorage.DefaultInstance;
                _functions     = Firebase.Functions.FirebaseFunctions.DefaultInstance;
                _auth          = FirebaseAuth.DefaultInstance;
                _phoneProvider = PhoneAuthProvider.GetInstance(_auth);

                // Listener for authentications changes
                _auth.StateChanged += this.AuthStateChanged;
                AuthStateChanged(this, null);
            }
        }
 public void StartPhoneNumberVerification(string phoneNumber)
 {
     PhoneAuthProvider.GetInstance(Auth).VerifyPhoneNumber(
         phoneNumber,
         60,
         TimeUnit.Seconds,
         Activity,
         MCallbacks);
 }
Example #11
0
        public void SendVerificationCode(string numeroCelular, PhoneValidationActivity Instance)
        {
            InitializeFirebase();

            PhoneVerificationCallback phoneAuthCallbacks = new PhoneVerificationCallback(Instance);

            auth = GetFirebaseAuth();

            PhoneAuthProvider.GetInstance(auth).VerifyPhoneNumber(numeroCelular, 30, TimeUnit.Seconds, Instance, phoneAuthCallbacks);
        }
 public void ResendVerificationCode(string phoneNumber, PhoneAuthProvider.ForceResendingToken token)
 {
     PhoneAuthProvider.GetInstance(Auth).VerifyPhoneNumber(
         phoneNumber,
         60,
         TimeUnit.Seconds,
         Activity,
         MCallbacks,
         token);
 }
        private void SendVerificationCode()
        {
            var callbacks = new PhoneAuthCallBacks(this);

            PhoneAuthProvider.GetInstance(_auth).VerifyPhoneNumber(
                _phoneNo,
                120,
                TimeUnit.Seconds,
                CrossCurrentActivity.Current.Activity,
                callbacks);
        }
        private Task <PhoneNumberVerificationResult> VerifyPhoneNumberForTestingAsync(Firebase.Auth.FirebaseAuth auth, string phoneNumber, string verificationCode, TimeSpan timeout)
        {
            var activity = CrossCurrentActivity.Current.Activity ?? throw new NullReferenceException("current activity is null");

            var tcs       = new TaskCompletionSource <PhoneNumberVerificationResult>();
            var callbacks = new Callbacks(tcs);

            auth.FirebaseAuthSettings.SetAutoRetrievedSmsCodeForPhoneNumber(phoneNumber, verificationCode);

            PhoneAuthProvider.GetInstance(auth).VerifyPhoneNumber(phoneNumber, (long)timeout.TotalMilliseconds, TimeUnit.Milliseconds, activity, callbacks);

            return(tcs.Task);
        }
Example #15
0
        private void SignInUser(string phoneNo)
        {
            InitFirebaseAuth();
            var callbacks = new PhoneAuthCallbacks(this);

            PhoneAuthProvider.GetInstance(_auth)
            .VerifyPhoneNumber(
                phoneNo,
                2,
                TimeUnit.Minutes,
                this,
                callbacks);
        }
Example #16
0
        private void SendVerificationCode()
        {
            auth = SessionManager.GetFirebaseAuth();
            PhoneAuthProvider.GetInstance(auth)
            .VerifyPhoneNumber(phone, 30, TimeUnit.Seconds, Activity, new PhoneVerificationCallbacks(
                                   onVerificationCompleted: (cred) =>
            {
                var code = cred.SmsCode;
                if (string.IsNullOrEmpty(code))
                {
                    return;
                }

                otpView.Value = code;
                VerifyCode(code);
            }, onVerificationFailed: (e) =>
            {
                try
                {
                    resendBtn.Enabled = false;
                    cdTimer.Cancel();
                    throw e;
                }
                catch (FirebaseNetworkException)
                {
                    OnboardingActivity.ShowNoNetDialog(false);
                }
                catch (FirebaseTooManyRequestsException ftmre)
                {
                    OnboardingActivity.ShowError(ftmre.Source, ftmre.Message);
                }
                catch (FirebaseAuthInvalidCredentialsException faice)
                {
                    OnboardingActivity.ShowError(faice.Source, faice.Message);
                }
                catch (FirebaseAuthInvalidUserException fiue)
                {
                    OnboardingActivity.ShowError(fiue.Source, fiue.Message);
                }
                catch (Exception ex)
                {
                    OnboardingActivity.ShowError(ex.Source, ex.Message);
                }
            }, onCodeSent: (code, token) =>
            {
                verificationId = code;
            }));
        }
Example #17
0
        // Sign in using phone number authentication using code input by the user.
        protected void VerifyReceivedPhoneCode()
        {
            PhoneAuthProvider phoneAuthProvider = PhoneAuthProvider.GetInstance(auth);
            // receivedCode should have been input by the user.
            Credential cred = phoneAuthProvider.GetCredential(phoneAuthVerificationId, receivedCode);

            if (signInAndFetchProfile)
            {
                auth.SignInAndRetrieveDataWithCredentialAsync(cred).ContinueWith(
                    HandleSignInWithSignInResult);
            }
            else
            {
                auth.SignInWithCredentialAsync(cred).ContinueWith(HandleSignInWithUser);
            }
        }
Example #18
0
        public Task <PhoneNumberVerificationResult> VerifyPhoneNumberAsync(IAuth auth, string phoneNumber, TimeSpan timeout)
        {
            var activity = CrossCurrentActivity.Current.Activity ?? throw new NullReferenceException("current activity is null");

            var tcs       = new TaskCompletionSource <PhoneNumberVerificationResult>();
            var callbacks = new Callbacks(tcs);

            var wrapper      = (AuthWrapper)auth;
            var firebaseAuth = (Firebase.Auth.FirebaseAuth)wrapper;

            firebaseAuth.FirebaseAuthSettings.SetAutoRetrievedSmsCodeForPhoneNumber(null, null);

            PhoneAuthProvider.GetInstance(firebaseAuth).VerifyPhoneNumber(phoneNumber, (long)timeout.TotalMilliseconds, TimeUnit.Milliseconds, activity, callbacks);

            return(tcs.Task);
        }
Example #19
0
    public void SignInGetPhoneOTP(string mobileNumber)
    {
        string phoneNumber        = "+91" + mobileNumber;
        uint   phoneAuthTimeoutMs = 120000;

        provider = PhoneAuthProvider.GetInstance(auth);
        Debug.Log(phoneNumber + ".....Phone number");
        AppHandler._instance._myData._mobileNumber = mobileNumber;
        provider.VerifyPhoneNumber(phoneNumber, phoneAuthTimeoutMs, null,
                                   verificationCompleted: (credential) =>
        {
            // Auto-sms-retrieval or instant validation has succeeded (Android only).
            // There is no need to input the verification code.
            // `credential` can be used instead of calling GetCredential().
            Debug.Log(".....auto verify");
            OnSuccessLogin();
        },
                                   verificationFailed: (error) =>
        {
            // The verification code was not sent.
            // `error` contains a human readable explanation of the problem.
            Debug.Log(".....failed because ..." + error);
        },
                                   codeSent: (id, token) =>
        {
            // Verification code was successfully sent via SMS.
            // `id` contains the verification id that will need to passed in with
            // the code from the user when calling GetCredential().
            // `token` can be used if the user requests the code be sent again, to
            // tie the two requests together.
            Debug.Log("inside codesent");
            PlayerPrefs.SetString("verifyid", id);
            //				PlayerPrefs.SetString("verifytoken",token);
            _OTPautoVerifyFail?.Invoke();
        },
                                   codeAutoRetrievalTimeOut: (id) =>
        {
            // Called when the auto-sms-retrieval has timed out, based on the given
            // timeout parameter.
            // `id` contains the verification id of the request that timed out.
            Debug.Log("inside timeout");
        });
    }
Example #20
0
    public void SignInPhone()
    {
        PhoneAuthProvider provider   = PhoneAuthProvider.GetInstance(auth);
        Credential        credential = provider.GetCredential(phoneVerificationId, otp.text);

        auth.SignInWithCredentialAsync(credential).ContinueWith(task => {
            if (task.IsFaulted)
            {
                Debug.Log("SignInWithCredentialAsync encountered an error: " + task.Exception);

                return;
            }

            Debug.Log("Phone Sign In successed.");
            // PhoneLoginSuccess();
            patientOtpPanel.SetActive(false);
            mainRegPanelPatient.SetActive(true);
        });
    }
Example #21
0
    public void PhoneSignup()                                                              // Registers user through phone number and links with the mail
    {
        PhoneAuthProvider provider   = PhoneAuthProvider.GetInstance(auth);
        Credential        credential = provider.GetCredential(phoneVerificationId, otp.text);

        auth.SignInWithCredentialAsync(credential).ContinueWith(task => {
            if (task.IsFaulted)
            {
                Debug.Log("SignInWithCredentialAsync encountered an error: " + task.Exception);

                return;
            }

            Debug.Log("Phone Sign In successed.");
            // PhoneLoginSuccess();

            otpPanel.SetActive(false);
        });
    }
    public void PhoneGetVerificationCode_Click()
    {
        provider = PhoneAuthProvider.GetInstance(auth);
        WriteLog("Verify Phone Number" + txtPhoneNumber.text);

        txtBtnGetCode.text = "Resend Verification Code";

        provider.VerifyPhoneNumber(txtPhoneNumber.text, 60, null,         //phoneAuthTimeoutMs = 60
                                   verificationCompleted: (credential) => {
            // Auto-sms-retrieval or instant validation has succeeded (Android only).
            // There is no need to input the verification code.
            // `credential` can be used instead of calling GetCredential().
            WriteLog("Auto-sms-retrieval or instant validation has succeeded (Android only).");

            OnVerifyCode(credential);
        },
                                   verificationFailed: (error) => {
            // The verification code was not sent.
            // `error` contains a human readable explanation of the problem.
            WriteLog("The verification code was not sent.");
            WriteLog(error.ToString());
        },
                                   codeSent: (id, token) => {
            // Verification code was successfully sent via SMS.
            // `id` contains the verification id that will need to passed in with
            // the code from the user when calling GetCredential().
            // `token` can be used if the user requests the code be sent again, to
            // tie the two requests together.
            WriteLog("Verification code was successfully sent via SMS.");
            WriteLog("Id: " + id);
            WriteLog("Token: " + token);
            phoneId = id;
        },
                                   codeAutoRetrievalTimeOut: (id) => {
            // Called when the auto-sms-retrieval has timed out, based on the given
            // timeout parameter.
            // `id` contains the verification id of the request that timed out.
            WriteLog("Auto-sms-retrieval has timed out");
            WriteLog("Id: " + id);
        });
    }
Example #23
0
    public void GetOTP()                                                                 //Function to send otp to the valid user mobile number
    {
        Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;    //Firebase auth instance creation to start authorization activity


        uint phoneAuthTimeoutMs    = 30000;                                              //
        PhoneAuthProvider provider = PhoneAuthProvider.GetInstance(auth);

        provider.VerifyPhoneNumber("+91" + phonenumber.text, phoneAuthTimeoutMs, null,
                                   verificationCompleted: (credential) =>
        {
            Debug.Log("1");

            //OnVerifyOTP(credential);
        },
                                   verificationFailed: (error) =>
        {
            Debug.Log("Verification failed");
        },
                                   codeSent: (id, token) =>
        {
            phoneVerificationId = id;
            Debug.Log("+91" + phonenumber.text);
            Debug.Log("SMS Has been sent and the verification Id is  " + id);
            runOTPTimer = true;
            resendOTPText.SetActive(false);
            resendOTPButton.SetActive(false);
        },
                                   codeAutoRetrievalTimeOut: (id) =>
        {
            //this is callback function and will be called after otp entry time is over.
            //enable resend otp button here
            resendOTPText.SetActive(true);
            resendOTPButton.SetActive(true);
            Debug.Log("Code Retrieval Time out");
        });
    }
    // Sign in Player
    private void SignInPlayer()
    {
        string typedPhoneNumber = AuthUIManager.instance.signUpPhoneInput.text;
        string phoneNumber      = "+62" + typedPhoneNumber.TrimStart('0');

        AuthUIManager.instance.SetMessage("Melakukan pendaftaran... .");
        FO.phoneAuthProvider = PhoneAuthProvider.GetInstance(FO.auth);

        FO.phoneAuthProvider.VerifyPhoneNumber(phoneNumber, AUTH_TIMEOUT, null,
                                               verificationCompleted: (credential) => {
            // Auto-sms-retrieval or instant validation has succeeded (Android only).
            // There is no need to input the verification code.
            // `credential` can be used instead of calling GetCredential().
            PlayerPrefs.SetString(UserPrefType.PLAYER_ID, typedPhoneNumber.ToString());
            FO.credential = credential;
            FO.auth
            .SignInWithCredentialAsync(FO.credential)
            .ContinueWithOnMainThread(task =>
            {
                if (task.IsCanceled)
                {
                    Debug.Log("Proses pendaftaran dibatalkan.");
                    AuthUIManager.instance.SetMessage("Proses pendaftaran dibatalkan");
                    return;
                }
                if (task.IsFaulted)
                {
                    Debug.Log("Proses pendaftaran belum berhasil. " + task.Exception);
                    AuthUIManager.instance.SetMessage("Proses pendaftaran belum berhasil. " + task.Exception);
                }
                if (task.IsCompleted)
                {
                    Debug.Log("Pendaftaran berhasil.");
                    AuthUIManager.instance.SetMessage("Pendaftaran berhasil.");
                    FO.user = task.Result;
                    ProceedToGame();
                }
            });
            AuthUIManager.instance.SetMessage("Verifikasi berhasil. ");
            ProceedToGame();
        },
                                               verificationFailed: (error) => {
            // The verification code was not sent.
            // `error` contains a human readable explanation of the problem.
            AuthUIManager.instance.SetMessage("Verifikasi belum berhasil. Cobalah beberapa saat lagi." + error);
        },
                                               codeSent: (id, token) => {
            // Verification code was successfully sent via SMS.
            // `id` contains the verification id that will need to passed in with
            // the code from the user when calling GetCredential().
            // `token` can be used if the user requests the code be sent again, to
            // tie the two requests together.
            PlayerPrefs.SetString(UserPrefType.VERIFICATION_ID, id);
            AuthUIManager.instance.SetMessage("Id verifikasi: " + id);
            AuthUIManager.instance.DisplayPanel(AuthPanelType.Verification, true);
        },
                                               codeAutoRetrievalTimeOut: (id) => {
            // Called when the auto-sms-retrieval has timed out, based on the given
            // timeout parameter.
            // `id` contains the verification id of the request that timed out.
            //AuthUIManager.instance.DisplayPanel(AuthPanelType.Verification, true);
        });
    }
Example #25
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
            {
                Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
                Window.SetStatusBarColor(Color.White.ToAndroid());
                Window.SetNavigationBarColor(Color.White.ToAndroid());
            }
            base.OnCreate(savedInstanceState);

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            Forms.SetFlags("CollectionView_Experimental");
            Forms.Init(this, savedInstanceState);

            /**
             * Subscribe to the "AuthenticatePhone" message, and start/handle firebase phone authentication
             */
            MessagingCenter.Subscribe <FirebaseAuthFunctions, string>(this, "AuthenticatePhone", (sender, phoneNumber) =>
            {
                var phoneVerificationCallbacks       = new PhoneAuthOnVerificationStateChangedCallbacks();
                phoneVerificationCallbacks.CodeSent += PhoneVerificationCodeSent;
                phoneVerificationCallbacks.VerificationCompleted += PhoneVerificationCompleted;
                phoneVerificationCallbacks.VerificationFailed    += PhoneVerificationFailed;

                PhoneAuthProvider.GetInstance(Auth).VerifyPhoneNumber(phoneNumber, 30, TimeUnit.Seconds, this, phoneVerificationCallbacks);
            });

            MessagingCenter.Subscribe <SignupPage>(this, "showingSocialOptions", (sender) =>
            {
                InitFirebaseAuth();
                if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
                {
                    Window.SetStatusBarColor(Android.Graphics.Color.ParseColor("#E81945"));
                    Window.SetNavigationBarColor(Android.Graphics.Color.ParseColor("#191919"));
                    Window.DecorView.SystemUiVisibility = StatusBarVisibility.Visible;
                }
            });

            MessagingCenter.Subscribe <ContinueSignup>(this, "RequestLocation", (sender) =>
            {
                if (Build.VERSION.SdkInt >= BuildVersionCodes.M)
                {
                    string lastPermission = "";
                    foreach (string permission in PermissionsLocation)
                    {
                        if (ContextCompat.CheckSelfPermission(this, permission) != (int)Permission.Granted)
                        {
                            if (ActivityCompat.ShouldShowRequestPermissionRationale(this, lastPermission))
                            {
                                Android.Views.View layout = FindViewById(Android.Resource.Id.Content);
                                Snackbar
                                .Make(layout, "Allow location access or manually select your preferred Country and State", Snackbar.LengthLong)
                                .SetAction("OK", v => ActivityCompat.RequestPermissions(this, PermissionsLocation, RequestLocationId))
                                .Show();
                            }
                            else
                            {
                                ActivityCompat.RequestPermissions(this, PermissionsLocation, RequestLocationId);
                            }
                            break;
                        }
                    }
                }
            });

            Window.SetBackgroundDrawable(new ColorDrawable(Color.White.ToAndroid()));

            App app = new App();

            LoadApplication(app);
        }
Example #26
0
    // Sign in Player
    IEnumerator SignInPlayer()
    {
        string phoneNumber = "+62" + PlayerPrefs.GetString(UserPrefType.PLAYER_ID).TrimStart('0');

        messageText.text     = "Melakukan pendaftaran... .";
        FO.phoneAuthProvider = PhoneAuthProvider.GetInstance(FO.auth);

        yield return(new WaitForSeconds(2f));

        FO.phoneAuthProvider.VerifyPhoneNumber(phoneNumber, AUTH_TIMEOUT, FO.forceResendingToken,
                                               verificationCompleted: (credential) =>
        {
            // Auto-sms-retrieval or instant validation has succeeded (Android only).
            // There is no need to input the verification code.
            // `credential` can be used instead of calling GetCredential().
            FO.credential = credential;
            FO.auth
            .SignInWithCredentialAsync(FO.credential)
            .ContinueWithOnMainThread(task => {
                if (task.IsCanceled)
                {
                    Debug.Log("Proses pendaftaran dibatalkan.");
                    messageText.text = "Proses pendaftaran dibatalkan.";
                    return;
                }
                if (task.IsFaulted)
                {
                    Debug.Log("Proses pendaftaran belum berhasil. " + task.Exception);
                    messageText.text = "Proses pendaftaran belum berhasil.";
                }
                if (task.IsCompleted)
                {
                    Debug.Log("Pendaftaran berhasil.");
                    FO.user          = task.Result;
                    messageText.text = "Pendaftaran berhasil.";
                    GoToScene("mainmenu");
                }
            });
        },
                                               verificationFailed: (error) =>
        {
            // The verification code was not sent.
            // `error` contains a human readable explanation of the problem.
            messageText.text = "Verifikasi otomatis belum berhasil. " + error;
            GoToScene("auth");
        },
                                               codeSent: (id, token) =>
        {
            // Verification code was successfully sent via SMS.
            // `id` contains the verification id that will need to passed in with
            // the code from the user when calling GetCredential().
            // `token` can be used if the user requests the code be sent again, to
            // tie the two requests together.
            PlayerPrefs.SetString(UserPrefType.VERIFICATION_ID, id.ToString());
        },
                                               codeAutoRetrievalTimeOut: (id) =>
        {
            // Called when the auto-sms-retrieval has timed out, based on the given
            // timeout parameter.
            // `id` contains the verification id of the request that timed out.
            messageText.text = "Verifikasi otomatis belum berhasil. Melakukan proses pendaftaran manual.";
            GoToScene("auth");
        });
    }
Example #27
0
    public void NewRegister()
    {
        if (tremsOfUseToggle.GetComponentInChildren <Toggle>().isOn&& labaRulesToggle.GetComponentInChildren <Toggle>().isOn)
        {
            string number = Verificator.IsValidPhoneNumber(phone_register.text);
            if (number == null)
            {
                Debug.Log("Неверно введен номер телефона");
                return;
            }
            if (!TestEmail.IsEmail(email_register.text))
            {
                Debug.Log("Неверно введен Email");
                return;
            }
            if (password_register.text.Trim().Length < 6)
            {
                Debug.Log("Пароль должен быть больше 6-ти символов");
                return;
            }
            if (name_register.text.Trim().Length < 2)
            {
                Debug.Log("Введите Имя");
                return;
            }
            if (lastName_register.text.Trim().Length < 1)
            {
                Debug.Log("Введите Фамилию");
                return;
            }
            if (patronymic_register.text.Trim().Length < 2)
            {
                Debug.Log("Введите Отчество");
                return;
            }


            Email        = email_register.text;
            Password     = password_register.text;
            Phone_Number = number;
            Name         = name_register.text;
            LastName     = lastName_register.text;
            Patronymic   = patronymic_register.text;
            Birthday     = "" + birthday_register[0].options[birthday_register[0].value].text + "/"
                           + birthday_register[1].options[birthday_register[1].value].text + "/"
                           + birthday_register[2].options[birthday_register[2].value].text;
            gameManager.ShowLoading(true);

            uint phoneAuthTimeoutMs = 60 * 1000;
            Provider = PhoneAuthProvider.GetInstance(Auth);
            Provider.VerifyPhoneNumber(Phone_Number, phoneAuthTimeoutMs, null,
                                       verificationCompleted: (credential) =>
            {
                Debug.Log("Completed");
                SignInAndUpdate(credential);
            },
                                       verificationFailed: (error) =>
            {
                Debug.Log("error");
                Debug.Log(error);
                gameManager.ShowLoading(false);
            },
                                       codeSent: (id, token) =>
            {
                Debug.Log(id);
                verificationId = id;
                gameManager.Panels[1].GetComponent <Animator>().Play("SSCR Fade-out");
                gameManager.Panels[2].GetComponent <Animator>().Play("SSCR Fade-in");
                gameManager.ShowLoading(false);
            },
                                       codeAutoRetrievalTimeOut: (id) =>
            {
                Debug.Log("Phone Auth, auto-verification timed out");
                gameManager.ShowLoading(false);
            });
        }
    }