diff --git a/common.php b/common.php index ee978b39a..a2f218e62 100644 --- a/common.php +++ b/common.php @@ -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)); } } -} \ No newline at end of file +} diff --git a/src/Authentication/Adapter/HashDoubleMD5.php b/src/Authentication/Adapter/HashDoubleMD5.php new file mode 100644 index 000000000..8bb954ec4 --- /dev/null +++ b/src/Authentication/Adapter/HashDoubleMD5.php @@ -0,0 +1,17 @@ +db; + parent::__construct($db, 'bb_users', 'username', 'user_password', 'MD5(MD5(?))'); + } +} diff --git a/src/Authentication/Adapter/HashPassword.php b/src/Authentication/Adapter/HashPassword.php new file mode 100644 index 000000000..0872c0ace --- /dev/null +++ b/src/Authentication/Adapter/HashPassword.php @@ -0,0 +1,28 @@ +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); + } +} diff --git a/src/ServiceProviders/AuthServiceProvider.php b/src/ServiceProviders/AuthServiceProvider.php new file mode 100644 index 000000000..62615dce7 --- /dev/null +++ b/src/ServiceProviders/AuthServiceProvider.php @@ -0,0 +1,24 @@ +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();