PHP code example of sinbadxiii / phalcon-foundation-auth
1. Go to this page and download the library: Download sinbadxiii/phalcon-foundation-auth library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
sinbadxiii / phalcon-foundation-auth example snippets
$di->setShared("auth", function () {
return new Sinbadxiii\PhalconAuth\Auth();
});
$authProvider = new \Sinbadxiii\PhalconAuth\AuthProvider();
$authProvider->register($di);
$di->setShared('dispatcher', function () use ($di) {
$dispatcher = new Dispatcher();
$eventsManager = $di->getShared('eventsManager');
$eventsManager->attach('dispatch', new App\Security\Authenticate());
$dispatcher->setEventsManager($eventsManager);
return $dispatcher;
});
use Sinbadxiii\PhalconFoundationAuth\Routes as AuthRoutes;
$router = $di->getRouter();
...
$router->mount(AuthRoutes::routes());
...
$router->handle($_SERVER['REQUEST_URI']);
$di->setShared('session', function () {
$session = new SessionManager();
$files = new SessionAdapter([
'savePath' => sys_get_temp_dir(),
]);
$session->setAdapter($files);
$session->start();
return $session;
});
$di->setShared("cache", function () {
$configCache = $this->getConfig()->path("cache");
$serializerFactory = new Phalcon\Storage\SerializerFactory();
$adapterFactory = new Phalcon\Cache\AdapterFactory($serializerFactory);
$adapter = $adapterFactory->newInstance(
$configCache->default, $configCache->options->toArray(),
);
return new Phalcon\Cache($adapter);
});
$di->set("security", function () use ($di) {
$security = new Phalcon\Security();
$security->setDI($di);
return $security;
}
);
//лучше всего шифровать данные кук
$di->set('cookies', function (){
$cookies = new Phalcon\Http\Response\Cookies();
$cookies->useEncryption(true);
$salt = $this->getConfig()->path('app.key');
$cookies->setSignKey($salt);
return $cookies;
}
);
$securityProvider = new \Sinbadxiii\PhalconFoundationAuth\Providers\SecurityProvider();
$securityProvider->register($di);
$cookieProvider = new \Sinbadxiii\PhalconFoundationAuth\Providers\CookiesProvider();
$cookieProvider->register($di);