summaryrefslogtreecommitdiffstats
path: root/application/controllers
diff options
context:
space:
mode:
authorBjörn Geiger2011-03-10 22:10:05 +0100
committerBjörn Geiger2011-03-10 22:10:05 +0100
commit7be4355001156faed62c71492234cba2c5bf96b4 (patch)
tree55bb96227ee354cc0c6d6788dc45020bd43d8bba /application/controllers
parentMerge branch 'master' of ssh://git.openslx.org/lsfks/master-teamprojekt/pbs2 (diff)
downloadpbs2-7be4355001156faed62c71492234cba2c5bf96b4.tar.gz
pbs2-7be4355001156faed62c71492234cba2c5bf96b4.tar.xz
pbs2-7be4355001156faed62c71492234cba2c5bf96b4.zip
Benutzervewaltung, Gruppenverwaltung, Membershipverwaltung und noch leerer RoleController
Diffstat (limited to 'application/controllers')
-rw-r--r--application/controllers/AuthController.php282
-rw-r--r--application/controllers/GroupController.php238
-rw-r--r--application/controllers/PersonController.php157
-rw-r--r--application/controllers/RoleController.php60
4 files changed, 597 insertions, 140 deletions
diff --git a/application/controllers/AuthController.php b/application/controllers/AuthController.php
index 8ccb25c..097417b 100644
--- a/application/controllers/AuthController.php
+++ b/application/controllers/AuthController.php
@@ -2,136 +2,168 @@
class AuthController extends Zend_Controller_Action
{
+ protected $personmapper;
private $db = null;
- public function init()
- {
- $this->db = Zend_Db_Table::getDefaultAdapter();
- }
-
- public function indexAction()
- {
- $this->_redirect('/auth/login');
- }
-
- public function loginAction()
- {
- if (Zend_Auth::getInstance()->hasIdentity()) {
- print_a('bereits angemeldet');
- }
- if (!isset($_POST["login"])){
- $loginForm = new Application_Form_AuthLogin();
- } else {
- $loginForm = new Application_Form_AuthLogin($_POST);
-
- if ($loginForm->isValid($_POST)) {
-
- $auth = Zend_Auth::getInstance();
-
- $adapter = new Zend_Auth_Adapter_DbTable(
- $this->db,
+
+ public function init()
+ {
+ $this->db = Zend_Db_Table::getDefaultAdapter();
+ $this->personmapper = new Application_Model_PersonMapper();
+ }
+
+ public function indexAction()
+ {
+ $this->_helper->redirector('login', 'auth');
+ }
+
+ public function loginAction()
+ {
+ if (Zend_Auth::getInstance()->hasIdentity()) {
+ print_a('Already logged in.');
+ } else {
+ if (!isset($_POST["login"])){
+ $loginForm = new Application_Form_AuthLogin();
+ } else {
+ $loginForm = new Application_Form_AuthLogin($_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->_redirect('/auth/login');
- return;
- } else {
- echo "Falsche Email oder Passwort";
- }
- }
- }
-
- $this->view->loginForm = $loginForm;
- }
-
- public function registerAction()
- {
- if (Zend_Auth::getInstance()->hasIdentity()) {
- print_a('bereits angemeldet');
+
+
+ $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->_redirect('/');
+ return;
+ } else {
+ echo "Wrong Email or Password.";
+ }
+ }
+ }
+
+ $this->view->loginForm = $loginForm;
+ }
+ }
+
+ public function registerAction()
+ {
+ if (Zend_Auth::getInstance()->hasIdentity()) {
+ print_a('Already logged in.');
+ } else {
+ if (!isset($_POST["register"])){
+ $registerForm = new Application_Form_AuthRegister();
+ } else {
+ $registerForm = new Application_Form_AuthRegister($_POST);
+
+ if ($registerForm->isValid($_POST)) {
+
+ $person = new Application_Model_Person($_POST);
+ $this->personmapper = new Application_Model_PersonMapper();
+
+ $date = new DateTime();
+ $person->setRegisterdate($date->getTimestamp());
+ $person->setPasswordSalt(MD5($date->getTimestamp()));
+ $person->setPassword(MD5($person->getPassword() . $person->getPasswordSalt()));
+ print_a($person);
+ try {
+ $this->personmapper->save($person);
+ }catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ echo "Email Address already existing..";
+ return;
+ }
+ echo "Successfully registered. <br/>";
+ echo "Continue to Login: <a href=\""."/auth/login"."\">Login</a>";
+ $this->_helper->redirector('login', 'auth');
+ return;
+ }
+ }
+
+ $this->view->registerForm = $registerForm;
+ }
+ }
+
+ public function logoutAction()
+ {
+ $auth = Zend_Auth::getInstance();
+ $auth->clearIdentity();
+ $this->_helper->redirector('login', 'auth');
+ }
+
+ public function recoverpasswordAction()
+ {
+ if (!isset($_POST["recoverPassword"])){
+ $recoverPasswordForm = new Application_Form_AuthRecoverPassword();
+ } else {
+ $recoverPasswordForm = new Application_Form_AuthRecoverPassword($_POST);
+ # Wiederherstellung funktioniert noch nicht!!!
+ /*if ($recoverPasswordForm->isValid($_POST)) {
+ $recoverPasswordForm->getView()->url();
+ $person = new Application_Model_Person($_POST);
+ $this->personmapper = new Application_Model_PersonMapper();
+
+ $result = $this->personmapper->findBy('email', $_POST['email']);
+ $email = $result[0]['email'];
+ $name = $result[0]['firstname'] . ' ' . $result[0]['name'];
+ $url = $this->getRequest()->getScheme() . '://' . $this->getRequest()->getHttpHost() . $this->view->url();
+ $recoverid = $this->random(100);
+ $mailbody = 'Um das Passwort zu ändern klicken Sie auf folgenden Link<br /><br /><a href="'. $url . '/auth/recoverpassword/?recoverid='. $recoverid . '">Passwort ändern</a>';
+ $mail = new Zend_Mail();
+ $mail->setBodyHtml($mailbody, 'utf8');
+ $mail->getBodyHtml()->getContent();
+ $mail->setFrom('admin@local', 'Admin');
+ $mail->addTo($email, $name);
+ $mail->setSubject('Password Wiederherstellung Preboot Server');
+ $mail->send();
+ }
+ */
}
- if (!isset($_POST["register"])){
- $registerForm = new Application_Form_AuthRegister();
- } else {
- $registerForm = new Application_Form_AuthRegister($_POST);
-
- if ($registerForm->isValid($_POST)) {
-
- $person = new Application_Model_Person($_POST);
- $personmapper = new Application_Model_PersonMapper();
-
- $date = new DateTime();
- $person->setRegisterdate($date->getTimestamp());
- $person->setPasswordSalt(MD5($date->getTimestamp()));
- $person->setPassword(MD5($person->getPassword() . $person->getPasswordSalt()));
- print_a($person);
- try {
- $personmapper->save($person);
- }catch(Zend_Exception $e)
- {
- echo "Caught exception: " . get_class($e) . "<br/>";
- echo "Message: " . $e->getMessage() . "<br/>";
- echo "Email Adresse bereits vorhanden.";
- return;
- }
- echo "Erfolgreich registriert. <br/>";
- echo "Weiter zum Login: <a href=\""."/auth/login"."\">Login</a>";
- $this->_redirect('/auth/login');
- return;
- }
- }
-
- $this->view->registerForm = $registerForm;
- }
-
- public function logoutAction()
- {
- // action body
- }
-
- public function recoverPasswordAction()
- {
- // action body
- }
-
- public function deleteAction()
- {
- if (!isset($_POST["delete"])){
- $deleteForm = new Application_Form_AuthDelete();
- } else {
- $deleteForm = new Application_Form_AuthDelete($_POST);
-
- if ($deleteForm->isValid($_POST)) {
-
- $person = new Application_Model_Person($_POST);
- $personmapper = new Application_Model_PersonMapper();
-
-
- $personmapper->delete($person);
- }
- }
-
- $this->view->deleteForm = $deleteForm;
- }
-
-
-
-}
-
-
-
-
-
-
-
+ $this->view->recoverPasswordForm = $recoverPasswordForm;
+ }
+
+ public function deleteAction()
+ {
+ $result = $this->personmapper->findBy('email', Zend_Auth::getInstance()->getIdentity());
+ $person = $result[0];
+ $personID = $person["personID"];
+ if (isset($personID)){
+ $this->personmapper = new Application_Model_PersonMapper();
+ $person = $this->personmapper->find($personID);
+ try {
+ $this->personmapper->delete($person);
+ }catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ return;
+ }
+ $auth = Zend_Auth::getInstance();
+ $auth->clearIdentity();
+ $this->_helper->redirector('login', 'auth');
+ }
+ }
+} \ No newline at end of file
diff --git a/application/controllers/GroupController.php b/application/controllers/GroupController.php
new file mode 100644
index 0000000..1de9207
--- /dev/null
+++ b/application/controllers/GroupController.php
@@ -0,0 +1,238 @@
+<?php
+
+class GroupController extends Zend_Controller_Action
+{
+ protected $groupMapper;
+ protected $groupGroupsMapper;
+ protected $membershipMapper;
+ protected $groupRequestMapper;
+ protected $personmapper;
+ protected $rolemapper;
+ protected $groupList;
+
+ public function init()
+ {
+ $this->groupMapper = new Application_Model_GroupMapper();
+ $this->groupGroupsMapper = new Application_Model_GroupGroupsMapper();
+ $this->membershipMapper = new Application_Model_MembershipMapper();
+ $this->groupRequestMapper = new Application_Model_GroupRequestMapper();
+ $this->personmapper = new Application_Model_PersonMapper();
+ $this->rolemapper = new Application_Model_RoleMapper();
+ $this->groupList = $this->groupMapper->fetchAll();
+ }
+
+ public function indexAction()
+ {
+ $this->view->groupList = $this->groupList;
+ }
+
+ public function addAction()
+ {
+ if (!isset($_POST["add"])){
+ $addForm = new Application_Form_GroupAdd(array('grouplist' => $this->groupList));
+ } else {
+ $addForm = new Application_Form_GroupAdd(array('grouplist' => $this->groupList),$_POST);
+
+ if ($addForm->isValid($_POST)) {
+ $group = new Application_Model_Group($_POST);
+ try {
+ $this->groupMapper->save($group);
+ } catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ return;
+ }
+ if($_POST['superordinatedGroupID'] != -1) {
+ $lastID = $this->groupMapper->getDbTable()->getDefaultAdapter()->lastInsertId();
+ $groupgroups = new Application_Model_GroupGroups();
+ $groupgroups->setParentID($_POST['superordinatedGroupID']);
+ $groupgroups->setGroupID($lastID);
+ try {
+ $this->groupGroupsMapper->save($groupgroups);
+ } catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ return;
+ }
+
+ }
+ echo "Group successfully added. <br/>";
+ }
+ }
+
+ $this->view->addForm = $addForm;
+ }
+
+ public function editAction()
+ {
+ if(!isset($_POST['groupID'])) {
+ $addForm = new Application_Form_GroupAdd(array('grouplist' => $this->groupList));
+ $this->view->addForm = $addForm;
+ return;
+ }
+ if (!isset($_POST["save"])){
+ $group = $this->groupMapper->find($_POST['groupID']);
+ $_POST['title'] = $group->getTitle();
+ $_POST['description'] = $group->getDescription();
+ $editForm = new Application_Form_GroupEdit();
+ } else {
+ $editForm = new Application_Form_GroupEdit($_POST);
+ if ($editForm->isValid($_POST)) {
+ $group = new Application_Model_Group($_POST);
+ try {
+ $this->groupMapper->save($group);
+ } catch(Zend_Exception $e)
+ {
+ echo "Email Address already existing.";
+ echo "Caught exception: " . get_class($e) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ return;
+ }
+ echo "Successfully saved. <br/>";
+ }
+ }
+
+ $this->view->editForm = $editForm;
+ }
+
+ public function showAction()
+ {
+ if($_POST['groupID']) {
+ $groupRequests = $this->groupRequestMapper->findBy('groupID', $_POST['groupID']);
+ if(isset($groupRequests)) {
+ foreach($groupRequests as $groupRequest) {
+ $person = $this->personmapper->find($groupRequest['personID']);
+ $groupRequestList[] = array(
+ 'grouprequestID' => $groupRequest['grouprequestID'],
+ 'person' => $person
+ );
+ }
+ $this->view->groupRequestList = $groupRequestList;
+ $this->view->roleList = $this->rolemapper->findBy('groupID', $_POST['groupID']);
+ }
+ $members = $this->membershipMapper->findBy('groupID', $_POST['groupID']);
+ if(isset($members)) {
+ foreach($members as $member) {
+ $person = $this->personmapper->find($member['personID']);
+ $membersList[] = array(
+ 'membershipID' => $member['membershipID'],
+ 'person' => $person
+ );
+ }
+ $this->view->memberslist = $membersList;
+ }
+ $groupgroups = $this->groupGroupsMapper->findBy('groupID', $_POST['groupID']);
+ if(is_object($groupgroups)) {
+ $parentGroup = $this->groupMapper->find($groupgroups->getParentID());
+ $this->view->$parentGroup = $parentGroup;
+ }
+ $group = $this->groupMapper->find($_POST['groupID']);
+ $this->view->group = $group;
+ }
+ }
+
+ public function linkAction()
+ {
+ if (!isset($_POST["link"])){
+ $linkForm = new Application_Form_GroupLink(array('grouplist' => $this->groupList));
+ } else {
+ $linkForm = new Application_Form_GroupLink(array('grouplist' => $this->groupList),$_POST);
+
+ if ($linkForm->isValid($_POST)) {
+ $groupgroups = new Application_Model_GroupGroups();
+ $groupgroups->setParentID($_POST['superordinatedGroupID']);
+ $groupgroups->setGroupID($_POST['groupID']);
+ try {
+ $this->groupGroupsMapper->save($groupgroups);
+ } catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ return;
+ }
+ echo "Groups successfully linked. <br/>";
+ }
+ }
+
+ $this->view->linkForm = $linkForm;
+ }
+
+ public function deleteAction()
+ {
+ if (isset($_POST["groupID"])){
+ $group = $this->groupMapper->find($_POST["groupID"]);
+ try {
+ $this->groupMapper->delete($group);
+ } catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ return;
+ }
+ echo "Group successfully deleted. <br/>";
+ }
+ }
+
+ public function grantpersonAction()
+ {
+ if(isset($_POST['grouprequestID']) && isset($_POST['roleID'])) {
+ $groupRequest = $this->groupRequestMapper->find($_POST['grouprequestID']);
+ try {
+ $this->groupRequestMapper->delete($groupRequest);
+ } catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ return;
+ }
+ $membership = new Application_Model_Membership();
+ $membership->setGroupID($groupRequest->getGroupID());
+ $membership->setPersonID($groupRequest->getPersonID());
+ $membership->setRoleID($_POST['roleID']);
+ try {
+ $this->membershipMapper->save($membership);
+ } catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ return;
+ }
+ echo "Chosen Person has been successfully added to the chosen group. <br />";
+ }
+ }
+
+ public function revokepersonAction()
+ {
+ if(isset($_POST['membershipID'])) {
+ $membership = $this->membershipMapper->find($_POST['membershipID']);
+ if(isset($membership)) {
+ try {
+ $this->membershipMapper->delete($membership);
+ } catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ return;
+ }
+ echo "Chosen Person has been successfully removed from the chosen group. <br />";
+ }
+
+ }
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/application/controllers/PersonController.php b/application/controllers/PersonController.php
index 986117a..0b6db2e 100644
--- a/application/controllers/PersonController.php
+++ b/application/controllers/PersonController.php
@@ -1,27 +1,154 @@
<?php
class PersonController extends Zend_Controller_Action
-{
-
- public function preDispatch()
- {
-
- if (!Zend_Auth::getInstance()->hasIdentity()) {
- // TODO: quick hack fixxen
- $this->_redirect('/Auth/login');
+{
+ protected $person;
+ protected $personmapper;
+ protected $membershipMapper;
+ protected $memberships;
+ protected $groupMapper;
+ protected $groups;
+ protected $groupRequestMapper;
+
+ public function init() {
+ if (Zend_Auth::getInstance()->hasIdentity()) {
+ $this->personmapper = new Application_Model_PersonMapper();
+ $result = $this->personmapper->findBy('email', Zend_Auth::getInstance()->getIdentity());
+ $this->person = new Application_Model_Person($result[0]);
+ $this->person->setID($result[0]['personID']);
+ $this->groupMapper = new Application_Model_GroupMapper();
+ $this->groupRequestMapper = new Application_Model_GroupRequestMapper();
+ $this->membershipMapper = new Application_Model_MembershipMapper();
+ $this->memberships = $this->membershipMapper->findBy("personID",$this->person->getID());
+ if(isset($this->memberships)) {
+ foreach($this->memberships as $membership) {
+ $group = $this->groupMapper->find($membership['groupID']);
+ $this->groups[] = array (
+ 'id' => $group->getID(),
+ 'title' => $group->getTitle()
+ );
+ }
+ }
+ } else {
+ $this->_helper->redirector('login', 'auth');
}
- }
+ }
+
+ public function indexAction()
+ {
+ $this->_helper->redirector('show', 'person');
+ }
- public function indexAction()
- {
- echo 'case2';
- // action body
- }
+ public function showAction()
+ {
+ $this->view->person = $this->person;
+ $this->view->groups = $this->groups;
+ }
+
+ public function editAction()
+ {
+ $this->view->person = $this->person;
+ if (!isset($_POST["save"])){
+ $editForm = new Application_Form_PersonEdit();
+ } else {
+ $editForm = new Application_Form_PersonEdit($_POST);
+ if ($editForm->isValid($_POST)) {
+ if(isset($_POST['newpassword'])) {
+ $date = new DateTime();
+ $this->person->setPassword($_POST['newpassword']);
+ $this->person->setPasswordSalt(MD5($date->getTimestamp()));
+ $this->person->setPassword(MD5($this->person->getPassword() . $this->person->getPasswordSalt()));
+ }
+ $this->person->setOptions($_POST);
+ try {
+ $this->personmapper->save($this->person);
+ } catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ echo "Email Address already existing.";
+ return;
+ }
+ echo "Successfully saved. <br/>";
+ }
+ }
-
+ $this->view->editForm = $editForm;
+ }
+ public function requestAction()
+ {
+ $this->view->person = $this->person;
+ $allgroups = $this->groupMapper->fetchAll();
+ $groupRequests = $this->groupRequestMapper->findBy('personID', $this->person->getID());
+ $count = 0;
+ foreach($allgroups as $group) {
+ foreach($groupRequests as $groupRequest) {
+ if($groupRequest['groupID'] == $group->getID()) {
+ unset($allgroups[$count]);
+ }
+ }
+ $count++;
+ }
+ if (!isset($_POST["request"])){
+ if(count($allgroups) <= 0) {
+ echo "No Groups to choose.";
+ }
+ $requestForm = new Application_Form_GroupRequest(array('grouplist' => $allgroups));
+ } else {
+ $requestForm = new Application_Form_GroupRequest(array('grouplist' => $allgroups), $_POST);
+ if ($requestForm->isValid($_POST)) {
+ $groupRequestMapper = new Application_Model_GroupRequestMapper();
+ $groupRequest = new Application_Model_GroupRequest();
+ $groupRequest->setGroupID($_POST['groupID']);
+ $date = new DateTime();
+ $groupRequest->setTime($date->getTimestamp());
+ $groupRequest->setPersonID($this->person->getID());
+ try {
+ $groupRequestMapper->save($groupRequest);
+ } catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ return;
+ }
+ echo "Successfully requested. <br />";
+ }
+ }
+ $this->view->requestForm = $requestForm;
+ }
+ public function leaveAction()
+ {
+ $this->view->person = $this->person;
+ if(isset($_POST['groupID'])) {
+ if(isset($this->memberships)) {
+ foreach($this->memberships as $membership) {
+ if($membership['groupID'] == $_POST['groupID']) {
+ $membershipObject = $this->membershipMapper->find($membership['membershipID']);
+ try {
+ $this->membershipMapper->delete($membershipObject);
+ } catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ return;
+ }
+ echo "You have been successfully removed from the chosen group. <br />";
+ }
+ }
+ }
+ }
+ }
}
+
+
+
+
+
+
+
+
diff --git a/application/controllers/RoleController.php b/application/controllers/RoleController.php
new file mode 100644
index 0000000..f5e436b
--- /dev/null
+++ b/application/controllers/RoleController.php
@@ -0,0 +1,60 @@
+<?php
+
+class RoleController extends Zend_Controller_Action
+{
+
+ public function init()
+ {
+
+ }
+
+ public function indexAction()
+ {
+
+ }
+
+ public function addAction()
+ {
+
+ }
+
+ public function editAction()
+ {
+
+ }
+
+ public function showAction()
+ {
+
+ }
+
+ public function deleteAction()
+ {
+
+ }
+
+ public function linkrightAction()
+ {
+ // action body
+ }
+
+ public function unlinkrightAction()
+ {
+ // action body
+ }
+
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+