/// <summary> /// This method returns the User /// </summary> public bool ValidateUser() { // initial value (default to true) bool isValid = true; // Erase by default ValidationMessage = ""; // if there is a UserNameComponent if (HasUserNameComponent) { // validate this control isValid = UserNameComponent.Validate(); // if the value for isValid is false if (!isValid) { // Set the Validation Message ValidationMessage = UserNameComponent.InvalidReason; } else { // Set the UserName UserName = UserNameComponent.Text; } } // if the value for HasNameComponent is true if (HasNameComponent) { // no validation is required, just capturing the value this.Name = NameComponent.Text; } // if still valid if ((isValid) && (HasEmailAddressComponent)) { // is this valid isValid = EmailAddressComponent.Validate(); // if not valid if (!isValid) { // Set the InvalidReason ValidationMessage = EmailAddressComponent.InvalidReason; } else { // next we must check if this is a valid email isValid = CheckValidEmail(EmailAddressComponent.Text); // if not valid if (!isValid) { // Set the text ValidationMessage = "Please enter a valid email address"; // set to false EmailAddressComponent.IsValid = false; } else { // Set the EmailAddress EmailAddress = EmailAddressComponent.Text; } } // if the Password exists if ((isValid) && (HasPasswordComponent)) { // validate this control isValid = PasswordComponent.Validate(); // if the value for isValid is false if (!isValid) { // Set the Validation Message ValidationMessage = PasswordComponent.InvalidReason; } else { // Set Password Password = PasswordComponent.Text; } } // if the Confirm Password exists if ((isValid) && (HasConfirmPasswordComponent)) { // validate this control isValid = ConfirmPasswordComponent.Validate(); // if the value for isValid is false if (!isValid) { // Set the Validation Message ValidationMessage = ConfirmPasswordComponent.InvalidReason; } else { // Set Password2 Password2 = ConfirmPasswordComponent.Text; } } // if still valid if (isValid) { // next we must check that the two passwords match if (!TextHelper.IsEqual(Password, Password2, true, true)) { // set to false isValid = false; // Set the failed reason ValidationMessage = "The passwords do not match"; // verify both components exist if ((HasPasswordComponent) && (HasConfirmPasswordComponent)) { // set both to not valid PasswordComponent.IsValid = false; ConfirmPasswordComponent.IsValid = false; } } } } // return value return(isValid); }
/// <summary> /// method returns the Data /// </summary> public async void ReceiveData(Message message) { // locals User user = null; bool refreshRequired = false; // If the message object exists if (NullHelper.Exists(message)) { // if this is a Check Unique request if (TextHelper.IsEqual(message.Text, "Check Unique")) { // if there are at least one parameter if (ListHelper.HasOneOrMoreItems(message.Parameters)) { // if User Name if ((TextHelper.IsEqual(message.Parameters[0].Name, "User Name")) && (NullHelper.Exists(message.Parameters[0].Value))) { // get the userName string userName = message.Parameters[0].Value.ToString(); // attempt to find the UserName user = await UserService.FindUserByUserName(userName); // if the user exists if (HasUserNameComponent) { // create a response Message response = new Message(); // if the user exists if (NullHelper.Exists(user)) { // set to true refreshRequired = true; // Send a response of Taken response.Text = "Taken"; // Create the parameters NamedParameter namedParameter = new NamedParameter(); // Set the name namedParameter.Name = "Validation Message"; // Set the value namedParameter.Value = "The User Name is already taken. Click the login button if this is you."; // Set the ValidationMessage this.ValidationMessage = namedParameter.Value.ToString(); // Add the parameter response.Parameters.Add(namedParameter); } else { // Send a response of Taken response.Text = "Available"; } // send a message to the user UserNameComponent.ReceiveData(response); // Not valid UserNameComponent.IsValid = false; } } //if EmailAddress else if ((TextHelper.IsEqual(message.Parameters[0].Name, "Email Address")) && (NullHelper.Exists(message.Parameters[0].Value))) { // get the email string email = message.Parameters[0].Value.ToString(); // attempt to find the UserName user = await UserService.FindUserByEmailAddress(email); // if the value for HasEmailAddressComponent is true if (HasEmailAddressComponent) { // create a response Message response = new Message(); // if the user exists if (NullHelper.Exists(user)) { // set to true refreshRequired = true; // Send a response of Taken response.Text = "Taken"; // Create the parameters NamedParameter namedParameter = new NamedParameter(); // Set the name namedParameter.Name = "Validation Message"; // Set the value namedParameter.Value = "This email address is already taken. Click the Login Button if this is you."; // set the ValidationMessage this.ValidationMessage = namedParameter.Value.ToString(); // Add the parameter response.Parameters.Add(namedParameter); // Not valid EmailAddressComponent.IsValid = false; } else { // Send a response of Available response.Text = "Available"; // Not valid EmailAddressComponent.IsValid = true; } // send a message to the user EmailAddressComponent.ReceiveData(response); } } } } } if (refreshRequired) { // update the UI Refresh(); } }