{auth}
Renders its content when a user is logged in, with the user's row as its data, and its else half for a guest.
Syntax
{auth} ... {/auth}
{auth} Hello {$name} {else} ... {/auth}
{auth} ... @else@ ... {/auth}
Description
{auth} renders its content once when a user is logged in to this application - by padLogin ( $row ) or padAttempt ( ... ) - with the user's row as its data: every field of it is a {$field} inside, {$name}, {$email}. The password and token fields were never kept, so they are not there.
For a guest the part after its own {else} renders, or the @else@ half. The tag owns that {else}: an {if} around it keeps its own. {guest} is the reverse and hands over no data.
Reading the user never starts a session the visitor did not bring - a guest's page makes no session - but a request that brings the remember-me cookie is logged in here, the first time anything asks. padUser ( 'name' ), padUserId () and padAuthCheck () ask the same from PHP.
The examples run without a login, so the runnable one shows the guest's half; the other is shown, not run.
Examples
Nobody logged in
Without a padLogin the else half renders - the user's row is not there.
{auth}
<p>Hello {$name} - <a href="#logout">log out</a></p>
{else}
<p><a href="#login">Log in</a> to see your orders.</p>
{/auth}
Log in to see your orders.
The user's row as data
After padLogin every field of the row is a field inside - the password and token fields were never kept.
{# login.php: if ( padAttempt ( $password, $row ['password'], $row ) ) padRedirectIntended (); #}
{auth}
<p>Hello {$name} ({$email}) - <a href="?logout">log out</a></p>
{if $role eq 'admin'}<a href="?admin">Administration</a>{/if}
@else@
<p><a href="?login">Log in</a></p>
{/auth}
See also
- {guest} Renders its content when nobody is logged in, and its else half for a user.
- {can} Renders its content when the user may do something a gate decides, and its else half when not.
- {cannot} Renders its content when the user may not do something a gate decides - can turned round.
- {feature} Renders its content while a feature flag is on for this visitor, and its else half while it is off.