@@ -27,10 +27,20 @@
if(isset($_COOKIE["pp_sid"]) && isset($_COOKIE["pp_skey"]))
$userID = GetUsersIDBySession($_COOKIE["pp_sid"],$_COOKIE["pp_skey"]);
if($userID == -1){
- echo "
Sign Up";
+ echo "
Sign Up";
echo "
Login";
} else {
- echo "
Logout";
+ $user = GetUserByID($userID);
+ echo '
+
+ '.$user[1].'
+
+
+ ';
}
?>
@@ -78,6 +88,11 @@ if (isset($_GET["page"])){
include "NewPaste.php";
} else if($_GET["page"] == "login"){
include "login.php";
+ } else if($_GET["page"] == "logout"){
+ header("Location: login.php?logout=1");
+ die();
+ } else if($_GET["page"] == "signup"){
+ include "signup.php";
} else {
$uid = $_GET["page"];
include "ViewPaste.php";
diff --git a/login.php b/login.php
index 7f8e1aa..39bd301 100644
--- a/login.php
+++ b/login.php
@@ -14,8 +14,7 @@ if(isset($_GET["logout"])){
UnsetBrowserCookies();
}
header("Location: index.php");
-}
-if(isset($_POST["type"])){
+} else if(isset($_POST["type"])) {
if($_POST["type"]=="login" && isset($_POST["user"]) && isset($_POST["pwd"])){
//Get options
$user = $_POST["user"];
@@ -28,7 +27,7 @@ if(isset($_POST["type"])){
$stmt = $conn->prepare('SELECT * FROM users WHERE user=?');
$stmt->execute(array($user));
if($result = $stmt->fetch(PDO::FETCH_ASSOC)){
- if (password_verify($pwd, $result["password"])){ //$hash = password_hash($pwd ,CRYPT_BLOWFISH);
+ if (password_verify($pwd, $result["password"])){
$skey = generate_skey();
$stmt = $conn->prepare("INSERT INTO sessions (skey, uid)
VALUES (:skey, :uid)");
@@ -51,5 +50,52 @@ if(isset($_POST["type"])){
} else echo "Fail!"; //TODO: No user or SQL fail.
$conn = null;
}
+ if($_POST["type"]=="register" && isset($_POST["user"]) && isset($_POST["pwd"])){
+ //Get options
+ $user = $_POST["user"];
+ $pwd = $_POST["pwd"];
+ $hash = password_hash($pwd ,CRYPT_BLOWFISH);
+ //Register the user
+ include "config/config.php";
+ $stmt = $conn->prepare("INSERT INTO users (user,password)
+ VALUES (:user, :pwd)");
+ $stmt->bindParam(':user', $user);
+ $stmt->bindParam(':pwd', $hash);
+ if($stmt->execute()){
+ header("Location: login");
+ } else {
+ echo "Fail!";
+ }
+ $conn = null;
+ }
+} else {
+ echo '
+
+
+
Login
+
+ ';
+ echo '
+
+ ';
+ echo '
+
+
+
+ ';
}
?>
\ No newline at end of file
diff --git a/post.php b/post.php
index f760650..59cbf90 100644
--- a/post.php
+++ b/post.php
@@ -31,26 +31,34 @@ if(isset($_POST["type"])){
/* Set paste details */
$title = "Untitled";
$text = $_POST["text"];
+ $exposure = 0;
if(isset($_POST["title"]))
$title = $_POST["title"];
+ if(isset($_POST["exposure"]) && is_numeric($_POST["exposure"]))
+ $$exposure = $_POST["exposure"];
$uid = generate_uid();
$created = time();
$expire = 0;
if(isset($_POST["expire"]) && is_numeric($_POST["expire"]))
$expire = $created + $_POST["expire"];
+ $owner = 0;
+ if(isset($_POST["asguest"]) && $_POST["asguest"]=="on")
+ $owner = 0;
+ else if(isset($_COOKIE["pp_sid"]) && isset($_COOKIE["pp_skey"])){
+ include "includes/user.php";
+ $owner = GetUsersIDBySession($_COOKIE["pp_sid"],$_COOKIE["pp_skey"]);
+ }
/* Add paste to database */
- $QuerySTR = "INSERT INTO pastes (uid,title,text,created)
- VALUES (:uid, :tit, :txt, :cre)";
- if($expire!=0)
- $QuerySTR = "INSERT INTO pastes (uid,title,text,created,expire)
- VALUES (:uid, :tit, :txt, :cre, :exp)";
+ $QuerySTR = "INSERT INTO pastes (uid,title,text,created,expire,exposure,owner)
+ VALUES (:uid, :tit, :txt, :cre, :exp, :exposure, :own)";
$stmt = $conn->prepare($QuerySTR);
- if($expire!=0)
- $stmt->bindParam(':exp', $expire);
+ $stmt->bindParam(':exp', $expire);
$stmt->bindParam(':uid', $uid);
$stmt->bindParam(':tit', $title);
$stmt->bindParam(':txt', $text);
$stmt->bindParam(':cre', $created);
+ $stmt->bindParam(':exposure', $exposure);
+ $stmt->bindParam(':own', $owner);
$stmt->execute();
$conn = null; //close connection to database
header("Location: ".$uid);
diff --git a/signup.php b/signup.php
new file mode 100644
index 0000000..29d5006
--- /dev/null
+++ b/signup.php
@@ -0,0 +1,29 @@
+
\ No newline at end of file