Plugin for validating custom user fields

plugins

(Michael Kitzman) #1

We have added a custom user field in our instance of Discourse that we have required on registration. We would like to validate this field against an external server using a REST api.

First I would like to know how we should hook into this process, either upon registration or editing this custom user field. Something like an OnFieldChange hook/event/thing.

Upon validation of this field, we want to adjust their trust level accordingly. I have searched around and haven’t seen a plugin that performs a similar task. Any help would be greatly appreciated.


(Daniel Stadelman) #2

@mdkitzman and I were able to figure out a way to validate the custom user field.

First we used the Discourse-Webhooks plugin to enable webhooks for DiscourseEvent triggers. We then monkey patched the UserCustomField to trigger a new event in a new plugin.

We then made a small web service that does the validation and uses the Discourse API to change the trust level.


(Ryan Harris) #3

We then made a small web service that does the validation and uses the Discourse API to change the trust level.

Forgive the noobie-ness of this but how did you get the value of your custom user field to be sent to your web service? I wrote a validator api for a custom user field and have the plugins in there but I don’t have any idea how to get the value posted.


(Mickey Binder) #4

I’m also looking for a way to validate custom fields. Would be nice if one could add a regex expression alongside the definition of the custom field, that the entered custom field value has to match. Is it something in that direction you made? Would you mind to share what kind of approach you took and how you created /included the api you wrote? Thanks


(Daniel Marquard) #5

+1! We have one field on our website that, despite having an example in the description, often is not submitted by users in the correct format. We really need validation on this field because it is used by one of our APIs to obtain additional information about users.