/// <summary> /// Gets the login page. /// </summary> public void GetLoginPage() { Credentials = CredentialsManager.GetAllCredentials(); SystemCredentials = CredentialsManager.GetSystemCredentials(); var p1 = new SystemLoginPage(); var page = new NavigationPage(p1); if (!string.IsNullOrEmpty(SystemCredentials.Key)) { int sysLoginCount = 0; string sysLoginAnswer = ""; bool sysLoginFinished = false; Task.Run(async() => { while (sysLoginAnswer != PheidiNetworkManager.GoodResult && sysLoginAnswer != AppResources.Erreur_MauvaisEmailOuMdp && sysLoginCount < 10) { sysLoginAnswer = await PheidiNetworkManager.SystemLogin(SystemCredentials.Value["Username"], SystemCredentials.Value["Password"]); sysLoginCount++; } sysLoginFinished = true; }); while (!sysLoginFinished) { Task.Delay(500).Wait(); } if (sysLoginAnswer == PheidiNetworkManager.GoodResult) { Page p2 = new ServerLoginPage(); if (ServerInfoList.Count == 0) { MainPage = page; NotificationManager.DisplayAlert(AppResources.Erreur_AucunServeur, AppResources.Erreur_Title, "OK", () => { }); } else if (ServerInfoList.Count == 1) { bool serverLoginFinished = false; int serverLoginCount = 0; string answer = ""; Task.Run(async() => { if (Credentials.Any((arg) => arg.Value["SystemCredentialsNoseq"] == SystemCredentials.Key && arg.Value["ServerNoseq"] == ServerInfoNoseq)) { var credentials = Credentials.First((arg) => arg.Value["SystemCredentialsNoseq"] == SystemCredentials.Key && arg.Value["ServerNoseq"] == ServerInfoList[0].Noseq); answer = await PheidiNetworkManager.UserLogin(credentials.Value["Username"], credentials.Value["Password"], false); if (answer != PheidiNetworkManager.GoodResult) { CredentialsManager.DeleteUser(credentials.Key); } else { UserNoseq = credentials.Key; } } else { while ((answer != PheidiNetworkManager.GoodResult && answer != AppResources.Erreur_MauvaisEmailOuMdp) && serverLoginCount < 10) { answer = await PheidiNetworkManager.UserLogin(SystemCredentials.Value["Username"], SystemCredentials.Value["Password"], false); serverLoginCount++; } if (answer == PheidiNetworkManager.GoodResult) { UserNoseq = SystemCredentials.Key; } } serverLoginFinished = true; }); while (!serverLoginFinished) { Task.Delay(500).Wait(); } if (answer != PheidiNetworkManager.GoodResult) { page.Navigation.PushAsync(p2); MainPage = page; } else if (answer == PheidiNetworkManager.GoodResult) { answer = string.Empty; Task.Run(async() => { answer = await PheidiNetworkManager.GetPMH(); }); while (string.IsNullOrEmpty(answer)) { Task.Delay(500).Wait(); } if (PMH.Count > 1) { Page p3 = new PmhPage(); page.Navigation.PushAsync(p3); MainPage = page; } else { Instance.GetToApplication(); } } } else { page.Navigation.PushAsync(p2); MainPage = page; } } else { MainPage = page; } } else { MainPage = page; if (!Current.Properties.ContainsKey("DeviceIsPublic")) { string message = AppResources.Alerte_SeulUsagerAppareil_Message; string title = AppResources.Alerte_SeulUsagerAppareil_Title; string confirm = AppResources.Oui; string cancel = AppResources.Non; System.Action onConfirm = () => { DeviceIsShared = false; }; System.Action onCancel = () => { DeviceIsShared = true; }; NotificationManager.DisplayAlert(message, title, confirm, cancel, onConfirm, onCancel); } } }
public ServerLoginPage() { NavigationPage.SetHasNavigationBar(this, false); InitializeComponent(); LastServerNoseq = App.ServerInfoNoseq; EntriesVisible(false); demiCercle.Foreground = App.ColorPrimary; //if (Device.RuntimePlatform == Device.iOS) { btnBack.TextColor = App.ColorPrimary; btnBack.Clicked += (sender, e) => OnBackButtonPressed(); btnBack.IsVisible = HasBackButton; btnBack.Text = AppResources.RetourBouton; } btnLogin.Clicked += (sender, e) => { Device.BeginInvokeOnMainThread(() => { Task.Run(async() => { Device.BeginInvokeOnMainThread(() => AppLoadingView.SetVisibility(true)); string s = ""; if (loginState == LoginState.ServerLogin) { s = await PheidiNetworkManager.UserLogin(usernameEntry.Text, passwordEntry.Text, true); if (s != PheidiNetworkManager.GoodResult) { App.NotificationManager.DisplayAlert(s, AppResources.Erreur_Title, "Ok", () => { }); } } if (loginState == LoginState.ServerAutoLogin) { if (App.Credentials.Any((arg) => arg.Value["SystemCredentialsNoseq"] == App.SystemCredentials.Key && arg.Value["ServerNoseq"] == App.ServerInfoNoseq)) { var credentials = App.Credentials.First((arg) => arg.Value["SystemCredentialsNoseq"] == App.SystemCredentials.Key && arg.Value["ServerNoseq"] == App.ServerInfoNoseq); s = await PheidiNetworkManager.UserLogin(credentials.Value["Username"], credentials.Value["Password"], false); if (s == PheidiNetworkManager.GoodResult) { App.UserNoseq = credentials.Key; } } else { s = await PheidiNetworkManager.UserLogin(App.SystemCredentials.Value["Username"], App.SystemCredentials.Value["Password"], false); if (s == PheidiNetworkManager.GoodResult) { App.UserNoseq = App.SystemCredentials.Key; } } if (s == AppResources.Erreur_MauvaisEmailOuMdp) { loginState = LoginState.ServerLogin; Device.BeginInvokeOnMainThread(() => EntriesVisible(true)); } else if (s != PheidiNetworkManager.GoodResult) { App.NotificationManager.DisplayAlert(s, AppResources.Erreur_Title, "Ok", () => { }); } } if (s == PheidiNetworkManager.GoodResult) { if (LastServerNoseq != App.ServerInfoNoseq) { DatabaseHelper.Database.DropTable <Geofence>(); DatabaseHelper.Database.CreateTable <Geofence>(); if (Application.Current.Properties.ContainsKey("LastGeofenceSync")) { Application.Current.Properties["LastGeofenceSync"] = "1753-01-01 00:00:00"; } } await PheidiNetworkManager.GetPMH(); if (App.PMH.Count > 1) { Device.BeginInvokeOnMainThread(async() => await Navigation.PushAsync(new PmhPage())); } else { Device.BeginInvokeOnMainThread(App.Instance.GetToApplication); } } Device.BeginInvokeOnMainThread(() => AppLoadingView.SetVisibility(false)); if (!string.IsNullOrEmpty(s)) { //Device.BeginInvokeOnMainThread(async () => await DisplayAlert("Problème de connexion", s, "OK")); } }); }); }; foreach (var server in App.ServerInfoList) { urlPicker.Items.Add(server.Domain); } urlPicker.Title = AppResources.SelectAdresse; urlPicker.SelectedIndexChanged += (sender, e) => { string item = urlPicker.SelectedItem.ToString(); App.CurrentServer = App.ServerInfoList.First(sein => sein.Domain == item); App.ServerInfoNoseq = App.CurrentServer.Noseq; EntriesVisible(false); loginState = LoginState.ServerAutoLogin; }; if (App.CurrentServer != null) { urlPicker.SelectedIndex = urlPicker.Items.IndexOf(App.CurrentServer.Domain); } urlPicker.SelectedIndex = urlPicker.SelectedIndex >= 0 ? urlPicker.SelectedIndex : 0; usernameEntry.Placeholder = AppResources.CourrielPlaceHolder; passwordEntry.Placeholder = AppResources.MotDePassePlaceHolder; btnLogin.Text = AppResources.ContinuerBouton; SetFooter(); mainLayout.RaiseChild(AppLoadingView); AppLoadingView.SetVisibility(false); }
public LoginPage(bool secondePage) { firstPageExist = !secondePage; Debug.WriteLine("LoginPage: ctor"); var watch = Stopwatch.StartNew(); //Cache la nav bar NavigationPage.SetHasNavigationBar(this, false); InitializeComponent(); Debug.WriteLine("Initialize: " + watch.Elapsed.Milliseconds); IsInSecondPage = secondePage; Debug.WriteLine("Setting Android: " + watch.Elapsed.Milliseconds); //Setting pour Android. if (Device.RuntimePlatform == Device.Android) { btnOtherAccount.BackgroundColor = Color.Transparent; btnOtherAccount.BorderColor = Color.Transparent; } btnOtherAccount.TextColor = App.ColorPrimary; btnBackToFirstPage.TextColor = App.ColorPrimary; btnBackToFirstPage.Clicked += (sender, e) => OnBackButtonPressed(); btnBackToFirstPage.IsVisible = false; Debug.WriteLine("Btn login: "******"Problème de connexion", s, "OK")); } }); }); }; Debug.WriteLine("Entry visible: " + watch.Elapsed.Milliseconds); EntriesVisible(secondePage); Debug.WriteLine("Url Picker: " + watch.Elapsed.Milliseconds); //Url Picker urlPicker.IsEnabled = secondePage; foreach (var server in App.ServerInfoList) { urlPicker.Items.Add(server.Domain); } urlPicker.Title = "Sélectionnez une adresse"; urlPicker.SelectedIndexChanged += (sender, e) => { string item = urlPicker.SelectedItem.ToString(); App.CurrentServer = App.ServerInfoList.First(sein => sein.Domain == item); App.ServerInfoNoseq = App.CurrentServer.Noseq; }; if (App.CurrentServer != null) { urlPicker.SelectedIndex = urlPicker.Items.IndexOf(App.CurrentServer.Domain); } Debug.WriteLine("User Picker: " + watch.Elapsed.Milliseconds); //User picker if (App.Credentials.Count > 0 && !secondePage) { foreach (var account in App.Credentials) { if (account.Value.ContainsKey("Username") && account.Value.ContainsKey("ServerNoseq")) { if (App.ServerInfoList.Any((arg) => account.Value["ServerNoseq"] == arg.Noseq)) { userPicker.Items.Add(account.Value["Username"] + " (" + App.ServerInfoList.First((arg) => account.Value["ServerNoseq"] == arg.Noseq).Domain + ")"); } } } if (userPicker.Items.Count == 0) { App.CredentialsManager.DeleteCredentials(); Device.BeginInvokeOnMainThread(App.Instance.GetLoginPage); } userPicker.SelectedIndexChanged += (sender, e) => { if (userPicker.SelectedIndex >= 0) { lastUserIndex = userPicker.SelectedIndex; string account = userPicker.Items[userPicker.SelectedIndex]; if (App.Credentials.Any((arg) => account == arg.Value["Username"] + " (" + App.ServerInfoList.First((si) => si.Noseq == arg.Value["ServerNoseq"]).Domain + ")")) { var user = App.Credentials.First((arg) => account == arg.Value["Username"] + " (" + App.ServerInfoList.First((si) => si.Noseq == arg.Value["ServerNoseq"]).Domain + ")"); App.UserNoseq = user.Key; App.ServerInfoNoseq = user.Value["ServerNoseq"]; App.CurrentServer = App.ServerInfoList.First((arg) => arg.Noseq == App.ServerInfoNoseq); usernameEntry.Text = user.Value["Username"]; passwordEntry.Text = user.Value["Password"]; urlPicker.SelectedIndex = urlPicker.Items.IndexOf(App.CurrentServer.Domain); } } }; userPicker.SelectedIndex = string.IsNullOrEmpty(App.UserNoseq) || App.CurrentServer == null ? 0 : App.Credentials.ContainsKey(App.UserNoseq) ? userPicker.Items.IndexOf(App.Credentials[App.UserNoseq]["Username"] + " (" + App.CurrentServer.Domain + ")") : 0; } usernameEntry.Placeholder = AppResources.CourrielPlaceHolder; lblCourriel.Text = AppResources.CourrielLabel; passwordEntry.Placeholder = AppResources.MotDePassePlaceHolder; lblPassword.Text = AppResources.MotDePasseLabel; lblRemember.Text = AppResources.MemoriserLabel; btnLogin.Text = AppResources.ConnexionBouton; btnOtherAccount.Text = AppResources.AutreCompteBouton; btnBackToFirstPage.Text = AppResources.RetourBouton; SetFooter(); mainLayout.RaiseChild(AppLoadingView); AppLoadingView.SetVisibility(false); Debug.WriteLine("TOTAL: " + watch.Elapsed.Milliseconds); }