Nefungujúci vlastný autentifikátor

- samson
- Člen | 11
Zdravím, snažím sa rozbehať vlastný autentikátor pripojený na databázu podla návodu https://doc.nette.org/…thentication#… avšak neustále mi to vyhadzuje chyby, tá posledná bola: Class MyAuthenticator used in service ‚authenticator‘ not found or is not instantiable.
Config.neon:
#
# WARNING: it is CRITICAL that this file & directory are NOT accessible directly via a web browser!
# https://nette.org/en/security-warning
#
parameters:
php:
date.timezone: Europe/Prague
application:
errorPresenter: Error
mapping:
*: App\*Module\Presenters\*Presenter
session:
expiration: 14 days
services:
- App\Model\UserManager
- App\Forms\SignFormFactory
- App\Model\MyAuthenticator
router: App\RouterFactory::createRouter
database: @Nette\Database\Connection
authenticator: MyAuthenticator( @database )
MyAuthenticator.php uložený v app/model:
<?php
namespace App\Model;
use Nette;
class MyAuthenticator extends Nette\Object implements Nette\Security\IAuthenticator
{
public $database;
function __construct(Nette\Database\Context $database)
{
$this->database = $database;
}
function authenticate(array $credentials)
{
list($username, $password) = $credentials;
$row = $this->database->table('reg')
->where('Nazov', $username)->fetch();
if (!$row) {
throw new Nette\Security\AuthenticationException('Používateľ sa nenašiel.');
}
if (!Nette\Security\Passwords::verify($password, $row->Heslo)) {
throw new Nette\Security\AuthenticationException('Nesprávne heslo.');
}
return new Nette\Security\Identity($row->Id, $row->Role, array('username' => $row->Nazov));
}
}
Neviete kde robím chybu? Ďakujem.

- JuniorJR
- Člen | 181
samson napsal(a):
JuniorJR napsal(a):
> authenticator: App\Model\MyAuthenticator( @database )Zmenil som to, teraz mám chybu: Service ‚security.user‘: Multiple services of type Nette\Security\IAuthenticator found: 27_App_Model_UserManager, authenticator
@samson Mas dve sluzby, ktere implementuji stejne rozhrani, podivej se
do classy App\Model\UserManager a uvidis tam, ze implementuje
Nette\Security\IAuthenticator. Musis tuto kolizi vyresit, jednoduse
receno se totiz pokousis udelat dvoji implementaci tohoto rozhrani, coz
pravdepodobne nechces, takze implementuj pouze na jednom miste. Napr. odstran
implements IAutheticator z App\Model\UserManager nebo
presun tu svoji logiku do nej a tu novou tridu vyhod.

- samson
- Člen | 11
Ešte jedna otázočka – práva pre užívateľské skupiny (https://doc.nette.org/…thentication#…) budem pridávať tiež do súboru s autentikátorom?
Podotázka: Kam by som vlastne mal napísať túto časť kódu?
$acl = new Permission;
// definujeme role
$acl->addRole('guest');
$acl->addRole('member');
$acl->addRole('administrator', 'member'); // administrator je potomkem member
// definujeme zdroje
$acl->addResource('file');
$acl->addResource('article');
// pravidlo: host může jen prohlížet články
$acl->allow('guest', 'article', 'view');
// pravidlo: člen může prohlížet vše, soubory i články
$acl->allow('member', Permission::ALL, 'view');
// administrátor dědí práva od člena, navíc má právo vše editovat
$acl->allow('administrator', Permission::ALL, array('view', 'edit'));
// zaregistrujeme autorizační handler
Environment::getUser()->setAuthorizationHandler($acl);
Editoval samson (12. 8. 2015 1:26)