/// <summary> /// Creator: Ben Hanna /// Created: 3/7/2020 /// Approver: Carl Davis, 3/13/2020 /// Approver: /// /// Toggles the animal's Adoptable state. /// detail view /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="sender"></param> /// <param name="e"></param> private void ChkEditAdoptable_Click(object sender, RoutedEventArgs e) { try { string caption = (bool)chkEditAdoptable.IsChecked ? "Set Adoptable" : "Set Non-Adoptable"; if (MessageBox.Show("Are you sure?", caption, MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No) { chkEditAdoptable.IsChecked = !(bool)chkEditAdoptable.IsChecked; return; } if (_animalManager.SetAnimalAdoptableState((bool)chkEditAdoptable.IsChecked, (int)lblEditAnimalID.Content)) { MessageBox.Show("Record Edited Successfully.", "Result"); } if ((bool)chkEditActive.IsChecked) { refreshActiveData(); } else { refreshInactiveData(); } } catch (Exception ex) { LogicLayerErrorHandler.ActivateDeactivateErrorMessage(ex.Message + "\n\n" + ex.InnerException); } }
/// <summary> /// Creator: Steven Cardona /// Created: 02/14/2020 /// Approver: Zach Behrensmeyer /// /// Adds items into dgUserList. /// </summary> /// <remarks> /// Updater: NA /// Updated: NA /// Update: NA /// </remarks> private void RefreshDgUserList() { try { dgUserList.ItemsSource = _userManager.RetrieveAllActivePetUniverseUsers(); } catch (Exception ex) { LogicLayerErrorHandler.DataLoadErrorMessage(ex.Message, ex.InnerException.Message); } }
/// <summary> /// Creator: Zach Behrensmeyer /// Created: 3/4/2020 /// Approver: Steven Cardona /// /// This Method is used to lockout the user /// /// </summary> /// <remarks> /// Updater: NA /// Updated: NA /// Update: NA /// /// </remarks> /// <param name="userEmail"></param> public void Lockout(string userEmail) { try { _userManager.LockoutUser(userEmail, DateTime.Now, DateTime.Now.AddMinutes(15)); } catch (Exception ex) { LogicLayerErrorHandler.LoginErrorMessage(ex.Message); } }
/// <summary> /// Creator: Zach Behrensmeyer /// Created: 3/5/2020 /// Approver: Steven Cardona /// /// This Method is used to get the actual unlock date from the db /// /// </summary> /// <remarks> /// Updater: NA /// Updated: NA /// Update: NA /// /// </remarks> /// <param name="userEmail"></param> /// <returns></returns> public DateTime getUnlockDate(string userEmail) { DateTime date = new DateTime(); try { date = _userManager.fetchUnlockDate(userEmail); } catch (Exception ex) { LogicLayerErrorHandler.LoginErrorMessage(ex.Message); } return(date); }
/// <summary> /// Creator: Zach Behrensmeyer /// Created: 3/4/2020 /// Approver: Steven Cardona /// /// This Method is used to unlock the user /// /// </summary> /// <remarks> /// Updater: NA /// Updated: NA /// Update: NA /// /// </remarks> /// <param name="userEmail"></param> public void UnlockByTime(string userEmail) { try { if (_userManager.UnlockUserByTime(userEmail) == true) { lblLockoutMessage.Content = ""; isLocked = false; } } catch (Exception ex) { LogicLayerErrorHandler.LoginErrorMessage(ex.Message); } }
/// <summary> /// Creator: Zach Behrensmeyer /// Created: 3/4/2020 /// Approver: Steven Cardona /// /// This Method is used to check that the user exists /// /// </summary> /// <remarks> /// Updater: NA /// Updated: NA /// Update: NA /// /// </remarks> /// <param name="userEmail"></param> public void CheckIfUserExists(string userEmail) { try { if (_userManager.CheckIfUserExists(userEmail) == true) { if (loginCount >= 3) { Lockout(userEmail); dt.Stop(); setTimer(); dt.Start(); isLocked = true; } } } catch (Exception ex) { LogicLayerErrorHandler.LoginErrorMessage(ex.Message); } }
/// <summary> /// Creator: Steven Cardona /// Created: 02/10/2020 /// Approver: Zach Behrensmeyer /// /// Create a new user by clicking save /// </summary> /// <remarks> /// Updater: Steven Cardona /// Updated: 03/01/2020 /// Update: Added Address validation checks /// </remarks> /// <param name="sender"></param> /// <param name="e"></param> private void btnSaveUser_Click(object sender, RoutedEventArgs e) { bool isCreated = false; PetUniverseUser newUser = new PetUniverseUser(); // Validate First Name if (!txtFirstName.Text.IsValidFirstName()) { "First Name cannot be blank".ErrorMessage("Validation"); //WPFErrorHandler.ErrorMessage("First name cannot be blank", "Validation"); txtFirstName.Text = ""; txtFirstName.Focus(); return; } else { newUser.FirstName = txtFirstName.Text; } // Validate Last Name if (!txtLastName.Text.IsValidLastName()) { WPFErrorHandler.ErrorMessage("Last name cannot be blank", "Validation"); txtLastName.Text = ""; txtLastName.Focus(); return; } else { newUser.LastName = txtLastName.Text; } // Validate Email if (!txtEmail.Text.IsValidEmail()) { WPFErrorHandler.ErrorMessage("Invalid email address", "Validation"); txtEmail.Text = ""; txtEmail.Focus(); return; } else { newUser.Email = txtEmail.Text; } // Validate Phone Number try { if (!txtPhoneNumber.Value.ToString().IsValidPhoneNumber()) { WPFErrorHandler.ErrorMessage("Invalid Phone Number", "Validation"); txtPhoneNumber.Text = ""; txtPhoneNumber.Focus(); return; } else { newUser.PhoneNumber = txtPhoneNumber.Value.ToString(); } } catch (Exception ex) { WPFErrorHandler.ErrorMessage(ex.Message, "Validation"); txtPhoneNumber.Text = ""; txtPhoneNumber.Focus(); return; } // Validate City if (!txtCity.Text.IsValidCity()) { string message = string.IsNullOrEmpty(txtCity.Text) ? "City cannot be blank" : "City must be less than 20 characters long"; WPFErrorHandler.ErrorMessage(message, "Validation"); txtCity.Text = ""; txtCity.Focus(); return; } else { newUser.City = txtCity.Text; } // Validate State if (cmbState.SelectedItem == null || !cmbState.SelectedItem.ToString().IsValidState()) { WPFErrorHandler.ErrorMessage("Please select a state", "Validation"); cmbState.Focus(); return; } else { newUser.State = cmbState.SelectedItem.ToString(); } // Validate Zipcode try { if (!txtZipcode.Text.IsValidState()) { WPFErrorHandler.ErrorMessage("Invalid Zipcode", "Validation"); txtZipcode.Text = ""; txtZipcode.Focus(); return; } else { newUser.ZipCode = txtZipcode.Text; } } catch (Exception ex) { WPFErrorHandler.ErrorMessage(ex.Message, "Validation"); } try { if (!txtAddress1.Text.IsValidAddress1()) { WPFErrorHandler.ErrorMessage("Invalid Address Line 1", "Validation"); txtAddress1.Text = ""; txtAddress1.Focus(); return; } else { newUser.Address1 = txtAddress1.Text; } } catch (Exception ex) { WPFErrorHandler.ErrorMessage(ex.Message, "Validation"); } try { if (!txtAddress1.Text.IsValidAddress2()) { WPFErrorHandler.ErrorMessage("Invalid Address Line 2", "Validation"); txtAddress2.Text = ""; txtAddress2.Focus(); return; } else { if (!string.IsNullOrEmpty(txtAddress2.Text)) { newUser.Address2 = txtAddress2.Text; } else { newUser.Address2 = null; } } } catch (Exception ex) { WPFErrorHandler.ErrorMessage(ex.Message, "Validation"); } newUser.Active = (bool)chkActive.IsChecked; try { if (_editMode == true && _originalUser == null) { isCreated = _userManager.CreateNewUser(newUser); if (isCreated) { WPFErrorHandler.SuccessMessage("Create new user was successful, add starting availability."); canAddUser.Visibility = Visibility.Hidden; canAddAvailability.Visibility = Visibility.Visible; } canAddUser.Visibility = Visibility.Hidden; } else if (_editMode == true && _originalUser != null) { bool isUpdated = _userManager.UpdateUser(_originalUser, newUser); if (isUpdated) { WPFErrorHandler.SuccessMessage("Information was updated for " + newUser.FirstName + " " + newUser.LastName); } canAddUser.Visibility = Visibility.Hidden; canUserView.Visibility = Visibility.Visible; } deactivateEditMode(); RefreshDgUserList(); } catch (Exception ex) { LogicLayerErrorHandler.UserCreationErrorMessage(ex.Message, ex.InnerException.Message); } }
/// <summary> /// Creator: Zach Behrensmeyer /// Created: 2/7/2020 /// Approver: Steven Cardona /// /// This Method is used to login the user after they click the button /// /// </summary> /// <remarks> /// Updater: Zach Behrensmeyer /// Updated: 3/15/2020 /// Update: Added code to create log source in the event viewer /// /// </remarks> /// <param name="sender"></param> /// <param name="e"></param> private void btnLogin_Click(object sender, RoutedEventArgs e) { // Create the source, if it does not already exist. if (!EventLog.SourceExists("PetUniverseLog")) { //An event log source should not be created and immediately used. //There is a latency time to enable the source, it should be created //prior to executing the application that uses the source. //Execute this sample a second time to use the new source. EventLog.CreateEventSource("PetUniverseLog", "PetUniverseLog"); return; } // Create an EventLog instance and assign its source. EventLog PULog = new EventLog(); PULog.Source = "PetUniverseLog"; loginCount += 1; isLocked = false; var userEmail = txtEmail.Text; var userPassword = pwdPassword.Password; unlockDate = getUnlockDate(userEmail); //Validating input if (!userEmail.IsValidEmail()) { //Display a message, always say user name or password bad //so bad users aren't sure what is wrong WPFErrorHandler.ErrorMessage("Invalid Username or Password.", "Login"); txtEmail.Focus(); return; } else if (!userPassword.IsValidPassword()) { WPFErrorHandler.ErrorMessage("Invalid Username or Password.", "Login"); txtEmail.Focus(); if (_userManager.CheckIfUserExists(userEmail) == true) { if (DateTime.Now > unlockDate) { //won't log them in, but will count as an active attempt to login if (loginCount >= 3) { isLocked = true; UnlockByTime(userEmail); if (dt == null) { setTimer(); } Lockout(userEmail); time = 901; dt.Start(); } } else { LogHelper.log.Error("User " + txtEmail.Text + " is locked out"); isLocked = true; UnlockByTime(userEmail); if (dt == null) { setTimer(); } Lockout(userEmail); time = 901; dt.Start(); } } return; } //Check if user is already locked out if (DateTime.Now > unlockDate) { //Make sure user actually exists if (_userManager.CheckIfUserExists(userEmail) == true) { //try to login try { _user = _userManager.AuthenticateUser(userEmail, userPassword); { string userRoles = ""; for (int i = 0; i < _user.PURoles.Count; i++) { userRoles += _user.PURoles[i]; if (i < _user.PURoles.Count - 1) { userRoles += ", "; } } if (pwdPassword.Password == "newuser") { var updatePassword = new UpdatePassword(_user, _userManager); if (updatePassword.ShowDialog() == false) { MessageBox.Show("You must change your password to continue"); return; } } else { this.Visibility = Visibility.Hidden; //Log successful login LogHelper.log.Info("Email: " + txtEmail.Text + " Successfully logged in."); var petUniverseHome = new PetUniverseHome(_user, userRoles); } } } catch (Exception ex) { if (loginCount >= 3) { isLocked = true; UnlockByTime(userEmail); if (dt == null) { setTimer(); } Lockout(userEmail); time = 901; dt.Start(); } //Log failed login LogHelper.log.Error("Someone failed to login using email: " + txtEmail.Text); LogicLayerErrorHandler.LoginErrorMessage(ex.Message); } } else { LogicLayerErrorHandler.LoginErrorMessage("Login Error."); } } else { LogHelper.log.Error("User " + txtEmail.Text + " is locked out"); isLocked = true; UnlockByTime(userEmail); if (dt == null) { setTimer(); } Lockout(userEmail); time = 901; dt.Start(); } }