70 lines
No EOL
1.8 KiB
PHP
70 lines
No EOL
1.8 KiB
PHP
<?php
|
|
/**
|
|
* Description of AuthController
|
|
*
|
|
*/
|
|
class AuthController extends Fiktiv_Controller_Action
|
|
{
|
|
/**
|
|
* Let the user connect with a world of
|
|
* possibilities
|
|
*/
|
|
public function loginAction()
|
|
{
|
|
// 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();
|
|
|
|
$auth->clearIdentity();
|
|
|
|
$this->_redirect('/');
|
|
}
|
|
|
|
} |