public function registerAction() { if ($this->getAuthService()->hasIdentity()) { return $this->redirect()->toRoute('edpuser'); } $request = $this->getRequest(); $form = $this->getRegisterForm(); if ($request->isPost()) { if (false === $form->isValid($request->post()->toArray())) { $this->flashMessenger()->setNamespace('edpuser-register-form')->addMessage($request->post()->toArray()); return $this->redirect()->toRoute('edpuser/register'); } else { $this->getUserService()->createFromForm($form); if (Module::getOption('login_after_registration')) { $result = $this->getAuthService()->add($this->getDbAuthAdapter())->authenticate($request); // Return early if an adapter returned a response if ($result instanceof Response) { return $result; } if ($this->getAuthService()->hasIdentity()) { return $this->redirect()->toRoute('edpuser'); } } return $this->redirect()->toRoute('edpuser/login'); } } return array('registerForm' => $form); }
public function findById($id) { $db = $this->getReadAdapter(); $sql = $db->select()->from($this->getTableName())->where('user_id = ?', $id); $this->events()->trigger(__FUNCTION__, $this, array('query' => $sql)); $row = $db->fetchRow($sql); $userModelClass = Module::getOption('user_model_class'); return $userModelClass::fromArray($row); }
public function get($userId, $metaKey) { $db = $this->getReadAdapter(); $sql = $db->select()->from($this->getTableName())->where('user_id = ?', $userId)->where('meta_key = ?', $metaKey); $this->events()->trigger(__FUNCTION__ . '.pre', $this, array('query' => $sql)); $row = $db->fetchRow($sql); $userMetaModelClass = Module::getOption('usermeta_model_class'); $userMeta = $userMetaModelClass::fromArray($row); $this->events()->trigger(__FUNCTION__ . '.post', $this, array('user' => $userId, 'row' => $row)); return $userMeta; }
public function init() { $this->setMethod('post')->loadDefaultDecorators()->setDecorators(array('FormErrors') + $this->getDecorators()); $this->addElement('text', 'email', array('filters' => array('StringTrim'), 'validators' => array('EmailAddress'), 'required' => true, 'label' => 'Email')); if (Module::getOption('enable_username')) { $emailElement = $this->getElement('email'); $emailElement->removeValidator('EmailAddress')->setLabel('Email or Username'); // @TODO: make translation-friendly } $this->addElement('password', 'password', array('filters' => array('StringTrim'), 'validators' => array(array('StringLength', true, array(6, 999))), 'required' => true, 'label' => 'Password')); $this->addElement('hash', 'csrf', array('ignore' => true, 'decorators' => array('ViewHelper'))); $this->addElement('submit', 'login', array('ignore' => true, 'label' => 'Sign In')); $this->events()->trigger('init', $this); }
public function initLate() { parent::initLate(); $this->removeElement('userId'); if (!Module::getOption('enable_username')) { $this->removeElement('username'); } if (!Module::getOption('enable_display_name')) { $this->removeElement('display_name'); } if (Module::getOption('registration_form_captcha')) { $this->addElement('captcha', 'captcha', array('label' => 'Please enter the 5 letters displayed below:', 'required' => true, 'captcha' => array('captcha' => 'Figlet', 'wordLen' => 5, 'timeout' => 300), 'order' => 500)); } $this->getElement('submit')->setLabel('Register'); }
protected function getNewSalt() { $algorithm = strtolower(Module::getOption('password_hash_algorithm')); switch ($algorithm) { case 'blowfish': $cost = Module::getOption('blowfish_cost'); break; case 'sha512': $cost = Module::getOption('sha512_rounds'); break; case 'sha256': $cost = Module::getOption('sha256_rounds'); break; default: throw new \Exception(sprintf('Unsupported hashing algorithm: %s', $algorithm)); break; } return Password::getSalt($algorithm, (int) $cost); }
public function getUserMetaRepository() { $class = Module::getOption('usermeta_model_class'); return $this->getEntityManager()->getRepository($class); }