void PasswordTextField_EditingDidEnd(object sender, EventArgs e) { var password = PasswordTextField.Text; //validate password if (HelperMethods.IsValidPassword(password)) { Settings.Password = password; } else { HelperMethods.SendBasicAlert("Validation", "Please input a valid email password (one number, one alpha character, and minimum length of 6)"); PasswordTextField.Text = string.Empty; } }
async void SubmitButton_TouchUpInside(object sender, EventArgs e) { UsernameTextField.Enabled = false; PasswordTextField.Enabled = false; string username = UsernameTextField.Text; string password = PasswordTextField.Text; if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password)) { if (!HelperMethods.IsValidPassword(password)) { HelperMethods.SendBasicAlert("Validation", "Passwords should contain letters and numbers and be at least 6 characters."); PasswordTextField.Layer.BorderColor = UIColor.Red.CGColor; PasswordTextField.Layer.BorderWidth = 1f; UsernameTextField.Enabled = true; PasswordTextField.Enabled = true; return; } //Save username/password to settings Settings.Username = username; Settings.Password = password; LoadingOverlay loadingIndicator = new LoadingOverlay(this.View.Frame, "Loading ..."); this.View.AddSubview(loadingIndicator); //AuthResponse BlobCache.LocalMachine.InvalidateObject <AuthResponse>(AuthResponse.getAuthResponse); AuthResponse response = await AuthResponse.GetAuthResponseAsync(0, Settings.Username, Settings.Password); Settings.AppID = response.AppId; Settings.AuthToken = response.AuthToken; APIManager manager = new APIManager(); { //LoginResponse authResponse = await manager.loginUser(Settings.AppID, Settings.Username, Settings.Password, Settings.AuthToken); LoginResponse authResponse = await manager.loginUser(Settings.AppID, Settings.Username, Settings.Password, Settings.AuthToken); if (authResponse.AuthToken != null) { Settings.AppID = authResponse.AppId; Settings.UserID = authResponse.MagAppUserId; Settings.AuthToken = authResponse.AuthToken; } else { loadingIndicator.Hide(); String responseMessage = ""; if (authResponse.ResponseMsg != null && authResponse.ResponseMsg != string.Empty) { responseMessage = authResponse.ResponseMsg; } else { responseMessage = "Unable to authenticate user."; } if (responseMessage == "Incorrect Password") { MessageViewController messageViewController = (MessageViewController)Storyboard.InstantiateViewController("MessageViewController"); this.PresentViewController(messageViewController, true, null); } else { HelperMethods.SendBasicAlert("Login", responseMessage); } UsernameTextField.Enabled = true; PasswordTextField.Enabled = true; return; } try { var responseProfile = await manager.getUserProfile(Settings.AppID, Settings.Username, Settings.AuthToken, Settings.Password); Settings.IsAmphibian = responseProfile.C1 == 1; Settings.IsCommercial = responseProfile.C2 == 1; Settings.IsExperimental = responseProfile.C3 == 1; Settings.IsHelicopter = responseProfile.C4 == 1; Settings.IsJets = responseProfile.C5 == 1; Settings.IsSingles = responseProfile.C7 == 1; Settings.IsSingleEngine = responseProfile.C6 == 1; Settings.IsTwinPistons = responseProfile.C8 == 1; Settings.IsTwinTurbines = responseProfile.C9 == 1; Settings.IsVintage = responseProfile.C10 == 1; Settings.IsWarbirds = responseProfile.C11 == 1; Settings.IsLightSport = responseProfile.C12 == 1; Settings.Email = Settings.Username; Settings.FirstName = responseProfile.FirstName; Settings.LastName = responseProfile.LastName; Settings.Phone = responseProfile.CellPhone; Settings.Company = responseProfile.Company; Settings.Hours = responseProfile.HourPerMonth; Settings.ManufacturerId = responseProfile.DesignationId; Settings.LocationPickerSelectedId = responseProfile.CountryId; Settings.Phone = responseProfile.CellPhone; Settings.DesignationId = responseProfile.DesignationId; Settings.PurposeId = responseProfile.FlyingPurposeId; Settings.HomeAirport = responseProfile.HomeAirport; Settings.Password = responseProfile.Password; Settings.PilotStatusId = responseProfile.PilotStatusId; Settings.PilotTypeId = responseProfile.PilotTypeId; Settings.PurchaseTimeFrame = responseProfile.PurchaseTimeFrame; loadingIndicator.Hide(); this.PerformSegue("LoadTabBarControllerSeque", this); } catch (Exception exe) { loadingIndicator.Hide(); HelperMethods.SendBasicAlert("Login", "Login Failed"); } } PasswordTextField.Layer.BorderColor = UIColor.Clear.CGColor; PasswordTextField.Layer.BorderWidth = 0f; UsernameTextField.Layer.BorderColor = UIColor.Clear.CGColor; UsernameTextField.Layer.BorderWidth = 0f; } else { //Update UI to reflect invalid username or password if (string.IsNullOrEmpty(username)) { UsernameTextField.Layer.BorderColor = UIColor.Red.CGColor; UsernameTextField.Layer.BorderWidth = 1f; } else { UsernameTextField.Layer.BorderColor = UIColor.Clear.CGColor; UsernameTextField.Layer.BorderWidth = 0f; } if (string.IsNullOrEmpty(password)) { PasswordTextField.Layer.BorderColor = UIColor.Red.CGColor; PasswordTextField.Layer.BorderWidth = 1f; } else { PasswordTextField.Layer.BorderColor = UIColor.Clear.CGColor; PasswordTextField.Layer.BorderWidth = 0f; } } UsernameTextField.Enabled = true; PasswordTextField.Enabled = true; }