-
Notifications
You must be signed in to change notification settings - Fork 19
Auth
Mariusz Łączak edited this page Feb 15, 2014
·
6 revisions
<?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
}
}
<?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
}
<?php
Auth::instance()->logout();
$this->response->redirect('');
{% if auth.logged_in() %}
{{ auth.get_user().username }}
{% endif %}
{% if auth.logged_in('admin') %}
{# __() is a function which translates #}
{{ linkTo('admin', __('Admin panel')) }}
{% endif %}