Пример #1
0
 /**
  * Checks whether the current user is authenticated and if so, provides the email.
  * @return [type] [description]
  */
 public function getAuth()
 {
     $api = new \todo\Api();
     if (Auth::check()) {
         $api->setProperty('auth', 1);
         $api->setProperty('user_email', Auth::user()->email);
     } else {
         $api->setProperty('auth', 0);
     }
     return $api->getResponse();
 }
Пример #2
0
 /**
  * Callback for /item
  * Return all items for current user and performs sorting.
  * @return [type] [description]
  */
 public function postAll()
 {
     $api = new \todo\Api();
     $data = array();
     $query = Item::where('user_id', '=', Auth::user()->id);
     // sort by due date
     if ((int) Input::get('date', true)) {
         $query->orderBy('due_date', 'ASC');
     }
     // sort by priority
     if ((int) Input::get('priority', true)) {
         $query->orderBy('priority', 'DESC');
     }
     $items = $query->get();
     foreach ($items as $item) {
         $new_item = array('id' => $item->id, 'user_id' => Auth::user()->id, 'title' => htmlentities($item->title), 'priority' => $item->priority, 'date' => $item->due_date, 'completed' => $item->completed ? true : false);
         if (!is_null($new_item['date'])) {
             $new_item['date'] = date('m/d/Y', strtotime($item->due_date));
         }
         // sanitize output
         foreach ($new_item as &$value) {
             $value = htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
         }
         $data[] = $new_item;
     }
     $api->setProperty('items', $data);
     return $api->getResponse();
 }