Permalink
Browse files

customized the readme for kiwiweb

  • Loading branch information...
1 parent 4414ee8 commit d5eeb4a8abed45ec3f3e1bdbd3344e9075a18879 @qzio qzio committed Apr 5, 2011
Showing with 71 additions and 94 deletions.
  1. +6 −94 README.md
  2. +65 −0 lib/user.php
View
100 README.md
@@ -1,98 +1,10 @@
-# Coltrane - small framework for the small hacks
+# kiwiweb - a web interface for the kiwi robot
-coltrane comes out of need for some kind of simple mvc structure for small rest-like php apps.
-Without much overhead or fancy features.
+kiwiweb uses https://github.com/qzio/coltrane
-everything in lib/ is required automatically, just drop whatever libs or modules you have there.
+ * point the document_root param of your httpd to the public/ directory
+ * make tmp/users.txt rw for the user running your httpd
-## directory structure
+## todo
- public/ # document root of the project
- | - posts.php # blog posts controller
- | - other static files, css, images etc
-
- templates/ # template files (views)
- | - posts.php
-
- lib/ # everything here is auto required by bootstrap.php
- | - helpers.php # default helpers
- | - restish.php # defines the is_get is_post is_put is_delete functions..
- | - other library, helper and model files
-
-
-# TODO
-"With rewrite" is the preffered way to go if possible, nicer urls is also a nice addition ;)
- - see rewrite rule for different http deamons at the bottom of this readme
-
-
-# some examples with comments
-
-## public/hello.php (controller)
-
- <?php
- require '../bootstrap.php';
-
- function on_before( $params = array() ) {
- // before filter
- return $params;
- }
-
- function on_get( $params = array() ) {
- $p['title'] = 'Hello World';
-
- if ( $params['name'] ) {
- $p['name'] = $params['name'];
- } else {
- $p['name'] = 'Unknown';
- }
-
- return render( basename(__FILE__), $p );
- }
-
- function on_post( $params = array() ) {
- // create a resource
-
- }
-
- function on_put($params = array() ) {
- // update a resource
- }
-
- function on_delete( $params = array() ) {
- // delete a resource
-
- }
-
- run(basename(__FILE__,'.php')); // this is the dispatcher
-
-
-## templates/hello.php (template)
-
- <h1><?=h( $p['title'] )?></h1>
- <p>
- greetings <?=h( $p['name'] )?>, or did I get your name correctly?
- </p>
-
- <?php
- /**
- * form_start with method = put will actually create a <form method="post">
- * and add a <input type="hidden" name="_method" value="put"/> in order return correct method.
- */
- ?>
- <?= form_start(array('method'=> 'get')) ?>
- <fieldset>
- <input type="text" name="name"/>
- <input type="submit"/>
- </fieldset>
- </form>
-
-## templates/layout.php (autoincluded if the first argument to template() doesn't start with '
-
- <!DOCTYPE html !>
- <html>
- <head>
- <title><?=h( $p['title'] )?></title>
- <body>
- <?= $p['_content'];?>
- </body>
- </html>
+include the image stream into templates/_webcam.php
View
@@ -0,0 +1,65 @@
+<?php
+
+function user_authenticate($params = array() ) {
+ if ( $user_data = user_file_find($params['username']) ) {
+ list($username, $salt, $encrypted_password) = $user_data;
+ if ( $encrypted_password === user_encrypt_password($params['password'], $salt)) {
+ return $username;
+ }
+ }
+ return false;
+}
+function user_encrypt_password($str, $salt) {
+ return sha1(trim($str) . $salt . cfg::secret );
+}
+
+
+function user_errors($params = array()) {
+ $errors = array();
+ if ($user_data = user_file_find($params['username'])) {
+ $errors['username'] = 'username is already taken';
+ }
+
+ return (empty($errors)) ? false : $errors;
+}
+
+function user_save( $params = array() ) {
+ if ($errors = user_errors($params)) {
+ return array(false, $errors);
+ }
+ $salt = sha1(mt_rand(0,100) . cfg::secret . 'blargh');
+ $encrypted_password = user_encrypt_password($params['password'], $salt);
+
+ if (user_file_write($params['username'], $salt, $encrypted_password)) {
+ return array(true, $params['username']);
+ }
+ return array(false, array('generic' => 'unable to save'));
+}
+
+function user_file_find($u) {
+ if ( $fp = fopen(cfg::user_file(), 'r') ) {
+ while($line = fgets($fp, 4096)) {
+ list($username, $salt, $password) = explode(':',trim($line));
+ if ($username === $u) {
+ return array($username, $salt, $password);
+ }
+ }
+ }
+ return false;
+}
+
+function user_file_write($username, $salt, $password) {
+ if ($fp = fopen(cfg::user_file(), 'a')) {
+ if ( fwrite($fp, "{$username}:{$salt}:{$password}\n") !== false ) {
+ return true;
+ }
+ }
+ return false;
+}
+
+function user_current() {
+ return (isset($_SESSION['username'])) ? $_SESSION['username'] : false;
+}
+function is_authenticated() {
+ return (user_current()) ? true : false;
+}

0 comments on commit d5eeb4a

Please sign in to comment.