public ValidationResult Validate(SignupViewModel instance) { var result = new ValidationResult { IsValid = true }; if (instance.ConfirmPassword != instance.Password) { result.IsValid = false; result.Messages.Add("Password confirmation does not match password."); } // Username validation if (UserService.UsernameAvailable(instance.Username).Result) { result.IsValid = false; result.Messages.Add("Username is not available."); } var matched = Regex.IsMatch(instance.Username, @"^[a-zA-Z]+([0-9A-Za-z|_|\.|\-]+)?$"); if (!matched) { result.IsValid = false; result.Messages.Add("Username is not valid."); } if (!EmailBusinessRule.Validate(instance.Email)) { result.IsValid = false; result.Messages.Add("Invalid email address."); } return(result); }
public async Task <IActionResult> Invite(string email) { if (!EmailBusinessRule.Validate(email)) { return(Json(new { Status = false, Message = "Invalid email address." })); } Guid.TryParse(CurrentUser.NameIdentifier, out Guid userId); if (!await ReferralService.SendInvite(email, userId)) { return(Json(new { Status = false, Message = "Error sending email. Try again later." })); } return(Json(new { Status = true })); }
public ValidationResult Validate(LoginViewModel instance) { var result = new ValidationResult { IsValid = true }; if (string.IsNullOrEmpty(instance.Password)) { result.IsValid = false; result.Messages.Add("Password field cannot be empty."); } if (!EmailBusinessRule.Validate(instance.Email)) { result.IsValid = false; result.Messages.Add("Invalid email address."); } return(result); }