added route groups
low motivation programming
This commit is contained in:
parent
b2c77b267e
commit
3b2114cd10
4 changed files with 59 additions and 45 deletions
|
@ -17,6 +17,6 @@
|
||||||
"jbbcode/jbbcode": "*",
|
"jbbcode/jbbcode": "*",
|
||||||
"corneltek/cliframework": "*",
|
"corneltek/cliframework": "*",
|
||||||
"phroute/phroute": "^2.1",
|
"phroute/phroute": "^2.1",
|
||||||
"illuminate/database": "5.2.7"
|
"illuminate/database": "5.2.*"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
namespace Sakura;
|
namespace Sakura;
|
||||||
|
|
||||||
use Phroute\Phroute\Dispatcher;
|
use Phroute\Phroute\Dispatcher;
|
||||||
use Phroute\Phroute\Exception\HttpRouteNotFoundException;
|
|
||||||
use Phroute\Phroute\Exception\HttpMethodNotAllowedException;
|
use Phroute\Phroute\Exception\HttpMethodNotAllowedException;
|
||||||
|
use Phroute\Phroute\Exception\HttpRouteNotFoundException;
|
||||||
use Phroute\Phroute\RouteCollector;
|
use Phroute\Phroute\RouteCollector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,7 +53,8 @@ class Router
|
||||||
'PATCH',
|
'PATCH',
|
||||||
'DELETE',
|
'DELETE',
|
||||||
'HEAD',
|
'HEAD',
|
||||||
'ANY'
|
'OPTIONS',
|
||||||
|
'ANY',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -130,6 +131,20 @@ class Router
|
||||||
return self::$basePath . self::$router->route($name, $args);
|
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.
|
* Handle requests.
|
||||||
*
|
*
|
||||||
|
|
|
@ -20,11 +20,9 @@ if (isset($_REQUEST['mode'])) {
|
||||||
// Compare time and session so we know the link isn't forged
|
// Compare time and session so we know the link isn't forged
|
||||||
if (!isset($_REQUEST['time']) || $_REQUEST['time'] < time() - 1000) {
|
if (!isset($_REQUEST['time']) || $_REQUEST['time'] < time() - 1000) {
|
||||||
$renderData['page'] = [
|
$renderData['page'] = [
|
||||||
|
|
||||||
'redirect' => $urls->format('AUTH_ACTION'),
|
'redirect' => $urls->format('AUTH_ACTION'),
|
||||||
'message' => 'Timestamps differ too much, refresh the page and try again.',
|
'message' => 'Timestamps differ too much, refresh the page and try again.',
|
||||||
'success' => 0,
|
'success' => 0,
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
// Prevent
|
// Prevent
|
||||||
|
@ -34,11 +32,9 @@ if (isset($_REQUEST['mode'])) {
|
||||||
// Match session ids for the same reason
|
// Match session ids for the same reason
|
||||||
if (!isset($_REQUEST['session']) || $_REQUEST['session'] != session_id()) {
|
if (!isset($_REQUEST['session']) || $_REQUEST['session'] != session_id()) {
|
||||||
$renderData['page'] = [
|
$renderData['page'] = [
|
||||||
|
|
||||||
'redirect' => $urls->format('AUTH_ACTION'),
|
'redirect' => $urls->format('AUTH_ACTION'),
|
||||||
'message' => 'Invalid session, please try again.',
|
'message' => 'Invalid session, please try again.',
|
||||||
'success' => 0,
|
'success' => 0,
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
// Prevent
|
// Prevent
|
||||||
|
@ -62,15 +58,6 @@ if (isset($_REQUEST['mode'])) {
|
||||||
|
|
||||||
if ($continue) {
|
if ($continue) {
|
||||||
switch ($_REQUEST['mode']) {
|
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':
|
case 'changepassword':
|
||||||
// Attempt change
|
// Attempt change
|
||||||
$passforget = Users::resetPassword(
|
$passforget = Users::resetPassword(
|
||||||
|
@ -146,26 +133,6 @@ if (isset($_REQUEST['mode'])) {
|
||||||
];
|
];
|
||||||
break;
|
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
|
// Unforgetting passwords
|
||||||
case 'forgotpassword':
|
case 'forgotpassword':
|
||||||
// Attempt send
|
// Attempt send
|
||||||
|
@ -187,6 +154,30 @@ if (isset($_REQUEST['mode'])) {
|
||||||
];
|
];
|
||||||
break;
|
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;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
26
routes.php
26
routes.php
|
@ -25,17 +25,23 @@ Router::post('/reactivate', 'AuthController@reactivatePost', 'auth.reactivate');
|
||||||
Router::get('/activate', 'AuthController@activate', 'auth.activate');
|
Router::get('/activate', 'AuthController@activate', 'auth.activate');
|
||||||
|
|
||||||
// News
|
// News
|
||||||
Router::get('/news', 'MetaController@news', 'news.index');
|
Router::group(['prefix' => 'news'], function () {
|
||||||
Router::get('/news/{category}', 'MetaController@news', 'news.category');
|
Router::get('/', 'MetaController@news', 'news.index');
|
||||||
Router::get('/news/{category}/{id}', 'MetaController@news', 'news.post');
|
Router::get('/{category}', 'MetaController@news', 'news.category');
|
||||||
|
Router::get('/{category}/{id}', 'MetaController@news', 'news.post');
|
||||||
|
});
|
||||||
|
|
||||||
// Forum
|
// Forum
|
||||||
Router::get('/forum', 'ForumController@index', 'forums.index');
|
Router::group(['prefix' => 'forum'], function () {
|
||||||
Router::get('/forum/{id}', 'ForumController@forum', 'forums.forum');
|
Router::get('/', 'ForumController@index', 'forums.index');
|
||||||
|
Router::get('/{id}', 'ForumController@forum', 'forums.forum');
|
||||||
|
});
|
||||||
|
|
||||||
// Members
|
// Members
|
||||||
Router::get('/members', 'UserController@members', 'members.index');
|
Router::group(['prefix' => 'members'], function () {
|
||||||
Router::get('/members/{rank}', 'UserController@members', 'members.rank');
|
Router::get('/', 'UserController@members', 'members.index');
|
||||||
|
Router::get('/{rank}', 'UserController@members', 'members.rank');
|
||||||
|
});
|
||||||
|
|
||||||
// User
|
// User
|
||||||
Router::get('/u/{id}', 'UserController@profile', 'user.profile');
|
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');
|
Router::get('/bg/{id}', 'FileController@background', 'file.background');
|
||||||
|
|
||||||
// Premium
|
// Premium
|
||||||
Router::get('/support', 'PremiumController@index', 'premium.index');
|
Router::group(['prefix' => 'support'], function () {
|
||||||
Router::get('/support/tracker', 'PremiumController@tracker', 'premium.tracker');
|
Router::get('/', 'PremiumController@index', 'premium.index');
|
||||||
|
Router::get('/tracker', 'PremiumController@tracker', 'premium.tracker');
|
||||||
|
});
|
||||||
|
|
||||||
// Management
|
// Management
|
||||||
/*
|
/*
|
||||||
|
|
Reference in a new issue