public function registrationAction() { $auth = new AuthenticationService(); if ($auth->hasIdentity()) { return $this->redirect()->toRoute('home'); } // process the form $form = new RegistrationForm(); $request = $this->getRequest(); if ($this->getRequest()->isPost()) { $form->setData($request->getPost()); if ($form->isValid()) { $data = $form->getData(); if ($data['password'] == $data['password_confirm']) { /** * Check if a user with the given username or email already * exists */ $sm = $this->getServiceLocator(); $mapper = $sm->get('User\\Model\\UserMapper'); $params = array('where' => 'username = "******"'); $user = $mapper->select($params); $params = array('where' => 'email = "' . $data['email'] . '"'); $email = $mapper->select($params); if (!$user && !$email) { $user = new User($data); // Hash the password with a random salt $user->setPassword_salt(mcrypt_create_iv(64)); $user->setPassword_hash(hash('sha256', $user->getPassword_salt() . $data['password'])); $user->setActive(0); // Insert the account into the database $mapper->save($user); $params = array('where' => 'username = "******"'); $user = $mapper->select($params); if ($user) { $user = $user[0]; // prompt the user to activate the account return $this->redirect()->toRoute('registration', array('action' => 'confirm', 'id' => $user->getId())); } } else { if ($user) { print "A user with this user name already exists."; } if ($email) { print "A user with this email already exists."; } } } else { print "The password was not confirmed."; } } } return new ViewModel(array('form' => $form)); }