How to determine first login of a user?

How to determine first login of a user?

by Christian Wolters -
Number of replies: 5

Hi @ll,

I guess this has been answered somewhere, but I could not find it or maybe it is just to easy?

Some context:

My goal is to provide specific new users with information on first login.

* Authentication is done via LDAP
* New users are redirected to /user/edit.php to complete custom profile files on first sign in

Now, in my theme I want to test:

  1. if if we are on /user/edit
  2. if a specific profile field holds a specific value
  3. if it is the first login of user
If all tests were successful, I would display custom instruction for these users before the main content.

I can do 1) via PAGE-Api und 2) via USER-Api, but how do I find out if it is the first login?

I've tried to determine where the redirect to /user/edit happens, but have not found that one either.

Thank you for any directions : )

Best regards
Christian


Average of ratings: -
In reply to Christian Wolters

Re: How to determine first login of a user?

by Benjamin Ellis -
Picture of Particularly helpful Moodlers
Hi,

There is a 'firstaccess' field in the User table that might be useful.
Average of ratings: Useful (2)
In reply to Benjamin Ellis

Re: How to determine first login of a user?

by Christian Wolters -
Hi Benjamin,

thank you for getting back to me : )

You are right, 'firstaccess' does give me the timestamp of the first login.

However, using this method I would have to define a time interval between first access and time of access
in which the information would be displayed.

I'm hestitating to implement this, as this does not work ideally in the following use case

* first time login -> user is presented with profile fields to complete
* user closes (for whatever reason, but it happens a lot) browser before completing profile
* user accesses moodle a again, three days later -> user is presented with profile fields to complete

Now in this case, firstaccess is already three days old.

Therefor, it can not be the only criteria to base the decision on.

Does anyone know, how moodle determines the redirect to to /user/edit.php to complete custom profile files on login?

Cheers
Christian
In reply to Christian Wolters

Re: How to determine first login of a user?

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
That's an easy question to answer. If the user has missing profile fields (off the top of my head, the fields checked are "firstname", "lastname", "email", but you can always check by looking for the function "user_not_fully_set_up()"), then the user is redirected on login. If those fields are filled in, then the user is not redirected.

As for your original question - why not simply add a checkbox to the user profile page for the user to tick when they've read and understood the instructions. That way you can keep sending them back there (by customising the user_not_fully_set_up() function) until they tick the box.
Average of ratings: Useful (4)
In reply to Davo Smith

Re: How to determine first login of a user?

by Christian Wolters -
Yes! Thank you 🙏 That was exactly the kind of function I was looking for!

Indeed, what a nice suggestion, I'll experiment in that direction.

Best regards
Christian
Average of ratings: Useful (1)