Example #1
0
 /**
  * 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 $form
  * @param \Zepi\Turbo\Framework $framework
  * @param \Zepi\Turbo\Request\RequestAbstract $request
  * @param \Zepi\Turbo\Response\Response $response
  * @return string|boolean
  */
 protected function sendRequest(Form $form, Framework $framework, RequestAbstract $request, Response $response)
 {
     $group = $form->searchPartByKeyAndType('user-data');
     $username = trim($group->getPart('username')->getValue());
     $result = $this->validateData($framework, $username);
     // If the validate function returned a string there was an error in the validation.
     if ($result !== true) {
         return $result;
     }
     // Load the user
     $user = $this->userManager->getUserForUsername($username);
     // Generate an request token
     $token = uniqid(md5($user->getMetaData('email')), true);
     $user->setMetaData('passwordRequestToken', $token);
     $user->setMetaData('passwordRequestTokenLifetime', time() + 3600);
     $this->userManager->updateUser($user);
     // Send the request mail
     $requestLink = $request->getFullRoute('/generate-new-password/' . $user->getUuid() . '/' . $token . '/');
     $this->mailHelper->sendMail($user->getMetaData('email'), $this->translate('New password requested', '\\Zepi\\Web\\AccessControl'), $this->render('\\Zepi\\Web\\AccessControl\\Mail\\RequestNewPassword', array('user' => $user, 'requestLink' => $requestLink)));
     return true;
 }
Example #2
0
 /**
  * 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;
 }