Page 1 of 1

[SOLVED] Last login time don't update

Posted: Sun Aug 11, 2019 2:04 pm
by Bosatzu
Hello everyone!

I just realize that the last login of the users do not update, but i don't know why.
login.png
login.png (156.38 KiB) Viewed 2730 times

Re: Last login time don't update

Posted: Mon Aug 12, 2019 8:10 pm
by amosbatto
The login date updates for me in PM 3.3.14 Enterprise (manual install) in Debian 9.5, but there is no last login date listed for PM 3.3.10 Community (manual install) in Debian 9.5.

What is your setup?

Re: Last login time don't update

Posted: Mon Aug 12, 2019 9:54 pm
by Bosatzu
This is the config.
config.png
config.png (120.36 KiB) Viewed 2718 times

Re: Last login time don't update

Posted: Tue Aug 13, 2019 11:15 pm
by amosbatto
The problem is that the Community Edition doesn't have the \ProcessMaker\Model\Users class which is used to update the last login date in the Enterprise Edition.

Here is how to fix it. Edit the file workflow/engine/methods/login/authentication.php and change line 307 from:
Code: Select all
    if ($RBAC->singleSignOn) {        
        G::header('Location: ' . $sLocation);
        die();
    }
To:
Code: Select all
    if ($RBAC->singleSignOn) {
        // Update the User's last login date:
        $u = new Users();
        $aUserProps = array(
           'USR_UID' => $aLog['USR_UID'],
           'USR_LAST_LOGIN' => $aLog['LOG_INIT_DATE']
        );
        $u->update($aUserProps);
        
        G::header('Location: ' . $sLocation);
        die();
    }


Then, change line 380 from:
Code: Select all
    if ($activeSession){
        setcookie("PM-TabPrimary", 101010010, time() + (24 * 60 * 60), '/');
    }
    
    G::header('Location: ' . $sLocation);
To:
Code: Select all
    if ($activeSession){
        setcookie("PM-TabPrimary", 101010010, time() + (24 * 60 * 60), '/');
    }
    
    // Update the User's last login date:
    $u = new Users();
    $aUserProps = array(
       'USR_UID' => $aLog['USR_UID'],
       'USR_LAST_LOGIN' => $aLog['LOG_INIT_DATE']
    );
    $u->update($aUserProps);

    $oPluginRegistry = PluginRegistry::loadSingleton();
    if ($oPluginRegistry->existsTrigger ( PM_AFTER_LOGIN )) {
        $oPluginRegistry->executeTriggers ( PM_AFTER_LOGIN , $_SESSION['USER_LOGGED'] );
    }

    G::header('Location: ' . $sLocation);

After making that code change, the last login date should appear:
LastLoginDateInUsersList.png
LastLoginDateInUsersList.png (63.45 KiB) Viewed 2692 times

Re: Last login time don't update

Posted: Thu Aug 15, 2019 10:32 am
by Bosatzu
amosbatto wrote: Tue Aug 13, 2019 11:15 pm The problem is that the Community Edition doesn't have the \ProcessMaker\Model\Users class which is used to update the last login date in the Enterprise Edition.

Here is how to fix it. Edit the file workflow/engine/methods/login/authentication.php and change line 307 from:
Code: Select all
    if ($RBAC->singleSignOn) {        
        G::header('Location: ' . $sLocation);
        die();
    }
To:
Code: Select all
    if ($RBAC->singleSignOn) {
        // Update the User's last login date:
        $u = new Users();
        $aUserProps = array(
           'USR_UID' => $aLog['USR_UID'],
           'USR_LAST_LOGIN' => $aLog['LOG_INIT_DATE']
        );
        $u->update($aUserProps);
        
        G::header('Location: ' . $sLocation);
        die();
    }


Then, change line 380 from:
Code: Select all
    if ($activeSession){
        setcookie("PM-TabPrimary", 101010010, time() + (24 * 60 * 60), '/');
    }
    
    G::header('Location: ' . $sLocation);
To:
Code: Select all
    if ($activeSession){
        setcookie("PM-TabPrimary", 101010010, time() + (24 * 60 * 60), '/');
    }
    
    // Update the User's last login date:
    $u = new Users();
    $aUserProps = array(
       'USR_UID' => $aLog['USR_UID'],
       'USR_LAST_LOGIN' => $aLog['LOG_INIT_DATE']
    );
    $u->update($aUserProps);

    $oPluginRegistry = PluginRegistry::loadSingleton();
    if ($oPluginRegistry->existsTrigger ( PM_AFTER_LOGIN )) {
        $oPluginRegistry->executeTriggers ( PM_AFTER_LOGIN , $_SESSION['USER_LOGGED'] );
    }

    G::header('Location: ' . $sLocation);

After making that code change, the last login date should appear:
LastLoginDateInUsersList.png

It works just perfect! thank you for your help.