mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-22 22:33:55 -07:00
Merge c4a79680a3
into d1d520e086
This commit is contained in:
commit
4c2e0fa17f
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()
|
||||
]);
|
||||
|
||||
$di->register(new \TorrentPier\ServiceProviders\AuthServiceProvider());
|
||||
|
||||
$di->register(new \TorrentPier\ServiceProviders\SphinxServiceProvider, [
|
||||
'config.sphinx' => $di->config->sphinx->toArray()
|
||||
]);
|
||||
|
@ -520,4 +522,4 @@ else if (defined('IN_TRACKER'))
|
|||
dummy_exit(mt_rand(60, 2400));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
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);
|
||||
};
|
||||
}
|
||||
}
|
|
@ -7,8 +7,41 @@ require_once __DIR__ . '/common.php';
|
|||
/** @var \TorrentPier\Di $di */
|
||||
$di = \TorrentPier\Di::getInstance();
|
||||
|
||||
/** @var \TorrentPier\Db\Adapter $db */
|
||||
$db = $di->db;
|
||||
/** @var \Zend\Authentication\AuthenticationService $auth */
|
||||
$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 */
|
||||
//$request = $di->request;
|
||||
|
@ -39,26 +72,26 @@ $db = $di->db;
|
|||
//$log = $di->log;
|
||||
//$log->debug('test debug information');
|
||||
|
||||
\TorrentPier\Log::info('You will see the style guide');
|
||||
|
||||
$query = function(\Zend\Db\Sql\Select $select) {
|
||||
$select->columns(['id' => 'user_id', 'name' => 'username']);
|
||||
$select->join(['t' => BB_TOPICS], 't.topic_poster = u.user_id', ['title' => 'topic_title']);
|
||||
// $select->where(['user_id > ?' => 0]);
|
||||
};
|
||||
|
||||
$users = $db->select(['u' => BB_USERS], $query)->all();
|
||||
$usersCount = $db->count(['u' => BB_USERS], $query);
|
||||
|
||||
$content = $di->view->make('styleguide', [
|
||||
'name' => $di->request->get('name', 'Admin'),
|
||||
'users' => $users,
|
||||
'users_count' => $usersCount
|
||||
]);
|
||||
|
||||
/** @var \Symfony\Component\HttpFoundation\Response $response */
|
||||
$response = \Symfony\Component\HttpFoundation\Response::create();
|
||||
$response->setContent($content);
|
||||
|
||||
$response->prepare($di->request);
|
||||
$response->send();
|
||||
//\TorrentPier\Log::info('You will see the style guide');
|
||||
//
|
||||
//$query = function(\Zend\Db\Sql\Select $select) {
|
||||
// $select->columns(['id' => 'user_id', 'name' => 'username']);
|
||||
// $select->join(['t' => BB_TOPICS], 't.topic_poster = u.user_id', ['title' => 'topic_title']);
|
||||
//// $select->where(['user_id > ?' => 0]);
|
||||
//};
|
||||
//
|
||||
//$users = $db->select(['u' => BB_USERS], $query)->all();
|
||||
//$usersCount = $db->count(['u' => BB_USERS], $query);
|
||||
//
|
||||
//$content = $di->view->make('styleguide', [
|
||||
// 'name' => $di->request->get('name', 'Admin'),
|
||||
// 'users' => $users,
|
||||
// 'users_count' => $usersCount
|
||||
//]);
|
||||
//
|
||||
///** @var \Symfony\Component\HttpFoundation\Response $response */
|
||||
//$response = \Symfony\Component\HttpFoundation\Response::create();
|
||||
//$response->setContent($content);
|
||||
//
|
||||
//$response->prepare($di->request);
|
||||
//$response->send();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue