Created
February 15, 2010 14:58
-
-
Save kirkegaard/304700 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_Rest_Controller { | |
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() { | |
if(Zend_Auth::getInstance()->hasIdentity()) { | |
$this->_redirect('/'); | |
} | |
$this->view->form = $this->getForm()->setAction('/auth/put/'); | |
$this->view->messages = implode(', ', $this->_flashMessenger->getMessages()); | |
} | |
public function getAction() {} | |
public function putAction() { | |
$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'); | |
} | |
public function postAction() {} | |
public function deleteAction() { | |
Zend_Auth::getInstance()->clearIdentity(); | |
$this->_redirect('/'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment