Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///// FOLDER STRUCTURE /////
- /genesis
- /genesis
- /model
- login.php (namespace Genesis\Model; class Login)
- /view
- login.php
- /controller
- login.php (namespace Genesis\Controller; class Login)
- /lib
- index.php
- autoload.php
- dbconnect.php
- index.php
- config.php
- ///// /GENESIS/GENESIS/INDEX.PHP /////
- <?php
- session_start();
- include_once('lib/index.php');
- ?>
- <!DOCTYPE html>
- <html class="no-js">
- <head>
- <meta charset="utf-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
- <title>Genesis</title>
- <meta name="description" content="">
- <meta name="viewport" content="width=device-width">
- <link rel="stylesheet" href="/genesis/css/stylesheets/login.css">
- <link href='http://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
- <script src="/genesis/js/vendor/modernizr-2.6.2-respond-1.1.0.min.js"></script>
- </head>
- <body>
- <div class="outer">
- <div class="container">
- <div class="inner">
- <?php
- if (isset($_POST['submit'])) {
- $login = new \Genesis\Controller\Login($dbh);
- var_dump($login->validateLogin($_POST['username'], $_POST['password']));
- } else {
- $login = new \Genesis\Controller\Login(NULL);
- $login = $login->viewLogin();
- }
- ?>
- </div>
- </div>
- </div>
- <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
- <script>window.jQuery || document.write('<script src="/genesis/js/vendor/jquery-1.10.1.min.js"><\/script>')</script>
- <script src="/genesis/js/plugins.js"></script>
- <script src="/genesis/js/main.js"></script>
- <script>
- var _gaq=[['_setAccount','UA-XXXXX-X'],['_trackPageview']];
- (function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
- g.src='//www.google-analytics.com/ga.js';
- s.parentNode.insertBefore(g,s)}(document,'script'));
- </script>
- </body>
- </html>
- ///// /GENESIS/GENESIS/CONFIG.PHP /////
- <?php
- define('ROOT_DIR', dirname(__FILE__));
- define('HOST', 'localhost');
- define('DATABASE', 'genesis');
- define('USERNAME', 'username');
- define('PASSWORD', 'password');
- ?>
- ///// /GENESIS/GENESIS/LIB/INDEX.PHP /////
- <?php
- require($_SERVER['DOCUMENT_ROOT'] . '/genesis/config.php');
- require('dbconnect.php');
- require('autoload.php');
- ?>
- ///// /GENESIS/GENESIS/LIB/AUTOLOAD.PHP /////
- <?php
- function autoload($className) {
- $className = ltrim($className, '\\');
- $fileName = '';
- $namespace = '';
- if ($lastNsPos = strripos($className, '\\')) {
- $namespace = substr($className, 0, $lastNsPos);
- $className = substr($className, $lastNsPos + 1);
- $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
- }
- $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
- require $fileName;
- }
- ?>
- ///// /GENESIS/GENESIS/LIB/DBCONNECT.PHP /////
- <?php
- $dsn = 'mysql:dbname=' . DATABASE . ';host=' . HOST;
- $user = USERNAME;
- $password = PASSWORD;
- try {
- $dbh = new PDO($dsn, $user, $password);
- } catch (PDOException $e) {
- echo 'Connection failed: ' . $e->getMessage();
- die();
- }
- ?>
- ///// /GENESIS/GENESIS/CONTROLLER/LOGIN.PHP /////
- <?php
- namespace Genesis\Controller;
- /**
- *
- */
- class Login {
- public $dbh;
- public $username;
- public $password;
- function __construct($dbh) {
- $this->dbh = $dbh;
- }
- public function viewLogin() {
- include(ROOT_DIR . '/view/login.php');
- }
- public function validateLogin($username, $password) {
- $login = new \Genesis\Model\Login($this->dbh);
- $login = $login->getUser($username, $password);
- return $login;
- }
- }
- ?>
- ///// /GENESIS/GENESIS/MODEL/LOGIN.PHP /////
- <?php
- namespace \Genesis\Model;
- /**
- *
- */
- class Login {
- private $dbh;
- public $result;
- function __construct($dbh) {
- $this->dbh = $dbh;
- $this->result = array();
- }
- public function getUser($username, $password) {
- try {
- $sth = $this->dbh->prepare('SELECT id, firstName, lastName, username FROM users WHERE username = :username AND password = :password');
- $sth->bindParam(':username', $username, PDO::PARAM_STR);
- $sth->bindParam(':password', $password, PDO::PARAM_STR);
- $sth->execute();
- $this->result = $sth->fetch(PDO::FETCH_ASSOC);
- } catch (Exception $e) {
- echo 'Getting user info failed: ' . $e->getMessage();
- die();
- }
- return $this->result;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement