added route groups

low motivation programming
This commit is contained in:
flash 2016-03-09 19:41:43 +01:00
parent b2c77b267e
commit 3b2114cd10
4 changed files with 59 additions and 45 deletions

View file

@ -17,6 +17,6 @@
"jbbcode/jbbcode": "*",
"corneltek/cliframework": "*",
"phroute/phroute": "^2.1",
"illuminate/database": "5.2.7"
"illuminate/database": "5.2.*"
}
}

View file

@ -8,8 +8,8 @@
namespace Sakura;
use Phroute\Phroute\Dispatcher;
use Phroute\Phroute\Exception\HttpRouteNotFoundException;
use Phroute\Phroute\Exception\HttpMethodNotAllowedException;
use Phroute\Phroute\Exception\HttpRouteNotFoundException;
use Phroute\Phroute\RouteCollector;
/**
@ -53,7 +53,8 @@ class Router
'PATCH',
'DELETE',
'HEAD',
'ANY'
'OPTIONS',
'ANY',
];
/**
@ -130,6 +131,20 @@ class Router
return self::$basePath . self::$router->route($name, $args);
}
/**
* Create group.
*
* @param array $filters The filters for this group.
* @param \Closure $callback The containers
*
* @return string The generated URI.
*/
public static function group($filters, $callback)
{
// Execute the inner function
self::$router->group($filters, $callback);
}
/**
* Handle requests.
*

View file

@ -20,11 +20,9 @@ if (isset($_REQUEST['mode'])) {
// Compare time and session so we know the link isn't forged
if (!isset($_REQUEST['time']) || $_REQUEST['time'] < time() - 1000) {
$renderData['page'] = [
'redirect' => $urls->format('AUTH_ACTION'),
'message' => 'Timestamps differ too much, refresh the page and try again.',
'success' => 0,
];
// Prevent
@ -34,11 +32,9 @@ if (isset($_REQUEST['mode'])) {
// Match session ids for the same reason
if (!isset($_REQUEST['session']) || $_REQUEST['session'] != session_id()) {
$renderData['page'] = [
'redirect' => $urls->format('AUTH_ACTION'),
'message' => 'Invalid session, please try again.',
'success' => 0,
];
// Prevent
@ -62,15 +58,6 @@ if (isset($_REQUEST['mode'])) {
if ($continue) {
switch ($_REQUEST['mode']) {
case 'logout':
// Add page specific things
$renderData['page'] = [
'redirect' => Router::route('main.index'),
'message' => 'Wrong logout page.',
'success' => 0,
];
break;
case 'changepassword':
// Attempt change
$passforget = Users::resetPassword(
@ -146,26 +133,6 @@ if (isset($_REQUEST['mode'])) {
];
break;
// Login processing
case 'login':
// Add page specific things
$renderData['page'] = [
'redirect' => Router::route('auth.login'),
'message' => 'Wrong login page.',
'success' => 0,
];
break;
// Registration processing
case 'register':
// Add page specific things
$renderData['page'] = [
'redirect' => Router::route('auth.register'),
'message' => 'Wrong registration page.',
'success' => 0,
];
break;
// Unforgetting passwords
case 'forgotpassword':
// Attempt send
@ -187,6 +154,30 @@ if (isset($_REQUEST['mode'])) {
];
break;
case 'logout':
$renderData['page'] = [
'redirect' => Router::route('main.index'),
'message' => 'Wrong logout page.',
'success' => 0,
];
break;
case 'login':
$renderData['page'] = [
'redirect' => Router::route('auth.login'),
'message' => 'Wrong login page.',
'success' => 0,
];
break;
case 'register':
$renderData['page'] = [
'redirect' => Router::route('auth.register'),
'message' => 'Wrong registration page.',
'success' => 0,
];
break;
}
}

View file

@ -25,17 +25,23 @@ Router::post('/reactivate', 'AuthController@reactivatePost', 'auth.reactivate');
Router::get('/activate', 'AuthController@activate', 'auth.activate');
// News
Router::get('/news', 'MetaController@news', 'news.index');
Router::get('/news/{category}', 'MetaController@news', 'news.category');
Router::get('/news/{category}/{id}', 'MetaController@news', 'news.post');
Router::group(['prefix' => 'news'], function () {
Router::get('/', 'MetaController@news', 'news.index');
Router::get('/{category}', 'MetaController@news', 'news.category');
Router::get('/{category}/{id}', 'MetaController@news', 'news.post');
});
// Forum
Router::get('/forum', 'ForumController@index', 'forums.index');
Router::get('/forum/{id}', 'ForumController@forum', 'forums.forum');
Router::group(['prefix' => 'forum'], function () {
Router::get('/', 'ForumController@index', 'forums.index');
Router::get('/{id}', 'ForumController@forum', 'forums.forum');
});
// Members
Router::get('/members', 'UserController@members', 'members.index');
Router::get('/members/{rank}', 'UserController@members', 'members.rank');
Router::group(['prefix' => 'members'], function () {
Router::get('/', 'UserController@members', 'members.index');
Router::get('/{rank}', 'UserController@members', 'members.rank');
});
// User
Router::get('/u/{id}', 'UserController@profile', 'user.profile');
@ -46,8 +52,10 @@ Router::get('/a/{id}', 'FileController@avatar', 'file.avatar');
Router::get('/bg/{id}', 'FileController@background', 'file.background');
// Premium
Router::get('/support', 'PremiumController@index', 'premium.index');
Router::get('/support/tracker', 'PremiumController@tracker', 'premium.tracker');
Router::group(['prefix' => 'support'], function () {
Router::get('/', 'PremiumController@index', 'premium.index');
Router::get('/tracker', 'PremiumController@tracker', 'premium.tracker');
});
// Management
/*