Skip to content
Mariusz Łączak edited this page Feb 15, 2014 · 6 revisions

Example usage

Log in

<?php
use Baseapp\Library\Auth;

if ($this->request->getPost('username') && $this->request->getPost('password'))
{
    $login = Auth::instance()->login($this->request->getPost('username'), $this->request->getPost('password'), $this->request->getPost('remember') ? TRUE : FALSE);
    if ( ! $login)
    {
        // Login failed, send back to form with error message
    }
    else
    {
        // Login successful
    }
}

Logged in User

<?php
if (Auth::instance()->logged_in())
{
    // User is logged in, continue on
}
else
{
    // User isn't logged in, redirect to the login form.
}
<?php
$user = Auth::instance()->get_user();
// Check for a user (NULL if not user is found)
if ($user !== null)
{
     // User is found, continue on
     $username = $user->username;
}
else
{
    // User was not found, redirect to the login form
}
<?php
if (Auth::instance()->logged_in("admin"))
{
    // Admin privileges
}
else
{
    // No access
}

Log out

<?php
Auth::instance()->logout();
$this->response->redirect('');

In Volt

{% if auth.logged_in() %}
    {{ auth.get_user().username }}
{% endif %}
{% if auth.logged_in('admin') %}
    {# __() is a function which translates #}
    {{ linkTo('admin', __('Admin panel')) }}
{% endif %}
Clone this wiki locally