Supporting each other

Community forums

Welcome, Guest
Username: Password: Remember me
The place for more technical questions for those who want to create new pagetypes or bespoke functionality.
  • Page:
  • 1

TOPIC:

User ever logged in? - adding multiple users 4 years 5 months ago #6734

  • jayaich
  • jayaich's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
  • Posts: 82
  • Thank you received: 5
Hi,

A quick question to start with - in the file 'user_library.php' is the code:
function check_if_first_time($username){
    global $xerte_toolkits_site;
    $query = "select login_id from {$xerte_toolkits_site->database_table_prefix}logindetails where username = ? ";
    $response = db_query_one($query, array($username));

        if(empty($response)) {
                return true;
        }
    return false;
}

The question is could this, or should this, be changed to check for the 'lastlogin' value rather than the login_id? By default the lastlogin value is NULL, and, obviously, gets set when the user actually logs in.

Why do this? Well, I've been asked if it is possible to 'add' 300+ users to Xerte without them actually having to log in. What is wanted is that a project is shared with these users without them having to go through the sequence of actually logging in, then notifying the admin team that they have done so and then share the project with the logged in user. To share the project the users name/id must appear in the drop-down list, and for that to happen the user must be in the logindetails table.

It seems a reasonable request, and looking through the code I think it could be done by simply adding the user to the 'logindetails' table (with a NULL lastlogin value). When the user actually logs in for the first time, their root directory and recycle bin should be created but the above code would prevent that (since the login_id would exist) unless it was changed to use the lastlogin field.

Does the code change seem reasonable?
Does adding users then seem possible? (We use the SAML2 authentication method; I know that using 'Db' authentication already has a mechanism for adding users.)

Thanks.

Please Log in or Create an account to join the conversation.

User ever logged in? - adding multiple users 4 years 5 months ago #6739

  • tom
  • tom's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 1303
  • Thank you received: 326
It won't solve your complete problem.

By adding the users (by hand) to the logindetails table, and you will be able to see/select them when sharing LO's
Your proposal will solve the issue that their workspace will be setup when the user actually logs in the first time.

However, that also means that the workspace of a user you want to share an LO with, doesn't necessarilly have a workspace. So the actual sharing of the LO (creating an entry in the templaterights table) will fail, because there is no folder.

The only way to add users to the system that can be selected to share an LO with, is by making sure that their workspace is initialised too.

Even in the case of Db authentication, that doesn't happen. After creating a user in the management.php page, the user has only an entry in the user table. The entry in the logindetails table is created during the first successful login.

Hope this clarifies things.
The following user(s) said Thank You: jayaich

Please Log in or Create an account to join the conversation.

User ever logged in? - adding multiple users 4 years 5 months ago #6744

  • jayaich
  • jayaich's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
  • Posts: 82
  • Thank you received: 5
Thanks for that. As suspected I'm going to have to write something for us locally. I did wonder if it might be possible to provide something for Xerte users generally, but as you say the users root directory/workspace needs to be created. I can see functions to perform this, but nothing that, in effect, does it already. In effect, we need to follow the code route as if a user had authenticated.

Thanks.

Please Log in or Create an account to join the conversation.

User ever logged in? - adding multiple users 4 years 5 months ago #6745

  • tom
  • tom's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 1303
  • Thank you received: 326
Yes, that is probably the best strategy.

Please Log in or Create an account to join the conversation.

User ever logged in? - adding multiple users 4 years 5 months ago #6746

  • jayaich
  • jayaich's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
  • Posts: 82
  • Thank you received: 5
Alternatively...

I'm wondering if we may do this the other way round. Let the users log in, and run a sort of post-login hook that will automatically perform the share when they first log in. Checks will be there to see that it only occurs once, when they first log in, and some form of lookup to see if the user logging in is to have the share or not. This way avoids having to re-create the login process. It should just require a local one-line change to add a call to a function, probably after the users root directory and recycle bin have been created. We then just need to write the function/hook. I'll think about this a bit more.

Please Log in or Create an account to join the conversation.

User ever logged in? - adding multiple users 4 years 5 months ago #6749

  • tom
  • tom's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 1303
  • Thank you received: 326
You could probably use a plugin for that. It probably requires a new plugin hook to be registered, but that's the way you could do it.

Have a look in index.php (startup(), body_start(), body_end(), etc ) and plugin.php. The apply_filters is a direct derivative of how wordpress handles plugins.

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Moderators: JohnSmith
Time to create page: 0.053 seconds
Copyright © 2024 The Xerte Project.
Xerte logo Apereo logo OSI Logo

Search