public PmhPage(bool hasBackButton = true) { InitializeComponent(); NavigationPage.SetHasNavigationBar(this, false); demiCercle.Foreground = App.ColorPrimary; foreach (var pmh in App.PMH) { pmhPicker.Items.Add(pmh.Key); } HasBackButton = hasBackButton; //if (Device.RuntimePlatform == Device.iOS) { btnBack.TextColor = App.ColorPrimary; btnBack.Clicked += (sender, e) => OnBackButtonPressed(); btnBack.IsVisible = hasBackButton; btnBack.Text = AppResources.RetourBouton; } pmhPicker.SelectedIndexChanged += (sender, e) => { noseq = App.PMH[pmhPicker.SelectedItem.ToString()]; }; pmhPicker.SelectedIndex = 0; btnContinue.Clicked += (sender, e) => { Device.BeginInvokeOnMainThread(() => { Task.Run(async() => { Device.BeginInvokeOnMainThread(() => AppLoadingView.SetVisibility(true)); string answer = await PheidiNetworkManager.SetPMH(noseq); if (answer == PheidiNetworkManager.GoodResult) { Device.BeginInvokeOnMainThread(() => { //CRASH SUR ANDROID, https://bugzilla.xamarin.com/show_bug.cgi?id=53179 if (Device.RuntimePlatform != Device.Android) { App.Instance.GetToApplication(); Navigation.RemovePage(this); } //Work Around else { Navigation.PopAsync(); App.Instance.GetToApplication(); } }); } else { App.NotificationManager.DisplayAlert(AppResources.Erreur_ProblemeConnexionServeur, AppResources.Erreur_Title, "OK", () => { }); } Device.BeginInvokeOnMainThread(() => AppLoadingView.SetVisibility(false)); }); }); }; btnContinue.Text = AppResources.ContinuerBouton; SetFooter(); mainLayout.RaiseChild(AppLoadingView); AppLoadingView.IsVisible = false; }
public SystemLoginPage() { //Cache la nav bar NavigationPage.SetHasNavigationBar(this, false); InitializeComponent(); //Bouton de login btnLogin.Clicked += (sender, e) => { Task.Run(async() => { Device.BeginInvokeOnMainThread(() => AppLoadingView.SetVisibility(true)); string answer = await PheidiNetworkManager.SystemLogin(usernameEntry.Text, passwordEntry.Text); if (answer == PheidiNetworkManager.GoodResult) { App.CredentialsManager.DeleteSystemCredentials(); App.CredentialsManager.SaveSystemCredentials(usernameEntry.Text, passwordEntry.Text); DatabaseHelper.Database.DropTable <Geofence>(); DatabaseHelper.Database.CreateTable <Geofence>(); Device.BeginInvokeOnMainThread(App.Instance.GetLoginPage); } else { App.NotificationManager.DisplayAlert(answer, AppResources.Erreur_Title, "OK", () => { }); } Device.BeginInvokeOnMainThread(() => AppLoadingView.SetVisibility(false)); }); }; usernameEntry.Placeholder = AppResources.CourrielPlaceHolder; passwordEntry.Placeholder = AppResources.MotDePassePlaceHolder; btnLogin.Text = AppResources.ConnexionBouton; var systemAccount = App.CredentialsManager.GetSystemCredentials(); SetEntryLayoutVisibility(string.IsNullOrEmpty(systemAccount.Key)); if (systemAccount.Value != null) { btnCurrentAccount.Text = systemAccount.Value["Username"]; } btnCurrentAccount.BackgroundColor = App.ColorPrimary; btnCurrentAccount.TextColor = Color.White; //btnCurrentAccount.BorderColor = App.ColorPrimary; btnCurrentAccount.Clicked += (sender, e) => { Task.Run(async() => { Device.BeginInvokeOnMainThread(() => AppLoadingView.SetVisibility(true)); int count = 0; string answer = ""; var credentials = App.CredentialsManager.GetSystemCredentials(); while (answer != PheidiNetworkManager.GoodResult && answer != AppResources.Erreur_MauvaisEmailOuMdp && count < 5) { answer = await PheidiNetworkManager.SystemLogin(credentials.Value["Username"], credentials.Value["Password"]); count++; } if (answer == PheidiNetworkManager.GoodResult) { Device.BeginInvokeOnMainThread(App.Instance.GetLoginPage); } else { if (answer == AppResources.Erreur_MauvaisEmailOuMdp) { Device.BeginInvokeOnMainThread(() => updateEntryLayout.IsVisible = true); } App.NotificationManager.DisplayAlert(answer, AppResources.Erreur_Title, "OK", () => { }); } Device.BeginInvokeOnMainThread(() => AppLoadingView.SetVisibility(false)); }); }; btnOtherAccount.TextColor = App.ColorPrimary; btnOtherAccount.BorderColor = App.ColorPrimary; btnOtherAccount.BackgroundColor = Color.White; btnOtherAccount.Text = AppResources.AutreCompteBouton; btnOtherAccount.Clicked += (sender, e) => { SetEntryLayoutVisibility(true); }; btnBackToMainAccount.IsVisible = !string.IsNullOrEmpty(systemAccount.Key); btnBackToMainAccount.TextColor = App.ColorPrimary; btnBackToMainAccount.BorderColor = App.ColorPrimary; btnBackToMainAccount.BackgroundColor = Color.White; btnBackToMainAccount.Text = AppResources.RetourBouton; btnBackToMainAccount.Clicked += (sender, e) => { SetEntryLayoutVisibility(false); }; demiCercle.Foreground = App.ColorPrimary; updateUsernameEntry.Placeholder = AppResources.CourrielPlaceHolder; updatePasswordEntry.Placeholder = AppResources.MotDePassePlaceHolder; btnUpdateLogin.Text = AppResources.ConnexionBouton; //Bouton de login btnUpdateLogin.FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Button)); btnUpdateLogin.Clicked += (sender, e) => { Task.Run(async() => { Device.BeginInvokeOnMainThread(() => AppLoadingView.SetVisibility(true)); string answer = await PheidiNetworkManager.SystemLogin(updateUsernameEntry.Text, updatePasswordEntry.Text); if (answer == PheidiNetworkManager.GoodResult) { var credentials = App.CredentialsManager.GetSystemCredentials(); credentials.Value["Password"] = updatePasswordEntry.Text; credentials.Value["Username"] = updateUsernameEntry.Text; App.CredentialsManager.UpdateSystemCredentials(credentials); Device.BeginInvokeOnMainThread(App.Instance.GetLoginPage); } else { App.NotificationManager.DisplayAlert(answer, AppResources.Erreur_Title, "OK", () => { }); } Device.BeginInvokeOnMainThread(() => AppLoadingView.SetVisibility(false)); }); }; SetFooter(); mainLayout.RaiseChild(AppLoadingView); AppLoadingView.SetVisibility(false); }
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); }