Changeset 151 for Dev/trunk/index.php


Ignore:
Timestamp:
11/08/11 17:02:55 (13 years ago)
Author:
fpvanagthoven
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/trunk/index.php

    r142 r151  
    22require 'classes/master.php'; //should be at top of every page
    33
     4/*  Page still has ambiguous design. Login and Register buttons are at same hierarchy level, makes user suspect the register button works based on input given here.
     5 *  Instead redirects to anoter page.
     6 *   
     7 */
     8
     9//Even voor tijdelijk, aangezien er nog pagina's missen en redirects daarom niet goed werken:
     10if (isset($_SESSION['username'])) {
     11    redirect("logout.php");
     12}
     13
     14$errorMessage[] = "";
     15
    416if (isset($_POST['register'])) {
    517    if ($_POST['username'] != null && $_POST['password'] != null) {
    6         $userDBI = new UserDatabaseInterface();
    7         $user_exists = $userDBI->checkUserName($_POST['username']);
     18        $dbi = new DatabaseInterface();
     19        $user_results = $dbi->get("user", array("name" => $_POST['username']));
     20        $user_exists = (count($user_results) > 0);
    821        if (!$user_exists) {
    9             $userDBI->addNewUser($_POST);
     22            if (strlen($_POST['password']) > 6) {
     23                $user = new User(null, $_POST['username'], $_POST['password']);
     24                $dbi->set($user);
     25                $_SESSION['username'] = $_POST['username'];
     26            } else {
     27                $errorMessage[] = "Password is too short!";
     28                //echo "Password is too short!";
     29            }
    1030        }
    1131        else
    12             echo "Username already exists, try something else";
     32            $errorMessage[] = "Username already exists, try something else!";
     33        //echo "Username already exists, try something else";
    1334    }
    1435    else
    15         echo "please fill in a username and password";
     36        $errorMessage[] = "Please fill in a username and password";
     37    //echo "please fill in a username and password";
    1638}
    1739
    18 if (isset($_SESSION['username']))
    19     redirect('mainmenu.php');
     40if (isset($_POST['login'])) {
     41    $dbi = new DatabaseInterface();
     42    $user_results = $dbi->get("user", array("name" => $_POST['username']));
     43    if (isset($user_results[0])) {
     44        if ($user_results[0]->password == $_POST['password']) {
     45            $_SESSION['username'] = $user_results[0]->name;
     46            // USER HAS LOGGED IN
     47        } else {
     48            $errorMessage[] = "Incorrect password!";
     49            //echo "Incorrect password!";
     50        }
     51    } else {
     52        $errorMessage[] = "Username doesn't exist!";
     53        //echo "Username doesn't exist!";
     54    }
     55}
     56
     57if (isset($_SESSION['username'])) {
     58    redirect('pipelineEditor.php');
     59}
    2060?>
    2161
     
    2767        <?php new StyleSheet("awesome"); ?>
    2868        <script type="text/javascript" src="js/menu.js"></script>
     69        <script type="text/javascript">
     70       
     71   
     72
     73        </script>
    2974    </head>
    3075    <body>
    3176        <div id="header">
    32 <?php new Logo(); ?>
     77            <?php new Logo(); ?>
    3378        </div>
    3479
     
    3782            <div id="content">
    3883                <div class="menu">
    39                     <form action="mainmenu.php" method="POST">
     84                    <form action="index.php" method="POST">
    4085                        <h3>Username</h3>
    4186                        <input type="text" name="username"><br />
    4287                        <h3>Password</h3>
    43                         <input type="password" name="password"><br/><br/><br/>
     88                        <input type="password" name="password"><br/><br />
     89                        <div id="errorDisplay">
     90                            <?php
     91                            foreach ($errorMessage as $message) {
     92                                echo "<h3 style='color: #FF0000;'>$message</h3>";
     93                            }
     94                            ?>
     95                        </div>
     96                        <br/>
    4497                        <input type="submit" name="login" class="surveyButton bigSurveyButton" value="Log in">
    4598                    </form>
Note: See TracChangeset for help on using the changeset viewer.