Ignore:
Timestamp:
01/06/12 10:29:09 (13 years ago)
Author:
jkraaijeveld
Message:

Got latest version from trunk. Ready to reorganise.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/branches/jos-branch/index.php

    r60 r208  
    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['userUid'])) {
     11    redirect("logout.php");
     12}
     13
     14$errorMessage[] = "";
     15
    416if (isset($_POST['register'])) {
    5     if ($_POST['username'] != null && $_POST['password'] != null) {
    6         $userDBI = new UserDatabaseInterface();
    7         $user_exists = $userDBI->checkUserName($_POST['username']);
    8         if (!$user_exists) {
    9             $userDBI->addNewUser($_POST);
     17    if (isset($_POST['username']) && isset($_POST['password'])) {
     18        $dbi = new DatabaseInterface();
     19        $user_results = $dbi->get("user", array("name" => $_POST['username']));
     20        if (count($user_results) == 0 || !$user_results) {
     21            if (strlen($_POST['password']) > 6) {
     22                $user = new User(null, $_POST['username'], $_POST['password']);
     23                $dbi->set($user);
     24                $_SESSION['userUid'] = $user->uid;
     25            } else {
     26                $errorMessage[] = "Password is too short";
     27            }
    1028        }
    1129        else
    12             echo "Username already exists, try something else";
     30            $errorMessage[] = "Username already exists, try something else!";
    1331    }
    1432    else
    15         echo "please fill in a username and password";
     33        $errorMessage[] = "Please fill in a username and password";
    1634}
    1735
    18 if (isset($_SESSION['username']))
    19     redirect('mainmenu.php');
     36if (isset($_POST['login'])) {   // User clicked the login button
     37    $dbi = new DatabaseInterface();
     38    $user_results = $dbi->get("user", array("name" => $_POST['username']));
     39    if (isset($user_results[0])) {
     40        if ($user_results[0]->password == $_POST['password']) {
     41            $_SESSION['userUid'] = $user_results[0]->uid;
     42        } else {
     43            $errorMessage[] = "Incorrect password!";
     44        }
     45    } else {
     46        $errorMessage[] = "Username doesn't exist!";
     47    }
     48}
     49
     50if (isset($_SESSION['userUid'])) {  // User just registered a new account
     51    redirect('selectSession.php');
     52}
    2053?>
    2154
     
    2558        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    2659        <title>Facilitator</title>
    27         <?php new StyleSheet(); ?>
     60        <?php new StyleSheet("awesome"); ?>
    2861        <script type="text/javascript" src="js/menu.js"></script>
     62        <script type="text/javascript">
     63       
     64   
     65
     66        </script>
    2967    </head>
    3068    <body>
    3169        <div id="header">
    32 <?php new Logo(); ?>
     70            <?php new Logo(); ?>
    3371        </div>
    3472
     
    3775            <div id="content">
    3876                <div class="menu">
    39                     <form action="mainmenu.php" method="POST">
     77                    <form action="index.php" method="POST">
    4078                        <h3>Username</h3>
    4179                        <input type="text" name="username"><br />
    4280                        <h3>Password</h3>
    43                         <input type="password" name="password"><br/><br/><br/>
     81                        <input type="password" name="password"><br/><br />
     82                        <div id="errorDisplay">
     83                            <?php
     84                            foreach ($errorMessage as $message) {
     85                                echo "<h3 style='color: #FF0000;'>$message</h3>";
     86                            }
     87                            ?>
     88                        </div>
     89                        <br/>
    4490                        <input type="submit" name="login" class="surveyButton bigSurveyButton" value="Log in">
    4591                    </form>
Note: See TracChangeset for help on using the changeset viewer.