From 19224a0cbb94c34a7ab52870e8d3e91bb4292e32 Mon Sep 17 00:00:00 2001 From: Fredric N Date: Mon, 23 Aug 2010 22:32:36 +0200 Subject: [PATCH 1/4] Translate updates --- application/configs/navigation.xml | 2 +- application/languages/en.ini | 11 ++++++++++- application/languages/se.ini | 11 ++++++++++- library/Fiktiv/View/Helper/Translate.php | 2 +- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/application/configs/navigation.xml b/application/configs/navigation.xml index c1a3430..b3b20c3 100644 --- a/application/configs/navigation.xml +++ b/application/configs/navigation.xml @@ -15,7 +15,7 @@ default - + index about default diff --git a/application/languages/en.ini b/application/languages/en.ini index 6bc18eb..0ffd8f4 100644 --- a/application/languages/en.ini +++ b/application/languages/en.ini @@ -1,4 +1,13 @@ home = home blog = blog about = about fiktiv -example = "This is an example of %s and %s" \ No newline at end of file +example = "This is an example of %s and %s" + +email = email +password = password +login = login +LOGIN_TXT = "Fill out your information below to login.

There is no sign up at this time.

" + +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 ... " \ No newline at end of file diff --git a/application/languages/se.ini b/application/languages/se.ini index ca7ef36..c83bee5 100644 --- a/application/languages/se.ini +++ b/application/languages/se.ini @@ -1,4 +1,13 @@ home = start blog = blog about = om fiktiv -example = "Det här är ett exempel på %s och %s" \ No newline at end of file +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.

Det går inte att registrera sig just nu.

" + +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 ... " \ No newline at end of file diff --git a/library/Fiktiv/View/Helper/Translate.php b/library/Fiktiv/View/Helper/Translate.php index a7e9de5..d015e1c 100644 --- a/library/Fiktiv/View/Helper/Translate.php +++ b/library/Fiktiv/View/Helper/Translate.php @@ -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); From 0e72e289745d3cb9927f63782d6b3d1b4f65e405 Mon Sep 17 00:00:00 2001 From: Fredric N Date: Mon, 23 Aug 2010 22:33:50 +0200 Subject: [PATCH 2/4] Begining of auth, Translate update, Url/Link update --- application/Bootstrap.php | 1 + application/configs/application.ini | 1 + application/models/User.php | 11 ----- .../blog/controllers/IndexController.php | 8 ---- .../blog/views/scripts/index/index.phtml | 4 +- .../default/controllers/AuthController.php | 47 ++++++++++++++++++- .../default/views/layout/default.phtml | 11 +++-- .../default/views/scripts/index/about.phtml | 4 +- .../default/views/scripts/index/index.phtml | 6 ++- library/Fiktiv/Translate/Adapter.php | 6 +++ 10 files changed, 72 insertions(+), 27 deletions(-) delete mode 100644 application/models/User.php diff --git a/application/Bootstrap.php b/application/Bootstrap.php index ad678f9..c3e1223 100644 --- a/application/Bootstrap.php +++ b/application/Bootstrap.php @@ -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; } diff --git a/application/configs/application.ini b/application/configs/application.ini index 06a3b61..bdc176f 100644 --- a/application/configs/application.ini +++ b/application/configs/application.ini @@ -17,6 +17,7 @@ db.host = 127.0.0.1 db.username = fiktivkod db.password = pw db.dbname = fiktivkod +db.port = 4401 [development : production] diff --git a/application/models/User.php b/application/models/User.php deleted file mode 100644 index 73e657a..0000000 --- a/application/models/User.php +++ /dev/null @@ -1,11 +0,0 @@ -fetchAll(); - - foreach ($users as $u) { - echo $u->firstName."
"; - } } } diff --git a/application/modules/blog/views/scripts/index/index.phtml b/application/modules/blog/views/scripts/index/index.phtml index 49daeac..a7881c7 100644 --- a/application/modules/blog/views/scripts/index/index.phtml +++ b/application/modules/blog/views/scripts/index/index.phtml @@ -1 +1,3 @@ -Blog > Index > Index \ No newline at end of file +

translate('u:blog') ?>

+ +

translate('BLOG_TXT') ?>

\ No newline at end of file diff --git a/application/modules/default/controllers/AuthController.php b/application/modules/default/controllers/AuthController.php index b9c8781..108fee7 100644 --- a/application/modules/default/controllers/AuthController.php +++ b/application/modules/default/controllers/AuthController.php @@ -1,10 +1,9 @@ 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 +60,11 @@ class AuthController extends Zend_Controller_Action public function logoutAction() { // Destroy the magic! + $auth = Zend_Auth::getInstance(); + + $auth->clearIdentity(); + + $this->_redirect('/'); } } \ No newline at end of file diff --git a/application/modules/default/views/layout/default.phtml b/application/modules/default/views/layout/default.phtml index 9272e86..54dc124 100644 --- a/application/modules/default/views/layout/default.phtml +++ b/application/modules/default/views/layout/default.phtml @@ -3,7 +3,7 @@ headTitle() . "\n" /* Newline for pretty source :) */ ?> - headMeta() . "\n" ?> + headMeta() . "\n" /* Newline for pretty source :) */ ?> @@ -13,8 +13,8 @@ @@ -22,5 +22,10 @@ layout()->content ?> + \ No newline at end of file diff --git a/application/modules/default/views/scripts/index/about.phtml b/application/modules/default/views/scripts/index/about.phtml index 60f8514..f635566 100644 --- a/application/modules/default/views/scripts/index/about.phtml +++ b/application/modules/default/views/scripts/index/about.phtml @@ -1 +1,3 @@ -About \ No newline at end of file +

translate('uw:about') ?>

+ +

translate('ABOUT_TXT') ?>

\ No newline at end of file diff --git a/application/modules/default/views/scripts/index/index.phtml b/application/modules/default/views/scripts/index/index.phtml index e13c823..4c7f57c 100644 --- a/application/modules/default/views/scripts/index/index.phtml +++ b/application/modules/default/views/scripts/index/index.phtml @@ -1,4 +1,8 @@ -Do nothing! +

app['url']) ?>

+ +

translate('START_TXT') ?>

+ +

Translated: translate('uw:example', 'home', 'about', true) ?>

diff --git a/library/Fiktiv/Translate/Adapter.php b/library/Fiktiv/Translate/Adapter.php index 7887e2f..44e0769 100644 --- a/library/Fiktiv/Translate/Adapter.php +++ b/library/Fiktiv/Translate/Adapter.php @@ -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; } } From b5d574ffd3703c298bb002ffb491f40c9de320d0 Mon Sep 17 00:00:00 2001 From: Fredric N Date: Mon, 23 Aug 2010 22:34:39 +0200 Subject: [PATCH 3/4] Missed some files in the last commit --- application/models/Users.php | 42 +++++++++++++++++++ .../default/views/scripts/auth/login.phtml | 6 +++ .../default/views/scripts/auth/logout.phtml | 0 library/Fiktiv/Controller/Action.php | 14 +++++++ library/Fiktiv/View/Helper/AuthLink.php | 18 ++++++++ library/Fiktiv/View/Helper/Url.php | 6 +++ 6 files changed, 86 insertions(+) create mode 100644 application/models/Users.php create mode 100644 application/modules/default/views/scripts/auth/login.phtml create mode 100644 application/modules/default/views/scripts/auth/logout.phtml create mode 100644 library/Fiktiv/Controller/Action.php create mode 100644 library/Fiktiv/View/Helper/AuthLink.php create mode 100644 library/Fiktiv/View/Helper/Url.php diff --git a/application/models/Users.php b/application/models/Users.php new file mode 100644 index 0000000..faeb8d5 --- /dev/null +++ b/application/models/Users.php @@ -0,0 +1,42 @@ +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; + } +} \ No newline at end of file diff --git a/application/modules/default/views/scripts/auth/login.phtml b/application/modules/default/views/scripts/auth/login.phtml new file mode 100644 index 0000000..5a9691c --- /dev/null +++ b/application/modules/default/views/scripts/auth/login.phtml @@ -0,0 +1,6 @@ +

translate('u:login') ?>

+ +

translate('LOGIN_TXT') ?>

+ +form ?> + diff --git a/application/modules/default/views/scripts/auth/logout.phtml b/application/modules/default/views/scripts/auth/logout.phtml new file mode 100644 index 0000000..e69de29 diff --git a/library/Fiktiv/Controller/Action.php b/library/Fiktiv/Controller/Action.php new file mode 100644 index 0000000..0ca0e90 --- /dev/null +++ b/library/Fiktiv/Controller/Action.php @@ -0,0 +1,14 @@ +view, 'translate'), $args); + } +} \ No newline at end of file diff --git a/library/Fiktiv/View/Helper/AuthLink.php b/library/Fiktiv/View/Helper/AuthLink.php new file mode 100644 index 0000000..c1a8fa0 --- /dev/null +++ b/library/Fiktiv/View/Helper/AuthLink.php @@ -0,0 +1,18 @@ + 'default', 'controller' => 'auth'); + + if ($auth->hasIdentity()) { + return '' . $this->view->translate('u:logout') . ''; + } + + return '' . $this->view->translate('u:login') . ''; + } + +} \ No newline at end of file diff --git a/library/Fiktiv/View/Helper/Url.php b/library/Fiktiv/View/Helper/Url.php new file mode 100644 index 0000000..38ccd0c --- /dev/null +++ b/library/Fiktiv/View/Helper/Url.php @@ -0,0 +1,6 @@ +url('controller', 'action', array()) if third is not array, assume "id" e.g. blog/post/id + */ \ No newline at end of file From 0f0ee9db2b680cb60fec3e9becf5a6dd13dd8d26 Mon Sep 17 00:00:00 2001 From: Fredric N Date: Mon, 23 Aug 2010 23:01:48 +0200 Subject: [PATCH 4/4] Error page update mostly play --- application/configs/navigation.xml | 15 +++++++++---- application/languages/en.ini | 6 +++++- application/languages/se.ini | 9 +++++++- .../default/controllers/AuthController.php | 8 ++++++- .../default/controllers/ErrorController.php | 4 ++-- .../default/views/scripts/auth/login.phtml | 3 +-- .../default/views/scripts/error/error.phtml | 21 ++++++++++++++++--- 7 files changed, 52 insertions(+), 14 deletions(-) diff --git a/application/configs/navigation.xml b/application/configs/navigation.xml index b3b20c3..e5d0554 100644 --- a/application/configs/navigation.xml +++ b/application/configs/navigation.xml @@ -9,17 +9,24 @@ + default + blog index index - blog - default + + + default + default + portfolio + index + + default + default index about - default - default diff --git a/application/languages/en.ini b/application/languages/en.ini index 0ffd8f4..b81a5aa 100644 --- a/application/languages/en.ini +++ b/application/languages/en.ini @@ -10,4 +10,8 @@ LOGIN_TXT = "Fill out your information below to login.

Th 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 ... " \ No newline at end of file +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" \ No newline at end of file diff --git a/application/languages/se.ini b/application/languages/se.ini index c83bee5..ffc2d64 100644 --- a/application/languages/se.ini +++ b/application/languages/se.ini @@ -10,4 +10,11 @@ LOGIN_TXT = "Ange dina uppgifter nedan för att logga in.

hasIdentity()) + $this->_redirect('/'); + + // Do authentication magic $form = new Zend_Form(); @@ -62,7 +67,8 @@ class AuthController extends Fiktiv_Controller_Action // Destroy the magic! $auth = Zend_Auth::getInstance(); - $auth->clearIdentity(); + if ($auth->hasIdentity()) + $auth->clearIdentity(); $this->_redirect('/'); } diff --git a/application/modules/default/controllers/ErrorController.php b/application/modules/default/controllers/ErrorController.php index e8d89ea..c66fbf1 100644 --- a/application/modules/default/controllers/ErrorController.php +++ b/application/modules/default/controllers/ErrorController.php @@ -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()); + } } \ No newline at end of file diff --git a/application/modules/default/views/scripts/auth/login.phtml b/application/modules/default/views/scripts/auth/login.phtml index 5a9691c..2e4a2ea 100644 --- a/application/modules/default/views/scripts/auth/login.phtml +++ b/application/modules/default/views/scripts/auth/login.phtml @@ -2,5 +2,4 @@

translate('LOGIN_TXT') ?>

-form ?> - +form ?> \ No newline at end of file diff --git a/application/modules/default/views/scripts/error/error.phtml b/application/modules/default/views/scripts/error/error.phtml index 852cd8c..34a0bd1 100644 --- a/application/modules/default/views/scripts/error/error.phtml +++ b/application/modules/default/views/scripts/error/error.phtml @@ -1,5 +1,20 @@ -translate('ERROR_404') ?> -var_dump($this->args); +

+ translate('ERROR_TXT_WHAT') ?>: error->exception->getMessage() ?> +

-?> \ No newline at end of file + + + + + + +error->exception->getTrace() as $call): ?> + + + + + + +
translate('u:class') ?>translate('u:function') ?>translate('u:line') ?>
\ No newline at end of file