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

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