public App() { OMGITServiceClient _client; EndpointAddress EndPoint = new EndpointAddress("https://webapps.oregonmed.net/OMGITWebservices/OMGMobileServices.svc"); BasicHttpBinding binding = CreateBasicHttp(); _client = new OMGITServiceClient(binding, EndPoint); // _client.AddLogMessageTickerAppAsync("Reached App", "Contains Last Log in: " + Application.Current.Properties.ContainsKey("LastLoggedInUser").ToString()); _client.AddLogMessageMobileAsync("Reached App version: " + GlobalData.OMGAppVersion, Helpers.Settings.UserName, 0, GlobalData.loginData); byte[] token = null; byte[] salt = null; string username = string.Empty; string authToken = string.Empty; OMGITWebServices.OMGAuthTokenData atd = new OMGITWebServices.OMGAuthTokenData(); //if (Application.Current.Properties.ContainsKey("LastLoggedInUser")) if (Helpers.Settings.UserName != string.Empty) { //username = Application.Current.Properties["LastLoggedInUser"] as string; username = Helpers.Settings.UserName; atd.UserName = username; _client.AddLogMessageMobileAsync("Last Logged In User:"******"Token")) if (Helpers.Settings.AuthToken != string.Empty) { //token = Application.Current.Properties[username + "Token"] as byte[]; token = Convert.FromBase64String(Helpers.Settings.AuthToken); } //Check to make sure a salt exists for the last logged in user //if (Application.Current.Properties.ContainsKey(username + "Salt")) if (Helpers.Settings.Salt != string.Empty) { //salt = Application.Current.Properties[username + "Salt"] as byte[]; salt = Convert.FromBase64String(Helpers.Settings.Salt); } //If both the token and salt exist decrypt the token if (token != null && salt != null) { authToken = Crypto.DecryptAes(token, username, salt); atd.AuthToken = authToken; } } atd.MobilePlatform = Device.OS.ToString(); atd.OMGAppID = Constants.AppName; atd.PhoneIdentifier = DependencyService.Get <IGetDeviceInfo>().GetDeviceInfo(); _client.ValidateAuthenticationTokenAsync(atd); _client.ValidateAuthenticationTokenCompleted += completedValidation; while (orm.ErrorMessage == "None" || orm.ErrorMessage == null) { continue; } //If the token is a valid non-expired token open the TickerDisplayPage page if not open the Login page if (orm.Success) { OMGITWebServices.OMGLoginData loginData = new OMGITWebServices.OMGLoginData(); loginData.UserName = username; loginData.OMGAppID = Constants.AppName + GlobalData.OMGAppVersion; if (Device.OS == TargetPlatform.iOS) { loginData.MobilePlatform = "iOS"; } else if (Device.OS == TargetPlatform.Android) { loginData.MobilePlatform = "Android"; } else { loginData.MobilePlatform = "Unknown Platform"; } loginData.PhoneIdentifier = DependencyService.Get <IGetDeviceInfo>().GetDeviceInfo(); GlobalData.SetLoginData(loginData); string ipaddress = DependencyService.Get <IIPAddressManager>().GetIPAddress(); _client.GetNotificationAdminsAsync(loginData); _client.GetNotificationAdminsCompleted += ClientNotificationAdminsCompleted; while (NotificationAdmins == null) { continue; } bool isAdmin = false; foreach (string s in NotificationAdmins) { if (loginData.UserName == s) { isAdmin = true; break; } } if (isAdmin) { MainPage = new NavigationPage(new AdminMainPage()); } else { MainPage = new NavigationPage(new UserNotificationSettingsPage()); } } else { // The root page of your application MainPage = new LoginPage(); } }
private async void Submit_Clicked(object sender, EventArgs e) { submit.IsEnabled = false; if (Application.Current.Properties.ContainsKey("DeviceToken")) { string DeviceToken = Application.Current.Properties["DeviceToken"] as string; } try { _client = new OMGITServiceClient(binding, EndPoint); _client.AddLogMessageTickerAppAsync("Reached Submit_Clicked", "test"); var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location); if (status == PermissionStatus.Granted) { var locator = CrossGeolocator.Current; locator.DesiredAccuracy = 50; var position = await locator.GetPositionAsync(timeoutMilliseconds : 10000); latitude = position.Latitude.ToString(); longitude = position.Longitude.ToString(); altitude = position.Altitude.ToString(); Debug.WriteLine("Position Status: {0}", position.Timestamp); Debug.WriteLine("Position Latitude: {0}", position.Latitude); Debug.WriteLine("Position Longitude: {0}", position.Longitude); } } catch (Exception ex) { Debug.WriteLine("Unable to get location, may need to increase timeout: " + ex); } OMGITWebServices.OMGLoginData loginData = new OMGITWebServices.OMGLoginData(); loginData.UserName = usernameEntry.Text.Trim().ToLower(); loginData.Password = passwordEntry.Text; string alertMessage = alert.Text; loginData.OMGAppID = Constants.AppName; loginData.Altitude = altitude; loginData.Latitude = latitude; loginData.Longitude = longitude; if (Device.OS == TargetPlatform.iOS) { loginData.MobilePlatform = "iOS"; } else if (Device.OS == TargetPlatform.Android) { loginData.MobilePlatform = "Android"; } else { loginData.MobilePlatform = "Unknown Platform"; } loginData.PhoneIdentifier = DependencyService.Get <IGetDeviceInfo>().GetDeviceInfo(); if (keepLoggedInSwitch.IsToggled) { loginData.CreateAuthToken = true; } GlobalData.SetLoginData(loginData); await Task.Run(() => { _client = new OMGITServiceClient(binding, EndPoint); _client.LoginAsync(loginData); _client.LoginCompleted += ClientOnLoginCompleted; }); try { while (returnMessage.ErrorMessage == null) { continue; } if (returnMessage.Success) { if (keepLoggedInSwitch.IsToggled) { var data = loginData.UserName; var salt = Crypto.CreateSalt(16); var bytes = Crypto.EncryptAes(returnMessage.AuthToken, data, salt); Application.Current.Properties["LastLoggedInUser"] = loginData.UserName; Application.Current.Properties[loginData.UserName + "Token"] = bytes; Application.Current.Properties[loginData.UserName + "Salt"] = salt; await Application.Current.SavePropertiesAsync(); } OMGITWebServices.OMGInstallationData installData = new OMGITWebServices.OMGInstallationData(); if (Application.Current.Properties.ContainsKey("DeviceToken")) { installData.DeviceToken = Application.Current.Properties["DeviceToken"] as string; } installData.Username = loginData.UserName; installData.OperatingSystem = loginData.MobilePlatform; await Task.Run(() => { _client = new OMGITServiceClient(binding, EndPoint); _client.RegisterForNotificationsAsync(installData); _client.RegisterForNotificationsCompleted += ClientOnRegisterCompleted; }); if (loginData.UserName == "hfowler" || loginData.UserName == "dfowler" || loginData.UserName == "sliu" || loginData.UserName == "khellwege") { if (alertMessage != "") { await Navigation.PushModalAsync(new AdminMainPage(alertMessage)); } else { await Navigation.PushModalAsync(new AdminMainPage()); } } else { if (alertMessage != "") { await Navigation.PushModalAsync(new TickerDisplayPage(alertMessage)); } else { await Navigation.PushModalAsync(new TickerDisplayPage()); } } } else { if (incorrectPasswords == 0) { Label errorMessage = new Label { Text = returnMessage.ErrorMessage, TextColor = Color.Red, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, BackgroundColor = Color.White }; loginForm.Children.Add(errorMessage); } returnMessage.ErrorMessage = null; incorrectPasswords += 1; submit.IsEnabled = true; } } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } }
private async void Submit_Clicked(object sender, EventArgs e) { submit.IsEnabled = false; if (Application.Current.Properties.ContainsKey("DeviceToken")) { string DeviceToken = Application.Current.Properties["DeviceToken"] as string; } try { _client = new OMGITServiceClient(binding, EndPoint); _client.AddLogMessageMobileAsync("Reached Submit_Clicked in Login Page", "", 0, GlobalData.loginData); // _client.AddLogMessageTickerAppAsync("Reached Submit_Clicked in LoginPage", ""); var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location); if (status == PermissionStatus.Granted) { var locator = CrossGeolocator.Current; locator.DesiredAccuracy = 50; var position = await locator.GetPositionAsync(timeoutMilliseconds : 10000); latitude = position.Latitude.ToString(); longitude = position.Longitude.ToString(); altitude = position.Altitude.ToString(); Debug.WriteLine("Position Status: {0}", position.Timestamp); Debug.WriteLine("Position Latitude: {0}", position.Latitude); Debug.WriteLine("Position Longitude: {0}", position.Longitude); } } catch (Exception ex) { Debug.WriteLine("Unable to get location, may need to increase timeout: " + ex); } OMGITWebServices.OMGLoginData loginData = new OMGITWebServices.OMGLoginData(); string dontuseForLogin1 = "@oregonmed.net"; string dontuseForLogin2 = "omgnet"; if (usernameEntry.Text.Trim().ToLower().Contains(dontuseForLogin1) || usernameEntry.Text.Trim().ToLower().Contains(dontuseForLogin2)) { await DisplayAlert("Only enter your username", "Don't use @oregonmed.net or OMGNET", "Close"); submit.IsEnabled = true; return; } loginData.UserName = usernameEntry.Text.Trim().ToLower(); loginData.Password = passwordEntry.Text; string alertMessage = alert.Text; loginData.OMGAppID = Constants.AppName + GlobalData.OMGAppVersion; loginData.Altitude = altitude; loginData.Latitude = latitude; loginData.Longitude = longitude; if (Device.OS == TargetPlatform.iOS) { loginData.MobilePlatform = "iOS"; } else if (Device.OS == TargetPlatform.Android) { loginData.MobilePlatform = "Android"; } else { loginData.MobilePlatform = "Unknown Platform"; } loginData.PhoneIdentifier = DependencyService.Get <IGetDeviceInfo>().GetDeviceInfo(); string ipaddress = DependencyService.Get <IIPAddressManager>().GetIPAddress(); loginData.IPAddress = ipaddress; if (keepLoggedInSwitch.IsToggled) { loginData.CreateAuthToken = true; } GlobalData.SetLoginData(loginData); await Task.Run(() => { _client = new OMGITServiceClient(binding, EndPoint); _client.LoginAsync(loginData); _client.LoginCompleted += ClientOnLoginCompleted; }); try { while (returnMessage.ErrorMessage == null) { continue; } await Task.Run(() => { _client = new OMGITServiceClient(binding, EndPoint); _client.GetNotificationAdminsAsync(loginData); _client.GetNotificationAdminsCompleted += ClientNotificationAdminsCompleted; }); while (NotificationAdmins == null) { continue; } if (returnMessage.Success) { if (keepLoggedInSwitch.IsToggled) { var data = loginData.UserName; var salt = Crypto.CreateSalt(16); var bytes = Crypto.EncryptAes(returnMessage.AuthToken, data, salt); Helpers.Settings.UserName = loginData.UserName; Helpers.Settings.AuthToken = Convert.ToBase64String(bytes); Helpers.Settings.Salt = Convert.ToBase64String(salt); //Application.Current.Properties["LastLoggedInUser"] = loginData.UserName; //Application.Current.Properties[loginData.UserName + "Token"] = bytes; //Application.Current.Properties[loginData.UserName + "Salt"] = salt; //await Application.Current.SavePropertiesAsync(); } OMGITWebServices.OMGInstallationData installData = new OMGITWebServices.OMGInstallationData(); //if (Application.Current.Properties.ContainsKey("DeviceToken")) if (Helpers.Settings.DeviceToken != string.Empty) { //installData.DeviceToken = Application.Current.Properties["DeviceToken"] as string; installData.DeviceToken = Helpers.Settings.DeviceToken; } installData.Username = loginData.UserName; installData.OperatingSystem = loginData.MobilePlatform; await Task.Run(() => { _client = new OMGITServiceClient(binding, EndPoint); _client.RegisterForNotificationsAsync(installData, loginData); _client.RegisterForNotificationsCompleted += ClientOnRegisterCompleted; //_client.RegisterForNotificationsV2Async(installData, loginData); //_client.RegisterForNotificationsV2Completed += ClientOnRegisterCompleted; }); while (registerReturnMessage.ErrorMessage == null) { continue; } bool isAdmin = false; foreach (string s in NotificationAdmins) { if (loginData.UserName == s) { isAdmin = true; break; } } if (isAdmin) { if (alertMessage != "") { Device.BeginInvokeOnMainThread(() => { Navigation.PushModalAsync(new NavigationPage(new AdminMainPage(alertMessage))); }); } else { Device.BeginInvokeOnMainThread(() => { Navigation.PushModalAsync(new NavigationPage(new AdminMainPage())); }); } } else { if (alertMessage != "") { Device.BeginInvokeOnMainThread(() => { Navigation.PushModalAsync(new NavigationPage(new UserNotificationSettingsPage())); }); } else { Device.BeginInvokeOnMainThread(() => { Navigation.PushModalAsync(new NavigationPage(new UserNotificationSettingsPage())); }); } } } else { if (incorrectPasswords == 0) { Label errorMessage = new Label { Text = returnMessage.ErrorMessage, TextColor = Color.Red, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, BackgroundColor = Color.White }; loginForm.Children.Add(errorMessage); } returnMessage.ErrorMessage = null; incorrectPasswords += 1; submit.IsEnabled = true; } } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } }