Guest User

Untitled

a guest
Dec 28th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. <?php
  2. //complete code for controllers/admin/users.php
  3. include_once "models/Admin_Table.class.php";
  4.  
  5. //is form submitted?
  6. $createNewAdmin = isset( $_POST['new-admin'] );
  7. //if it is...
  8. if( $createNewAdmin ) {
  9. //grab form input
  10. $newEmail = $_POST['email'];
  11. $newPassword = $_POST['password'];
  12. $adminTable = new Admin_Table($db);
  13. try {
  14. //try to create a new admin user
  15. $adminTable->create( $newEmail, $newPassword );
  16. //tell user how it went
  17. $adminFormMessage = "New user created for $newEmail!";
  18. } catch ( Exception $e ) {
  19. //if operation failed, tell user what went wrong
  20. $adminFormMessage = $e->getMessage();
  21. }
  22. }
  23. //end of new code
  24.  
  25.  
  26. $newAdminForm = include_once "views/admin/new-admin-form-html.php";
  27. return $newAdminForm;
  28.  
  29. <?php
  30. //complete code for blog/admin.php
  31. error_reporting( E_ALL );
  32. ini_set( "display_errors", 1 );
  33.  
  34. include_once "models/Page_Data.class.php";
  35. $pageData = new Page_Data();
  36. $pageData->title = "PHP/MySQL blog demo";
  37. $pageData->addCSS("css/blog.css");
  38. $pageData->addScript("js/editor.js");
  39. //$pageData->content = include_once "views/admin/admin-navigation.php";
  40.  
  41. $dbInfo = "mysql:host=localhost;dbname=simple_blog";
  42. $dbUser = "root";
  43. $dbPassword = "root";
  44. $db = new PDO( $dbInfo, $dbUser, $dbPassword );
  45. $db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
  46.  
  47. /*
  48. $navigationIsClicked = isset( $_GET['page'] );
  49. if ( $navigationIsClicked ) {
  50. //prepare to load corresponding controller
  51. $contrl = $_GET['page'];
  52. } else {
  53. //prepare to load default controller
  54. $contrl = "entries";
  55. }
  56. */
  57. include_once "models/Admin_User.class.php";
  58. $admin = new Admin_User();
  59. //load the login controller, which will show the login form
  60. $pageData->content = include_once "controllers/admin/login.php";
  61.  
  62. //load the controller
  63. //$pageData->content .= include_once "controllers/admin/$contrl.php";
  64.  
  65.  
  66.  
  67.  
  68.  
  69. //add a new if statement
  70. //show admin module only if user is logged in
  71. if( $admin->isLoggedIn() ) {
  72. $pageData->content .= include "views/admin/admin-navigation.php";
  73. $navigationIsClicked = isset( $_GET['page'] );
  74. if ($navigationIsClicked ) {
  75. $controller = $_GET['page'];
  76. } else {
  77. $controller = "entries";
  78. }
  79. $pathToController = "controllers/admin/$controller.php";
  80. $pageData->content .= include_once $pathToController;
  81. } //end if-statement
  82.  
  83.  
  84.  
  85. $page = include_once "views/page.php";
  86. echo $page;
Add Comment
Please, Sign In to add comment