Since: 2.6.0
Author: Henry Ruhs
Exemplo n.º 1
0
 /**
  * process
  *
  * @since 3.0.0
  *
  * @return string
  */
 public function process()
 {
     $specialFilter = new Filter\Special();
     $emailFilter = new Filter\Email();
     /* process post */
     $postArray = ['name' => $specialFilter->sanitize($this->_request->getPost('name')), 'user' => $specialFilter->sanitize($this->_request->getPost('user')), 'email' => $emailFilter->sanitize($this->_request->getPost('email')), 'task' => $this->_request->getPost('task'), 'solution' => $this->_request->getPost('solution')];
     /* handle error */
     $messageArray = $this->_validate($postArray);
     if ($messageArray) {
         return $this->_error(['message' => $messageArray]);
     }
     /* handle success */
     $passwordHash = new Hash(Config::getInstance());
     $passwordHash->init(uniqid());
     $createArray = ['name' => $postArray['name'], 'user' => $postArray['user'], 'password' => $passwordHash->getHash(), 'email' => $postArray['email'], 'language' => $this->_registry->get('language'), 'groups' => Db::forTablePrefix('groups')->where('alias', 'members')->findOne()->id, 'status' => Db::getSetting('verification') ? 0 : 1];
     $mailArray = ['name' => $postArray['name'], 'user' => $postArray['user'], 'password' => $passwordHash->getRaw(), 'email' => $postArray['email']];
     /* create */
     if (!$this->_create($createArray)) {
         return $this->_error(['message' => $this->_language->get('something_wrong')]);
     }
     /* mail */
     if (!$this->_mail($mailArray)) {
         return $this->_error(['message' => $this->_language->get('email_failed')]);
     }
     return $this->_success(['message' => Db::getSetting('verification') ? $this->_language->get('registration_verification') : $this->_language->get('registration_sent')]);
 }
Exemplo n.º 2
0
 /**
  * process the class
  *
  * @since 3.0.0
  *
  * @return string
  */
 public function process()
 {
     $specialFilter = new Filter\Special();
     /* process post */
     $postArray = ['id' => $specialFilter->sanitize($this->_request->getPost('id')), 'password' => $specialFilter->sanitize($this->_request->getPost('password')), 'task' => $this->_request->getPost('task'), 'solution' => $this->_request->getPost('solution')];
     /* query user */
     $user = Db::forTablePrefix('users')->where(['id' => $postArray['id'], 'status' => 1])->findOne();
     /* handle error */
     $messageArray = $this->_validate($postArray, $user);
     if ($messageArray) {
         return $this->_error(['message' => $messageArray]);
     }
     /* handle success */
     $passwordHash = new Hash(Config::getInstance());
     $passwordHash->init(uniqid());
     $resetArray = ['id' => $user->id, 'password' => $passwordHash->getHash()];
     $mailArray = ['name' => $user->name, 'email' => $user->email, 'password' => $passwordHash->getRaw()];
     /* reset */
     if (!$this->_reset($resetArray)) {
         return $this->_error(['message' => $this->_language->get('something_wrong')]);
     }
     /* mail */
     if (!$this->_mail($mailArray)) {
         return $this->_error(['message' => $this->_language->get('email_failed')]);
     }
     return $this->_success();
 }
Exemplo n.º 3
0
 /**
  * setUpBeforeClass
  *
  * @since 3.0.0
  */
 public static function setUpBeforeClass()
 {
     $passwordHash = new Hash(Config::getInstance());
     $passwordHash->init('test');
     Db::setSetting('captcha', 1);
     Db::forTablePrefix('users')->whereIdIs(1)->findOne()->set('password', $passwordHash->getHash())->save();
 }
Exemplo n.º 4
0
 /**
  * benchValidate
  *
  * @since 3.0.0
  *
  * @param array $parameterArray
  *
  * @ParamProviders({"providerHash"})
  */
 public function benchValidate($parameterArray = [])
 {
     /* setup */
     $hash = new Hash($this->_config);
     $hash->init($parameterArray[0]);
     /* bench */
     $hash->validate($parameterArray[0], function_exists('password_verify') ? $parameterArray[1][0][1] : $parameterArray[1][1]);
 }
Exemplo n.º 5
0
 /**
  * validate the captcha
  *
  * @since 2.2.0
  *
  * @param string $task plain task
  * @param string $hash hashed solution
  *
  * @return integer
  */
 public function validate($task = null, $hash = null)
 {
     $output = ValidatorInterface::FAILED;
     $captchaHash = new Hash(Config::getInstance());
     /* validate captcha */
     if ($task && $captchaHash->validate($task, $hash)) {
         $output = ValidatorInterface::PASSED;
     }
     return $output;
 }
 /**
  * validate the password
  *
  * @since 2.6.0
  *
  * @param string $password plain password
  * @param string $hash hashed password
  *
  * @return integer
  */
 public function validate($password = null, $hash = null)
 {
     $output = ValidatorInterface::FAILED;
     $passwordHash = new Hash(Config::getInstance());
     /* validate password */
     if ($password && $passwordHash->validate($password, $hash)) {
         $output = ValidatorInterface::PASSED;
     }
     return $output;
 }
Exemplo n.º 7
0
 /**
  * append the captcha
  *
  * @since 2.6.0
  *
  * @param string $type type of the captcha
  *
  * @return Form
  */
 public function captcha($type = null)
 {
     /* task */
     if ($type === 'task') {
         $this->label($this->_captcha->getTask(), array('for' => 'task'));
         /* number */
         $this->number(array('id' => 'task', 'min' => $this->_captcha->getMin(), 'max' => $this->_captcha->getMax() * 2, 'name' => 'task', 'required' => 'required'));
     }
     /* solution */
     if ($type === 'solution') {
         $captchaHash = new Hash(Config::getInstance());
         $captchaHash->init($this->_captcha->getSolution());
         /* hidden */
         $this->hidden(array('name' => 'solution', 'value' => $captchaHash->getHash()));
     }
     return $this;
 }
 /**
  * testValidate
  *
  * @since 2.6.0
  *
  * @param string $raw
  * @param array $hashArray
  *
  * @dataProvider providerHash
  */
 public function testValidate($raw = null, $hashArray = array())
 {
     /* setup */
     $hash = new Hash($this->_config);
     $hash->init($raw);
     /* actual */
     $actual = $hash->validate($raw, function_exists('password_verify') ? $hashArray[0][1] : $hashArray[1]);
     /* compare */
     $this->assertTrue($actual);
 }