× Other Plugins

User Check plugin: needs to cope with existing users

2 years 10 months ago 2 years 10 months ago by Civica Digital. Reason: an additional point!
Civica Digital
Posts: 19
Topic Author
User Check plugin: needs to cope with existing users #1

I just installed the User Check plugin, as we have had problems with users with usernames containing spaces and upper case letters.

The plugin is great -- it does exactly what I need, and solves a big problem with regard to new user accounts.

However, we do have a problem with existing users who already have invalid usernames.

I want to fix the existing user accounts by removing the upper case letters and spaces, but the plugin is preventing me from doing so. It says that a Moodle account in that name already exists, which is true, but it exists for the current user so I don't want to get the error message in this case.

So I'd suggest a couple of tweaks to the plugin:
  • Change the "user update" validation so it doesn't bother checking for an existing Moodle account if the username change is only upper case to lower case.
  • Maybe allow admin users to override the plugin validation? ie have a config setting in the plugin to only activate it on the front-end. This would allow us to fix existing user accounts in admin without worrying about the plugin while still enforcing it for new user registrations

Finally, an additional suggestion: The plugin currently only does its checks server-side, on save. It would be great if it could also add a little bit of Javascript to the registration page to force input in the username field into lower case immediately. Something like this:
var input = document.getElementById('username');
input.onkeyup = function(){
    this.value = this.value.toLowerCase();
    if(this.value === ' ') { return false; }

Finally, one further point: It isn't just the username field that can cause problems. The user's real name can also be an issue. I have a few users who have entered their full name as something like "J.Smith". This ends up in Moodle with "J.Smith" in the firstname field and the surname field being empty. When this happens, any attempt by the user to navigate to the courses on the site will result in them being dumped into the Moodle user profile page because Moodle wants them to enter a surname.

It would be good if in addition to validating the username, this plugin could also enforce that the name field must include a space.


Simon C.
2 years 10 months ago
Antonio Durán
Posts: 6874
User Check plugin: needs to cope with existing users #2
Hi Simon.

Thanks for your suggestions.

I agree that plugin should let you change username to lowercase, as you say.
For this to happen, edit file: /plugins/user/joomdleusercheck/helper.php
if ((!$isnew) && ($user['username'] == $data['username']) && ($user['email'] == $data['email']))
        if ((!$isnew) && ((strcasecmp ($user['username'], $data['username']) == 0)  && ($user['email'] == $data['email'])))

I will add this change for next plugin release.

I don't think it is needed to allow override to admins, as with this change you should always be able to fix an uperrcase username.

As for the Javascript: this is done by each register extension, so it is not an easy thing to do. It would need a different plugin also.

I like your idea on the name field. I will try t add it as an option for next plugin release.
2 years 9 months ago
Antonio Durán
Posts: 6874
User Check plugin: needs to cope with existing users #3
We just released a new version with the commented fix, as well as the new option to require a space in name.

Thanks for your feedback.