This commit is contained in:
Andrea Adamczyk
2019-07-05 16:00:43 -04:00
parent a07867510d
commit 448e0722fa
7 changed files with 196 additions and 8 deletions

View File

@@ -326,6 +326,8 @@ try {
}
if ($RBAC->singleSignOn) {
// Update the User's last login date
updateUserLastLogin($aLog);
G::header('Location: ' . $sLocation);
die();
}
@@ -336,6 +338,8 @@ try {
if ($changePassword === true) {
$user = new User();
$currentUser = $user->changePassword($_SESSION['USER_LOGGED'], $_POST['form']['USR_PASSWORD']);
// Update the User's last login date
updateUserLastLogin($aLog);
G::header('Location: ' . $currentUser["__REDIRECT_PATH__"]);
return;
}
@@ -394,6 +398,9 @@ try {
setcookie("PM-TabPrimary", 101010010, time() + (24 * 60 * 60), '/');
}
// Update the User's last login date
updateUserLastLogin($aLog);
$oPluginRegistry = PluginRegistry::loadSingleton();
if ($oPluginRegistry->existsTrigger ( PM_AFTER_LOGIN )) {
$oPluginRegistry->executeTriggers ( PM_AFTER_LOGIN , $_SESSION['USER_LOGGED'] );

View File

@@ -116,12 +116,6 @@ if (isset($_SESSION['USER_LOGGED'])) {
$aLog['USR_UID'] = $aRow['USR_UID'];
$weblog->update($aLog);
$aLog = array();
$aLog['USR_UID'] = $aRow['USR_UID'];
$aLog['USR_LAST_LOGIN'] = $endDate;
$user = new Users();
$aUser = $user->update($aLog);
}
}
} else {

View File

@@ -3,6 +3,7 @@
namespace ProcessMaker\Model;
use Illuminate\Database\Eloquent\Model;
use Exception;
class User extends Model
{
@@ -39,4 +40,26 @@ class User extends Model
{
return User::find($usrUid)->groups()->get();
}
/**
* Scope for the specified user
*
* @param \Illuminate\Database\Eloquent\Builder $query @param \Illuminate\Database\Eloquent\Builder $query
* @param array $filters
*
* @return \Illuminate\Database\Eloquent\Builder
* @throws Exception
*/
public function scopeUserFilters($query, array $filters)
{
if (!empty($filters['USR_ID'])) {
$query->where('USR_ID', $filters['USR_ID']);
} elseif (!empty($filters['USR_UID'])) {
$query->where('USR_UID', $filters['USR_UID']);
} else {
throw new Exception("There are no filter for loading a user model");
}
return $query;
}
}

View File

@@ -2,6 +2,7 @@
use Illuminate\Session\TokenMismatchException;
use Illuminate\Support\Str;
use ProcessMaker\Model\User;
/**
* We will send a case note in the actions by email
@@ -493,3 +494,29 @@ if (!function_exists('set_magic_quotes_runtime')) {
return false;
}
}
/**
* Update the USER table with the last login date
*
* @param array $userLog
* @return int
* @throws Exception
*
* @see workflow/engine/methods/login/authentication.php
*/
function updateUserLastLogin($userLog, $keyLastLogin = 'LOG_INIT_DATE')
{
try {
$filters = [];
$filters['USR_UID'] = $userLog['USR_UID'];
$user = User::query();
$user->userFilters($filters);
$res = $user->update(['USR_LAST_LOGIN' => $userLog[$keyLastLogin]]);
return $res;
} catch (Exception $e) {
throw new Exception($e->getMessage());
}
}