public override IEnumerable <string> ValidateField(Form form, Field field, IEnumerable <object> postedValues, HttpContextBase context, IFormStorage formStorage) { var invalidFields = new List <string>(); var formFields = context.Request.Form; if (formFields["phone_intl_" + field.Id] != null) { try { var submittedNumber = formFields.Get("phone_intl_" + field.Id); var phoneNumberUtil = PhoneNumbers.PhoneNumberUtil.GetInstance(); var phoneNumber = phoneNumberUtil.Parse(submittedNumber, null); var isValid = phoneNumberUtil.IsValidNumber(phoneNumber); if (!isValid) { invalidFields.Add("The number entered is not valid"); return(invalidFields); } } catch (Exception e) { invalidFields.Add(e.Message); return(invalidFields); } } return(base.ValidateField(form, field, postedValues, context, formStorage)); }
public FormHandler(IProfilingLogger logger, SyncFormService syncFormService, IFormService formService, IFormStorage formStorage, AppCaches appCaches, ISyncSerializer <Form> serializer, ISyncItemFactory itemFactory, SyncFileService syncFileService) : base(logger, appCaches, serializer, itemFactory, syncFileService) { this.syncFormService = syncFormService; this.formService = formService; this.formStorage = formStorage; }
public override IEnumerable <string> ValidateField(Form form, Field field, IEnumerable <object> postedValues, HttpContextBase context, IFormStorage formStorage) { var errors = new List <string>(); var fieldValues = postedValues.ToList(); if (!fieldValues[0].ToString().Equals(fieldValues[1].ToString(), StringComparison.InvariantCultureIgnoreCase)) { if (string.IsNullOrEmpty(ValidationErrorMessage) || string.IsNullOrWhiteSpace(ValidationErrorMessage)) { ValidationErrorMessage = "The values entered do not match"; } errors.Add(ValidationErrorMessage); } return(errors.Any() ? errors : base.ValidateField(form, field, fieldValues, context, formStorage)); }
public SyncFormService( IPrevalueSourceService prevalueSourceService, IPrevalueSourceStorage prevalueSourceStorage, IDataSourceService dataSourceService, IDataSourceStorage dataSourceStorage, IFormService formService, IFormStorage formStorage, IWorkflowServices workflowServices, IWorkflowStorage workflowStorage) { this.prevalueSourceStorage = prevalueSourceStorage; this.prevalueSourceService = prevalueSourceService; this.dataSourceService = dataSourceService; this.dataSourceStorage = dataSourceStorage; this.formService = formService; this.formStorage = formStorage; this.workflowServices = workflowServices; this.workflowStorage = workflowStorage; }
/// <summary> /// Validates the field. /// </summary> /// <param name="form">The form.</param> /// <param name="field">The field.</param> /// <param name="postedValues">The posted values.</param> /// <param name="context">The context.</param> /// <returns></returns> public override IEnumerable <string> ValidateField(Form form, Field field, IEnumerable <object> postedValues, HttpContextBase context, IFormStorage formStorage) { var errorMessages = new List <string>(base.ValidateField(form, field, postedValues, context, formStorage)); if (postedValues != null) { foreach (string value in postedValues) { if (!ValidateEmailAddress(value)) { errorMessages.Add("Please enter a valid email address"); break; } } } return(errorMessages); }
public override IEnumerable <string> ValidateField(Form form, Field field, IEnumerable <object> postedValues, HttpContextBase context, IFormStorage formStorage) { string verifyUrl = null; string verifyPostParameter = null; if (ProviderName == Provider.Name.hCaptcha.ToString()) { verifyUrl = Consts.hCaptcha.VerifyUrl; verifyPostParameter = Consts.hCaptcha.VerifyPostParameter; } else if (ProviderName == Provider.Name.reCaptcha.ToString()) { verifyUrl = Consts.reCaptcha.VerifyUrl; verifyPostParameter = Consts.reCaptcha.VerifyPostParameter; } if (verifyUrl == null) { throw new Exception("\"uCaptchaProvider\" is missing or incorrect in AppSettings."); } string errorMessage; if (field.Settings.ContainsKey("ErrorMessage") && !string.IsNullOrEmpty(field.Settings["ErrorMessage"])) { errorMessage = field.Settings["ErrorMessage"]; } else { errorMessage = "You must check the \"I am human\" checkbox to continue"; } var returnStrings = new List <string>(); var secretKey = AppSettingsManager.GetuCaptchaSecretKey(); using (var client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded")); client.DefaultRequestHeaders.Add("Accept", "*/*"); var parameters = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("response", context.Request.Form[verifyPostParameter]), new KeyValuePair <string, string>("secret", secretKey), new KeyValuePair <string, string>("remoteip", context.Request.UserHostAddress) }; var request = new HttpRequestMessage(HttpMethod.Post, verifyUrl) { Content = new FormUrlEncodedContent(parameters) }; var response = client.SendAsync(request).Result; if (response.IsSuccessStatusCode) { var jsonString = response.Content.ReadAsStringAsync(); jsonString.Wait(); var result = JsonConvert.DeserializeObject <uCaptchaVerifyResponse>(jsonString.Result); if (!result.Success) { returnStrings.Add(errorMessage); } } if (!response.IsSuccessStatusCode) { returnStrings.Add(errorMessage); } } return(returnStrings); }
public override IEnumerable <string> ValidateField(Form form, Field field, IEnumerable <object> postedValues, HttpContextBase context, IFormStorage formStorage) { var fieldValueObject = field.Values.FirstOrDefault(); if (fieldValueObject == null) { return new List <string> { "Recaptcha token not set." } } ; var fieldValue = fieldValueObject.ToString(); if (fieldValue == "failed") { return new List <string> { "Recaptcha failed." } } ; if (!double.TryParse(fieldValue, out var score)) { return(new List <string> { $"Recaptcha Failed. (error: {fieldValue})" }); } double.TryParse(ScoreThreshold, out var scoreThreshold); if (scoreThreshold <= 0 || scoreThreshold > 1) { scoreThreshold = 0.5; } if (score < scoreThreshold) { return new List <string> { "Recaptcha score too low." } } ; return(new List <string>()); } }
public override IEnumerable <string> ValidateField(Form form, Field field, IEnumerable <object> postedValues, HttpContextBase context, IFormStorage formStorage) { var returnStrings = new List <string>(); var token = HttpContext.Current.Request["g-recaptcha-response"]; string secret = Configuration.GetSetting("RecaptchaPrivateKey"); var client = new WebClient(); var jsonResult = client.DownloadString(string.Format("https://www.google.com/recaptcha/api/siteverify?secret={0}&response={1}", secret, token)); var obj = JsonConvert.DeserializeObject <CaptchaResponse>(jsonResult); if (!obj.Success) { returnStrings.Add("Recaptcha Failed. Try again!"); } return(returnStrings); }