Esempio n. 1
0
 /**
  * 
  * @param integer $nextDays
  * @return array
  */
 public function getSpecificDays($nextDays = 30, $previousDays = 0)
 {
     $now = new \DateTime();
     return array_filter($this->specificDays, function ($val, $key) use($now, $nextDays, $previousDays) {
         $time = new \DateTime($key);
         $diff = (int) $now->diff($time)->format('%r%a');
         return $diff >= $previousDays * -1 && $diff <= $nextDays;
     }, ARRAY_FILTER_USE_BOTH);
 }
 public function renderEmail()
 {
     $person = $this->userManager->get($this->user->getId());
     $this->template->person = $person;
     $now = new DateTime();
     $diff = $now->diff($person->change_email_requested);
     if ($diff->h < 1 && $diff->days == 0) {
         $this->template->openStepTwo = TRUE;
     }
 }
Esempio n. 3
0
 public function validityCheck($form)
 {
     $values = $form->getValues();
     if ($values->password != $values->password2) {
         $form->addError('Obě varianty hesla musí být stejné.');
     }
     $bdate = new \Nette\Utils\DateTime($values->birthdate);
     $diff = $bdate->diff(new \Nette\Utils\DateTime());
     $diff = $diff->format('%d');
     if ($diff < 7) {
         $form->addError('Uživatelé by měli být starší než jeden týden. ' . $diff . ' dní je příliš málo.');
     }
     $data = $this->model->getSelection()->where(array("email" => $values->email))->fetch();
     if ($data) {
         $form->addError('Email ' . $values->email . ' je již používán.');
     }
 }
Esempio n. 4
0
 /**
  * process wigle request and determine what to do
  * returns status code
  *
  * @param Coords $coords
  * @param int       $idSource
  * @return bool|string
  */
 public function processDownloadRequestCreation($coords, $idSource)
 {
     $coords = new Coords(round($coords->getLatStart() - 0.005, 2), round($coords->getLatEnd() + 0.005, 2), round($coords->getLonStart() - 0.005, 2), round($coords->getLonEnd() + 0.005, 2));
     $existingRequest = $this->getRequestAlreadyExistingInLatLngRange($coords, $idSource);
     if ($existingRequest) {
         // nalezeno
         $er = $existingRequest->toArray();
         // pokud processed = N pak je ve fronte a neni stazeno
         if ($er["processed"] == "N") {
             return self::STATE_ERR_ALREADY_IN_QUEUE;
         } else {
             $today = new DateTime();
             $diff = $today->diff($er["processed_date"]);
             if ($diff->days < self::MIN_DAYS_BEFORE_UPDATE_AREA) {
                 return self::STATE_ERR_RECENTLY_DOWNLOADED;
             } else {
                 return $this->addAllNotDownloadedRequests($coords, $idSource);
             }
         }
     } else {
         return $this->addAllNotDownloadedRequests($coords, $idSource);
     }
 }
Esempio n. 5
0
 /**
  * @param string $token
  * @param int $expirationTime
  * @return bool
  */
 public function isTokenValid($token, $expirationTime = 10)
 {
     try {
         $user = $this->read()->where("recoveryToken", $token)->limit(1)->fetch();
         if ($user) {
             $current = new DateTime();
             $diff = $current->diff(new DateTime($user->getRecoveryTokenInserted()));
             if ($diff->format("%h") == 0 && $diff->format("%i") <= $expirationTime) {
                 return true;
             } else {
                 return false;
             }
         } else {
             return false;
         }
     } catch (\PDOException $e) {
         return false;
     }
 }
 /**
  * @param $id int
  * @param $tokenOne string
  * @param $tokenTwo string
  */
 public function changeEmailStepTwo($id, $tokenOne, $tokenTwo)
 {
     $person = $this->get($id);
     $now = new DateTime();
     $diff = $now->diff($person->change_email_requested);
     if ($diff->h >= 1) {
         // todo throw exception
         return FALSE;
     }
     $verified = FALSE;
     if (Passwords::verify($tokenOne, $person->change_email_tokenOne)) {
         if (Passwords::verify($tokenTwo, $person->change_email_tokenTwo)) {
             $verified = TRUE;
         }
     } else {
         // swithed codes?
         if (Passwords::verify($tokenOne, $person->change_email_tokenTwo)) {
             if (Passwords::verify($tokenTwo, $person->change_email_tokenOne)) {
                 $verified = TRUE;
             }
         }
     }
     if (!$verified) {
         // todo throw excaption
         return FALSE;
     }
     $newEmail = $person->change_email;
     $data = array('email' => $newEmail, 'change_email' => '', 'change_email_tokenOne' => '', 'change_email_tokenTwo' => '', 'change_email_requested' => '');
     $this->get($id)->update($data);
     return $newEmail;
 }