LMSouq
moodle-core Open

Prevent local duplicates with the External Database Authentication Plugin on Moodle

FA
Fabi
1 month ago
3 views
Problem Description
I'm using Moodle's external database plugin and am having a very annoying problem. Here's an example: **username:** johndoe@gmail.com logs in with his password and both are saved in an external DB. Moodle grabs that data (username, password) and saves it locally (mysql) with that user's external DB id. Keep in mind the external DB is the main DB where everything happens, Moodle is only for authorized users that need to take tests. So in Moodle, I have: username: johndoe@gmail.com password: blabla userid: 1234 It works great, **except** for when johndoe@gmail.com decides to update his username/email on the external DB, so he wants it to be johndoe@hotmail.com now. When he tries to log in, it logs in fine, since Moodle checks with the external DB for both username/password. **Problem:** A new record is created within Moodle for johndoe@hotmail.com with same password **AND** userid. **My question is:** Where can I safely check with the local DB if userid already exists and **NOT** create a new record? I do not want to update the moodlelib doc because I don't want to have upgrading problems in the future. I can update the External DB plugin, but can't figure out where would be best. Here's a workaround someone did - https://moodle.org/mod/forum/discuss.php?d=232163 - but it's done in a cron job instead of immediately on Login. **UPDATE:** It looks like I'll have to update moodlelib and the external db plugin, I'll post my solution if nobody posts.

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base