Archived
1
0
Fork 0
This repository has been archived on 2026-05-10. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
fiktivkod/application/modules/default/controllers/AuthController.php
2010-08-23 23:01:48 +02:00

76 lines
No EOL
2 KiB
PHP

<?php
/**
* Description of AuthController
*
*/
class AuthController extends Fiktiv_Controller_Action
{
/**
* Let the user connect with a world of
* possibilities
*/
public function loginAction()
{
// Redirect if user is logged in
if (Zend_Auth::getInstance()->hasIdentity())
$this->_redirect('/');
// Do authentication magic
$form = new Zend_Form();
$emailElement = new Zend_Form_Element_Text('email');
$emailElement->setLabel($this->translate('u:email'))
->setRequired(true)
->addValidator(new Zend_Validate_EmailAddress());
$passwordElement = new Zend_Form_Element_Password('password');
$passwordElement->setLabel($this->translate('u:password'))
->setRequired(true);
$buttonElement = new Zend_Form_Element_Submit('login');
$form->addElements(array($emailElement, $passwordElement, $buttonElement));
if ($this->_request->isPost() && $form->isValid($this->_request->getParams())) {
$users = new Users();
if ($users->login($this->_request->getParam('email'), $this->_request->getParam('password'))) {
// TODO: redirect user
} else {
// TODO: Wrong email / password
echo "Wrong email / password";
}
}
echo "You are ";
$auth = Zend_Auth::getInstance();
if ($auth->hasIdentity()) {
$user = $auth->getIdentity();
echo $user->firstName;
} else {
echo "Nobody";
}
$this->view->form = $form;
}
/**
* This baby makes sure the user is
* no longer connected to the site
*/
public function logoutAction()
{
// Destroy the magic!
$auth = Zend_Auth::getInstance();
if ($auth->hasIdentity())
$auth->clearIdentity();
$this->_redirect('/');
}
}