\DewdropAuth

This class provides authentication and authorization services for Dewdrop applications outside of WordPress.

First, this component needs to be made available within the Silex application object. A good place to do this is the application bootstrap:

$application['auth'] = $application->share(
    function (\Silex\Application $app) {
        $auth = new Auth($app);
        $auth->setTitle('My Project');
        return $auth;
    }
);

\Dewdrop\Bootstrap\Detector creates a 'users-gateway' service, an instance of \Dewdrop\Db\Table\UsersTableGateway. This requires database schema similar to the following:

CREATE TABLE security_levels (
    security_level_id SERIAL PRIMARY KEY,
    name VARCHAR(64) NOT NULL UNIQUE
);

CREATE TABLE users (
    user_id SERIAL PRIMARY KEY,
    security_level_id INTEGER NOT NULL REFERENCES security_levels,
    username VARCHAR(64) NOT NULL UNIQUE,
    first_name VARCHAR(128) NOT NULL,
    last_name VARCHAR(128) NOT NULL,
    email_address VARCHAR(512) NOT NULL UNIQUE,
    password_hash VARCHAR(60) NOT NULL
);

CREATE TABLE user_password_change_tokens (
    user_password_change_token_id SERIAL PRIMARY KEY,
    user_id INTEGER NOT NULL REFERENCES users,
    token VARCHAR(60) NOT NULL UNIQUE,
    date_created TIMESTAMP NOT NULL DEFAULT NOW(),
    used BOOLEAN NOT NULL DEFAULT FALSE
);

Of course additional tables and columns are permissible, but those above are required. You can extend the user table and user row classes, \Dewdrop\Auth\Db\UsersTableGateway and \Dewdrop\Auth\Db\UserRowGateway if necessary.

You can easily generate a password hash for development and testing purposes using a Dewdrop CLI command:

$ ./vendor/bin/dewdrop auth-hash-password --plaintext 

Next, the component needs to be initialized early in the application lifecycle. Notice how in the following example the Dewdrop user management component is also registered with the admin component:

$zend = realpath(__DIR__ . '/../zend');

if (file_exists($zend)) {
    define('PROJECT_ROOT', $zend);
} else {
    define('PROJECT_ROOT', realpath(__DIR__ . '/../'));
}

require_once PROJECT_ROOT . '/vendor/autoload.php';

$silex = \Dewdrop\Pimple::getInstance();

$silex['auth']->init();

$silex['admin']->registerComponentsInPath();

$silex['admin']->registerComponent(new \Dewdrop\Admin\Component\Stock\Users\Component());

$silex->run();

Summary

Methods
Properties
Constants
__construct()
assignRouteClass()
forgotPassword()
setTitle()
getTitle()
setHeaderHtml()
getHeaderHtml()
setLayoutScriptPath()
getLayoutScriptPath()
setLayoutScript()
getLayoutScript()
getUser()
hasUser()
init()
No public properties found
No constants found
getSecurityFirewallsConfig()
$app
$routeClassMap
$title
$headerHtml
$layoutScriptPath
$layoutScript
N/A
No private methods found
No private properties found
N/A

Properties

$app

$app : \Silex\Application

Silex application

Type

\Silex\Application

$routeClassMap

$routeClassMap : array

Route class map

Type

array

$title

$title : string

Title. This will be escaped and used in the title tag.

Type

string

$headerHtml

$headerHtml : string

Optionally specify some HTML to use in the header of the panel on each page (e.g. a logo image). If not specified, then the title text will be used.

Type

string

$layoutScriptPath

$layoutScriptPath : string

Layout script path

Type

string

$layoutScript

$layoutScript : string

Layout script filename

Type

string

Methods

__construct()

__construct(\Silex\Application  $app) 

Constructor

Parameters

\Silex\Application $app

assignRouteClass()

assignRouteClass(string  $route, string  $className) : \Dewdrop\Auth

Allow over-riding of default page classes for auth routes. Makes it possible to do custom pages, rather than being stuck with the Dewdrop defaults.

Parameters

string $route
string $className

Returns

\Dewdrop\Auth

forgotPassword()

forgotPassword(\Dewdrop\Auth\Db\UserRowGateway  $user) : \Dewdrop\Auth

Generate a password change token and send the given user an email with a link to reset password

Parameters

\Dewdrop\Auth\Db\UserRowGateway $user

Returns

\Dewdrop\Auth

setTitle()

setTitle(string  $title) : \Dewdrop\Auth

Set title

Parameters

string $title

Returns

\Dewdrop\Auth

getTitle()

getTitle() : string

Get title

Returns

string

setHeaderHtml()

setHeaderHtml(  $headerHtml) : $this

HTML to use on the header of the panel on each page.

Parameters

$headerHtml

Returns

$this

getHeaderHtml()

getHeaderHtml() : string

Get the HTML that should be used in the header of the panel on each page.

Returns

string

setLayoutScriptPath()

setLayoutScriptPath(string  $layoutScriptPath) : \Dewdrop\Auth

Set layout script path

Parameters

string $layoutScriptPath

Returns

\Dewdrop\Auth

getLayoutScriptPath()

getLayoutScriptPath() : string

Get layout script path

Returns

string

setLayoutScript()

setLayoutScript(string  $layoutScript) : \Dewdrop\Auth

Set layout script

Parameters

string $layoutScript

Returns

\Dewdrop\Auth

getLayoutScript()

getLayoutScript() : string

Get layout script

Returns

string

hasUser()

hasUser() : boolean

Returns whether user is available

Returns

boolean

init()

init() : \Dewdrop\Auth

Initializations

Returns

\Dewdrop\Auth

getSecurityFirewallsConfig()

getSecurityFirewallsConfig() : array

Get security firewalls configuration

Returns

array