General developer forum

force users to complete custom profile fileds when login

 
 
Picture of Michael E
Re: force users to complete custom profile fileds when login
 

I just found the answer myself.

    1. Open the file lib/moodlelib.php
    2. Search for: function user_not_fully_set_up($user) {(approx. line 3383)
    The complete function looks like this:
    function user_not_fully_set_up($user) {
        if (isguestuser($user)) {
            return false;
        }
        return (empty($user->firstname) or empty($user->lastname) or empty($user->email) or over_bounce_threshold($user));
    }
    3. Edit the return string according to your needs. Use the shortname of the field you want to force users to fill in. The correct usage is: empty($user->profile['short_fieldname'])
    If the fieldname for example is managersemail (from the Face-to-Face mod), change the return string to:

return (empty($user->firstname) or empty($user->lastname) or empty($user->email) or empty($user->profile['managersemail']) or over_bounce_threshold($user));

Hope that helps!

 
Average of ratings:Useful (1)
Picture of David Hempy
Re: force users to complete custom profile fileds when login
 

Thank you, Michael!  I just implemented this on our 2.5 server

I added a permissions check to only require the extra fields from students (not admins, teachers, etc.).  That part kinda works, but has issues since students are difficult to detect outside of a course.  I'm going to tinker with it some more later, but here's a start if anyone else wants to pursue it.

    return (empty($user->firstname) or empty($user->lastname) or empty($user->email) or over_bounce_threshold($user)
       or (
           (    empty($user->profile['BirthMonth'])
             or empty($user->profile['BirthDate'])
             or empty($user->profile['BirthYear'])  
           ) and !has_capability('report/courseoverview:view', context_system::instance())  // Allows teacher to avoid required birthdate.
       )       
    );

 
Average of ratings: -
Ben Ellis - chilled ;)
Re: force users to complete custom profile fileds when login
Group Plugin developers

Maybe we should ask for it as a new feature in tracker as I find myself facing the same issue.  

I am against hacking Moodle core code so I am intending to develop a plugin e.g. block that will direct the user to providing the information though I doubt I could force them to provide the info.  If anyone can think of a way to, I will gladly use listen.







 
Average of ratings: -
Picture of Olumuyiwa Taiwo
Re: force users to complete custom profile fileds when login
Group Particularly helpful Moodlers

I'm also against hacking core code, so I've created MDL-46946 to track this issue. Please vote for it if you want it fixed.

 
Average of ratings: -
Just wondering . . .
Re: force users to complete custom profile fileds when login
Group Particularly helpful Moodlers
OK,voted.

I think you should comment on the code to say the code snippet is here.

-Derek

 
Average of ratings: -
Picture of Olumuyiwa Taiwo
Re: force users to complete custom profile fileds when login
Group Particularly helpful Moodlers

Derek, I'm not quite sure what you mean by "comment on the code" since the function concerned is fairly short and I've already mentioned that it's in /lib/moodlelib.php. Can you please clarify?

 
Average of ratings: -
Picture of Kane Davis
Re: force users to complete custom profile fileds when login
 

its possible to do this with a custom auth provider. its a little hackish but it beats modifying core. just act on the user authenticated hook and force a redirect to the profile edit page. 

sorry for the latish reply; i just had a client ask for this functionality last week.

 
Average of ratings: -
Picture of Rocky Knowledge
Re: force users to complete custom profile fileds when login
 

Hi Michael, 

I've tried to force update profile on Moodle 3.0.3 by your trick, but moodel return me an exception:

Default exception handler: L'accesso al corso o attivit\xc3\xa0 non \xc3\xa8 consentito. Debug: User not fully set-up

Error code: requireloginerror, referer: http://192.168.3.135/moodle/user/edit.php

* line 2621 of /lib/moodlelib.php: require_login_exception thrown, referer: http://192.168.3.135/moodle/user/edit.php

* line 44 of /lib/editor/atto/autosave-ajax.php: call to require_login(), referer: http://192.168.3.135/moodle/user/edit.php

Can you help me?

Thanks

RK

 
Average of ratings: -