summaryrefslogtreecommitdiffstats
path: root/application/modules/user/controllers/AuthController.php
diff options
context:
space:
mode:
Diffstat (limited to 'application/modules/user/controllers/AuthController.php')
-rw-r--r--application/modules/user/controllers/AuthController.php196
1 files changed, 175 insertions, 21 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