public static async void fineAzioni()
 {
     try
     {
         await loginService.LoginAsync("@kfc", "1", false);
     }
     catch (NullReferenceException) { }
 }
        private async void Login_ClickedAsync(object sender, EventArgs e) //Effettua il Log In
        {
            wait = !wait;
            if (usernameEntry.Text == "Giulio1234" && passwordEntry.Text == "1234")
            {
                App.Current.MainPage = new MainPage();

                MessagingCenter.Send(new EditUserViewCell()
                {
                }, "RefreshUF");
            }

            if (!string.IsNullOrEmpty(usernameEntry.Text) && !string.IsNullOrEmpty(passwordEntry.Text))
            {
                Loading.IsVisible       = true;
                LoadingLottie.IsVisible = true;
                LoadingLottie.Play();
                var response = await loginService.LoginAsync(usernameEntry.Text, passwordEntry.Text, remember);

                LoadingLottie.IsVisible = false;
                Loading.IsVisible       = false;



                if (response == null)
                {
                    await DisplayAlert("Fondo Merende", "Errore di connessione", "OK");
                }
                else if (response.message == "Invalid login: wrong credentials.")
                {
                    await DisplayAlert("Fondo Merende", "Username o Password Errati", "OK");
                }
                else if (response.success == true)
                {
                    await userService.GetUserData();

                    App.Current.MainPage = new MainPage();
                    MessagingCenter.Send(new EditUserViewCell()
                    {
                    }, "RefreshUF");


                    wait = true;
                }
                else
                {
                    await DisplayAlert("Fondo Merende", "Errore da investigare", "OK");
                }
            }

            else
            {
                await DisplayAlert("Fondo Merende", "Username o Password mancanti", "OK");
            }
        }
        public static async Task <bool> cambiaCodice(Utente u)
        {
            LoginServiceManager login = new LoginServiceManager();

            var result = await login.LoginAsync(u.Username, u.Password, false);

            try
            {
                if (result.success == true && result != null)
                {
                    if (ControllaRegistrato(u) && !VerificaCodice(u.Codiceunivoco))
                    {
                        foreach (var app in utenti)
                        {
                            if (app.Username != u.Username || app.Password != u.Password)
                            {
                                continue;
                            }
                            app.Codiceunivoco = u.Codiceunivoco;
                            break;
                        }
                        await GestoreJson.Serializza(utenti);

                        fineAzioni();
                        return(true);
                    }
                }
            }
            catch (NullReferenceException)
            {
            }

            return(false);
        }
        public static async Task <bool> AggiungiUtente(Utente u)
        {
            LoginServiceManager login = new LoginServiceManager();

            var result = await login.LoginAsync(u.Username, u.Password, false);

            try
            {
                if (result.success == true && result != null)
                {
                    if (!ControllaRegistrato(u) && !VerificaCodice(u.Codiceunivoco))
                    {
                        utenti.Add(u);
                        await GestoreJson.Serializza(utenti);

                        fineAzioni();
                        return(true);
                    }
                }
            }
            catch (NullReferenceException)
            {
            }

            return(false);
        }
        public static async Task <bool> checkBeforeAction(string codice)
        {
            LoginServiceManager login = new LoginServiceManager();

            riempiLista();
            foreach (var app in utenti)
            {
                if (app.Codiceunivoco == codice)
                {
                    var result = await login.LoginAsync(app.Username, app.Password, false);

                    if (result.success == true)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemple #6
0
        public async void LogIn()
        {
            LoginServiceManager login = new LoginServiceManager();
            var resultLogin           = await login.LoginAsync(Preferences.Get("username", null), Preferences.Get("password", null), Preferences.Get("Logged", false));

            //   await userService.GetUserData();
            if (resultLogin == null)
            {
                App.Current.MainPage.DisplayAlert("Fondo Merende", "Connessione Al Fondo Merende fallita", "Ok");
            }
            else if (resultLogin.success)
            {
                await userService.GetUserData();

                App.Current.MainPage = new MainPage();
            }
            else
            {
                App.Current.MainPage = new NavigationPage(new LoginPage());
            }
        }