private async Task InternalLoginAsync(string email, string pwd)
        {
            var authOptions         = new FirebaseAuthOptions(Secrets.FIREBASE_API_KEY);
            var firebaseAuthService = new FirebaseAuthService(authOptions);

            var request = new VerifyPasswordRequest()
            {
                Email    = email,
                Password = pwd
            };

            try
            {
                VerifyPasswordResponse response = await firebaseAuthService.VerifyPassword(request);

                _currentUser = new User
                {
                    Email = response.Email,
                    Token = response.IdToken
                };
            }
            catch (FirebaseAuthException e)
            {
                _telemetry.LogError("Error in firebase login", e);
            }
        }
Exemplo n.º 2
0
        internal async Task <string> ConnectApiAsync(string apiKey)
        {
            var authOptions = new FirebaseAuthOptions(apiKey);
            var firebase    = new FirebaseAuthService(authOptions);
            var request     = new VerifyPasswordRequest()
            {
                Email    = EMAIL,
                Password = PASSWORD
            };

            string authToken = String.Empty;

            try
            {
                var response = await firebase.VerifyPassword(request);

                authToken = response.IdToken;

                //authToken = response.RefreshToken;
            }
            catch (FirebaseAuthException e)
            {
                Application.Restart();
            }

            return(authToken);
        }
Exemplo n.º 3
0
        public async Task <User> LoginUser(LoginInput User)
        {
            var authOptions = new FirebaseAuthOptions("AIzaSyDHXodPd4jjaXSzwxrdCzJMptaiMPNeYME");
            var firebase    = new FirebaseAuthService(authOptions);

            User user = new User();

            // Set up data
            var request = new VerifyPasswordRequest()
            {
                Email    = User.Email,
                Password = User.Password
            };

            // Execute login query
            var response = await firebase.VerifyPassword(request);

            // Get Data
            user.Email     = response.Email;
            user.IdToken   = response.IdToken;
            user.ExpiresIn = response.ExpiresIn;
            user.LocalId   = response.LocalId;

            return(user);
        }
Exemplo n.º 4
0
        private async void login_Click(object sender, EventArgs e)
        {
            if (email_text.Text.Count() > 0 && password_text.Text.Count() > 0)
            {
                VerifyPasswordRequest request = new VerifyPasswordRequest();
                request.Email    = email_text.Text;
                request.Password = password_text.Text;
                try
                {
                    VerifyPasswordResponse response = await fService.VerifyPassword(request);

                    if (remember_me_check.Checked)
                    {
                        Settings.Default["email"]    = email_text.Text;
                        Settings.Default["password"] = password_text.Text;
                        Settings.Default.Save();
                    }

                    String uid = response.LocalId;

                    FirebaseResponse user_record = await client.GetAsync("users/" + uid);

                    UserData data = user_record.ResultAs <UserData>();

                    if (data.role == UserData.ROLE_ORGANIZER || data.role == UserData.ROLE_ADMIN)
                    {
                        DeliveryApp deliveryApp = new DeliveryApp();
                        deliveryApp.ShowDialog();
                    }
                    else if (data.role == UserData.ROLE_FULFILLMENT)
                    {
                        FulFillmentStuffForm target = new FulFillmentStuffForm();
                        target.Show();
                        Close();
                    }
                }
                catch (FirebaseAuthException ex)
                {
                    String msg = ex.Message;
                    if (remember_me_check.Checked)
                    {
                        /*Settings.Default["email"] = "";
                         * Settings.Default["password"] = "";
                         * Settings.Default.Save();*/
                    }
                    MessageBox.Show("Email address or password may not correct.");
                }
                catch (Exception ex) {
                    MessageBox.Show("Network status may not good, Try again later.");
                    Close();
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Change the current context to login.
        /// </summary>
        public async Task <bool> LoginAsync()
        {
            if (Email != string.Empty && Password != string.Empty)
            {
                var request = new VerifyPasswordRequest()
                {
                    Email    = this.Email,
                    Password = this.Password,
                };

                try
                {
                    var response = await _firebase.VerifyPassword(request);

                    if (response != null)
                    {
                        var userData = await _firebase.GetUserData(new GetUserDataRequest()
                        {
                            IdToken = response.IdToken
                        });

                        if (userData != null)
                        {
                            //save a flag to the application data to know that a user is logged in
                            SettingsImp.UserValue = JsonConvert.SerializeObject(userData.users[0]);

                            if (CheckIfVerified(userData))
                            {
                                await Xamarin.Forms.DependencyService.Get <IFirebaseAuthenticator>().LoginWithEmailPassword(this.Email, this.Password);

                                //SettingsImp.UserNameValue = await GetUserDataAsync();
                                return(true);
                            }
                            else
                            {
                                if (await _pageDialogservice.DisplayAlertAsync("Not Verified", "To use this account please verfiy your email address.", "Resend Email", "Cancel"))
                                {
                                    var sendverification = await _firebase.SendVerification(
                                        new SendVerificationEmailRequest()
                                    {
                                        RequestType = "VERIFY_EMAIL",
                                        IdToken     = response.IdToken,
                                    });
                                }
                            }
                        }
                    }
                }
                catch (FirebaseAuthException e)
                {
                    await _pageDialogservice.DisplayAlertAsync("Error", GetRigthErrorMessage(e), "Cancel");
                }

                //could not find user
                return(false);
            }
            else
            {
                //if the login process failed
                return(false);
            }
        }