Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //complete code for controllers/admin/users.php
- include_once "models/Admin_Table.class.php";
- //is form submitted?
- $createNewAdmin = isset( $_POST['new-admin'] );
- //if it is...
- if( $createNewAdmin ) {
- //grab form input
- $newEmail = $_POST['email'];
- $newPassword = $_POST['password'];
- $adminTable = new Admin_Table($db);
- try {
- //try to create a new admin user
- $adminTable->create( $newEmail, $newPassword );
- //tell user how it went
- $adminFormMessage = "New user created for $newEmail!";
- } catch ( Exception $e ) {
- //if operation failed, tell user what went wrong
- $adminFormMessage = $e->getMessage();
- }
- }
- //end of new code
- $newAdminForm = include_once "views/admin/new-admin-form-html.php";
- return $newAdminForm;
- <?php
- //complete code for blog/admin.php
- error_reporting( E_ALL );
- ini_set( "display_errors", 1 );
- include_once "models/Page_Data.class.php";
- $pageData = new Page_Data();
- $pageData->title = "PHP/MySQL blog demo";
- $pageData->addCSS("css/blog.css");
- $pageData->addScript("js/editor.js");
- //$pageData->content = include_once "views/admin/admin-navigation.php";
- $dbInfo = "mysql:host=localhost;dbname=simple_blog";
- $dbUser = "root";
- $dbPassword = "root";
- $db = new PDO( $dbInfo, $dbUser, $dbPassword );
- $db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
- /*
- $navigationIsClicked = isset( $_GET['page'] );
- if ( $navigationIsClicked ) {
- //prepare to load corresponding controller
- $contrl = $_GET['page'];
- } else {
- //prepare to load default controller
- $contrl = "entries";
- }
- */
- include_once "models/Admin_User.class.php";
- $admin = new Admin_User();
- //load the login controller, which will show the login form
- $pageData->content = include_once "controllers/admin/login.php";
- //load the controller
- //$pageData->content .= include_once "controllers/admin/$contrl.php";
- //add a new if statement
- //show admin module only if user is logged in
- if( $admin->isLoggedIn() ) {
- $pageData->content .= include "views/admin/admin-navigation.php";
- $navigationIsClicked = isset( $_GET['page'] );
- if ($navigationIsClicked ) {
- $controller = $_GET['page'];
- } else {
- $controller = "entries";
- }
- $pathToController = "controllers/admin/$controller.php";
- $pageData->content .= include_once $pathToController;
- } //end if-statement
- $page = include_once "views/page.php";
- echo $page;
Add Comment
Please, Sign In to add comment