Anonymous Anonymous - 4 months ago
618 0

No description

PHP

index

<?php

require_once 'includes/global.inc.php'; //starts the session and loads a few class files

var_dump($_POST);
error_reporting(-1);
ini_set('display_errors', 'On');

//echo "Username: " . $_POST['username'];
//echo "   Password: " . $_POST['password'];
//echo "   Password2: " . $_POST['password2'];
//echo "   Email: " . $_POST['email'];
//echo "   Company: " . $_POST['company'];

$username = "";
$password = "";
$password2 = "";
$email = "";
$error = "";

echo "<script type='text/javascript'>alert('before checking if posted');</script>";

if(isset($_POST['submitr'])) {
    echo "<script type='text/javascript'>alert('found that login button was pressed');</script>";
    $username = $_POST['username'];
    $password = $_POST['password'];
    $password2 = $_POST['password2'];
    $email = $_POST['email'];
    $company = $_POST['company'];

    $success = true;
    $userTools = new UserTools();

    echo "<script type='text/javascript'>alert('$success');</script>";

    if($userTools->checkUsernameExists($username)) {
        $error .= "That username is already taken.<br/> \n\r";
        $success = false;
    }

    echo "<script type='text/javascript'>alert('$success');</script>";

    if($password != $password2) {
        $error .= "Passwords do not match.<br/> \n\r";
        $success = false;
    }

    echo "<script type='text/javascript'>alert('$success');</script>";

    if($success) {
        echo "<script type='text/javascript'>alert('successful');</script>";
        $data['company'] = $company;
        $data['username'] = $username;
        $data['password'] = md5($password);
        $data['email'] = $email;
        $newUser = new User($data);
        $newUser->save(true);
        $userTools->login($username,$password);
        header("Location: Home.php");
    }
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <style>@import "CSS/homeStyle.css";</style>
    <title>Surv-it: info page</title>
</head>
<body style="background:lightgreen">

<nav class="navbar navbar-default navbar-fixed-top">
    <div class="container-fluid">
        <div class="navbar-header">
            <a class="navbar-brand" href="#">
                <img alt="Surv-It" src="Images/Surv-it-Logo.png" height="40" width="80"/>
            </a>
        </div>
        <ul class="nav navbar-nav navbar-right">
            <li><a href="#" id="logLink"><span class="glyphicon glyphicon-user"></span> Log In </a></li>
            <li><a href="#" id="signLink"><span class="glyphicon glyphicon-plus"></span> Sign Up </a></li>
        </ul>
    </div>
</nav>

<div>
    <!-- TODO finish info page -->
    <h1>WELCOME!</h1>
</div>

<div id="logMod" class="modal">
    <div class="modal-content" style="width:50%;margin-left:25%;margin-top:10%">
        <div class="modal-header" style="background: green; color: white">
            <span class="close">&times;</span>
            <h4 style="text-align: center">Log In</h4>
        </div>
        <div class="modal-body">
            <p style="color:red">CLICK X CLOSE</p>
            <a href="Home.html">CLICK TO SKIP FOR TESTING</a>
            <form style="text-align: center;padding:10px" id="logForm">
                Username: <input type="text" value="username"><br>
                Password: <input style="margin-top:5px" type="password" value="password"><br>
                <input style="margin-top:5px" type="submit" value="Submit" name="submitl"/>
            </form>
        </div>
    </div>
</div>
<div id="signMod" class="modal">
    <div class="modal-content" style="width:50%;margin-left:25%;margin-top:10%">
        <div class="modal-header" style="background: green; color: white">
            <span class="close">&times;</span>
            <h4 style="text-align: center">Sign Up</h4>
        </div>
        <div class="modal-body">
            <p style="color:red">CLICK OUTSIDE WINDOW TO CLOSE</p>
            <?php echo ($error != "") ? $error : ""; ?>
            <form action="index.php" method="post" style="align-content: left;text-align: center;padding:10px" id="signForm">
                Company: <input type="text" value="" name="company"><br>
                Email: <input style="margin-top:5px" type="text" value="" name="email"><br>
                Username: <input style="margin-top:5px" type="text" value="" name="username"><br>
                Password: <input style="margin-top:5px" type="password" value="" name="password"><br>
                Verify Password: <input style="margin-top:5px" type="password" value="" name="password2"><br>
                <input style="margin-top:10px" type="submit" value="Submit" name="submitr">
            </form>
        </div>
    </div>
</div>
<script>
    var modal1 = document.getElementById('logMod');
    var btn1 = document.getElementById("logLink");
    var modal2 = document.getElementById('signMod');
    var btn2 = document.getElementById("signLink");
    var span = document.getElementsByClassName("close")[0];
    btn1.onclick = function() {
        modal1.style.display = "block";
    }
    span.onclick = function() {
        modal1.style.display = "none";
        modal2.style.display = "none";
    }
    window.onclick = function(event) {
        if (event.target == modal1) {
            modal1.style.display = "none";
        }
    }
    btn2.onclick = function() {
        modal2.style.display = "block";
    }
    window.onclick = function(event) {
        if (event.target == modal2) {
            modal2.style.display = "none";
        }
    }
</script>

</body>
</html>