summaryrefslogtreecommitdiffstats
path: root/application/modules/fbgui/controllers/AuthController.php
diff options
context:
space:
mode:
Diffstat (limited to 'application/modules/fbgui/controllers/AuthController.php')
-rw-r--r--application/modules/fbgui/controllers/AuthController.php59
1 files changed, 55 insertions, 4 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;
}