Example #1
0
        private async void DoAutomaticLogin()
        {
            UserEntity user = new UserEntity {
                Email = config.GetEmailUser(),
                Pass  = config.GetPassUser()
            };
            await System.Threading.Tasks.Task.Delay(10000);

            bool loginResult = await user.LoginAsync();

            if (loginResult)
            {
                IsUserLoggedIn = true;
                config.SetEmailUser(user.Email);
                config.SetPassUser(user.Pass);

                DeviceEntity device = new DeviceEntity {
                    DeviceId    = App.config.GetDeviceId(),
                    DeviceToken = App.firebaseInstanceId.Token,
                    User        = user
                };

                bool updateTokenResult = await device.UpdateTokenAsync();

                if (updateTokenResult)
                {
                    MainPage = new NavigationPage(new MainPage());
                }
                else
                {
                    //update token fallito, provo con nuovo device
                    bool newDeviceResult = await device.NewDeviceOrUpdateTokenIfExistsAsync();

                    if (newDeviceResult)
                    {
                        MainPage = new NavigationPage(new Login());
                    }
                    else
                    {
                        //TODO mostro un errore e vado alla login
                        //await DisplayAlert("Error",
                        //    string.Format("", device.LastErrorMessage), "OK");
                    }
                }
            }
            else
            {
                MainPage = new NavigationPage(new Login());
            }
        }
Example #2
0
        async void OnLoginButtonClicked(object sender, EventArgs e)
        {
            IsWaiting = true;

            UserEntity user = new UserEntity {
                Email = usernameEntry.Text,
                Pass  = passwordEntry.Text
            };

            bool loginResult = await user.LoginAsync();

            if (loginResult)
            {
                App.IsUserLoggedIn = true;
                App.config.SetEmailUser(user.Email);
                App.config.SetPassUser(user.Pass);

                DeviceEntity device = new DeviceEntity {
                    DeviceId    = App.config.GetDeviceId(),
                    DeviceToken = App.firebaseInstanceId.Token,
                    User        = user
                };

                bool newDeviceResult = await device.NewDeviceOrUpdateTokenIfExistsAsync();

                if (!newDeviceResult)
                {
                    await DisplayAlert("Error",
                                       string.Format("", device.LastErrorMessage), "OK");
                }
                else
                {
                    Navigation.InsertPageBefore(new MainPage(), this);
                    await Navigation.PopAsync();
                }
            }
            else
            {
                messageLabel.Text  = string.Format("Login failed. Message={0}", user.LastErrorMessage);
                passwordEntry.Text = string.Empty;
                bool clearDataStoredResult = App.config.ClearDataStored();
                if (!clearDataStoredResult)
                {
                    Debug.WriteLine("Error, unable to clear data storage");
                }
            }

            IsWaiting = false;
        }
Example #3
0
        async void OnSignUpButtonClicked(object sender, EventArgs e)
        {
            IsWaiting = true;

            UserEntity user = new UserEntity {
                Email = emailEntry.Text,
                Pass  = passwordEntry.Text,
                Lang  = (string)langPicker.SelectedItem
            };

            bool signupResult = await user.SignUpAsync();

            if (signupResult)
            {
                App.IsUserLoggedIn = true;
                App.config.SetEmailUser(user.Email);
                App.config.SetPassUser(user.Pass);
                App.config.SetLangUser((string)langPicker.SelectedItem);

                DeviceEntity device = new DeviceEntity {
                    DeviceId    = App.config.GetDeviceId(),
                    DeviceToken = App.firebaseInstanceId.Token,
                    User        = user
                };

                bool newDeviceResult = await device.NewDeviceOrUpdateTokenIfExistsAsync();

                if (!newDeviceResult)
                {
                    await DisplayAlert("Error",
                                       string.Format("", device.LastErrorMessage), "OK");
                }
                else
                {
                    Navigation.InsertPageBefore(new MainPage(), this);
                    await Navigation.PopAsync();
                }
            }
            else
            {
                messageLabel.Text = string.Format("Sign Up failed. Message={0}", user.LastErrorMessage);
            }

            IsWaiting = false;
        }