async void Change_username_btn_Clicked(System.Object sender, System.EventArgs e)
        {
            var  user        = new MyUser();
            var  newUsername = New_username_entry.Text;
            bool usernameOk;
            var  authProvider = new FirebaseAuthProvider(new FirebaseConfig(WebAPIKey));

            void UsernameValidation()
            {
                //deve contenere tra i 6 e i 18 caratteri alfanumerici
                var userPattern = "[A-Za-z][A-Za-z0-9._]{5,17}";

                if (newUsername != null)
                {
                    if (Regex.IsMatch(newUsername, userPattern))
                    {
                        usernameOk = true;
                        LabelUserError.TextColor = Color.Transparent;
                    }

                    else
                    {
                        usernameOk = false;
                        LabelUserError.TextColor = Color.Red;
                    }
                }
                else
                {
                    usernameOk = false;
                    LabelUserError.TextColor = Color.Red;
                }
            }

            UsernameValidation();

            if (usernameOk)
            {
                try
                {
                    //This is the saved firebaseauthentication that was saved during the time of login
                    var savedfirebaseauth = JsonConvert.DeserializeObject <Firebase.Auth.FirebaseAuth>(Preferences.Get("MyLoginToken", ""));
                    //Here we are Refreshing the token
                    var RefreshedContent = await authProvider.RefreshAuthAsync(savedfirebaseauth);

                    Preferences.Set("MyLoginToken", JsonConvert.SerializeObject(RefreshedContent));
                    //Cambio password utente
                    await authProvider.UpdateProfileAsync(savedfirebaseauth.FirebaseToken, newUsername, "");

                    await App.Current.MainPage.DisplayAlert("Success.", "New Username set correctly.", "Ok");

                    await Navigation.PushAsync(new LoginPage());
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    await App.Current.MainPage.DisplayAlert("Ops... Something went wrong.", "Try to logout and log back in.", "Ok");
                }
            }
        }
Exemple #2
0
        //Update user data
        private async void Update()
        {
            try
            {
                Label nombreUsuario = new Label();
                nombreUsuario.SetBinding(Label.TextProperty, new Binding("Nombre", source: AppShell.Inicio));
                string nombre  = nombreUsuario.Text;
                var    usuario = await FirebaseHelper.ObtenerUsuario(nombre);

                string passSinEspacios = Regex.Replace(NewPassword, @"\s", "");
                if (!string.IsNullOrEmpty(passSinEspacios))
                {
                    if ((passSinEspacios.Length < 8 && passSinEspacios.Length > 15) || !passSinEspacios.ToCharArray().Any(Char.IsDigit))
                    {
                        UserDialogs.Instance.Alert("La contraseña debe tener como mínimo 8 caracteres y un máximo de 15, incluyendo una letra minúscula, una mayúscula y un número.", "Error", "OK");
                    }
                    else
                    {
                        var authProvider = new FirebaseAuthProvider(new FirebaseConfig(Constantes.WebAPIkey));
                        try
                        {
                            //This is the saved firebaseauthentication that was saved during the time of login
                            var savedfirebaseauth = JsonConvert.DeserializeObject <Firebase.Auth.FirebaseAuth>(Preferences.Get("MyFirebaseRefreshToken", ""));
                            //Here we are Refreshing the token
                            var RefreshedContent = await authProvider.RefreshAuthAsync(savedfirebaseauth);

                            Preferences.Set("MyFirebaseRefreshToken", JsonConvert.SerializeObject(RefreshedContent));
                            //Now lets grab user information
                            string token = savedfirebaseauth.FirebaseToken;
                            await authProvider.ChangeUserPassword(token, passSinEspacios);

                            var isupdate = await FirebaseHelper.ActualizarUsuario(nombre, usuario.FirebaseToken, usuario.UsuarioId);

                            if (isupdate)
                            {
                                UserDialogs.Instance.Alert("", "Contraseña actualizada", "Ok");
                            }
                            else
                            {
                                UserDialogs.Instance.Alert("No se ha podido actualizar.", "Error", "Ok");
                            }
                        }
                        catch (Exception)
                        {
                            UserDialogs.Instance.Alert("Por favor, introduzca un nombre de usuario y una contraseña correctos", "Fallo cambio contraseña", "OK");
                        }
                    }
                }
                else
                {
                    UserDialogs.Instance.Alert("Por favor, introduzca una nueva contraseña.", "Inserte una contraseña válida", "Ok");
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine($"Error catch:{e}");
            }
        }
Exemple #3
0
        public async Task GetProfileInfoAndRefreshToken(string userString)
        {
            var authProvider = new FirebaseAuthProvider(new FirebaseConfig(WebApiKey));

            try
            {
                var savedFirebaseAuth = JsonConvert.DeserializeObject<FirebaseAuth>(userString);
                var refreshContent = await authProvider.RefreshAuthAsync(savedFirebaseAuth);
                Preferences.Set("AppUser", JsonConvert.SerializeObject(savedFirebaseAuth));
            }
            catch (Exception ex)
            {
                await App.Current.MainPage.DisplayAlert("Refresh Error", ex.Message, "OK");
            }
        }
        async private void GetProfileInformationAndRefreshToken()
        {
            var authProvider = new FirebaseAuthProvider(new FirebaseConfig(webApiKey));

            try
            {
                var savedFirebaseAuth = JsonConvert.DeserializeObject <FirebaseAuth>(Preferences.Get("MyFirebaseRefreshToken", ""));
                var RefreshedContent  = await authProvider.RefreshAuthAsync(savedFirebaseAuth);

                Preferences.Set("MyFirebaseRefreshToken", JsonConvert.SerializeObject(RefreshedContent));

                DatabaseMethods.authID = savedFirebaseAuth.User.LocalId;
                await UserFunAsync();
            }
            catch (Exception e)
            {
                await App.Current.MainPage.DisplayAlert("Alert", "GET PROFILE " + e.Message, "ok");
            }
        }
Exemple #5
0
        async public void RefreshToken()
        {
            FirebaseAuthProvider authProvider = new FirebaseAuthProvider(new FirebaseConfig(WebAPIKey));

            try
            {
                //This is the saved firebaseauthentication that was saved during the time of login
                var savedfirebaseauth = JsonConvert.DeserializeObject <Firebase.Auth.FirebaseAuth>(Preferences.Get("MyLoginToken", ""));
                //Here we are Refreshing the token
                var RefreshedContent = await authProvider.RefreshAuthAsync(savedfirebaseauth);

                RefreshLoginToken(RefreshedContent);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                await App.Current.MainPage.DisplayAlert("Attention.", "Oh no! Token expired.", "Ok");
            }
        }
Exemple #6
0
        async private void GetProfileInformationAndRefreshToken()
        {
            var authProvider = new FirebaseAuthProvider(new FirebaseConfig(WebAPIkey));

            try
            {
                //This is the saved firebaseauthentication that was saved during the time of login
                var savedfirebaseauth = JsonConvert.DeserializeObject <Firebase.Auth.FirebaseAuth>(Preferences.Get("MyFirebaseRefreshToken", ""));
                //Here we are Refreshing the token
                var RefreshedContent = await authProvider.RefreshAuthAsync(savedfirebaseauth);

                Preferences.Set("MyFirebaseRefreshToken", JsonConvert.SerializeObject(RefreshedContent));
                //Now lets grab user information
                MyUserName.Text = savedfirebaseauth.User.Email;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                await App.Current.MainPage.DisplayAlert("Alert", "Oh no !  Token expired", "OK");
            }
        }
        async void change_pwd_btn_Clicked(System.Object sender, System.EventArgs e)
        {
            var user        = new MyUser();
            var userNewPwd  = new_pwd_entry.Text;
            var userConfPwd = repeat_pwd_entry.Text;


            var  authProvider = new FirebaseAuthProvider(new FirebaseConfig(WebAPIKey));
            bool passwordOk;

            void PasswordValidation()
            {
                //tra 8-20 cifre, un carattere maiuscolo, un carattere minuscolo, un numero e un carattere speciale
                var passwordPattern = "(?=.*[A-Z])(?=.*\\d)(?=.*[¡!@#$%*¿?\\-_.\\(\\)])[A-Za-z\\d¡!@#$%*¿?\\-\\(\\)&]{8,20}";

                if (userNewPwd != null)
                {
                    if (Regex.IsMatch(userNewPwd, passwordPattern))
                    {
                        passwordOk = true;
                        LabelPwdError.TextColor = Color.Transparent;
                    }

                    else
                    {
                        passwordOk = false;
                        LabelPwdError.TextColor = Color.Red;
                    }
                }
                else
                {
                    passwordOk = false;
                    LabelPwdError.TextColor = Color.Red;
                }
            }

            void PasswordConfirmationValidation()
            {
                if (!user.IsPasswordMatching(userNewPwd, userConfPwd))
                {
                    passwordOk = false;
                    LabelConfirmPwdError.TextColor = Color.Red;
                }
                else
                {
                    passwordOk = true;
                    LabelConfirmPwdError.TextColor = Color.Transparent;
                }
            }

            PasswordValidation();
            PasswordConfirmationValidation();

            if (passwordOk)
            {
                try
                {
                    //This is the saved firebaseauthentication that was saved during the time of login
                    var savedfirebaseauth = JsonConvert.DeserializeObject <Firebase.Auth.FirebaseAuth>(Preferences.Get("MyLoginToken", ""));
                    //Here we are Refreshing the token
                    var RefreshedContent = await authProvider.RefreshAuthAsync(savedfirebaseauth);

                    Preferences.Set("MyLoginToken", JsonConvert.SerializeObject(RefreshedContent));
                    //Cambio password utente
                    await authProvider.ChangeUserPassword(savedfirebaseauth.FirebaseToken, userNewPwd);

                    await App.Current.MainPage.DisplayAlert("Success.", "New password set correctly.", "Ok");

                    await Navigation.PushAsync(new LoginPage());
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    await App.Current.MainPage.DisplayAlert("Ops... Something went wrong.", "Try to logout and log back in.", "Ok");
                }
            }
        }
 public async Task <FirebaseAuthLink> RefreshLoginAsync(FirebaseAuth firebaseAuth)
 {
     return(await _firebaseAuthProvider.RefreshAuthAsync(firebaseAuth));
 }