Custom form validation

Custom form validation

Bob Nguyen -
回帖数:5

Hi community,

Currently, I'm going to integrate Moodle with some other systems. And there're some custom validation I need to do before create user on Moodle. I'm looking for a way that I can custom the validation of create user, or in general, I'm looking for a way to override an existed form validation without modifying the existing code. Are there any way that I can do that?

Thank you!!

回复Bob Nguyen

Re: Custom form validation

Benjamin Ellis -
Hi,

You need to say how you intend to integrate the user - is the account going to be created when the user 1st logs in or will the user record be made using one of the web services available. Your solution to your dilemma will depend very much on this. However, I suspect you will have to create some kind of plugin for the extra validation.
回复Benjamin Ellis

Re: Custom form validation

Bob Nguyen -
Hi Benjamin,
Thank you so much for your reply.
I will have a central user management system. Users will be created on Moodle (and other systems as well), then it will be synced automatically to the central user mgmt. system. But yep, before the user is being created, I wanna call some API from my user mgmt. system to have some extra validation. So I'm asking if there're some hooks that I can extends the user creation validation, and from there I can put my API call to user mgmt. system to validate.
Thank you~
回复Bob Nguyen

Re: Custom form validation

Mark Sharp -
Core developers的头像 Particularly helpful Moodlers的头像 Plugin developers的头像
A couple of possibilities come to mind. The user_created event (https://docs.moodle.org/dev/Events_API#Existing_events) could be used to run your checks after a user has been created. You could possible use the user_loggedin to call your api.
The other way is around the authentication plugins. If your remote system has oauth2 you can configure Moodle to use that instead of the standard manual authentication. With authentication plugins you can also get your remote system to map fields to custom user fields in Moodle, so this might be a handy way to link data between the systems.
You can, of course, create your own authentication plugin.
回复Bob Nguyen

Re: Custom form validation

Benjamin Ellis -

Hi,

Seems to me it would be better to create and manage and validate your users on your central user management system and then sync that with Moodle - either creating the record when the user 1st logs in, using a scheduled task or using a web service for realtime updates.  Not sure why you would have other systems create users, sounds complicated and a recipe for data inconsistencies - but if you have to, have those systems create the users in your central user management application where you can validate the data before it is pushed to Moodle.  Only my 2 pennies worth but good luck with your project. 

回复Benjamin Ellis

Re: Custom form validation

Michael Hughes -
Core developers的头像 Particularly helpful Moodlers的头像 Plugin developers的头像
I definitely second this, if you already have a system that is mastering the users that you have, use it.

You definitely don't want to end up in a situation where you can't tell which one of these is authoritative. There *should* be enough combination of auth plugins to read your central system to provision users (authenticate) and then *authorising* them against specific centrally held roles is the second step.

It's really easy to conflate both authentication and authorisation into the same process.