/** * Authorizes the user with his username and password. Initializes * the user session if the user data are valid. * * @access protected * @param \Zepi\Web\UserInterface\Form\Form $registrationForm * @param \Zepi\Turbo\Framework $framework * @param \Zepi\Turbo\Request\RequestAbstract $request * @param \Zepi\Turbo\Response\Response $response * @return string|boolean */ protected function createUser(Form $registrationForm, Framework $framework, RequestAbstract $request, Response $response) { $group = $registrationForm->searchPartByKeyAndType('user-data'); $username = trim($group->getPart('username')->getValue()); $email = trim($group->getPart('email')->getValue()); $password = trim($group->getPart('password')->getValue()); $tos = $group->getPart('tos-accepted')->getValue(); $result = $this->validateData($framework, $username, $email, $password, $tos); // If the validate function returned a string there was an error in the validation. if ($result !== true) { return $result; } // Create the new user $user = new User('', '', $username, '', array('email' => $email)); $user->setNewPassword($password); // Generate an activation code $activationToken = uniqid(md5($email), true); $user->setMetaData('activationToken', $activationToken); $user = $this->userManager->addUser($user); // Add the disabled access level $this->accessControlManager->grantPermission($user->getUuid(), '\\Zepi\\Web\\AccessControl\\Entity\\User', '\\Global\\Disabled', 'Registration'); // Send the registration mail $activationLink = $request->getFullRoute('/activate/' . $user->getUuid() . '/' . $activationToken . '/'); $this->mailHelper->sendMail($user->getMetaData('email'), $this->translate('Your registration', '\\Zepi\\Web\\AccessControl'), $this->render('\\Zepi\\Web\\AccessControl\\Mail\\Registration', array('user' => $user, 'activationLink' => $activationLink))); return true; }
/** * Activates the user or returns an error message * * @access protected * @param string $uuid * @param string $activationToken * @return array */ protected function activateUser($uuid, $activationToken) { // Check the uuid if (!$this->userManager->hasUserForUuid($uuid)) { return array('result' => false, 'message' => $this->translate('Account with the given UUID does not exist.', '\\Zepi\\Web\\AccessControl')); } // Compare the activation token $user = $this->userManager->getUserForUuid($uuid); if ($user->getMetaData('activationToken') !== $activationToken) { return array('result' => false, 'message' => $this->translate('The given activation token is not valid.', '\\Zepi\\Web\\AccessControl')); } // Remove the disabled access level $this->accessControlManager->revokePermission($uuid, get_class($user), '\\Global\\Disabled'); $this->accessControlManager->grantPermission($uuid, get_class($user), '\\Global\\Active', 'Activation'); return array('result' => true, 'message' => $this->translate('Your account was activated successfully.', '\\Zepi\\Web\\AccessControl')); }
/** * Execute the installation the access control module * * @access public * @param \Zepi\Turbo\Framework $framework * @param \Zepi\Turbo\Request\CliRequest $request * @param \Zepi\Turbo\Response\Response $response */ public function execute(Framework $framework, CliRequest $request, Response $response) { // Execute the installer only if there are no users $dataRequest = new \Zepi\DataSource\Core\Entity\DataRequest(1, 0, 'name', 'ASC'); if ($this->userManager->count($dataRequest) > 0) { return; } $username = ''; while ($username === '') { $username = trim($this->cliHelper->inputText('Please enter the username for the super-admin user:'******''; while ($password === '') { $password = trim($this->cliHelper->inputText('Please enter the password for the super-admin user:'******'', '', $username, '', array()); $user->setNewPassword($password); // Save the super-admin user $user = $this->userManager->addUser($user); // Add the super-admin access level $this->accessControlManager->grantPermission($user->getUuid(), '\\Zepi\\Web\\AccessControl\\Entity\\User', '\\Global\\*', 'CLI'); }