summaryrefslogtreecommitdiffstats
path: root/application
diff options
context:
space:
mode:
authorBjörn Geiger2011-03-21 10:06:49 +0100
committerBjörn Geiger2011-03-21 10:06:49 +0100
commite4d3c4db0929770ebf70fd0d943821c5ca128519 (patch)
treea4fe4dd820d6fa705ff26460aa9ecdcf2efc6418 /application
parentidee mit untergruppen herausfinden (diff)
downloadpbs2-e4d3c4db0929770ebf70fd0d943821c5ca128519.tar.gz
pbs2-e4d3c4db0929770ebf70fd0d943821c5ca128519.tar.xz
pbs2-e4d3c4db0929770ebf70fd0d943821c5ca128519.zip
Login in User Module
Diffstat (limited to 'application')
-rw-r--r--application/modules/user/controllers/AuthController.php196
-rw-r--r--application/modules/user/forms/Login.php27
-rw-r--r--application/modules/user/forms/RecoverPassword.php28
-rw-r--r--application/modules/user/forms/Register.php105
-rw-r--r--application/modules/user/views/scripts/auth/login.phtml5
-rw-r--r--application/modules/user/views/scripts/auth/recoverpassword.phtml4
-rw-r--r--application/modules/user/views/scripts/auth/register.phtml4
7 files changed, 347 insertions, 22 deletions
diff --git a/application/modules/user/controllers/AuthController.php b/application/modules/user/controllers/AuthController.php
index 80a411d..ff5893f 100644
--- a/application/modules/user/controllers/AuthController.php
+++ b/application/modules/user/controllers/AuthController.php
@@ -3,25 +3,179 @@
class User_AuthController extends Zend_Controller_Action
{
- public function init()
- {
- /* Initialize action controller here */
- }
-
- public function indexAction()
- {
- // action body
- $membershipID = $this->_request->getParam('membershipID');
- if($membershipID == ''){
- $_SESSION['membershipID'] = 1;
- }
- else{
- $_SESSION['membershipID'] = $membershipID;
- }
- $pbsNotifier = new Pbs_Notifier();
- echo $pbsNotifier->notify("membershipID is set to ".$_SESSION['membershipID'],'ok');
- }
-
-
-}
+ protected $personmapper = null;
+ private $db = null;
+
+ public function init()
+ {
+ $this->db = Zend_Db_Table::getDefaultAdapter();
+ $this->personmapper = new Application_Model_PersonMapper();
+ }
+
+ public function indexAction()
+ {
+ // action body
+ $membershipID = $this->_request->getParam('membershipID');
+ if($membershipID == ''){
+ $_SESSION['membershipID'] = 1;
+ }
+ else{
+ $_SESSION['membershipID'] = $membershipID;
+ }
+ $pbsNotifier = new Pbs_Notifier();
+ echo $pbsNotifier->notify("membershipID is set to ".$_SESSION['membershipID'],'ok');
+ }
+
+ public function loginAction()
+ {
+ 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->_redirect('/user/');
+ return;
+ } else {
+ echo "Wrong Email or Password.";
+ }
+ }
+ }
+ $this->view->loginForm = $loginForm;
+ }
+ }
+
+ public function logoutAction()
+ {
+ $this->_helper-> viewRenderer-> setNoRender();
+ $auth = Zend_Auth::getInstance();
+ $auth->clearIdentity();
+ $this->_helper->redirector('login', 'auth');
+ return;
+ }
+
+ public function registerAction()
+ {
+ if (Zend_Auth::getInstance()->hasIdentity()) {
+ print_a('Already logged in.');
+ } else {
+ if (!isset($_POST["register"])){
+ $registerForm = new user_Form_Register();
+ } else {
+ $registerForm = new user_Form_Register($_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=\""."/dev/auth/login"."\">Login</a>";
+ $this->_helper->redirector('login', 'auth');
+ return;
+ }
+ }
+ $this->view->registerForm = $registerForm;
+ }
+ }
+
+ public function deleteAction()
+ {
+ $this->_helper-> viewRenderer-> setNoRender();
+ $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');
+ return;
+ }
+ }
+
+ public function recoverpasswordAction()
+ {
+ if (!isset($_POST["recoverPassword"])){
+ $recoverPasswordForm = new user_Form_RecoverPassword();
+ } else {
+ $recoverPasswordForm = new user_Form_RecoverPassword($_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();
+ }
+ */
+ }
+ $this->view->recoverPasswordForm = $recoverPasswordForm;
+ }
+} \ No newline at end of file
diff --git a/application/modules/user/forms/Login.php b/application/modules/user/forms/Login.php
index 58c5cc9..342e0b2 100644
--- a/application/modules/user/forms/Login.php
+++ b/application/modules/user/forms/Login.php
@@ -5,7 +5,32 @@ class user_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/user/forms/RecoverPassword.php b/application/modules/user/forms/RecoverPassword.php
new file mode 100644
index 0000000..90feb87
--- /dev/null
+++ b/application/modules/user/forms/RecoverPassword.php
@@ -0,0 +1,28 @@
+<?php
+
+class user_Form_RecoverPassword extends Zend_Form
+{
+
+ public function init()
+ {
+ $this->setName("RecoverPassword");
+ $this->setMethod('post');
+
+ $this->addElement('text', 'email', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 30)),
+ ),
+ 'required' => true,
+ 'label' => 'Email:',
+ ));
+ $this->addElement('submit', 'recoverPassword', array(
+ 'required' => false,
+ 'ignore' => true,
+ 'label' => 'Recover Password',
+ ));
+ }
+
+
+}
+
diff --git a/application/modules/user/forms/Register.php b/application/modules/user/forms/Register.php
new file mode 100644
index 0000000..9c2a42d
--- /dev/null
+++ b/application/modules/user/forms/Register.php
@@ -0,0 +1,105 @@
+<?php
+
+class user_Form_Register extends Zend_Form
+{
+
+ public function init()
+ {
+ $this->setName("Register");
+ $this->setMethod('post');
+
+ $this->addElement('text', 'title', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 50)),
+ ),
+ 'required' => true,
+ 'label' => 'Title:',
+ ));
+
+
+ $this->addElement('text', 'name', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 50)),
+ ),
+ 'required' => true,
+ 'label' => 'Name:',
+ ));
+
+ $this->addElement('text', 'firstname', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 50)),
+ ),
+ 'required' => true,
+ 'label' => 'Firstname:',
+ ));
+
+ $this->addElement('text', 'street', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 50)),
+ ),
+ 'required' => true,
+ 'label' => 'Street:',
+ ));
+
+ $this->addElement('text', 'housenumber', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 50)),
+ ),
+ 'required' => true,
+ 'label' => 'Housenumber:',
+ ));
+
+ $this->addElement('text', 'city', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 50)),
+ ),
+ 'required' => true,
+ 'label' => 'City:',
+ ));
+
+ $this->addElement('text', 'postalcode', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 50)),
+ ),
+ 'required' => true,
+ 'label' => 'Postalcode:',
+ ));
+
+ $this->addElement('text', 'email', array(
+ 'filters' => array('StringTrim', 'StringToLower'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 50)),
+ ),
+ 'required' => true,
+ 'label' => 'Email:',
+ ));
+
+ $this->addElement('password', 'password', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 50)),
+ ),
+ 'required' => true,
+ 'label' => 'Password:',
+ ));
+
+ $this->addElement('submit', 'register', array(
+ 'required' => false,
+ 'ignore' => true,
+ 'label' => 'Register',
+ ));
+
+
+ }
+
+
+
+}
+
diff --git a/application/modules/user/views/scripts/auth/login.phtml b/application/modules/user/views/scripts/auth/login.phtml
new file mode 100644
index 0000000..d68d2af
--- /dev/null
+++ b/application/modules/user/views/scripts/auth/login.phtml
@@ -0,0 +1,5 @@
+<?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
diff --git a/application/modules/user/views/scripts/auth/recoverpassword.phtml b/application/modules/user/views/scripts/auth/recoverpassword.phtml
new file mode 100644
index 0000000..881e00e
--- /dev/null
+++ b/application/modules/user/views/scripts/auth/recoverpassword.phtml
@@ -0,0 +1,4 @@
+<?php
+$this->recoverPasswordForm->setAction($this->url());
+echo $this->recoverPasswordForm;
+?>
diff --git a/application/modules/user/views/scripts/auth/register.phtml b/application/modules/user/views/scripts/auth/register.phtml
new file mode 100644
index 0000000..2033b04
--- /dev/null
+++ b/application/modules/user/views/scripts/auth/register.phtml
@@ -0,0 +1,4 @@
+<?php
+$this->registerForm->setAction($this->url());
+echo $this->registerForm;
+?> \ No newline at end of file