diff options
-rw-r--r-- | application/modules/fbgui/controllers/AuthController.php | 59 | ||||
-rw-r--r-- | application/modules/fbgui/forms/Login.php | 27 | ||||
-rw-r--r-- | application/modules/fbgui/views/scripts/auth/login.phtml | 6 |
3 files changed, 86 insertions, 6 deletions
diff --git a/application/modules/fbgui/controllers/AuthController.php b/application/modules/fbgui/controllers/AuthController.php index 16c5d7c..e9b6666 100644 --- a/application/modules/fbgui/controllers/AuthController.php +++ b/application/modules/fbgui/controllers/AuthController.php @@ -5,22 +5,73 @@ class Fbgui_AuthController extends Zend_Controller_Action public function init() { - /* Initialize action controller here */ + $this->db = Zend_Db_Table::getDefaultAdapter(); + $this->personmapper = new Application_Model_PersonMapper(); } public function indexAction() { - // action body + $this->_helper-> viewRenderer-> setNoRender(); + $this->_helper->redirector('login', 'auth'); } public function loginAction() { - // action body + if (Zend_Auth::getInstance()->hasIdentity()) { + $this->_redirect('/user/'); + } else { + if (!isset($_POST["login"])){ + $loginForm = new user_Form_Login(); + } else { + $loginForm = new user_Form_Login($_POST); + + if ($loginForm->isValid($_POST)) { + + $auth = Zend_Auth::getInstance(); + + $adapter = new Zend_Auth_Adapter_DbTable( + $this->db, + 'pbs_person', + 'email', + 'password', + 'MD5(CONCAT(?, password_salt))' + ); + + + $adapter->setIdentity($loginForm->getValue('email')); + $adapter->setCredential($loginForm->getValue('password')); + + $result = $auth->authenticate($adapter); + + // TODO: erweiterte fehlerbeschreibung des Users + + if ($result->isValid()) { + $this->personmapper = new Application_Model_PersonMapper(); + $result = $this->personmapper->findBy('email', Zend_Auth::getInstance()->getIdentity()); + $person = new Application_Model_Person($result[0]); + $person->setID($result[0]['personID']); + $date = new DateTime(); + $person->setLogindate($date->getTimestamp()); + $this->personmapper->save($person); + $this->_helper->redirector('selectmembership', 'person'); + return; + } else { + echo "Wrong Email or Password."; + } + } + } + $this->view->loginForm = $loginForm; + } } public function logoutAction() { - // action body + $this->_helper-> viewRenderer-> setNoRender(); + $auth = Zend_Auth::getInstance(); + $auth->clearIdentity(); + Zend_Session::namespaceUnset('userIDs'); + $this->_helper->redirector('login', 'auth'); + return; } diff --git a/application/modules/fbgui/forms/Login.php b/application/modules/fbgui/forms/Login.php index da9ac3a..6f50627 100644 --- a/application/modules/fbgui/forms/Login.php +++ b/application/modules/fbgui/forms/Login.php @@ -5,7 +5,32 @@ class fbgui_Form_Login extends Zend_Form public function init() { - /* Form Elements & Other Definitions Here ... */ + $this->setName("Login"); + $this->setMethod('post'); + + $this->addElement('text', 'email', array( + 'filters' => array('StringTrim', 'StringToLower'), + 'validators' => array( + array('StringLength', false, array(0, 50)), + ), + 'required' => true, + 'label' => 'E-Mail:', + )); + + $this->addElement('password', 'password', array( + 'filters' => array('StringTrim'), + 'validators' => array( + array('StringLength', false, array(0, 50)), + ), + 'required' => true, + 'label' => 'Password:', + )); + + $this->addElement('submit', 'login', array( + 'required' => false, + 'ignore' => true, + 'label' => 'Login', + )); } diff --git a/application/modules/fbgui/views/scripts/auth/login.phtml b/application/modules/fbgui/views/scripts/auth/login.phtml index 354ce53..d68d2af 100644 --- a/application/modules/fbgui/views/scripts/auth/login.phtml +++ b/application/modules/fbgui/views/scripts/auth/login.phtml @@ -1 +1,5 @@ -<br /><br /><center>View script for controller <b>Auth</b> and script/action name <b>login</b></center>
\ No newline at end of file +<?php +$this->loginForm->setAction($this->url()); +echo $this->loginForm; +?> +<div><button onclick="location.href='/user/auth/recoverpassword'">Recover Password</button></div>
\ No newline at end of file |