diff options
author | Simon | 2011-03-28 15:33:38 +0200 |
---|---|---|
committer | Simon | 2011-03-28 15:33:38 +0200 |
commit | fc14745fad31d7c68fa50079e26deea17e608c2b (patch) | |
tree | e27847ff93686c42ab4e7ba5a3e78c0eab2b13ba /application/modules/fbgui | |
parent | Merge branch 'master' of openslx.org:lsfks/master-teamprojekt/pbs2 (diff) | |
parent | Membership Select im fbgui module (diff) | |
download | pbs2-fc14745fad31d7c68fa50079e26deea17e608c2b.tar.gz pbs2-fc14745fad31d7c68fa50079e26deea17e608c2b.tar.xz pbs2-fc14745fad31d7c68fa50079e26deea17e608c2b.zip |
Merge branch 'master' of openslx.org:lsfks/master-teamprojekt/pbs2
Diffstat (limited to 'application/modules/fbgui')
4 files changed, 152 insertions, 44 deletions
diff --git a/application/modules/fbgui/controllers/AuthController.php b/application/modules/fbgui/controllers/AuthController.php index e9b6666..f5c3a27 100644 --- a/application/modules/fbgui/controllers/AuthController.php +++ b/application/modules/fbgui/controllers/AuthController.php @@ -3,27 +3,27 @@ class Fbgui_AuthController extends Zend_Controller_Action { - public function init() - { + public function init() + { $this->db = Zend_Db_Table::getDefaultAdapter(); $this->personmapper = new Application_Model_PersonMapper(); - } + } - public function indexAction() - { + public function indexAction() + { $this->_helper-> viewRenderer-> setNoRender(); $this->_helper->redirector('login', 'auth'); - } + } - public function loginAction() - { + public function loginAction() + { if (Zend_Auth::getInstance()->hasIdentity()) { - $this->_redirect('/user/'); + $this->_redirect('/fbgui/'); } else { if (!isset($_POST["login"])){ - $loginForm = new user_Form_Login(); + $loginForm = new fbgui_Form_Login(); } else { - $loginForm = new user_Form_Login($_POST); + $loginForm = new fbgui_Form_Login($_POST); if ($loginForm->isValid($_POST)) { @@ -31,48 +31,107 @@ class Fbgui_AuthController extends Zend_Controller_Action $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."; - } + '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', 'auth'); + return; + } else { + echo "Wrong Email or Password."; + } } } $this->view->loginForm = $loginForm; } - } + } - public function logoutAction() - { + public function logoutAction() + { $this->_helper-> viewRenderer-> setNoRender(); $auth = Zend_Auth::getInstance(); $auth->clearIdentity(); Zend_Session::namespaceUnset('userIDs'); + Zend_Session::forgetMe(); $this->_helper->redirector('login', 'auth'); return; - } + } + + public function selectmembershipAction() + { + if (Zend_Auth::getInstance()->hasIdentity()) { + $userIDsNamespace = Zend_Session::namespaceGet('userIDs'); + if(isset($userIDsNamespace['membershipID'])) { + $this->_redirect('/fbgui/'); + } else { + $personmapper = new Application_Model_PersonMapper(); + $result = $personmapper->findBy('email', Zend_Auth::getInstance()->getIdentity()); + $person = new Application_Model_Person($result[0]); + $person->setID($result[0]['personID']); + $membershipMapper = new Application_Model_MembershipMapper(); + $memberships = $membershipMapper->findBy("personID",$person->getID()); + if(count($memberships) > 0) { + if(isset($_POST['selectmembership'])) { + $roleSession = new Zend_Session_Namespace('userIDs'); + $roleSession->membershipID = $_POST['membershipID']; + $roleSession->personID = $person->getID(); + $membership = $membershipMapper->find($_POST['membershipID']); + $roleSession->groupID = $membership->getGroupID(); + $roleSession->roleID = $membership->getRoleID(); + $this->_redirect('/fbgui/'); + return; + } else { + $groupMapper = new Application_Model_GroupMapper(); + $roleMapper = new Application_Model_RoleMapper(); + if(isset($memberships)) { + foreach($memberships as $membership) { + $group = $groupMapper->find($membership['groupID']); + $role = $roleMapper->find($membership['roleID']); + $membershipList[] = array( + 'membershipID' => $membership['membershipID'], + 'group' => $group->getTitle(), + 'role' => $role->getTitle() + ); + } + } + $membershipSelectForm = new fbgui_Form_MembershipSelect(array('membershiplist' => $membershipList)); + $this->view->membershipSelectForm = $membershipSelectForm; + } + } else { + $this->_redirect('/fbgui/'); + } + } + + } else { + $this->_helper->redirector('login', 'auth'); + } + } + + public function changemembershipAction() + { + $this->_helper-> viewRenderer-> setNoRender(); + Zend_Session::namespaceUnset('userIDs'); + $this->_helper->redirector('selectmembership', 'auth'); + return; + } } @@ -81,3 +140,7 @@ class Fbgui_AuthController extends Zend_Controller_Action + + + + diff --git a/application/modules/fbgui/forms/MembershipSelect.php b/application/modules/fbgui/forms/MembershipSelect.php new file mode 100644 index 0000000..5b21fa7 --- /dev/null +++ b/application/modules/fbgui/forms/MembershipSelect.php @@ -0,0 +1,42 @@ +<?php + +class fbgui_Form_MembershipSelect extends Zend_Form +{ + private $membershiplist; + + public function setMembershiplist($membershiplist){ + $this->membershiplist = $membershiplist; + + } + + public function getMembershiplist(){ + return $this->membershiplist; + } + + public function init() + { + $this->setName("MembershipSelect"); + $this->setMethod('post'); + + $membershipfield = $this->createElement('select','membershipID'); + $membershipfield ->setLabel('Membership:'); + + if(count($this->membershiplist)>0){ + foreach($this->membershiplist as $membership => $m){ + $membershipfield->addMultiOption($m['membershipID'], $m['group'] . ' - ' . $m['role']); + } + } + + $membershipfield->setRegisterInArrayValidator(false); + $this->addElement($membershipfield); + + $this->addElement('submit', 'selectmembership', array( + 'required' => false, + 'ignore' => true, + 'label' => 'Select Membership', + )); + } + + +} + diff --git a/application/modules/fbgui/views/scripts/auth/login.phtml b/application/modules/fbgui/views/scripts/auth/login.phtml index d68d2af..17b1c16 100644 --- a/application/modules/fbgui/views/scripts/auth/login.phtml +++ b/application/modules/fbgui/views/scripts/auth/login.phtml @@ -1,5 +1,4 @@ <?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 +?>
\ No newline at end of file diff --git a/application/modules/fbgui/views/scripts/auth/selectmembership.phtml b/application/modules/fbgui/views/scripts/auth/selectmembership.phtml new file mode 100644 index 0000000..2bfe4d6 --- /dev/null +++ b/application/modules/fbgui/views/scripts/auth/selectmembership.phtml @@ -0,0 +1,4 @@ +<?php +$this->membershipSelectForm->setAction($this->url()); +echo $this->membershipSelectForm; +?>
\ No newline at end of file |