-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
daba1a7
commit fb20cca
Showing
19 changed files
with
413 additions
and
128 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,111 @@ | ||
<?php | ||
|
||
use Limber\Router\Router; | ||
use Controllers\LoginController; | ||
use Controllers\DatabaseController; | ||
use Controllers\CollectionController; | ||
use Controllers\Controller; | ||
|
||
$router = new Router(); | ||
|
||
$router->get('/', function() { | ||
header('Location: /queryDatabase'); | ||
exit; | ||
|
||
LoginController::ensureUserIsLogged(); | ||
|
||
Controller::redirectTo('/queryDatabase'); | ||
|
||
}); | ||
|
||
// XXX This hack makes index to work in sub-folder case. | ||
$router->get(MPG_SERVER_PATH . '/index', function() { | ||
|
||
LoginController::ensureUserIsLogged(); | ||
|
||
Controller::redirectTo('/queryDatabase'); | ||
|
||
}); | ||
|
||
$router->get( | ||
'/createDatabase', | ||
MPG_SERVER_PATH . '/login', | ||
LoginController::class . '@renderViewAction' | ||
); | ||
|
||
$router->post( | ||
MPG_SERVER_PATH . '/login', | ||
LoginController::class . '@renderViewAction' | ||
); | ||
|
||
$router->get( | ||
MPG_SERVER_PATH . '/createDatabase', | ||
DatabaseController::class . '@renderCreateViewAction' | ||
); | ||
|
||
$router->get( | ||
'/queryDatabase', | ||
MPG_SERVER_PATH . '/queryDatabase', | ||
DatabaseController::class . '@renderQueryViewAction' | ||
); | ||
|
||
$router->post( | ||
'/ajax/database/listCollections', | ||
MPG_SERVER_PATH . '/ajaxDatabaseListCollections', | ||
DatabaseController::class . '@listCollectionsAction' | ||
); | ||
|
||
$router->post( | ||
'/ajax/database/createCollection', | ||
MPG_SERVER_PATH . '/ajaxDatabaseCreateCollection', | ||
DatabaseController::class . '@createCollectionAction' | ||
); | ||
|
||
$router->post( | ||
'/ajax/collection/insertOne', | ||
MPG_SERVER_PATH . '/ajaxCollectionInsertOne', | ||
CollectionController::class . '@insertOneAction' | ||
); | ||
|
||
$router->post( | ||
'/ajax/collection/count', | ||
MPG_SERVER_PATH . '/ajaxCollectionCount', | ||
CollectionController::class . '@countAction' | ||
); | ||
|
||
$router->post( | ||
'/ajax/collection/deleteOne', | ||
MPG_SERVER_PATH . '/ajaxCollectionDeleteOne', | ||
CollectionController::class . '@deleteOneAction' | ||
); | ||
|
||
$router->post( | ||
'/ajax/collection/find', | ||
MPG_SERVER_PATH . '/ajaxCollectionFind', | ||
CollectionController::class . '@findAction' | ||
); | ||
|
||
$router->post( | ||
'/ajax/collection/updateOne', | ||
MPG_SERVER_PATH . '/ajaxCollectionUpdateOne', | ||
CollectionController::class . '@updateOneAction' | ||
); | ||
|
||
$router->post( | ||
'/ajax/collection/enumFields', | ||
MPG_SERVER_PATH . '/ajaxCollectionEnumFields', | ||
CollectionController::class . '@enumFieldsAction' | ||
); | ||
|
||
$router->get( | ||
'/manageIndexes', | ||
MPG_SERVER_PATH . '/manageIndexes', | ||
CollectionController::class . '@renderIndexesViewAction' | ||
); | ||
|
||
$router->post( | ||
'/ajax/collection/createIndex', | ||
MPG_SERVER_PATH . '/ajaxCollectionCreateIndex', | ||
CollectionController::class . '@createIndexAction' | ||
); | ||
|
||
$router->post( | ||
'/ajax/collection/listIndexes', | ||
MPG_SERVER_PATH . '/ajaxCollectionListIndexes', | ||
CollectionController::class . '@listIndexesAction' | ||
); | ||
|
||
$router->post( | ||
'/ajax/collection/dropIndex', | ||
MPG_SERVER_PATH . '/ajaxCollectionDropIndex', | ||
CollectionController::class . '@dropIndexAction' | ||
); | ||
|
||
$router->get( | ||
MPG_SERVER_PATH . '/logout', | ||
LoginController::class . '@logoutAction' | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
namespace Controllers; | ||
|
||
use Capsule\Response; | ||
|
||
class LoginController extends Controller { | ||
|
||
public static function ensureUserIsLogged() { | ||
|
||
if ( !isset($_SESSION['mpg']['user_is_logged']) ) { | ||
|
||
Controller::redirectTo('/login#'); | ||
|
||
} | ||
|
||
} | ||
|
||
public function processFormData() : array { | ||
|
||
$errors = []; | ||
|
||
$_SESSION['mpg'] = []; | ||
|
||
if ( isset($_POST['user']) && !empty($_POST['user']) ) { | ||
$_SESSION['mpg']['mongodb_user'] = $_POST['user']; | ||
} | ||
|
||
if ( isset($_POST['password']) && !empty($_POST['password']) ) { | ||
$_SESSION['mpg']['mongodb_password'] = $_POST['password']; | ||
} | ||
|
||
if ( isset($_POST['host']) && !empty($_POST['host']) ) { | ||
$_SESSION['mpg']['mongodb_host'] = $_POST['host']; | ||
} else { | ||
$errors[] = 'Host'; | ||
} | ||
|
||
if ( isset($_POST['port']) && !empty($_POST['port']) ) { | ||
$_SESSION['mpg']['mongodb_port'] = $_POST['port']; | ||
} else { | ||
$errors[] = 'Port'; | ||
} | ||
|
||
if ( isset($_POST['database']) && !empty($_POST['database']) ) { | ||
$_SESSION['mpg']['mongodb_database'] = $_POST['database']; | ||
} | ||
|
||
return $errors; | ||
|
||
} | ||
|
||
public function renderViewAction() : Response { | ||
|
||
if ( isset($_POST['login']) ) { | ||
|
||
$errors = $this->processFormData(); | ||
|
||
if ( count($errors) >= 1 ) { | ||
|
||
return new Response(200, $this->renderView('login', [ | ||
'errors' => $errors | ||
])); | ||
|
||
} else { | ||
|
||
$_SESSION['mpg']['user_is_logged'] = true; | ||
Controller::redirectTo('/index'); | ||
|
||
} | ||
|
||
} else { | ||
return new Response(200, $this->renderView('login')); | ||
} | ||
|
||
} | ||
|
||
public function logoutAction() { | ||
|
||
$_SESSION['mpg'] = []; | ||
|
||
Controller::redirectTo('/login'); | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.