source: Dev/branches/Cartis/index.php @ 297

Last change on this file since 297 was 242, checked in by cartis, 13 years ago
File size: 3.4 KB
RevLine 
[47]1<?php
2require 'classes/master.php'; //should be at top of every page
[10]3
[151]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
[207]9//Even voor tijdelijk, aangezien er nog pagina's missen en redirects daarom niet goed werken:
[191]10if (isset($_SESSION['userUid'])) {
[151]11    redirect("logout.php");
12}
13
14$errorMessage[] = "";
15
[47]16if (isset($_POST['register'])) {
[191]17    if (isset($_POST['username']) && isset($_POST['password'])) {
[151]18        $dbi = new DatabaseInterface();
19        $user_results = $dbi->get("user", array("name" => $_POST['username']));
[191]20        if (count($user_results) == 0 || !$user_results) {
[151]21            if (strlen($_POST['password']) > 6) {
22                $user = new User(null, $_POST['username'], $_POST['password']);
23                $dbi->set($user);
[191]24                $_SESSION['userUid'] = $user->uid;
[151]25            } else {
[191]26                $errorMessage[] = "Password is too short";
[151]27            }
[47]28        }
29        else
[151]30            $errorMessage[] = "Username already exists, try something else!";
[47]31    }
32    else
[151]33        $errorMessage[] = "Please fill in a username and password";
[44]34}
[60]35
[191]36if (isset($_POST['login'])) {   // User clicked the login button
[151]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']) {
[191]41            $_SESSION['userUid'] = $user_results[0]->uid;
[151]42        } else {
43            $errorMessage[] = "Incorrect password!";
44        }
45    } else {
46        $errorMessage[] = "Username doesn't exist!";
47    }
48}
49
[191]50if (isset($_SESSION['userUid'])) {  // User just registered a new account
[242]51   //aangepast voor Flow
52    redirect('dashboardDataSelection.php');
[151]53}
[38]54?>
55
[10]56<!DOCTYPE html>
57<html>
58    <head>
59        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
60        <title>Facilitator</title>
[142]61        <?php new StyleSheet("awesome"); ?>
[38]62        <script type="text/javascript" src="js/menu.js"></script>
[151]63        <script type="text/javascript">
64       
65   
66
67        </script>
[10]68    </head>
69    <body>
70        <div id="header">
[151]71            <?php new Logo(); ?>
[47]72        </div>
73
[10]74        <div id="wrapper">
[47]75
[10]76            <div id="content">
[58]77                <div class="menu">
[151]78                    <form action="index.php" method="POST">
[48]79                        <h3>Username</h3>
[47]80                        <input type="text" name="username"><br />
[48]81                        <h3>Password</h3>
[151]82                        <input type="password" name="password"><br/><br />
83                        <div id="errorDisplay">
84                            <?php
85                            foreach ($errorMessage as $message) {
86                                echo "<h3 style='color: #FF0000;'>$message</h3>";
87                            }
88                            ?>
89                        </div>
90                        <br/>
[47]91                        <input type="submit" name="login" class="surveyButton bigSurveyButton" value="Log in">
92                    </form>
93                    <form action="register.php" method="POST">
94                        <input type="submit" name="register" class="surveyButton bigSurveyButton" value="Register">
95                    </form>
[10]96                </div>
97            </div>
98        </div>
99    </body>
[47]100</html>
Note: See TracBrowser for help on using the repository browser.