Page 1 of 1

CurrentUserInfo Filter

Posted: Fri Dec 02, 2022 2:47 pm
by mobhar

I found this code in AdvancedSecurity.php template file that sometimes will cause the issue:

<# if (hasUserId) { #>
    $filter = GetUserFilter(Config("USER_ID_FIELD_NAME"), $this->CurrentUserID);
<# } else { #>
    $filter = GetUserFilter(Config("LOGIN_USERNAME_FIELD_NAME"), $this->currentUserName());
<# } #>

Oftentimes, User ID field is not unique for each user. The issue is, this will cause unwanted result when we are using CurrentUserInfo("{fieldname}") global function. It will not point to the correct user from users table.

How to change that code so that we simply always use filter based on current UserName, even we enable also User ID field? That would be better if we only use:

    $filter = GetUserFilter(Config("LOGIN_USERNAME_FIELD_NAME"), $this->currentUserName());

Thank you.


Re: CurrentUserInfo Filter suggestion

Posted: Sat Dec 03, 2022 9:05 am
by arbei

User ID should be unique. If not, you should not use CurrentUserInfo(), you may get the user data your self, e.g.

$userInfo = ExecuteRow(SELECT * FROM MyUserTable WHERE " . GetUserFilter(Config("LOGIN_USERNAME_FIELD_NAME"), CurrentUserName()); // Get the record
$foobar = ExecuteScalar(SELECT Afield FROM MyUserTable WHERE " . GetUserFilter(Config("LOGIN_USERNAME_FIELD_NAME"), CurrentUserName()); // Get a field

You can also write your own function in Global Code.


Re: CurrentUserInfo Filter

Posted: Sat Dec 03, 2022 3:29 pm
by mobhar

Never mind. I created my Extension to change that logic so that the filter will always based on current username which is always unique for each user all the time.