summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.zfproject.xml7
-rw-r--r--application/Bootstrap.php1
-rw-r--r--application/configs/application.ini3
-rw-r--r--application/controllers/AuthController.php67
-rw-r--r--application/controllers/PersonController.php26
-rw-r--r--application/models/PersonMapper.php105
-rw-r--r--application/views/scripts/auth/login.phtml5
-rw-r--r--application/views/scripts/index/index.phtml52
-rw-r--r--application/views/scripts/person/index.phtml1
-rw-r--r--tests/application/controllers/PersonControllerTest.php20
10 files changed, 206 insertions, 81 deletions
diff --git a/.zfproject.xml b/.zfproject.xml
index c760b0b..ead4122 100644
--- a/.zfproject.xml
+++ b/.zfproject.xml
@@ -16,6 +16,9 @@
<actionMethod actionName="index"/>
<actionMethod actionName="login"/>
</controllerFile>
+ <controllerFile controllerName="Person">
+ <actionMethod actionName="index"/>
+ </controllerFile>
</controllersDirectory>
<formsDirectory>
<formFile formName="AuthLogin"/>
@@ -106,6 +109,9 @@
<viewControllerScriptsDirectory forControllerName="Auth">
<viewScriptFile forActionName="login"/>
</viewControllerScriptsDirectory>
+ <viewControllerScriptsDirectory forControllerName="Person">
+ <viewScriptFile forActionName="index"/>
+ </viewControllerScriptsDirectory>
</viewScriptsDirectory>
<viewHelpersDirectory/>
<viewFiltersDirectory enabled="false"/>
@@ -141,6 +147,7 @@
<testApplicationBootstrapFile filesystemName="bootstrap.php"/>
<testApplicationControllerDirectory>
<testApplicationControllerFile filesystemName="AuthControllerTest.php"/>
+ <testApplicationControllerFile filesystemName="PersonControllerTest.php"/>
</testApplicationControllerDirectory>
</testApplicationDirectory>
<testLibraryDirectory>
diff --git a/application/Bootstrap.php b/application/Bootstrap.php
index 613100c..26169dd 100644
--- a/application/Bootstrap.php
+++ b/application/Bootstrap.php
@@ -3,6 +3,5 @@
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
-
}
diff --git a/application/configs/application.ini b/application/configs/application.ini
index 5aa767b..d421af8 100644
--- a/application/configs/application.ini
+++ b/application/configs/application.ini
@@ -7,13 +7,12 @@ bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
-
-[database]
resources.db.adapter = PDO_MYSQL
resources.db.params.host = localhost
resources.db.params.username = root
resources.db.params.password = lsfks-openslx
resources.db.params.dbname = pbs
+resources.db.isDefaultTableAdapter = true
[staging : production]
diff --git a/application/controllers/AuthController.php b/application/controllers/AuthController.php
index c054437..070c2e8 100644
--- a/application/controllers/AuthController.php
+++ b/application/controllers/AuthController.php
@@ -2,45 +2,44 @@
class AuthController extends Zend_Controller_Action
{
-
public function loginAction()
{
- $db = $this->_getParam('pbs_person');
+ $db = Zend_Db_Table::getDefaultAdapter();
+
if (!isset($_POST["login"])){
- $loginForm = new Application_Form_AuthLogin();
+ $loginForm = new Application_Form_AuthLogin();
} else {
+ $loginForm = new Application_Form_AuthLogin($_POST);
+
+ if ($loginForm->isValid($_POST)) {
+ $adapter = new Zend_Auth_Adapter_DbTable(
+ $db,
+ 'pbs_person',
+ 'email',
+ 'password',
+ 'MD5(CONCAT(?, password_salt))'
+ );
+
+ $adapter->setIdentity($loginForm->getValue('email'));
+ $adapter->setCredential($loginForm->getValue('password'));
+
+ $result = $adapter->authenticate();
+
+ if ($result->isValid()) {
+ //$this->_helper->FlashMessenger('Erfolgreich angemeldet');
+ $this->_userNamespace->username = 'testt';
+
+ Zend_Debug::dump($_SESSION, $label="_SESSION nach Login: ", $echo=true);
+ Zend_Debug::dump($this->_userNamespace, $label="userNamespace: ", $echo=true);
+ $this->view->loginStatus = "Eingeloggt als " . $this->_userNamespace->username;
+ #$this->_redirect('/');
+ return;
+ } else {
+ //$this->_helper->FlashMessenger('E-Mail oder Passwort falsch');
+ }
+ }
+ }
- $loginForm = new Application_Form_AuthLogin($_POST);
-
- if ($loginForm->isValid($_POST)) {
-
- $adapter = new Zend_Auth_Adapter_DbTable(
- $db,
- 'users',
- 'username',
- 'password',
- 'MD5(CONCAT(?, password_salt))'
- );
-
- $adapter->setIdentity($loginForm->getValue('email'));
- $adapter->setCredential($loginForm->getValue('password'));
-
- $result = $auth->authenticate($adapter);
-
- if ($result->isValid()) {
- $this->_helper->FlashMessenger('Erfolgreich angemeldet');
- $this->redirect('/');
- return;
- }
-
- }
- }
$this->view->loginForm = $loginForm;
-
}
-
-
}
-
-
-
diff --git a/application/controllers/PersonController.php b/application/controllers/PersonController.php
new file mode 100644
index 0000000..9a8aea2
--- /dev/null
+++ b/application/controllers/PersonController.php
@@ -0,0 +1,26 @@
+<?php
+
+class PersonController extends Zend_Controller_Action
+{
+
+ public function init()
+ {
+
+ }
+
+ public function indexAction()
+ {
+ if (!Zend_Auth::getInstance()->hasIdentity()) {
+ echo 'case1';
+
+
+ echo "already logged in as: " . Zend_Auth::getInstance()->getIdentity();
+ #$this->_redirect($this->url(array('Auth','login')));
+ }
+ echo 'case2';
+ // action body
+ }
+
+
+}
+
diff --git a/application/models/PersonMapper.php b/application/models/PersonMapper.php
index c7894c2..632c3ee 100644
--- a/application/models/PersonMapper.php
+++ b/application/models/PersonMapper.php
@@ -2,7 +2,112 @@
class Application_Model_PersonMapper
{
+
+ protected $_dbTable;
+ public function setDbTable($dbTable)
+ {
+ if (is_string($dbTable)) {
+ $dbTable = new $dbTable();
+ }
+ if (!$dbTable instanceof Zend_Db_Table_Abstract) {
+ throw new Exception('Invalid table data gateway provided');
+ }
+
+ $this->_dbTable = $dbTable;
+
+ return $this;
+ }
+
+ public function getDbTable()
+ {
+ if (null === $this->_dbTable) {
+ $this->setDbTable('Application_Model_DbTable_Person');
+ }
+
+ return $this->_dbTable;
+ }
+
+ public function save(Application_Model_Person $person)
+ {
+
+ $data = array(
+ 'personID' => $tablenamevar->getID(),
+ 'title' => $tablenamevar->getTitle(),
+ 'name' => $tablenamevar->getName(),
+ 'firstname' => $tablenamevar->getFirstname(),
+ 'street' => $tablenamevar->getStreet(),
+ 'housenumber' => $tablenamevar->getHousenumber(),
+ 'city' => $tablenamevar->getCity(),
+ 'postalcode' => $tablenamevar->getPostalcode(),
+ 'logindate' => $tablenamevar->getLogindate(),
+ 'registerdate' => $tablenamevar->getRegisterdate(),
+ 'email' => $tablenamevar->getEmail(),
+ 'login' => $tablenamevar->getLogin(),
+ 'password' => $tablenamevar->getPassword()
+ );
+
+ if (null === ($id = $person->getID()) ) {
+ unset($data['id']);
+ $this->getDbTable()->insert($data);
+ } else {
+ $this->getDbTable()->update($data, array('id = ?' => $id));
+ }
+ }
+
+ public function find($id, Application_Model_Person $person)
+ {
+ $result = $this->getDbTable()->find($id);
+ if (0 == count($result)) {
+ return;
+ }
+
+ $row = $result->current();
+
+ $tablenamevar->setID($row->personID)
+ ->setTitle($row->title)
+ ->setName($row->name)
+ ->setFirstname($row->firstname)
+ ->setStreet($row->street)
+ ->setHousenumber($row->housenumber)
+ ->setCity($row->city)
+ ->setPostalcode($row->postalcode)
+ ->setLogindate($row->logindate)
+ ->setRegisterdate($row->registerdate)
+ ->setEmail($row->email)
+ ->setLogin($row->login)
+ ->setPassword($row->password);
+ }
+
+ public function fetchAll()
+ {
+ $resultSet = $this->getDbTable()->fetchAll();
+ $entries = array();
+ foreach ($resultSet as $row) {
+ $entry = new Application_Model_Person();
+
+ $entry->setID($row->personID)
+ ->setTitle($row->title)
+ ->setName($row->name)
+ ->setFirstname($row->firstname)
+ ->setStreet($row->street)
+ ->setHousenumber($row->housenumber)
+ ->setCity($row->city)
+ ->setPostalcode($row->postalcode)
+ ->setLogindate($row->logindate)
+ ->setRegisterdate($row->registerdate)
+ ->setEmail($row->email)
+ ->setLogin($row->login)
+ ->setPassword($row->password);
+
+ $entries[] = $entry;
+ }
+
+ return $entries;
+ }
+
+
+
}
diff --git a/application/views/scripts/auth/login.phtml b/application/views/scripts/auth/login.phtml
index c3b3a55..0618564 100644
--- a/application/views/scripts/auth/login.phtml
+++ b/application/views/scripts/auth/login.phtml
@@ -1,6 +1,9 @@
<?php
$this->loginForm->setAction($this->url());
echo $this->loginForm;
-#var_dump($this);
+
+echo "<pre>";
+print_r($_SESSION);
+echo "</pre>";
?>
diff --git a/application/views/scripts/index/index.phtml b/application/views/scripts/index/index.phtml
index 4b38f0a..b3c2b57 100644
--- a/application/views/scripts/index/index.phtml
+++ b/application/views/scripts/index/index.phtml
@@ -1,43 +1,9 @@
-<style>
- a:link,
- a:visited
- {
- color: #0398CA;
- }
-
- span#zf-name
- {
- color: #91BE3F;
- }
-
- div#welcome
- {
- color: #FFFFFF;
- background-image: url(http://framework.zend.com/images/bkg_header.jpg);
- width: 600px;
- height: 400px;
- border: 2px solid #444444;
- overflow: hidden;
- text-align: center;
- }
-
- div#more-information
- {
- background-image: url(http://framework.zend.com/images/bkg_body-bottom.gif);
- height: 100%;
- }
-</style>
-<div id="welcome">
- <h1>Welcome to the <span id="zf-name">Zend Framework!</span></h1>
-
- <h3>This is your project's main page</h3>
-
- <div id="more-information">
- <p><img src="http://framework.zend.com/images/PoweredBy_ZF_4LightBG.png" /></p>
- <p>
- Helpful Links: <br />
- <a href="http://framework.zend.com/">Zend Framework Website</a> |
- <a href="http://framework.zend.com/manual/en/">Zend Framework Manual</a>
- </p>
- </div>
-</div> \ No newline at end of file
+<?php
+echo "already logged in as: " . Zend_Auth::getInstance()->getIdentity();
+echo "<pre>";
+print_r($_SESSION);
+echo "</pre>";
+Zend_Debug::dump($_SESSION, $label="_SESSION nach Login: ", $echo=true);
+ $this->view->loginStatus = "Eingeloggt als " . $this->_userNamespace->username;
+?>
+<h1>Zend-Framework Index</h1>
diff --git a/application/views/scripts/person/index.phtml b/application/views/scripts/person/index.phtml
new file mode 100644
index 0000000..7a96e97
--- /dev/null
+++ b/application/views/scripts/person/index.phtml
@@ -0,0 +1 @@
+<br /><br /><center>View script for controller <b>Person</b> and script/action name <b>index</b></center> \ No newline at end of file
diff --git a/tests/application/controllers/PersonControllerTest.php b/tests/application/controllers/PersonControllerTest.php
new file mode 100644
index 0000000..351702e
--- /dev/null
+++ b/tests/application/controllers/PersonControllerTest.php
@@ -0,0 +1,20 @@
+<?php
+
+require_once 'PHPUnit/Framework/TestCase.php';
+
+class PersonControllerTest extends PHPUnit_Framework_TestCase
+{
+
+ public function setUp()
+ {
+ /* Setup Routine */
+ }
+
+ public function tearDown()
+ {
+ /* Tear Down Routine */
+ }
+
+
+}
+