Skip to content

Commit

Permalink
new user almost working
Browse files Browse the repository at this point in the history
  • Loading branch information
paleomedia committed Apr 20, 2015
1 parent 71294c3 commit 4fa12c2
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 12 deletions.
11 changes: 10 additions & 1 deletion dao.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,16 @@ public function getComments () {

public function newUser ($username, $password, $email) {
$conn = $this->getConnection();

$saveQuery =
"INSERT INTO users
(username, password, email)
VALUES
(:username, :password, :email)";
$q = $conn->prepare($saveQuery);
$q->bindParam(":username", $username);
$q->bindParam(":password", $password);
$q->bindParam(":email", $email);
return $q->execute();
}

public function saveBills ($id, $session, $title, $bill_id, $connection) {
Expand Down
12 changes: 6 additions & 6 deletions dash.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
<div class="loginbox">
<form action="login.php" method="POST">
<div class="loginbox">
<input type="text" name="username" id="username" placeholder="Username" />
<input type="text" name="username" id="username" placeholder="Username" tabindex="1" />
</div>
<input type="submit" value="Go">
<input type="submit" value="Go" tabindex="3">
<div>
<input type="password" name="password" id="password" placeholder="Password">
<input type="password" name="password" id="password" placeholder="Password" tabindex="2">
</div>
</form>
<p span id="newuser">or <a href="newaccount.php">create new account</a>
Expand All @@ -49,11 +49,11 @@
<div class="loginbox">
<form action="login.php" method="POST">
<div class="loginbox">
<input type="text" name="username" id="username" placeholder="Username" />
<input type="text" name="username" id="username" placeholder="Username" tabindex="1" />
</div>
<input type="submit" value="Go">
<input type="submit" value="Go" tabindex="3">
<div>
<input type="password" name="password" id="password" placeholder="Password">
<input type="password" name="password" id="password" placeholder="Password" tabindex="2">
</div>
</form>
<p span id="newuser">or <a href="newaccount.php">create new account</a>
Expand Down
2 changes: 1 addition & 1 deletion lawmakers.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//convert json object to php associative array
$legislators = json_decode($jsondata, true);

echo "<pre>" . print_r($data, 1) . "</pre>";
// echo "<pre>" . print_r($legislators, 1) . "</pre>";

$dao = new Dao();
$connection = $dao->getConnection();
Expand Down
2 changes: 1 addition & 1 deletion login.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<? php
<?php

if (!isset($_SESSION)) {
session_start();
Expand Down
4 changes: 1 addition & 3 deletions newaccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
<input type="text" name="username" id="username" placeholder="Username" />
<input type="email" name="email" id="email" placeholder="Email" />
<input type="password" name="password" id="password" placeholder="Password">
<input type="text" name="username" id="username" placeholder="Username" />
<input type="text" name="username" id="username" placeholder="Username" />
<input type="text" name="username" id="username" placeholder="Username" />
<input type="password" name="passconfirm" id="passwordconfirm" placeholder="Confirm password">
</div>
<input type="submit" value="Go">
</form>
Expand Down
30 changes: 30 additions & 0 deletions newuser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

if (!isset($_SESSION)) {
session_start();
}

require_once("dao.php");

if (isset($_POST["username"]) && isset($_POST["password"]) && isset($_POST["email"])) {
$username = $_POST["username"];
$password = $_POST["password"];
$email = $_POST["email"];

try {
$dao = new Dao();
if ($dao -> newUser($username, $password, $email)) {
$_SESSION["name"] = $username;
$dao -> redirect("index.php", "Welcome to idleg, $username!");
}
else {
$dao -> redirect("index.php", "User setup failed.");
}
}
catch (Exception $e) {
var_dump($e);
die;
}
}

?>
1 change: 1 addition & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ input[type=submit] {
color: white;
}
input[type=search],
input[type=email],
input[type=text],
input[type=password],
textarea {
Expand Down

0 comments on commit 4fa12c2

Please sign in to comment.