Created
February 1, 2010 13:47
-
-
Save kirkegaard/291696 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Planner_AuthController extends Zend_Controller_Action { | |
protected $_flashMessenger = null; | |
protected $_form = null; | |
public function getForm() { | |
if(null === $this->_form) { | |
$this->_form = new Planner_Form_Login(); | |
} | |
return $this->_form; | |
} | |
public function init() { | |
$this->_flashMessenger = $this->_helper->getHelper('FlashMessenger'); | |
} | |
public function indexAction() { | |
$this->_forward('login'); | |
} | |
public function loginAction() { | |
$this->view->form = $this->getForm(); | |
$this->view->messages = implode(', ', $this->_flashMessenger->getMessages()); | |
} | |
public function processAction() { | |
$form = $this->getForm(); | |
if($this->getRequest()->isPost()) { | |
if($form->isValid($this->getRequest()->getPost())) { | |
$values = $this->_form->getValues(); | |
$adapter = new App_Auth_Adapter_Doctrine('Planner_Model_User', 'email', 'password', 'sha256'); | |
$adapter->setIdentity($values['username']); | |
$adapter->setCredential($values['password']); | |
$result = Zend_Auth::getInstance()->authenticate($adapter); | |
if(!$result->isValid()) { | |
if(is_array($result->getMessages())) { | |
foreach($result->getMessages() as $message) { | |
$this->_flashMessenger->addMessage($message); | |
} | |
} | |
} else { | |
$this->_redirect('/'); | |
} | |
} | |
} | |
$this->_redirect('auth/login'); | |
} | |
public function logoutAction() { | |
Zend_Auth::getInstance()->clearIdentity(); | |
$this->_redirect('/'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment