mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-22 22:33:55 -07:00
Refactoring authentication and user visitor
This commit is contained in:
parent
d36e5deadf
commit
c4a79680a3
5 changed files with 130 additions and 26 deletions
|
@ -50,6 +50,8 @@ $di->register(new \TorrentPier\ServiceProviders\DbServiceProvider, [
|
||||||
'config.db' => $di->config->db->toArray()
|
'config.db' => $di->config->db->toArray()
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$di->register(new \TorrentPier\ServiceProviders\AuthServiceProvider());
|
||||||
|
|
||||||
$di->register(new \TorrentPier\ServiceProviders\SphinxServiceProvider, [
|
$di->register(new \TorrentPier\ServiceProviders\SphinxServiceProvider, [
|
||||||
'config.sphinx' => $di->config->sphinx->toArray()
|
'config.sphinx' => $di->config->sphinx->toArray()
|
||||||
]);
|
]);
|
||||||
|
|
17
src/Authentication/Adapter/HashDoubleMD5.php
Normal file
17
src/Authentication/Adapter/HashDoubleMD5.php
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace TorrentPier\Authentication\Adapter;
|
||||||
|
|
||||||
|
use TorrentPier\Db\Adapter;
|
||||||
|
use TorrentPier\Di;
|
||||||
|
use Zend\Authentication\Adapter\DbTable\CredentialTreatmentAdapter;
|
||||||
|
|
||||||
|
class HashDoubleMD5 extends CredentialTreatmentAdapter
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
/** @var Adapter $db */
|
||||||
|
$db = Di::getInstance()->db;
|
||||||
|
parent::__construct($db, 'bb_users', 'username', 'user_password', 'MD5(MD5(?))');
|
||||||
|
}
|
||||||
|
}
|
28
src/Authentication/Adapter/HashPassword.php
Normal file
28
src/Authentication/Adapter/HashPassword.php
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace TorrentPier\Authentication\Adapter;
|
||||||
|
|
||||||
|
use TorrentPier\Db\Adapter;
|
||||||
|
use TorrentPier\Di;
|
||||||
|
use Zend\Authentication\Adapter\DbTable\CallbackCheckAdapter;
|
||||||
|
use Zend\Db\Sql;
|
||||||
|
|
||||||
|
class HashPassword extends CallbackCheckAdapter
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
/** @var Adapter $db */
|
||||||
|
$db = Di::getInstance()->db;
|
||||||
|
parent::__construct($db, 'bb_users', 'username', 'user_password', [$this, 'credentialValidation']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $hash
|
||||||
|
* @param string $password
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function credentialValidation($hash, $password)
|
||||||
|
{
|
||||||
|
return password_verify($password, $hash);
|
||||||
|
}
|
||||||
|
}
|
24
src/ServiceProviders/AuthServiceProvider.php
Normal file
24
src/ServiceProviders/AuthServiceProvider.php
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace TorrentPier\ServiceProviders;
|
||||||
|
|
||||||
|
use Pimple\Container;
|
||||||
|
use Pimple\ServiceProviderInterface;
|
||||||
|
use Zend\Authentication\AuthenticationService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class AuthServiceProvider
|
||||||
|
* @package TorrentPier\ServiceProviders
|
||||||
|
*/
|
||||||
|
class AuthServiceProvider implements ServiceProviderInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function register(Container $container)
|
||||||
|
{
|
||||||
|
$container['auth'] = function ($container) {
|
||||||
|
return new AuthenticationService(isset($container['config.service.auth.storage']) ?: null);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,8 +6,41 @@ require_once __DIR__ . '/common.php';
|
||||||
|
|
||||||
$di = \TorrentPier\Di::getInstance();
|
$di = \TorrentPier\Di::getInstance();
|
||||||
|
|
||||||
/** @var \TorrentPier\Db\Adapter $db */
|
/** @var \Zend\Authentication\AuthenticationService $auth */
|
||||||
$db = $di->db;
|
$auth = $di->auth;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//$auth = new \Zend\Authentication\AuthenticationService();
|
||||||
|
|
||||||
|
//$auth->clearIdentity();
|
||||||
|
|
||||||
|
////$auth->setAdapter($authAdapter);
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//$storage = new \Zend\Authentication\Storage\Session();
|
||||||
|
//$auth->setStorage($storage);
|
||||||
|
//
|
||||||
|
////$user = null;
|
||||||
|
////
|
||||||
|
////if ($auth->hasIdentity()) {
|
||||||
|
//// $user = $auth->getIdentity();
|
||||||
|
////}
|
||||||
|
//
|
||||||
|
|
||||||
|
$authAdapter = new \TorrentPier\Authentication\Adapter\HashDoubleMD5();
|
||||||
|
$authAdapter->setIdentity('admin')->setCredential('admin');
|
||||||
|
|
||||||
|
//$auth->authenticate($authAdapter);
|
||||||
|
|
||||||
|
var_dump(
|
||||||
|
$auth->authenticate($authAdapter)->isValid(),
|
||||||
|
$auth->hasIdentity(),
|
||||||
|
$auth->getIdentity()
|
||||||
|
);
|
||||||
|
|
||||||
|
///** @var \TorrentPier\Db\Adapter $db */
|
||||||
|
//$db = $di->db;
|
||||||
|
|
||||||
///** @var \Symfony\Component\HttpFoundation\Request $request */
|
///** @var \Symfony\Component\HttpFoundation\Request $request */
|
||||||
//$request = $di->request;
|
//$request = $di->request;
|
||||||
|
@ -39,26 +72,26 @@ $db = $di->db;
|
||||||
//$log = $di->log;
|
//$log = $di->log;
|
||||||
//$log->debug('test debug information');
|
//$log->debug('test debug information');
|
||||||
|
|
||||||
\TorrentPier\Log::info('You will see the style guide');
|
//\TorrentPier\Log::info('You will see the style guide');
|
||||||
|
//
|
||||||
$query = function(\Zend\Db\Sql\Select $select) {
|
//$query = function(\Zend\Db\Sql\Select $select) {
|
||||||
$select->columns(['id' => 'user_id', 'name' => 'username']);
|
// $select->columns(['id' => 'user_id', 'name' => 'username']);
|
||||||
$select->join(['t' => BB_TOPICS], 't.topic_poster = u.user_id', ['title' => 'topic_title']);
|
// $select->join(['t' => BB_TOPICS], 't.topic_poster = u.user_id', ['title' => 'topic_title']);
|
||||||
// $select->where(['user_id > ?' => 0]);
|
//// $select->where(['user_id > ?' => 0]);
|
||||||
};
|
//};
|
||||||
|
//
|
||||||
$users = $db->select(['u' => BB_USERS], $query)->all();
|
//$users = $db->select(['u' => BB_USERS], $query)->all();
|
||||||
$usersCount = $db->count(['u' => BB_USERS], $query);
|
//$usersCount = $db->count(['u' => BB_USERS], $query);
|
||||||
|
//
|
||||||
$content = $di->view->make('styleguide', [
|
//$content = $di->view->make('styleguide', [
|
||||||
'name' => $di->request->get('name', 'Admin'),
|
// 'name' => $di->request->get('name', 'Admin'),
|
||||||
'users' => $users,
|
// 'users' => $users,
|
||||||
'users_count' => $usersCount
|
// 'users_count' => $usersCount
|
||||||
]);
|
//]);
|
||||||
|
//
|
||||||
/** @var \Symfony\Component\HttpFoundation\Response $response */
|
///** @var \Symfony\Component\HttpFoundation\Response $response */
|
||||||
$response = \Symfony\Component\HttpFoundation\Response::create();
|
//$response = \Symfony\Component\HttpFoundation\Response::create();
|
||||||
$response->setContent($content);
|
//$response->setContent($content);
|
||||||
|
//
|
||||||
$response->prepare($di->request);
|
//$response->prepare($di->request);
|
||||||
$response->send();
|
//$response->send();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue