Advertisement
Guest User

Untitled

a guest
Sep 21st, 2016
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.66 KB | None | 0 0
  1. <?php
  2. //COntroller
  3.  
  4. /**
  5.  * Class Songs
  6.  * This is a demo class.
  7.  *
  8.  * Please note:
  9.  * Don't use the same name for class and method, as this might trigger an (unintended) __construct of the class.
  10.  * This is really weird behaviour, but documented here: http://php.net/manual/en/language.oop5.decon.php
  11.  *
  12.  */
  13. class Session extends Controller
  14. {
  15.     /**
  16.      * PAGE: index
  17.      * This method handles what happens when you move to http://yourproject/songs/index
  18.      */
  19.  
  20.  
  21.     public function index()
  22.     {
  23.  
  24.     }
  25.  
  26.     public function register()
  27.     {
  28.  
  29.  
  30.             if ($_SERVER["REQUEST_METHOD"] == "POST") {
  31.                 $password1 = $_POST["password1"];
  32.                 $password2 = $_POST["password2"];
  33.  
  34.                     if ($password1 == $password2) {
  35.                         $username = $_POST["username"];
  36.                         $lastname = $_POST["lastname"];
  37.                         $email = $_POST["email"];
  38.                         $password1 = $_POST["password1"];
  39.                         $password2 = $_POST["password2"];
  40.  
  41.                         //encript password
  42.                         $password1 = md5(md5("joasdjf".$password1."jwdfgsadfas"));
  43.  
  44.                                 // if not
  45.                                 if(!(!isset($username) || trim($username) == '' || !isset($lastname) || trim($lastname) == '' || !isset($email) || trim($email) == '' || !isset($password1) || trim($password1) == '' || !isset($password2) || trim($password2) == ''))
  46.                                 {
  47.                                     if ($users = $this->model->createNewUser($username,$lastname,$email,$password1,$password2)) {
  48.                                         header('Location: http://mvc.balkangaming.net');
  49.                                     }
  50.                                 }
  51.  
  52.  
  53.                     }else echo " ";
  54.  
  55.         }
  56.  
  57.         var_dump($this->model->userLoggedIn());
  58.  
  59.         require APP . 'view/_templates/header.php';
  60.         require APP . 'view/session/register.php';
  61.         require APP . 'view/_templates/footer.php';
  62.     }
  63.  
  64.     public function login()
  65.     {
  66.  
  67.         if ($_SERVER["REQUEST_METHOD"] == "POST") {
  68.                 $username = $_POST["username"];
  69.                 $password = $_POST["password"];
  70.  
  71.             if (!isset($username) || trim($username) == '' || !isset($password) || trim($password) == '' )
  72.             {
  73.                 var_dump($username);
  74.                 var_dump($password);
  75.  
  76.                 //encript password
  77.                 echo "you did not entered data";
  78.  
  79.  
  80.             }
  81.             else {
  82.  
  83.                     $password = md5(md5("joasdjf".$password."jwdfgsadfas"));
  84.  
  85.                     if ($users = $this->model->loginUser($username,$password)) {
  86.                         var_dump($users = $this->model->loginUser($username,$password));
  87.                         session_start();
  88.                         $_SESSION['username'] = $username;
  89.                         echo "Logged in successfuly";
  90.                     }else echo "Username or password does not match";
  91.  
  92.             }
  93.         }
  94.  
  95.  
  96.         require APP . 'view/_templates/header.php';
  97.         require APP . 'view/session/login.php';
  98.         require APP . 'view/_templates/footer.php';
  99.     }
  100.  
  101.  
  102.     public function logout() {
  103.         $this->model->logout();
  104.         header('Location: http://mvc.balkangaming.net/');
  105.     }
  106.  
  107.     public function checkEmail()
  108.     {
  109.         $email = $_POST["email"];
  110.  
  111.         $users = $this->model->checkIfEmailExists($email);
  112.     }
  113.  
  114.     public function checkUsername()
  115.     {
  116.         $name = $_POST["username"];
  117.  
  118.         $users = $this->model->checkIfUserExists($name);
  119.     }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement