private bool ValidateFields(bool delete) { ForgotPasswordLabel.Enabled = false; ForgotPasswordLabel.Hide(); bool validCurrentPassword = Validator.ValidateUserPassword(currentPasswordTextBox, user.Password, currentPasswordValidateErrorLabel); if (delete) { firstNameValidateErrorLabel.Hide(); lastNameValidateErrorLabel.Hide(); emailValidateErrorLabel.Hide(); newPasswordValidateErrorLabel.Hide(); repeatNewPasswordValidateErrorLabel.Hide(); apiKeyValidateErrorLabel.Hide(); if (!validCurrentPassword) { if (currentPasswordTextBox.Text.Length > 0) { ForgotPasswordLabel.Enabled = true; ForgotPasswordLabel.Show(); } return(false); } return(true); } bool validFirstName = Validator.ValidateFirstNameTextBox(firstNameTextBox, firstNameValidateErrorLabel); bool validLastName = Validator.ValidateLastNameTextBox(lastNameTextBox, lastNameValidateErrorLabel); bool validEmail = Validator.ValidateEmailTextBox(emailTextBox, emailValidateErrorLabel, user.Id); if (!validCurrentPassword) { if (currentPasswordTextBox.Text.Length > 0) { ForgotPasswordLabel.Enabled = true; ForgotPasswordLabel.Show(); } } bool validNewPassword = Validator.ValidatePasswordTextBox(newPasswordTextBox, newPasswordValidateErrorLabel, true); bool validRepeatNewPassword = Validator.ValidateRepeatPasswordTextBox(newPasswordTextBox, repeatNewPasswordTextBox, repeatNewPasswordValidateErrorLabel, true); bool validApiKey = Validator.ValidateApiKeyTextBox(apiKeyTextBox, apiKeyValidateErrorLabel, user.Id); if (validFirstName && validLastName && validEmail && validCurrentPassword && validNewPassword && validRepeatNewPassword && validApiKey) { return(true); } return(false); }
private async void ValidateLogInUser() { ForgotPasswordLabel.Enabled = false; ForgotPasswordLabel.Hide(); bool validUsername = Validator.ValidateLogInUsername(usernameTextBox, usernameValidateErrorLabel); _ = Validator.ValidateUserPassword(passwordTextBox, "", passwordValidateErrorLabel); if (validUsername) { user = GlobalConfig.Connection.FindUserByUsername(usernameTextBox.Text); bool validPassword = Validator.ValidateUserPassword(passwordTextBox, user.Password, passwordValidateErrorLabel); if (!validPassword) { if (passwordTextBox.Text.Length > 0) { ForgotPasswordLabel.Enabled = true; ForgotPasswordLabel.Show(); } validUser = false; return; } validUser = true; if (user.LastLogin != null) { await Email.SendFavoritesToWatchEmail(user); } user.LastLogin = DateTime.UtcNow; GlobalConfig.Connection.UpdateUser(user); } }