summaryrefslogblamecommitdiffstats
path: root/application/controllers/AuthController.php
blob: 8ccb25c200892df8cb3c0b8b06b9683e67333e35 (plain) (tree)
1
2
3
4
5
6
7
8
9



                                                   
                           
                          
     
                                                       
     





                                        
                                 
     


                                                                        









                                                                                
                                              














                                                                                                        
                                                                                







                                                                                   
     

                                    
     


                                                                        













                                                                                                               
                                                         










                                                                                                 
                                                                                        




                                                              











                                           
                                  
     
                                      














                                                                                     
     
   

 
 





 

 
<?php

class AuthController extends Zend_Controller_Action
{
	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,
        		            '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');
		}
        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;
    }
   


}