Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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
You can’t perform that action at this time.