public function signup()
 {
     if ($this->request->is('post')) {
         $table = TableRegistry::get('Users');
         $salt = uniqid(mt_rand(), true);
         $user = $table->newEntity(['name' => $this->request->data('name'), 'email' => $this->request->data('email'), 'password' => pbkdf2("sha256", $this->request->data('password'), $salt), 'salt' => $salt, 'date_created' => Time::createFromTimestamp(time())]);
         if ($user->isValid() && $this->request->data('password') == $this->request->data('confirm_password') && $table->save($user)) {
             $key = $user->makeKey();
             $this->Cookie->write('ta_login_id', $user->id);
             $this->Cookie->write('ta_login_email', $user->email);
             $this->Cookie->write('ta_login_key', $key);
             return $this->redirect("/");
         } else {
             if ($user->isValid()) {
                 if ($this->request->data('password') == $this->request->data('confirm_password')) {
                     $this->Flash->set('The email you entered is already in use.', ['element' => 'error']);
                 } else {
                     $this->Flash->set('The password and confirmation you entered did not match.', ['element' => 'error']);
                 }
             } else {
                 $this->Flash->set('Please make sure your email is valid and name is longer than three characters.', ['element' => 'error']);
             }
         }
     }
     $this->viewBuilder()->layout("auth");
 }
 public function index()
 {
     if (strpos(UrlHelper::build('/', true), 'dev') == false) {
         $this->set('files', []);
         $this->set('stats', []);
         return;
     }
     $files = [];
     $dev_folders_to_check = ['../src', '../plugins', '../webroot', '../config'];
     $prod_folders_to_check = ['../../production/src', '../../production/plugins', '../../production/webroot', '../../production/config'];
     $d = 0;
     foreach ($dev_folders_to_check as $folder) {
         $dir = new Folder($folder);
         $tree = $dir->tree(null, ['.htaccess', 'error_log'])[1];
         sort($tree);
         foreach ($tree as $entry) {
             $file = new File($entry);
             preg_match('/.*development(.*)/', $entry, $filename);
             $filename = $filename[1];
             $files[$filename]['dev_date'] = Time::createFromTimestamp(round($file->lastChange() / 60) * 60);
             $d++;
         }
     }
     $ud = $d;
     // Unique Files Dev. Will Subtract 1 for each file match.
     $nd = 0;
     // Newer Files Dev.
     $p = 0;
     $up = 0;
     $np = 0;
     foreach ($prod_folders_to_check as $folder) {
         $dir = new Folder($folder);
         $tree = $dir->tree(null, ['.htaccess', 'error_log'])[1];
         sort($tree);
         foreach ($tree as $entry) {
             $file = new File($entry);
             preg_match('/.*production(.*)/', $entry, $filename);
             $filename = $filename[1];
             $date = Time::createFromTimestamp(round($file->lastChange() / 60) * 60);
             $files[$filename]['prod_date'] = $date;
             if (isset($files[$filename]['dev_date'])) {
                 $ud--;
                 if ($date < $files[$filename]['dev_date']) {
                     $nd++;
                 } elseif ($date > $files[$filename]['dev_date']) {
                     $np++;
                 } else {
                     unset($files[$filename]);
                 }
             } else {
                 $up++;
             }
             $p++;
         }
     }
     $stats = ['files_dev' => $d, 'files_prod' => $p, 'unique_dev' => $ud, 'unique_prod' => $up, 'newer_dev' => $nd, 'newer_prod' => $np];
     $this->set('files', $files);
     $this->set('stats', $stats);
 }
function time_format($stamp)
{
    return Time::createFromTimestamp($stamp);
}
 public function testGetBatch()
 {
     $identifier = 'test_email_notification_custom';
     $this->_createNotificationContent($identifier);
     $data = ['locale' => 'eng', 'recipient_user_id' => 'f9df9eab-a6a3-4c89-9579-3eaeeb47e25f', 'transport' => 'email', 'config' => ['placeholder1' => 'PL1', 'placeholder2' => 'PL2']];
     $notification1 = $this->NotificationQueue->createNotification($identifier, $data);
     $res1 = $this->NotificationQueue->enqueue($notification1);
     $notification2 = $this->NotificationQueue->createNotification($identifier, $data);
     $notification2->created = Time::createFromTimestamp(strtotime('+5hour'));
     // this is critical, as we're ordering by created when getting a batch
     $res2 = $this->NotificationQueue->enqueue($notification2);
     $batch = $this->NotificationQueue->getBatch(1);
     $this->assertTrue(is_array($batch));
     $this->assertEquals(count($batch), 1);
     $firstNotification = $this->NotificationQueue->get($notification1->id);
     $secondNotification = $this->NotificationQueue->get($notification2->id);
     $this->assertTrue($firstNotification->locked);
     $this->assertFalse($secondNotification->locked);
     $this->assertEquals($batch[0]->id, $firstNotification->id);
     // notification1 must not be in the batch, as it is locked by the first batch
     $batch2 = $this->NotificationQueue->getBatch();
     $this->assertTrue(is_array($batch2));
     $this->assertEquals(count($batch2), 1);
     $this->assertEquals($batch2[0]->id, $secondNotification->id);
     $this->NotificationQueue->clearLocks();
     // make sure sent notifications are not added to the batch
     $this->NotificationQueue->success($notification1->id);
     $batch2 = $this->NotificationQueue->getBatch();
     $this->assertTrue(is_array($batch2));
     $this->assertEquals(count($batch2), 1);
     $this->assertEquals($batch2[0]->id, $secondNotification->id);
     $this->NotificationQueue->clearLocks();
     $notification1->sent = false;
     $this->NotificationQueue->save($notification1);
     // make sure notifications which have reached the max send tries are not in the batch
     $notification2->send_tries = $this->NotificationQueue->getMaxSendTries();
     $this->NotificationQueue->save($notification2);
     $batch3 = $this->NotificationQueue->getBatch();
     $this->assertTrue(is_array($batch3));
     $this->assertEquals(count($batch3), 1);
     $this->assertEquals($batch3[0]->id, $firstNotification->id);
     // notification to be sent in the future shouldn't be in the batch
     $data['send_after'] = Time::parse('+2 hours');
     $notification3 = $this->NotificationQueue->createNotification($identifier, $data);
     $this->NotificationQueue->save($notification3);
     $batch4 = $this->NotificationQueue->getBatch();
     $this->assertTrue(is_array($batch4));
     $this->assertEmpty(count($batch4));
 }
Example #5
0
 protected function changeDate($item)
 {
     if (is_array($item)) {
         foreach ($item as $i) {
             $this->changeDate($i);
         }
         return null;
     }
     if (!Validation::positionIsEmpty($this->query, $item)) {
         $this->query[$item] = Time::createFromTimestamp($this->query[$item]);
     }
 }
 public function notifications($user = null, $page = 1)
 {
     // Getting the Activities personalized feed
     // NEW : User must subscribe individually to each Pole's Feed to be notified.
     // We only get the Activities for which the User is not the creator
     // that were created after the last time he read them.
     if (!$user) {
         $user = $this->loggedInUser->id;
     }
     // Then get all the subscriptions
     $Subscriptions = TableRegistry::get('Social.Subscriptions');
     $subscriptions = $Subscriptions->find()->where(['Subscriptions.user_id' => $user])->all();
     $subscriptions = (new Collection($subscriptions))->extract('feed_id')->toArray();
     $query = $this->Activities->find()->contain(['Authors' => ['fields' => ['id', 'first_name', 'last_name', 'avatar']]])->limit(__MAX_NOTIFICATIONS_LISTED)->page($page)->order(['Activities.created DESC'])->matching('Feeds', function ($q) use($subscriptions) {
         return $q->where(['Feeds.id IN' => $subscriptions]);
     });
     if ($this->request->is('ajax')) {
         if (isset($this->request->query['last_check'])) {
             $last_check = Time::createFromTimestamp($this->request->query['last_check'] / 1000);
             $activities = $query->where(['Activities.subject_id !=' => $user, 'Activities.created >' => $last_check->format('Y-m-d H:i:s')])->all();
         } else {
             $activities = $query->where(['Activities.subject_id !=' => $user])->all();
         }
         $count = $this->Activities->find()->contain(['Authors' => ['fields' => ['id', 'first_name', 'last_name', 'avatar']]])->limit(20000)->order(['Activities.created DESC'])->where(['Activities.subject_id !=' => $user, 'Activities.created >' => $this->loggedInUser->notifications_last_read])->matching('Feeds', function ($q) use($subscriptions) {
             return $q->where(['Feeds.id IN' => $subscriptions]);
         })->count();
         $view = new View($this->request, $this->response, null);
         $view->layout = 'ajax';
         // layout to use or false to disable
         $view->set('loggedInUser', $this->loggedInUser);
         $view->set('all_poles', $this->all_poles->toArray());
         $view->set('activities', $activities->toArray());
         $data['html'] = $view->render('Social.Activities/ajax_notifications');
         $this->layout = 'ajax';
         $data['count'] = $count;
         $data['success'] = true;
         $this->set('data', $data);
         $this->render('/Shared/json/data');
     } else {
         $activities = $query->where(['Activities.subject_id !=' => $user])->all();
         $this->set('activities', $activities->toArray());
         // UI
         $this->set('section_title', __('Notifications'));
         $this->set('page_title', __('Notifications'));
         // Handling the breadcrumb
         $this->breadcrumb = array(__('Notifications') => '#');
     }
 }
 public function apiManage($edit = 0)
 {
     $this->viewBuilder()->layout("ajax");
     $this->render(false);
     $name = $this->request->data("name");
     $email = $this->request->data("email");
     $access_level = $this->request->data("access_level");
     $password = $this->request->data("password");
     $password_confirm = $this->request->data("password_confirm");
     $salt = uniqid(mt_rand(), true);
     /*$name = "Test2";
     		$email = "*****@*****.**";
     		$access_level = 2;
     		$password = "******";
     		$password_confirm = "123";*/
     $table = TableRegistry::get("Users");
     if ($password != $password_confirm) {
         echo json_encode(["status" => "400", "response" => "Could not save 3"]);
         return;
     }
     $entity = null;
     if ($edit == 0) {
         $entity = $table->newEntity(["name" => $name, "email" => $email, "password" => pbkdf2("sha256", $password, $salt), "salt" => $salt, 'date_created' => Time::createFromTimestamp(time())]);
     } else {
         $entity = $table->find()->where(["id" => $edit])->all();
         if ($entity->count() == 0) {
             echo json_encode(["status" => "400", "response" => "Could not save 1"]);
             return;
         } else {
             $entity = $entity->first();
             $entity->name = $name;
             $entity->email = $email;
             if ($password != "") {
                 $entity->password = pbkdf2("sha256", $password, $salt);
                 $entity->salt = $salt;
             }
         }
     }
     if ($table->save($entity)) {
         if ($edit == 0) {
             if ($access_level > 0) {
                 $assignment = TableRegistry::get("StaffAssignments")->newEntity(["user_id" => $entity->id, "theater_id" => $this->adminTheater, "access_level" => $access_level]);
                 TableRegistry::get("StaffAssignments")->save($assignment);
             }
         } else {
             $assignment = TableRegistry::get("StaffAssignments")->find()->where(["user_id" => $entity->id])->all();
             if ($assignment->count() > 0) {
                 $assignment = $assignment->first();
                 $assignment->access_level = $access_level;
                 TableRegistry::get("StaffAssignments")->save($assignment);
             } else {
                 $assignment = TableRegistry::get("StaffAssignments")->newEntity(["user_id" => $entity->id, "theater_id" => $this->adminTheater, "access_level" => $access_level]);
                 TableRegistry::get("StaffAssignments")->save($assignment);
             }
         }
         echo json_encode(["status" => "200", "response" => "Saved"]);
         return;
     } else {
         echo json_encode(["status" => "400", "response" => "Could not save"]);
         return;
     }
 }
 /**
  * _removeExpiredLock
  *
  * @return void
  */
 protected function _removeExpiredLock()
 {
     $dir = new Folder(CONFIG . $this->_config['lockout']['file_path'], true);
     $files = $dir->find();
     foreach ($files as $fileName) {
         $file = new File($dir->pwd() . DS . $fileName);
         $lastChange = Time::createFromTimestamp($file->lastChange());
         if ($lastChange->wasWithinLast($this->_config['lockout']['expires'])) {
             continue;
         }
         $file->delete();
     }
 }
Example #9
0
 function timeHour()
 {
     $time = Time::createFromTimestamp($this->start_time);
     return date('g:i a', $time->timestamp);
 }
 /**
  * Returns the site sitemap.
  * If the sitemap doesn't exist or has expired, it generates and writes
  *  the sitemap.
  * @return \Cake\Network\Response
  * @uses _sitemap()
  */
 public function sitemap()
 {
     //If the sitemap doesn't exists, it writes the sitemap
     if (!is_readable(SITEMAP)) {
         $sitemap = $this->_sitemap();
     } else {
         $time = Time::createFromTimestamp(filemtime(SITEMAP));
         //If the sitemap has expired, it writes a new sitemap
         if ($time->modify(config('main.sitemap_expiration'))->isPast()) {
             $sitemap = $this->_sitemap();
         } else {
             $sitemap = file_get_contents(SITEMAP);
         }
     }
     $this->response->body($sitemap);
     $this->response->type('x-gzip');
     return $this->response;
 }
 /**
  * Se a data for nula, usa data atual
  *
  * @param mixed $data A data a ser ajustada
  * @return integer Se null, retorna a data/hora atual
  * @access protected
  */
 protected function _ajustaDataHora($data)
 {
     if (is_null($data)) {
         return Time::now();
     }
     if (is_integer($data) || ctype_digit($data)) {
         return Time::createFromTimestamp($data);
     }
     $tsLong = strtotime((string) $data);
     return $tsLong ? $tsLong : $data;
 }