Пример #1
0
        /// <summary>
        /// Anmeldedaten prüfen, lokal speichern und an den Server melden
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        async void Save(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(Nutzername))
            {
                Nutzername = Nutzername.ToLower();
                bool?exists = AllVM.Datenbank.User.Exists(Nutzername);

                if (exists == true)
                {
                    string pw  = AllVM.Datenbank.User.GetPasswort(Nutzername);
                    string hpw = AllVM.HashPassword(Passwort);
                    if (hpw == pw)
                    {
                        AllVM.Initial(Nutzername);
                        Application.Current.Properties.Clear();
                        Application.Current.Properties.Add("userid", Nutzername);
                        Application.Current.Properties.Add("userpw", pw);
                        await Application.Current.SavePropertiesAsync();

                        App.Current.MainPage = new AppShell();
                    }
                    else
                    {
                        DependencyService.Get <IMessage>().ShortAlert("Passwort stimmt nicht!");
                    }
                }
                else if (exists == false)
                {
                    DependencyService.Get <IMessage>().ShortAlert("Nutzername unbekannt");
                }
                else
                {
                    DependencyService.Get <IMessage>().ShortAlert("Fehler beim Prüfen");
                }
            }
            else
            {
                DependencyService.Get <IMessage>().ShortAlert("Nutzername eingeben!");
            }
        }
Пример #2
0
        /// <summary>
        /// Lokale Variablen prüfen und ggf. automatisch Anmelden
        /// </summary>
        private void AutoLogin()
        {
            string user = null, passwort = null;

            try
            {
                var current = Connectivity.NetworkAccess;
                if (current == NetworkAccess.Internet)
                {
                    if (Current.Properties.ContainsKey("userid"))
                    {
                        if (Current.Properties["userid"] != null)
                        {
                            user = Current.Properties["userid"].ToString();
                        }
                    }

                    if (Current.Properties.ContainsKey("userpw"))
                    {
                        if (Current.Properties["userpw"] != null)
                        {
                            passwort = Current.Properties["userpw"].ToString();
                        }
                    }

                    if (!string.IsNullOrWhiteSpace(user) && !string.IsNullOrWhiteSpace(passwort))
                    {
                        bool?exists = AllVM.Datenbank.User.Exists(user);
                        if (exists == true)
                        {
                            string pw = AllVM.Datenbank.User.GetPasswort(user);

                            if (user != null && (passwort == pw))
                            {
                                AllVM.Initial(user);
                                MainPage = new AppShell();
                            }
                            else
                            {
                                DependencyService.Get <IMessage>().ShortAlert("Passwort stimmt nicht");
                                MainPage = new NavigationPage(new Login());
                            }
                        }
                        else if (exists == false)
                        {
                            DependencyService.Get <IMessage>().ShortAlert("Nutzer existiert nicht");
                            MainPage = new NavigationPage(new Login());
                        }
                        else
                        {
                            DependencyService.Get <IMessage>().ShortAlert("Fehler beim Prüfen");
                            MainPage = new NavigationPage(new Login());
                        }
                    }
                    else
                    {
                        MainPage = new NavigationPage(new Login());
                    }
                }
            }
            catch (Exception ex)
            {
                _        = ex.Message;
                MainPage = new NavigationPage(new Login());
            }
        }