General developer forum

 
 
Picture of Richard Egan
Force students to change their details
 

Hi there,

On our site students are enrolling themselves via an automated system in another CMS and only username, email and password are set up. This means their first and last name are something like 'default' or whatever but this needs to be changed - students need to be forced to change their details on log in.

I was writing some code that did a header redirect:

if($PAGE->title != "Edit Profile" && $USER->lastname = "changeme") {header( 'Location: http://www.example.com/user/edit.php' )}

However although this works for a few initial clicks, the lastname is changed back to "changeme" and thus the person is stuck on the edit profile page.

Is there a way I can get the lastname of the student as a variable so I can run the query if(lastname = "changeme") without the lastname being changed?

Or is there another solution to the problem altogether? (getting the student to change First and Last name on first time entering the site?

thanks,

Richard

 
Average of ratings: -
Picture of Simon Trendell
Re: Force students to change their details
 

I've not checked to see if what you're trying to do will work, but there is an error in your line of code there.

if($PAGE->title != "Edit Profile" && $USER->lastname == "changeme") {header( 'Location: http://www.example.com/user/edit.php' )}

The single equals is setting $USER->lastname equal to "changeme" and that is therefore always true. Change that to == as above and that should get you at least a step closer.

 
Average of ratings: -
Picture of Trevor Furtado Souza
Re: Force students to change their details
 

Richard,

Look the function user_not_fully_set_up($user) in /lib/moodlelib.php. Here is on line 3380.

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));
}

if you add or $USER->lastname == "changeme" in last return.
I think you will have the wished result.

 
Average of ratings:Useful (1)