source: Dev/branches/jos-branch/index.php @ 237

Last change on this file since 237 was 235, checked in by fpvanagthoven, 13 years ago

getObject.php is de nieuwe pagina die gewoon PHP objecten in JSON zet en echoet. Nu werkt alleen de questionEditor er op, uiteindelijk zou dit ook de infopanel en de sequencer moeten gaan serven.

File size: 3.4 KB
RevLine 
[47]1<?php
2require 'classes/master.php'; //should be at top of every page
[10]3
[208]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$errorMessage[] = "";
10
[47]11if (isset($_POST['register'])) {
[208]12    if (isset($_POST['username']) && isset($_POST['password'])) {
[230]13        $user_results = User::get(array("name" => $_POST['username']));
[208]14        if (count($user_results) == 0 || !$user_results) {
15            if (strlen($_POST['password']) > 6) {
16                $user = new User(null, $_POST['username'], $_POST['password']);
[235]17                $user->save();
[208]18                $_SESSION['userUid'] = $user->uid;
19            } else {
20                $errorMessage[] = "Password is too short";
21            }
[47]22        }
23        else
[208]24            $errorMessage[] = "Username already exists, try something else!";
[47]25    }
26    else
[208]27        $errorMessage[] = "Please fill in a username and password";
[44]28}
[60]29
[208]30if (isset($_POST['login'])) {   // User clicked the login button
[230]31    $user_results = User::get(array("name" => $_POST['username']));
[208]32    if (isset($user_results[0])) {
33        if ($user_results[0]->password == $_POST['password']) {
[235]34           
[208]35            $_SESSION['userUid'] = $user_results[0]->uid;
[235]36            var_dump($user_results[0]);
[208]37        } else {
38            $errorMessage[] = "Incorrect password!";
39        }
40    } else {
41        $errorMessage[] = "Username doesn't exist!";
42    }
43}
44
45if (isset($_SESSION['userUid'])) {  // User just registered a new account
[235]46    redirect('mainmenu.php');
[208]47}
[38]48?>
49
[10]50<!DOCTYPE html>
51<html>
52    <head>
53        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
54        <title>Facilitator</title>
[235]55        <?php new StyleSheet("visualeditors"); ?>
[38]56        <script type="text/javascript" src="js/menu.js"></script>
[208]57        <script type="text/javascript">
58       
59   
60
61        </script>
[10]62    </head>
63    <body>
64        <div id="header">
[208]65            <?php new Logo(); ?>
[47]66        </div>
67
[10]68        <div id="wrapper">
[47]69
[10]70            <div id="content">
[235]71                <div class="largeFrame">
72                    <div class="largeTitle">Log in</div>
73                    <div class="content">
74                        <form action="index.php" method="POST">
75                            <h3>Username</h3>
76                            <input type="text" name="username"><br />
77                            <h3>Password</h3>
78                            <input type="password" name="password"><br/><br />
79                            <div id="errorDisplay">
80                                <?php
81                                foreach ($errorMessage as $message) {
82                                    echo "<h3 style='color: #FF0000;'>$message</h3>";
83                                }
84                                ?>
85                            </div>
86                            <br/>
87                            <input type="submit" name="login" class="bigButton vertical" value="Log in">
88                        </form>
89                        <form action="register.php" method="POST">
90                            <input type="submit" name="register" class="bigButton vertical" value="Register" style="margin-bottom: 0.25em;">
91                        </form>
92                    </div>
93
[10]94                </div>
95            </div>
96        </div>
97    </body>
[230]98</html>
Note: See TracBrowser for help on using the repository browser.