/** * Displays a form for registering a user. */ public function registerAction() { // create the form $registerForm = new Application_Form_Personnel_Register(); // form has been submitted through post request if ($this->_request->isPost()) { $formData = $this->_request->getPost(); // if the form doesn't validate, pass to view and return if ($registerForm->isValid($formData)) { // create new user object $data = array(); $data["username"] = $this->getRequest()->getParam('username'); $data["password"] = Unplagged_Helper::hashString($this->getRequest()->getParam('password')); $data["email"] = $this->getRequest()->getParam('email'); $data["verificationHash"] = Unplagged_Helper::generateRandomHash(); $data["state"] = 'registered'; $user = new Application_Model_Personnel($data); // write back to persistence manager and flush it $this->_em->persist($user); $this->_em->flush(); // send registration mail Unplagged_Mailer::sendRegistrationMail($user); $this->_helper->flashMessenger->addMessage('Die Registrierung wurde erfolgreich abgeschlossen.'); $this->_helper->redirector('index', 'index'); } } // send form to view $this->view->registerForm = $registerForm; }
public function loginAction() { $auth = Zend_Auth::getInstance(); if ($auth->hasIdentity()) { $this->_helper->redirector('index', 'index'); } $loginForm = new Application_Form_Auth_Login(); $request = $this->getRequest(); if ($request->isPost()) { $formData = $this->_request->getPost(); if ($loginForm->isValid($formData)) { $username = $this->getRequest()->getParam('username'); $password = Unplagged_Helper::hashString($this->getRequest()->getParam("password")); $adapter = new Unplagged_Auth_Adapter_Doctrine($this->_em, "Application_Model_Personnel", "username", "password", $username, $password); $result = $auth->authenticate($adapter); if ($result->isValid()) { $defaultNamespace = new Zend_Session_Namespace('Default'); $defaultNamespace->user = $result->getIdentity(); $this->_helper->flashMessenger->addMessage('Sie wurden erfolgreich am System angemeldet.'); $this->_helper->redirector('index', 'index'); } else { $this->_helper->flashMessenger->addMessage('Das Login ist fehlgeschlagen.'); $this->_helper->redirector('login', 'auth'); } } } $this->view->loginForm = $loginForm; }