Archived
1
0
Fork 0

Merge branch 'master' of git://haze.shylip.com/fiktivkod

This commit is contained in:
H Hautakoski 2010-08-24 15:45:06 +02:00
commit f796b576e3
22 changed files with 227 additions and 40 deletions

View file

@ -60,6 +60,7 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
// Set helper path
$view->addHelperPath('Fiktiv/View/Helper/', 'Fiktiv_View_Helper');
$view->app = $this->getApplication()->getOption('app');
return $view;
}

View file

@ -17,6 +17,7 @@ db.host = 127.0.0.1
db.username = fiktivkod
db.password = pw
db.dbname = fiktivkod
db.port = 4401
[development : production]

View file

@ -9,17 +9,24 @@
<pages>
<blog>
<label>u:blog</label>
<route>default</route>
<module>blog</module>
<controller>index</controller>
<action>index</action>
<module>blog</module>
<route>default</route>
</blog>
<portfolio>
<label>u:portfolio</label>
<route>default</route>
<moudule>default</moudule>
<controller>portfolio</controller>
<action>index</action>
</portfolio>
<about>
<label>u:about</label>
<label>uw:about</label>
<route>default</route>
<module>default</module>
<controller>index</controller>
<action>about</action>
<module>default</module>
<route>default</route>
</about>
</pages>
</start>

View file

@ -1,4 +1,17 @@
home = home
blog = blog
about = about fiktiv
example = "This is an example of %s and %s"
example = "This is an example of %s and %s"
email = email
password = password
login = login
LOGIN_TXT = "Fill out your information below to login.<br /><p class="yellow">There is no sign up at this time.</p>"
START_TXT = "Welcome to fiktivkod.org. ...."
ABOUT_TXT = "Fiktiv (fiktivkod.org) is ... that started ..."
BLOG_TXT = "We at fiktivkod use this blog to tell our stories about happy times and maybe not so happy experience ... "
ERROR_404 = "Oops, something went wrong"
ERROR_TXT_WHAT = "The following went wrong"

View file

@ -1,4 +1,20 @@
home = start
blog = blog
about = om fiktiv
example = "Det här är ett exempel på %s och %s"
example = "Det här är ett exempel på %s och %s"
email = e-post
password = lösenord
login = logga in
LOGIN_TXT = "Ange dina uppgifter nedan för att logga in.<br /><p class="yellow">Det går inte att registrera sig just nu.</p>"
START_TXT = "Välkommen till fiktivkod.org. ...."
ABOUT_TXT = "Fiktiv (fiktivkod.org) är ... som startade ..."
BLOG_TXT = "Här på bloggen delar vi med oss av våra erfarenheter och andra dumheter ... "
ERROR_404 = "Oops, något blev fel"
ERROR_TXT_WHAT = "Följande har gått fel"
class = klass
function = funktion
line = rad

View file

@ -1,11 +0,0 @@
<?php
/**
* User model
*/
class User extends Zend_Db_Table
{
protected $_schema = 'fiktivkod';
protected $_name = 'User';
protected $_primary = 'id';
}

View file

@ -0,0 +1,42 @@
<?php
/**
* User model
*/
class Users extends Zend_Db_Table
{
protected $_schema = 'fiktivkod';
protected $_name = 'User';
protected $_primary = 'id';
/**
* Authenticate user
*
* @param string $email
* @param string $password
*/
public function login($email, $password)
{
$auth = Zend_Auth::getInstance();
// Setup auth adapter
$authAdapter = new Zend_Auth_Adapter_DbTable($this->getAdapter(), $this->_name, 'email', 'password');
// Set credentials
$authAdapter->setIdentity($email);
$authAdapter->setCredential($password);
// Authenticate
$result = $auth->authenticate($authAdapter);
// Check result
if ($result->isValid()) {
// Keep all but password and salt in session.
$storage = $auth->getStorage();
$storage->write($authAdapter->getResultRowObject(null, array('password', 'salt')));
return true;
}
return false;
}
}

View file

@ -4,14 +4,6 @@ class Blog_IndexController extends Zend_Controller_Action
{
public function indexAction()
{
$user = new User();
$users = $user->fetchAll();
foreach ($users as $u) {
echo $u->firstName."<br />";
}
}
}

View file

@ -1 +1,3 @@
Blog > Index > Index
<h1><?=$this->translate('u:blog') ?></h1>
<p><?=$this->translate('BLOG_TXT') ?></p>

View file

@ -1,10 +1,9 @@
<?php
/**
* Description of AuthController
*
*/
class AuthController extends Zend_Controller_Action
class AuthController extends Fiktiv_Controller_Action
{
/**
* Let the user connect with a world of
@ -12,7 +11,51 @@ class AuthController extends Zend_Controller_Action
*/
public function loginAction()
{
// Redirect if user is logged in
if (Zend_Auth::getInstance()->hasIdentity())
$this->_redirect('/');
// Do authentication magic
$form = new Zend_Form();
$emailElement = new Zend_Form_Element_Text('email');
$emailElement->setLabel($this->translate('u:email'))
->setRequired(true)
->addValidator(new Zend_Validate_EmailAddress());
$passwordElement = new Zend_Form_Element_Password('password');
$passwordElement->setLabel($this->translate('u:password'))
->setRequired(true);
$buttonElement = new Zend_Form_Element_Submit('login');
$form->addElements(array($emailElement, $passwordElement, $buttonElement));
if ($this->_request->isPost() && $form->isValid($this->_request->getParams())) {
$users = new Users();
if ($users->login($this->_request->getParam('email'), $this->_request->getParam('password'))) {
// TODO: redirect user
} else {
// TODO: Wrong email / password
echo "Wrong email / password";
}
}
echo "You are ";
$auth = Zend_Auth::getInstance();
if ($auth->hasIdentity()) {
$user = $auth->getIdentity();
echo $user->firstName;
} else {
echo "Nobody";
}
$this->view->form = $form;
}
/**
@ -22,6 +65,12 @@ class AuthController extends Zend_Controller_Action
public function logoutAction()
{
// Destroy the magic!
$auth = Zend_Auth::getInstance();
if ($auth->hasIdentity())
$auth->clearIdentity();
$this->_redirect('/');
}
}

View file

@ -6,9 +6,9 @@ class ErrorController extends Zend_Controller_Action
{
$this->view->args = $this->_request->getParams();
$error = $this->_request->getParam('error_handler');
$this->view->error = $this->_request->getParam('error_handler');
var_dump($error->exception->getTrace());
}
}

View file

@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?=$this->headTitle() . "\n" /* Newline for pretty source :) */ ?>
<?=$this->headMeta() . "\n" ?>
<?=$this->headMeta() . "\n" /* Newline for pretty source :) */ ?>
<link rel="stylesheet" type="text/css" href="<?=$this->baseUrl()?>/css/default.css" media="screen" />
</head>
<body>
@ -13,8 +13,8 @@
<div id="nav">
<?=$this->navigation()->menu() ?>
<span class="float-right">
<a href="<?=$this->baseUrl() ?>/sv">sv</a>
<a href="<?=$this->baseUrl() ?>/en">en</a>
<a href="<?=$this->url(array('lang' => 'sv')) ?>">sv</a>
<a href="<?=$this->url(array('lang' => 'en')) ?>">en</a>
</span>
</div>
@ -22,5 +22,10 @@
<?=$this->layout()->content ?>
<div id="footer">
<?=$this->authLink() ?>
|
<a href="http://<?=$this->app['url'] ?>"><?=$this->app['name'] ?></a> v<?=$this->app['version'] ?> © 2010
</div>
</body>
</html>

View file

@ -0,0 +1,5 @@
<h1><?=$this->translate('u:login') ?></h1>
<p><?=$this->translate('LOGIN_TXT') ?></p>
<?=$this->form ?>

View file

@ -1,5 +1,20 @@
<?php
<h1><?=$this->translate('ERROR_404') ?></h1>
var_dump($this->args);
<p>
<?=$this->translate('ERROR_TXT_WHAT') ?>: <strong><?=$this->error->exception->getMessage() ?></strong>
</p>
?>
<table>
<tr>
<th><?=$this->translate('u:class') ?></th>
<th><?=$this->translate('u:function') ?></th>
<th><?=$this->translate('u:line') ?></th>
</tr>
<?php foreach ($this->error->exception->getTrace() as $call): ?>
<tr>
<td><?=$call['class'] ?></td>
<td><?=$call['function'] ?></td>
<td><?=$call['line'] ?></td>
</tr>
<?php endforeach; ?>
</table>

View file

@ -1 +1,3 @@
About
<h1><?=$this->translate('uw:about') ?></h1>
<p><?=$this->translate('ABOUT_TXT') ?></p>

View file

@ -1,4 +1,8 @@
Do nothing!
<h1><?=ucfirst($this->app['url']) ?></h1>
<p><?=$this->translate('START_TXT') ?></p>
<p>Translated: <?=$this->translate('uw:example', 'home', 'about', true) ?></p>
<form>
<fieldset>

View file

@ -0,0 +1,14 @@
<?php
/**
* Wrapper for Zend_Controller_Action
*
* We might want to extend ZCA in the future
*/
class Fiktiv_Controller_Action extends Zend_Controller_Action
{
protected function translate()
{
$args = func_get_args();
return call_user_func_array(array($this->view, 'translate'), $args);
}
}

View file

@ -47,6 +47,12 @@ abstract class Fiktiv_Translate_Adapter extends Zend_Translate_Adapter
case 'ua':
return strtoupper($text);
break;
case 'l':
return strtolower($text[0]);
break;
case 'la':
return strtolower($text);
break;
}
}

View file

@ -0,0 +1,18 @@
<?php
class Fiktiv_View_Helper_AuthLink extends Zend_View_Helper_Abstract
{
public function authLink()
{
$auth = Zend_Auth::getInstance();
$options = array('module' => 'default', 'controller' => 'auth');
if ($auth->hasIdentity()) {
return '<a href="' . $this->view->url(array_merge($options, array('action' => 'logout'))) . '">' . $this->view->translate('u:logout') . '</a>';
}
return '<a href="' . $this->view->url(array_merge($options, array('action' => 'login'))) . '">' . $this->view->translate('u:login') . '</a>';
}
}

View file

@ -17,7 +17,7 @@ class Fiktiv_View_Helper_Translate extends Zend_View_Helper_Translate
{
$options = func_get_args();
$key = array_shift($options);
if ($options[count($options)-1] === true) {
foreach ($options as &$opt) {
$opt = parent::translate($opt);

View file

@ -0,0 +1,6 @@
<?php
/**
* Url view helper
*
* TODO: $view->url('controller', 'action', array(<args>)) if third is not array, assume "id" e.g. blog/post/id
*/