2 autentizace jedna pro admina a druha pro registrovaného uživatele

cvit84
Člen | 43
+
0
-

Potřebuju udělat dvě autentizace a nevím jak. Jednu Pro Administrátora a druhou pro frontend.
Každá bude brát uživatele s jiné tabulky. V servisech lze registrovat pouze jednu autentizaci. Nebo spíše nevím jak udělat druhou.

services:
	- App\Router\RouterFactory::createRouter
	- App\Models\Db\QueryFile
	- App\Models\Db\ForumRepository
#	autheticator: Models\Security\Autheticator
#	authorizator: Models\Security\Acl
#	autheticator: Models\Security\Autheticator
	create: App\FrontModule\Security\Autheticator
#	autowired: self
<?php


namespace App\FrontModule\Security;


use App\Models\Db\QueryFile;
use Models\Db\DbAccessManager;
use Models\Db\DbUser;
use Nette\Database\Context;
use Nette\Security\AuthenticationException;
use Nette\Security\IAuthenticator;
use Nette\Security\Identity;
use Nette\Security\IIdentity;
use Nette\Security\Passwords;
use Nette\Security\SimpleIdentity;
use Nette\Utils\Arrays;
use Nette\Utils\ArrayHash;
use Nette\Security\Authenticator as Autentifikator;



class Autheticator  implements Autentifikator{



    /**
     * @var QueryFile
     */
    private $queryFile;

    /**
     * @var Passwords
     */
    private $passwords;

    const EXPIRATION='2 days';




    public function __construct(QueryFile $queryFile, Passwords $passwords) {

        $this->queryFile = $queryFile;
        $this->passwords = $passwords;

    }



    public function authenticate(string $user, string $password): SimpleIdentity {





        $row=$this->queryFile->getUserByEmail($user);




        if (!$row){
            throw new AuthenticationException('E-mail nenalezen.');

        } elseif (!$this->passwords->verify($password, $row->password)) {
            throw new AuthenticationException('Heslo se neshoduje.');
        }


        //$arrayRow=$row->toArray();
        //$roleArray=$arrayRow['role'];

        $arrayRow = $row->toArray();
        unset($arrayRow['password']);



        return new SimpleIdentity($row['id'], null, $arrayRow);




    }



}
Pepino
Člen | 257
+
+2
-

Můžeš jich zaregistrovat kolik chceš.

services:
	-
		create: UserAuthenticator
		autowired: self
	-
		create: AdminAuthenticator
		autowired: self

Editoval Pepino (26. 8. 2022 11:55)