geniv/nette-authenticator

此包已被弃用且不再维护。未建议替代包。

Nette 框架的标识扩展

v1.1.9 2018-02-25 11:42 UTC

This package is not auto-updated.

Last update: 2020-01-19 15:22:26 UTC


README

安装

$ composer require geniv/nette-authenticator

"geniv/nette-authenticator": ">=1.0.0"

require

"php": ">=5.6.0",
"nette/nette": ">=2.4.0",
"dibi/dibi": ">=3.0.0"

在应用程序中包含

可用的源驱动程序

  • 数组 (基础标识: key, id, hash)
  • Neon (格式与数组相同)
  • Dibi (基础标识: id, login, hash, active, role, added)
  • Combine (组合驱动程序 Array, Neon, Dibi;顺序定义 combineOrder)

哈希值来自:Passwords::hash($password)

neon 配置

# login
authenticator:
#   autowired: false    # default null, false => disable autowiring (in case multiple linked extension) | self
    source: "Dibi"
    tablePrefix: %tablePrefix%
#   source: "Array"
    userlist: 
        Foo:
            id: 1
            hash: "@@hash!@@"
            role: guest
            username: mr Foo
        Bar:
            id: 2
            hash: "@@hash!@@"
            role: moderator
            username: mr Bar
#   source: "Neon"
#   path: %appDir%/authenticator.neon
#   source: "Combine"
#   combineOrder:
#       - Array
#       - Neon
#       - Dibi
#   classArray: Authenticator\Drivers\ArrayDriver
#   classNeon: Authenticator\Drivers\NeonDriver
#   classDibi: Authenticator\Drivers\DibiDriver

neon 扩展配置

extensions:
    authenticator: Authenticator\Bridges\Nette\Extension

演示者

use Authenticator\LoginForm;

protected function createComponentLoginForm(LoginForm $loginForm)
{
    //$loginForm->setTemplatePath(__DIR__ . '/templates/LoginForm.latte');
    // callback from $loginForm (support redirect)
    $loginForm->onLoggedIn[] = function (User $user) {
        $this->flashMessage('Login!', 'info');
        $this->redirect('this');
    };
    $loginForm->onLoggedInException[] = function (AuthenticationException $e) {
        $this->flashMessage('Login exception! ' . $e->getMessage(), 'danger');
    };
    $loginForm->onLoggedOut[] = function (User $user) {
        $this->flashMessage('Logout!', 'info');
        $this->redirect('this');
    };

    //OR

    // callback from $this->user (don't support redirect)
    $this->user->onLoggedIn[] = function (User $user) {
        $this->flashMessage('Login!', 'info');
    };
    $this->user->onLoggedOut[] = function (User $user) {
        $this->flashMessage('Logout!', 'info');
    };
    return $loginForm;
}

用法

    {if !$user->isLoggedIn()}
        {control loginForm}
    {else}
        <a n:href="loginForm:Out!">Logout</a>
    {/if}