* @package PHPCI * @subpackage Web */ class SessionController extends \PHPCI\Controller { public function init() { $this->response->disableLayout(); $this->_userStore = b8\Store\Factory::getStore('User'); } /** * Handles user login (form and processing) */ public function login() { if ($this->request->getMethod() == 'POST') { $user = $this->_userStore->getByEmail($this->getParam('email')); if ($user && password_verify($this->getParam('password', ''), $user->getHash())) { $_SESSION['user_id'] = $user->getId(); header('Location: ' . PHPCI_URL); die; } } $form = new b8\Form(); $form->setMethod('POST'); $form->setAction('/session/login'); $email = new b8\Form\Element\Email('email'); $email->setLabel('Email Address'); $email->setRequired(true); $email->setClass('span3'); $form->addField($email); $pwd = new b8\Form\Element\Password('password'); $pwd->setLabel('Password'); $pwd->setRequired(true); $pwd->setClass('span3'); $form->addField($pwd); $pwd = new b8\Form\Element\Submit(); $pwd->setValue('Login »'); $pwd->setClass('btn-success'); $form->addField($pwd); $this->view->form = $form->render(); return $this->view->render(); } /** * Handles user logout. */ public function logout() { $_SESSION = array(); session_destroy(); header('Location: ' . PHPCI_URL); die; } }