forked from ITwrxOrg/Forget-Me-Not
fix issue #4
This commit is contained in:
parent
0c9ed3e257
commit
55def9973a
|
@ -16,30 +16,30 @@ proc vSize(sizeName: string, sizeValue: int, inputName: string, inputData: strin
|
|||
case inputType:
|
||||
of "string":
|
||||
if not (inputData.len >= sizeValue):
|
||||
msgString = inputName & " must have a character count of at least " & $sizeValue & " ."
|
||||
msgString = "The '" & inputName & "' field must have a character count of at least " & $sizeValue & " ."
|
||||
addFormError(inputName, msgString)
|
||||
of "integer":
|
||||
if not (parseIntIf(inputData) >= sizeValue):
|
||||
msgString = inputName & " must have a value of at least " & $sizeValue & " ."
|
||||
msgString = "The '" & inputName & "' field must have a value of at least " & $sizeValue & " ."
|
||||
addFormError(inputName, msgString)
|
||||
of "float":
|
||||
if not (parseFloat(inputData) >= sizeValue.float):
|
||||
msgString = inputName & " must have a value of at least " & $sizeValue & " ."
|
||||
msgString = "The '" & inputName & "' field must have a value of at least " & $sizeValue & " ."
|
||||
addFormError(inputName, msgString)
|
||||
of "max":
|
||||
#how we determine size depends on input type.
|
||||
case inputType:
|
||||
of "string":
|
||||
if inputData.len > sizeValue:
|
||||
msgString = inputName & " must have a character count that is no greater than " & $sizeValue & " ."
|
||||
msgString = "The '" & inputName & "' field must have a character count that is no greater than " & $sizeValue & " ."
|
||||
addFormError(inputName, msgString)
|
||||
of "integer":
|
||||
if parseIntIf(inputData) > sizeValue:
|
||||
msgString = inputName & " must have a value that is no greater than " & $sizeValue & " ."
|
||||
msgString = "The '" & inputName & "' field must have a value that is no greater than " & $sizeValue & " ."
|
||||
addFormError(inputName, msgString)
|
||||
of "float":
|
||||
if parseFloat(inputData) > sizeValue.float:
|
||||
msgString = inputName & " must have a value that is no greater than " & $sizeValue & " ."
|
||||
msgString = "The '" & inputName & "' field must have a value that is no greater than " & $sizeValue & " ."
|
||||
addFormError(inputName, msgString)
|
||||
|
||||
proc vType(inputName: string, inputData: string, validators: seq[string]): string =
|
||||
|
@ -51,18 +51,18 @@ proc vType(inputName: string, inputData: string, validators: seq[string]): strin
|
|||
discard parseIntIf(inputData)
|
||||
inputType = "integer"
|
||||
except:
|
||||
msgString = inputName & " must be a whole number."
|
||||
msgString = "The '" & inputName & "' field must be a whole number."
|
||||
addFormError(inputName, msgString)
|
||||
elif "float" in validators:
|
||||
try:
|
||||
discard parseFloat(inputData)
|
||||
inputType = "float"
|
||||
except:
|
||||
msgString = inputName & " must be a floating point number; a number with a decimal point. i.e. '1.5'"
|
||||
msgString = "The '" & inputName & "' field must be a floating point number; a number with a decimal point. i.e. '1.5'"
|
||||
addFormError(inputName, msgString)
|
||||
elif "boolean" in validators:
|
||||
if (inputData == "true") or not (inputData == "false"):
|
||||
msgString = inputName & " must be interpretable as a boolean. i.e. true, or false."
|
||||
msgString = "The '" & inputName & "' field must be interpretable as a boolean. i.e. true, or false."
|
||||
addFormError(inputName, msgString)
|
||||
inputType = "boolean"
|
||||
else:
|
||||
|
@ -92,7 +92,7 @@ proc vRegex(inputName: string, inputData: string, inputType: string, validators:
|
|||
conditionFieldInputData = formInput(conditionField)
|
||||
if conditionFieldInputData.len == 0:
|
||||
if inputData.len == 0:
|
||||
msgString = inputName & " is required when " & conditionField & " isn't set."
|
||||
msgString = "The '" & inputName & "' field is required when " & conditionField & " isn't set."
|
||||
addFormError(inputName, msgString)
|
||||
if match(v, re"^(must_unset_with):([a-z_]+)$"):
|
||||
let vNameSeq = v.split(':')
|
||||
|
@ -102,7 +102,7 @@ proc vRegex(inputName: string, inputData: string, inputType: string, validators:
|
|||
conditionFieldInputData = formInput(conditionField)
|
||||
if conditionFieldInputData.len > 0:
|
||||
if inputData.len > 0:
|
||||
msgString = inputName & " must be empty if " & conditionField & " is not."
|
||||
msgString = "The '" & inputName & "' field must be empty if " & conditionField & " is not."
|
||||
addFormError(inputName, msgString)
|
||||
if match(v, re"^(required_with):([a-z_]+)$"):
|
||||
let vNameSeq = v.split(':')
|
||||
|
@ -112,7 +112,7 @@ proc vRegex(inputName: string, inputData: string, inputType: string, validators:
|
|||
conditionFieldInputData = formInput(conditionField)
|
||||
if conditionFieldInputData.len > 0:
|
||||
if inputData.len == 0:
|
||||
msgString = inputName & " is also required when " & conditionField & " is set."
|
||||
msgString = "The '" & inputName & "' field is also required when " & conditionField & " is set."
|
||||
addFormError(inputName, msgString)
|
||||
if match(v, re"^(required_with):([a-z_]+):(without):([a-z_]+)$"):
|
||||
let vNameSeq = v.split(':')
|
||||
|
@ -125,7 +125,7 @@ proc vRegex(inputName: string, inputData: string, inputType: string, validators:
|
|||
conditionField2InputData = formInput(conditionField2)
|
||||
if conditionField1InputData.len > 0 and not conditionField2InputData.len > 0:
|
||||
if inputData.len == 0:
|
||||
msgString = inputName & " is required when " & conditionField1 & " is set and " & conditionField2 & " isn't set."
|
||||
msgString = "The '" & inputName & "' field is required when " & conditionField1 & " is set and " & conditionField2 & " isn't set."
|
||||
addFormError(inputName, msgString)
|
||||
if match(v, re"^(required_with):([a-z_]+):(without):([a-z_]+):(and_without):([a-z_]+)$"):
|
||||
let vNameSeq = v.split(':')
|
||||
|
@ -141,7 +141,7 @@ proc vRegex(inputName: string, inputData: string, inputType: string, validators:
|
|||
conditionField3InputData = formInput(conditionField3)
|
||||
if conditionField1InputData.len > 0 and not conditionField2InputData.len > 0 and not conditionField3InputData.len > 0:
|
||||
if inputData.len == 0:
|
||||
msgString = inputName & " is required when " & conditionField1 & " is set and " & conditionField2 & " and " & conditionField3 & " aren't set."
|
||||
msgString = "The '" & inputName & "' field is required when " & conditionField1 & " is set and " & conditionField2 & " and " & conditionField3 & " aren't set."
|
||||
addFormError(inputName, msgString)
|
||||
if match(v, re"^(required_when):([a-z_]+):(equals):([a-z_]+)$"):
|
||||
let vNameSeq = v.split(':')
|
||||
|
@ -152,7 +152,7 @@ proc vRegex(inputName: string, inputData: string, inputType: string, validators:
|
|||
let conditionField2 = vNameSeq[3]
|
||||
if conditionField1InputData.len > 0 and conditionField1InputData == conditionField2:
|
||||
if inputData.len == 0:
|
||||
msgString = inputName & " is required when " & conditionField1 & " equals " & conditionField2
|
||||
msgString = "The '" & inputName & "' field is required when " & conditionField1 & " equals " & conditionField2
|
||||
addFormError(inputName, msgString)
|
||||
if match(v, re"^(required_when):([a-z_]+):(equals):([a-z_]+):(without):([a-z_]+)$"):
|
||||
let vNameSeq = v.split(':')
|
||||
|
@ -166,17 +166,17 @@ proc vRegex(inputName: string, inputData: string, inputType: string, validators:
|
|||
conditionField3InputData = formInput(conditionField3)
|
||||
if conditionField1InputData.len > 0 and conditionField1InputData == conditionField2 and conditionField3InputData.len == 0:
|
||||
if inputData.len == 0:
|
||||
msgString = inputName & " is required when " & conditionField1 & " equals " & conditionField2 & " and " & conditionField3 & " is not set."
|
||||
msgString = "The '" & inputName & "' field is required when " & conditionField1 & " equals " & conditionField2 & " and " & conditionField3 & " is not set."
|
||||
addFormError(inputName, msgString)
|
||||
|
||||
proc vStandard(inputName: string, inputData: string, inputType: string, validators: seq[string]) =
|
||||
if "email" in validators:
|
||||
if not isEmail(inputData):
|
||||
msgString = inputName & " is not recognized as a valid email address."
|
||||
msgString = "The '" & inputName & "' field is not recognized as a valid email address."
|
||||
addFormError(inputName, msgString)
|
||||
if "min_complexity" in validators:
|
||||
if not isStrongPassword(inputData):
|
||||
msgString = inputName & " is not random/complex enough. Try to make your " & inputName & " more unpredictable by adding random numbers, random letter casing, unrelated words, special characters, etc."
|
||||
msgString = "The '" & inputName & "' field is not random/complex enough. Try to make your " & inputName & " more unpredictable by adding random numbers, random letter casing, unrelated words, special characters, etc."
|
||||
addFormError(inputName, msgString)
|
||||
|
||||
proc vHardcoded*(inputDataAll: Table[string, string], validators: seq[string]) =
|
||||
|
@ -194,7 +194,7 @@ proc vHardcoded*(inputDataAll: Table[string, string], validators: seq[string]) =
|
|||
else:
|
||||
inputDT = now()
|
||||
if inputDT <= nowDT:
|
||||
msgString = "send_date and send_time combined must be a DateTime in the future (compared to the DateTime at form submit)."
|
||||
msgString = "The 'send_date' and 'send_time' fields combined must be a DateTime in the future (compared to the DateTime at form submit)."
|
||||
addFormError("send_date", msgString)
|
||||
|
||||
proc vInput*(inputName: string, validators: seq[string]) =
|
||||
|
@ -206,7 +206,7 @@ proc vInput*(inputName: string, validators: seq[string]) =
|
|||
#check if 'required' is set and validate input if it exists. otherwise return error.
|
||||
if "required" in validators:
|
||||
if (inputData.len == 0):
|
||||
msgString = inputName & " is required."
|
||||
msgString = "The '" & inputName & "' field is required."
|
||||
addFormError(inputName, msgString)
|
||||
else:
|
||||
#proceed with validation.
|
||||
|
|
Loading…
Reference in New Issue