Exemplo n.º 1
0
 public function verify($username, $password)
 {
     $credentials = ['username' => $username, 'password' => $password];
     $person = new Person();
     $resp = $person->getUsername($credentials['username']);
     if (!empty($resp)) {
         if (\Hash::check($credentials['password'], $resp['password'])) {
             $auth = true;
         } else {
             //check for old hashing
             if (md5($credentials['password']) == $resp['password']) {
                 //convert old pass to new hashing
                 $resp['password'] = bcrypt($credentials['password']);
                 $id = my_encode($resp['id']);
                 $person->update($id, $resp);
                 $auth = true;
             } else {
                 $auth = false;
             }
         }
     } else {
         //invalid user
         $auth = false;
     }
     if ($auth) {
         $result = $person->respondWithItem($resp, new UserTransformer());
         session()->put('user', $result);
         return my_decode($resp['id']);
     }
     return false;
 }
Exemplo n.º 2
0
 public function show($id, Request $request)
 {
     $id = (int) my_decode($id);
     //get report info
     $data['report'] = $this->report->respondWithItem($this->report->get('report_' . $id), new ReportTransformer());
     //get user info
     $user = $this->person->get('person_' . my_decode($data['report']['person_id']));
     $data['report']['person_name'] = (isset($user['first_name']) ? $user['first_name'] : '') . ' ' . (isset($user['last_name']) ? $user['last_name'] : '');
     $data['count_image'] = 0;
     $data['count_audio'] = 0;
     $data['count_video'] = 0;
     //if report type is group, get group members not including the member already selected
     $data['report_group'] = $this->group->get('family_' . $id);
     $data['users'] = $this->person->all()['data'];
     //get item info
     $items = $this->item->respondWithCollection($this->item->getItemsByReport($id)['items'], new ItemTransformer());
     $data['total_items'] = count($items);
     //get first image of the items in data
     foreach ($items as $i => $row) {
         $media = $this->data->getDataByItem((int) my_decode($row['id']));
         if (isset($media['items']) && !empty($media['items'])) {
             //get first image
             $row['image'] = "";
             foreach ($media['items'] as $m) {
                 if (strpos($m['media'], 'Image') !== false) {
                     $row['image'] = 'itemShort' . $m['id'] . '.png';
                     break;
                 }
             }
         }
         $items[$i] = $row;
     }
     //get count of media items
     foreach ($items as $i => $row) {
         $media = $this->data->getDataByItem((int) my_decode($row['id']));
         if (isset($media['items']) && !empty($media['items'])) {
             foreach ($media['items'] as $m) {
                 if (strpos($m['media'], 'Image') !== false) {
                     $data['count_image'] += 1;
                 } elseif (strpos($m['media'], 'Audio') !== false) {
                     $data['count_audio'] += 1;
                 } elseif (strpos($m['media'], 'Video') !== false) {
                     $data['count_video'] += 1;
                 } else {
                 }
             }
         }
     }
     $data['items'] = $items;
     return view('report_details', $data);
 }
Exemplo n.º 3
0
 public function update($id, $data)
 {
     $id = my_decode($id);
     $docId = $this->type . '_' . $id;
     //get old records
     $info = $this->cb->get($docId);
     $data = array_replace((array) $info->value, $this->fill($data));
     $data['updated'] = Carbon::now()->toDateTimeString();
     try {
         $resp = (array) $this->cb->replace($docId, $data);
         if (empty($resp['error'])) {
             $resp = $data;
         }
     } catch (\CouchbaseException $e) {
         $resp['error'] = $e->getMessage();
     }
     return $resp;
 }
Exemplo n.º 4
0
 public function show($id, Request $request)
 {
     $id = (int) my_decode($id);
     //get report info
     $data['item'] = $this->item->respondWithItem($this->report->get('item_' . $id), new ItemTransformer());
     //get item tag
     $result = $this->tag->get('tags_' . $id);
     $data['tags'] = !isset($result['error']) ? $result : [];
     $data['firstImage'] = '';
     //get item medias
     $data['images'] = [];
     $data['audios'] = [];
     $data['videos'] = [];
     $result = $this->data->getDataByItem($id);
     if (isset($result['items']) && !empty($result['items'])) {
         foreach ($result['items'] as $i => $m) {
             if (strpos($m['media'], 'Image') !== false) {
                 $data['images'][] = ['id' => $m['id'], 'img_short' => 'itemShort' . $m['id'] . '.png', 'img' => $m['media']];
                 if (empty($data['firstImage'])) {
                     $data['firstImage'] = 'itemShort' . $m['id'] . '.png';
                 }
             } elseif (strpos($m['media'], 'Audio') !== false) {
                 $data['audios'][] = ['id' => $m['id'], 'ado' => $m['media']];
             } elseif (strpos($m['media'], 'Video') !== false) {
                 $data['videos'][] = ['id' => $m['id'], 'vdo' => $m['media']];
             } else {
             }
         }
     }
     //get item commments
     $result = $this->comment->getCommentsByItem($id);
     $data['comments'] = [];
     if (isset($result['items']) && !empty($result['items'])) {
         //get user info
         foreach ($result['items'] as $item) {
             $user = $this->person->get('person_' . $item['person_id']);
             $item['userimage'] = isset($user['userimage']) ? $user['userimage'] : '';
             $item['first_name'] = isset($user['first_name']) ? $user['first_name'] : '';
             $item['last_name'] = isset($user['last_name']) ? $user['last_name'] : '';
             $data['comments'][] = $item;
         }
     }
     return view('item_details', $data);
 }
Exemplo n.º 5
0
 /**
  * Delete a report
  *
  * @param         $id
  * @param Request $request
  */
 public function destroy($id)
 {
     $id = 'item_comment_' . my_decode($id);
     $resp = $this->model->delete($id);
     if (!isset($resp['error'])) {
         return response(['success' => 'Comment deleted.']);
     }
     return response(['error' => $resp['error']]);
 }
Exemplo n.º 6
0
 public function show($id, Request $request)
 {
     $id = (int) my_decode($id);
     $data['user'] = $this->person->respondWithItem($this->person->get('person_' . $id), new UserTransformer());
     //get invidvidual reports
     $response = $this->report->individual($id);
     $data['totalIReport'] = 0;
     $data['individual'] = [];
     $item = new Item();
     if (!isset($response['error'])) {
         $data['individual'] = $this->report->respondWithCollection($response['data'], new ReportTransformer());
         foreach ($data['individual'] as $i => $row) {
             $items = $item->getItemsByReport((int) my_decode($row['id']));
             $data['individual'][$i]['items'] = $items['totalRecords'];
         }
         $data['totalIReport'] = $response['totalRecords'];
     }
     $response = $this->report->group($id);
     $data['totalGReport'] = 0;
     $data['group'] = [];
     if (!isset($response['error'])) {
         $data['group'] = $this->report->respondWithCollection($response['data'], new ReportTransformer());
         foreach ($data['group'] as $i => $row) {
             $items = $item->getItemsByReport((int) my_decode($row['id']));
             $data['group'][$i]['items'] = $items['totalRecords'];
         }
         $data['totalGReport'] = $response['totalRecords'];
     }
     return view('users_profile', $data);
 }
Exemplo n.º 7
0
Route::get('/setup', 'Tools\\SetupController@index');
Route::get('/admin', 'Tools\\SetupController@addAdmin');
/*
|--------------------------------------------------------------------------
| API Resource (REST)
|--------------------------------------------------------------------------
|
| This route contains all the resource of the api
*/
Route::post('oauth/access_token', function () {
    $resp = Authorizer::issueAccessToken();
    if ($resp) {
        session()->put($resp['access_token'], session()->get('user'));
        $resp['user'] = session()->get('user');
        //store to custom oauth session
        $data = ['id' => $resp['access_token'], 'person_id' => my_decode($resp['user']['id']), 'username' => $resp['user']['username'], 'role' => $resp['user']['role']];
        \App\OauthCustomSession::create($data);
    }
    return Response::json($resp);
});
//public api
Route::group(['prefix' => 'api'], function () {
    Route::post('account/register', 'Api\\AccountController@register');
    Route::post('account/forgot_password', 'Api\\AccountController@forgotPassword');
});
Route::group(['middleware' => ['api', 'oauth'], 'prefix' => 'api'], function () {
    Route::resource('users', 'Api\\UsersController', ['except' => ['create', 'edit']]);
    Route::get('users/{userId}/reports', 'Api\\ReportsController@index');
    Route::resource('reports', 'Api\\ReportsController', ['except' => ['index', 'create', 'edit']]);
    Route::get('reports/{reportId}/items', 'Api\\ItemsController@index');
    Route::resource('items', 'Api\\ItemsController', ['except' => ['index', 'create', 'edit']]);
Exemplo n.º 8
0
 /**
  * Delete a user
  *
  * @param         $id
  * @param Request $request
  *
  * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
  */
 public function destroy($id)
 {
     $id = 'person_' . my_decode($id);
     $resp = $this->person->delete($id);
     if (!isset($resp['error'])) {
         return response(['success' => 'User deleted.']);
     }
     return response(['error' => $resp['error']]);
 }
Exemplo n.º 9
0
 /**
  * Delete a report
  *
  * @param         $id
  * @param Request $request
  */
 public function destroy($id)
 {
     $id = 'report_' . my_decode($id);
     $resp = $this->report->delete($id);
     if (!isset($resp['error'])) {
         return response(['success' => 'Report deleted.']);
     }
     return response(['error' => $resp['error']]);
 }