Software /
code /
prosody
Comparison
util/dataforms.lua @ 4434:51a7c85751b9
util.dataforms: Fix form verification
author | Florian Zeitz <florob@babelmonkeys.de> |
---|---|
date | Fri, 02 Dec 2011 19:24:54 +0100 |
parent | 4397:1378e3c79c34 |
child | 4435:ea69296afaef |
comparison
equal
deleted
inserted
replaced
4433:f0e72fbe4d6a | 4434:51a7c85751b9 |
---|---|
118 tag = field_tag; | 118 tag = field_tag; |
119 break; | 119 break; |
120 end | 120 end |
121 end | 121 end |
122 | 122 |
123 local reader = field_readers[field.type]; | 123 if not tag then |
124 local verifier = field.verifier or field_verifiers[field.type]; | 124 if field.required then |
125 if reader then | 125 errors[field.name] = "Required value missing"; |
126 data[field.name] = reader(tag); | 126 end |
127 if verifier then | 127 else |
128 errors[field.name] = verifier(data[field.name], tag, field.required); | 128 local reader = field_readers[field.type]; |
129 local verifier = field.verifier or field_verifiers[field.type]; | |
130 if reader then | |
131 data[field.name] = reader(tag); | |
132 if verifier then | |
133 errors[field.name] = verifier(data[field.name], tag, field.required); | |
134 end | |
129 end | 135 end |
130 end | 136 end |
131 end | 137 end |
132 if next(errors) then | 138 if next(errors) then |
133 return data, errors; | 139 return data, errors; |
159 field_readers["jid-single"] = | 165 field_readers["jid-single"] = |
160 field_readers["text-single"]; | 166 field_readers["text-single"]; |
161 | 167 |
162 field_verifiers["jid-single"] = | 168 field_verifiers["jid-single"] = |
163 function (data, field_tag, required) | 169 function (data, field_tag, required) |
164 if #data == 0 and required then | 170 if ((not data) or (#data == 0)) and required then |
165 return "Required value missing"; | 171 return "Required value missing"; |
166 end | 172 end |
167 if not jid_prep(data) then | 173 if not jid_prep(data) then |
168 return "Invalid JID"; | 174 return "Invalid JID"; |
169 end | 175 end |