Esempio n. 1
0
 /**
  * Save past text into database
  * Return generated hash
  * @param array $data
  * @return string
  */
 public function save($data)
 {
     $data->hash = Random::generate(6, '0-9a-zA-Z');
     $data->inserted = $this->dateTime->getTimestamp();
     $data->id_user = '';
     $this->dtb->table('pastes')->insert($data);
     return $data->hash;
 }
Esempio n. 2
0
 /**
  * @param  Entities\UserEntity             $e
  * @param  string                          $token
  * @throws UserNotFoundException
  * @throws ActivationLimitExpiredException
  */
 public function checkForTokenExpiration(Entities\UserEntity $e, $token)
 {
     if ($e->token !== $token) {
         throw new UserNotFoundException($this->translator->translate('locale.sign.incorrect_token'));
     }
     $current = new DateTime();
     $created = $e->tokenCreatedAt;
     $currentTimestamp = $current->getTimestamp();
     $createdTimestamp = $created->getTimestamp();
     $diff = $currentTimestamp - $createdTimestamp;
     if ($diff >= Authenticator::ACTIVATION_LIMIT_TIMESTAMP) {
         throw new ActivationLimitExpiredException($this->translator->translate('locale.sign.authentication_expired'));
     }
 }
Esempio n. 3
0
 /**
  * Get Date from ::addDate() field
  *
  * @param Nette\Forms\Controls\TextInput|string $input
  *
  * @return string
  */
 public static function getDateValue($input)
 {
     if ($input instanceof Nette\Forms\Controls\TextInput) {
         $value = $input->getValue();
     } else {
         $value = $input;
     }
     if (preg_match('~^\\d{1,2}[/.]{1}[ ]{0,1}\\d{1,2}[/.]{1}[ ]{0,1}\\d{4}$~', $value, $arr)) {
         $dateArr = preg_split('/[.\\/]{1}[ ]{0,1}/s', $arr[0]);
         $date = new Nette\Utils\DateTime($dateArr[2] . '-' . $dateArr[1] . '-' . $dateArr[0]);
         return $date->getTimestamp() < 10 ? NULL : $date->format('Y-m-d');
     }
     return empty($value) || $value == '0000-00-00' ? NULL : $value;
 }