From: Gabriel Dunne Date: Mon, 18 Apr 2011 01:46:10 +0000 (-0700) Subject: Style and .htaccess X-Git-Tag: v0.1~81 X-Git-Url: https://git.quilime.com/?a=commitdiff_plain;h=3d5d4d1de0e25472cfe76db33a12fbba6c083ab5;p=clmpr.git Style and .htaccess --- diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..d5fd0d3 --- /dev/null +++ b/.htaccess @@ -0,0 +1,7 @@ +Options +FollowSymLinks +RewriteEngine On + +# redirect every other request to the index +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule . index.php [L] \ No newline at end of file diff --git a/bookmarklet.js b/bookmarklet.js new file mode 100644 index 0000000..9e15d0c --- /dev/null +++ b/bookmarklet.js @@ -0,0 +1,18 @@ +(function() +{ + var w = window, + b = document, + c = encodeURIComponent, + d = w.open( + 'http://clmpr.com/put.php?' + + 'location=' + c(b.location) + + '&title=' + c(b.title) + , 'clmpr_popup' + , 'left=' + (( w.screenX || w.screenLeft ) + 10) + + ',top=' + (( w.screenY || w.screenTop) + 10 ) + + ',height=420px, width=550px, resizable=1, alwaysRaised=1'); + w.setTimeout(function() { + d.focus() + } , 300) +} +)(); \ No newline at end of file diff --git a/data.php b/data.php index f95c57c..c445a27 100644 --- a/data.php +++ b/data.php @@ -1,5 +1,6 @@ prepare($sql); - $q->execute( array( $user )); - if ($q->rowCount() == 1) { - return $q->fetch(); + try { + if ($user) { + $sql = "SELECT * FROM users WHERE user = ?"; + $q = $dbh->prepare($sql); + $q->execute( array( $user )); + if ($q->rowCount() == 1) { + return $q->fetch(); + } } + throw( new PDOException(sprintf("user %s doesn't exist", $args['user']))); + } + catch (PDOException $e) { + echo $e->getMessage(); } + return false; } \ No newline at end of file diff --git a/error.php b/error.php new file mode 100644 index 0000000..a1c2b1c --- /dev/null +++ b/error.php @@ -0,0 +1,7 @@ +' . $code; + + exit; \ No newline at end of file diff --git a/get.php b/get.php index d132e30..01578d7 100644 --- a/get.php +++ b/get.php @@ -1,36 +1,50 @@ beginTransaction(); try { - if ($params['user']) { - $user = get_users($dbh, array('user' => $params['user'] )); - if ($user) { - $q = $dbh->prepare(" SELECT * FROM `clumps` JOIN users ON users.id = clumps.user_id WHERE `user_id` = ? ORDER BY date DESC "); + $q = $dbh->prepare(" SELECT * FROM clumps JOIN users ON users.id = clumps.user_id WHERE user_id = ? ORDER BY date DESC "); $q->execute( array( $user['id'] )); } - - } else + else { + throw( new PDOException(sprintf("user %s doesn't exist", $params['user']))); + } + } + else { - $q = $dbh->prepare("SELECT * FROM `clumps` JOIN users ON users.id = clumps.user_id ORDER BY date DESC"); + $q = $dbh->prepare("SELECT * FROM clumps JOIN users ON users.id = clumps.user_id ORDER BY date DESC"); $q->execute(); } } catch(PDOException $e) { echo $e->getMessage(); + exit; } + include 'head.html'; + echo ''; \ No newline at end of file diff --git a/head.html b/head.html new file mode 100644 index 0000000..174073a --- /dev/null +++ b/head.html @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/index.php b/index.php index fbc682d..e4c0d05 100644 --- a/index.php +++ b/index.php @@ -1,12 +1,49 @@ - - + $dbh = get_db_connection(); + $dbh->beginTransaction(); + + $switch = explode("/", $_SERVER['SCRIPT_URL']); + + switch($section = $switch[1]) + { + case 'get' : + include 'get.php'; + exit; + + case 'put' : + exit; + + default : + if ($section != '') { + $user = get_users($dbh, array( 'user' => $section )); + if ( isset($user['user']) ) { + $get = function( $user ) { + $_GET['user'] = $user; + include 'get.php'; + exit; + }; + $get( $user['user'] ); + } else { + // else 404 + $_GET['error'] = '404'; + include 'error.php'; + exit; + } + } + } + + $dbh = null; + + +?> + + clmpr - + @@ -18,21 +55,8 @@

bookmarklet: -clmpr \ No newline at end of file + +
++ diff --git a/put.php b/put.php index b39ddc1..cb7753d 100644 --- a/put.php +++ b/put.php @@ -24,6 +24,12 @@ echo "clumped.

"; echo 'ok'; + + } else { + + include 'head.html'; + include 'signin.php'; + } exit; } diff --git a/signin.php b/signin.php index c2bd50a..4243dbb 100644 --- a/signin.php +++ b/signin.php @@ -16,23 +16,20 @@ echo json_encode(array('mssg' => 'logged out')); exit; } - $dbh = get_db_connection(); $dbh->beginTransaction(); $sql = "SELECT * FROM `clmpr`.`users` WHERE `user` = ? AND `pass` = PASSWORD(?)"; $q = $dbh->prepare($sql); $q->execute( array( $params['user'], $params['pass'] )); - if ($q->rowCount() == 1) { $res = $q->fetch(); $_SESSION['user'] = array( 'user' => $res['user'], 'id' => $res['id'] ); - echo json_encode(array('success'=>true, 'mssg' => 'welcome, ' . $params['user'])); + echo json_encode(array('success'=>true, 'res' => $res)); } else { $_SESSION['user'] = null; echo json_encode(array('error'=>true, 'mssg' => 'invalid login')); } - $dbh = null; exit; } @@ -40,7 +37,7 @@ } catch(PDOException $e) { - echo json_encode(array('success' => true, 'mssg' => $e->getMessage() )); + echo json_encode(array('error' => true, 'mssg' => $e->getMessage() )); } ?> @@ -52,14 +49,15 @@ var pass = $('#npass').val(); $('#register').text("creating user..."); $.post('signup.php', { user : user, pass : pass }, function(result) { - $('#register').html(result.mssg); + if (result.success = 'true') { + window.location.reload(); + } }, 'json'); return false; } $('#signin_form').submit(function() { - alert('Handler for .submit() called.'); return false; }); function onSignIn() @@ -68,7 +66,7 @@ var pass = $('#pass').val(); $('#signin').text("signing in..."); $.post('signin.php', { user : user, pass : pass }, function(result) { - $('#signin').html(result.mssg); + window.location.reload(); }, 'json'); } @@ -82,17 +80,15 @@ return false; } -

- -

- hi,
+ hi, +
logout @@ -107,6 +103,8 @@
+ +

@@ -120,4 +118,6 @@ + +

diff --git a/signup.php b/signup.php index 3beb5ea..b9eb442 100644 --- a/signup.php +++ b/signup.php @@ -19,14 +19,22 @@ $count = $q->execute( array( ':user' => $params['user'], ':pass' => $params['pass'] )); if ($count == 1) { - echo json_encode(array('success' => true, 'mssg' => 'welcome, ' . $params['user'] . '. your password is ' . $params['pass'] . '' )); + // login newly registered user + $sql = "SELECT * FROM `clmpr`.`users` WHERE `user` = ? AND `pass` = PASSWORD(?)"; + $q = $dbh->prepare($sql); + $q->execute( array( $params['user'], $params['pass'] )); + if ($q->rowCount() == 1) { + $res = $q->fetch(); + $_SESSION['user'] = array( 'user' => $res['user'], 'id' => $res['id'] ); + echo json_encode(array('success'=>true, 'res' => $res)); + } else { + $_SESSION['user'] = null; + echo json_encode(array('error'=>true, 'mssg' => 'invalid login')); + } } else { echo json_encode(array('exists' => true, 'mssg' => 'user already exists' )); } - $dbh = null; - - } } diff --git a/style.css b/style.css new file mode 100644 index 0000000..51baa87 --- /dev/null +++ b/style.css @@ -0,0 +1,5 @@ +body { + font-family: times; + font-size:14px; + line-height:1.3em; +} \ No newline at end of file