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



                                                   
 
                                 
     
                                                 
                        
                                             
                                                              
                        


                                                                        


                                                                 






                                                                 

                                

                                                                                  





                                                                                                             
                                                 

                                                                                        





                                                                                                        
 
                                            
     









































                                                                                              
 





 
<?php

class AuthController extends Zend_Controller_Action
{

    public function loginAction()
    {
        $db = Zend_Db_Table::getDefaultAdapter();
                        
 		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(
		            $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
				//	siehe http://framework.zend.com/manual/en/zend.auth.introduction.html

		        if ($result->isValid()) {
		            #$this->_helper->FlashMessenger('Erfolgreich angemeldet');	
					$this->_redirect('/');
		            return;
		        } else {
					//$this->_helper->FlashMessenger('E-Mail oder Passwort falsch');
				} 
		    }
		}

        $this->view->loginForm = $loginForm;
    }

    public function registerAction()
    {
        $db = Zend_Db_Table::getDefaultAdapter();
                        
     		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);
    		        if ($person != null) {
    		            echo "Erfolgreich registriert";
    #		            var_dump($person);
    					//$this->_redirect('/auth/login');
    		            return;
    		        } else {
    					echo "Die angegebene Email-Adresse existiert bereits";
    				} 
    		    }
    		}
    
            $this->view->registerForm = $registerForm;
    }

    public function logoutAction()
    {
        // action body
    }

    public function recoverPasswordAction()
    {
        // action body
    }

    public function deleteAccountAction()
    {
        // action body
    }


}