CurrentUserInfo Filter

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
mobhar
User
Posts: 11703

CurrentUserInfo Filter

Post 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.


arbei
User
Posts: 9355

Post 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.


mobhar
User
Posts: 11703

Post 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.


Post Reply