How to set custom values for the session
When using the DB authenticator, you can retrieve additional user data at login time and make it available throughout the application as session macros.
Setup
Add a ReadUserCommandText to the Auth node in your Config.yaml. Any columns beyond the required USER_NAME, PASSWORD_HASH, and IS_ACTIVE become custom session values:
Auth: DB
IsClearPassword: True
ReadUserCommandText: |
select
WEB_USER_NAME as USER_NAME,
WEB_PASSWORD as PASSWORD_HASH,
WEB_ENABLED as IS_ACTIVE,
LAST_NAME + ' ' + NAME as FULL_NAME,
ID as PERSON_ID,
coalesce((select top 1 1 from ADMIN_OPERATOR
where PERSON.ID = ADMIN_OPERATOR.PERSON_ID), 0) as IS_ADMIN_OPERATOR
from PERSON
where (WEB_USER_NAME = :P1) and (WEB_ENABLED = 1)See Custom User Table for more details on customizing the authentication query.
Using session macros
Each custom column is available as a macro in the form %Auth:ColumnName%. You can use these macros in YAML metadata anywhere macro expansion is supported.
Filter data by user — show only records belonging to the logged-in user:
MainTable:
Model: MY_MODEL
DefaultFilter: PERSON_ID = '%Auth:PERSON_ID%'Conditional filter — show all records for admin users, filtered records for others:
MainTable:
Model: MY_MODEL
DefaultFilter: |
('%Auth:IS_ADMIN_OPERATOR%' = 1
or PERSON_ID = '%Auth:PERSON_ID%')Display user info — use in display labels or templates:
DisplayLabel: Activities for %Auth:FULL_NAME%See also: How to filter data by connected user, Macros.
