Skip to content

Commit

Permalink
adding more files
Browse files Browse the repository at this point in the history
  • Loading branch information
qzio committed Apr 5, 2011
1 parent d5eeb4a commit ebb8720
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 0 deletions.
20 changes: 20 additions & 0 deletions public/session.php
@@ -0,0 +1,20 @@
<?php
require dirname(__FILE__) . '/../bootstrap.php';

function on_get( $params = array() ) {
return template(basename(__FILE__));
}

function on_post( $params = array() ) {
if ($_SESSION['username'] = user_authenticate($params)) {
redirect('/success.php?flash_notice='.urlencode('successfull login'));
}
return template(basename(__FILE__), array('flash_error' => 'failed login'));
}

function on_delete() {
unset($_SESSION['username']);
redirect('/');
}

run(basename(__FILE__,'.php') );
31 changes: 31 additions & 0 deletions public/style.css
@@ -0,0 +1,31 @@
body {
background: black; color: white;
}

/** grid **/
#wrapper {
text-align: left;
width: 600px;
margin: 0 auto;
}
#stream-wrapper {
height: 320px;
border: 1px solid red;
}

.flash {
padding: 1em;
}
.notice {
border: 1px solid yellow;
}
.error {
border: 1px solid red;
}

form {
display: inline;
}
fieldset {
display: inline;
}
8 changes: 8 additions & 0 deletions public/success.php
@@ -0,0 +1,8 @@
<?php
require_once dirname(__FILE__).'/../bootstrap.php';

function on_get($params) {
return template(basename(__FILE__), $params);
}

run(basename(__FILE__,'.php'));
37 changes: 37 additions & 0 deletions public/user.php
@@ -0,0 +1,37 @@
<?php
require dirname(__FILE__).'/../bootstrap.php';

function validate($params) {
$errors = array();
if (empty($params['username'])) {
$errors['username'] = 'need to specify a username';
}
if (empty($params['email'])) {
$errors['email'] = 'need to specify a email';
}
if (strlen($params['password']) < 2) {
$errors['password'] = 'need to have a password';
}
return (empty($errors)) ? false : $errors;
}

function on_get($params = array()) {
if (isset($params['new'])) {
$params['title'] = 'create a new user!';
}

return template(basename(__FILE__), $params);
}

function on_post($params) {
$user_create = user_save($params);

$ok = array_shift($user_create);
if (!$ok) {
$params['user_errors'] = array_shift($user_create);
return template(basename(__FILE__), $params);
}
redirect('/success.php?flash_notice='.urlencode('a new user was registered'));
}

echo run(basename(__FILE__, '.php'));
5 changes: 5 additions & 0 deletions templates/error.php
@@ -0,0 +1,5 @@
<div class="error">
error!
<?php if (isset($render_me)) echo "tried to render ".h($render_me); ?>
<?php var_dump($p); ?>
</div>
36 changes: 36 additions & 0 deletions templates/layout.php
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8"/>
<link rel="stylesheet" type="text/css" href="/style.css"/>
<title></title>
</head>
<body>
<div id="wrapper">
<?php if (is_authenticated()) { ?>
<div>
Du är inloggad som <?=user_current()?>
|
<?= form_start(array('action' => '/session.php', 'method' => 'delete'))?>
<input type="submit" value="logout" />
</form>

<?php } else { ?>
<div>
<a href="/session.php">Logga in</a>
|
<a href="/user.php">registrera</a>
</div>
<?php } ?>
<?php if (isset($p['flash_notice'])) { ?>
<div class="msg notice"><?=h($p['flash_notice'])?></div>
<?php } else if (isset($p['flash_error'])) { ?>
<div class="msg error"><?=h($p['flash_error'])?></div>
<?php } ?>
<?= $p['_content']?>
<?= template('_webcam.php')?>
<address>copyleft! <?php unset($p['_content']); //var_dump($p)?></address>
</div>

</body>
</html>
7 changes: 7 additions & 0 deletions templates/session.php
@@ -0,0 +1,7 @@
<?=form_start(array('action' => '/session.php', 'method' => 'post'))?>
<fieldset>
<input type="text" name="username" />
<input type="password" name="password" />
<input type="submit" value="submit"/>
</fieldset>
</form>
2 changes: 2 additions & 0 deletions templates/success.php
@@ -0,0 +1,2 @@
<h1>IAM SUCCESS</h1>
<a href="#">DOWNLOAD THE CLIENT!</a>
6 changes: 6 additions & 0 deletions templates/user.php
@@ -0,0 +1,6 @@
<?= form_start(array('action'=>'/user.php','method' => 'post'))?>
<?php if (isset($p['user_errors'])) var_dump($p['user_errors']); ?>
<input type="text" name="username" placeholder="username" value=""/>
<input type="password" name="password" placeholder="password" value=""/>
<input type="submit" value="register!"/>
</form>

0 comments on commit ebb8720

Please sign in to comment.