public function getInterfaceLocale() { $locale = Input::get("l"); $translating = Input::get("t"); $primary = Input::get("p"); $displayLocales = Input::get("d"); $display = implode(',', $displayLocales ?: []); App::setLocale($locale); Cookie::queue($this->cookieName(self::COOKIE_LANG_LOCALE), $locale, 60 * 24 * 365 * 1); Cookie::queue($this->cookieName(self::COOKIE_TRANS_LOCALE), $translating, 60 * 24 * 365 * 1); Cookie::queue($this->cookieName(self::COOKIE_PRIM_LOCALE), $primary, 60 * 24 * 365 * 1); Cookie::queue($this->cookieName(self::COOKIE_DISP_LOCALES), $display, 60 * 24 * 365 * 1); if (App::runningUnitTests()) { return Redirect::to('/'); } return !is_null(Request::header('referer')) ? Redirect::back() : Redirect::to('/'); }
/** * Redirect back, with a fallback if no previous page. * * @param string $fallback * * @return \Illuminate\Http\RedirectResponse */ protected function redirectBackWithFallback($fallback = '/') { if (!Request::header('referer')) { return Redirect::to($fallback); } return Redirect::back(); }
public function users() { $auth_token = Request::header('Authorization'); $user = User::where('auth_token', '=', $auth_token)->first(); if ($user) { $users = User::getActiveUsersInfo()->get(); foreach ($users as $u) { $user_element["id"] = $u->id; $user_element["names"] = $u->nombres; $user_element["last_name"] = $u->apellido_pat; $user_element["username"] = $u->num_documento; $perfiles = User::getPerfilesPorUsuario2($u->id)->get(); $perfiles_array = array(); foreach ($perfiles as $perfil) { $perfiles_array[] = ['id' => $perfil->idperfiles, 'name' => $perfil->nombre]; } $user_element["profiles"] = $perfiles_array; $permisos = User::getPermisosPorUsuarioId($u->id)->get(); $permisos_array = array(); foreach ($permisos as $p) { $permisos_array[] = ['id' => $p->idpermisos]; } $user_element["actions"] = $permisos_array; $user_element["auth_token"] = $u->auth_token; $user_array[] = $user_element; } return Response::json($user_array, 200); } $response = ['error' => 'Error en la autenticación.']; $status_code = 401; return Response::json($response, $status_code); }
public function login() { $apps_key = Request::header('Application-Key'); $auth_key = Request::header('Authorization'); if (System::where('api_token', $apps_key)->get()->count() < 1) { return Response::json(['status' => 400, 'message' => http_codes(400)], 400); } if (!($credentials = array_filter(explode(" ", $auth_key)))) { return Response::json(['error' => 'invalid_credentials'], 401); } if (!($auth = array_filter(explode(":", base64_decode($credentials[1]))))) { return Response::json(['error' => 'invalid_credentials'], 401); } if (!Auth::attempt(['name' => $auth[0], 'password' => $auth[1]])) { return Response::json(['status' => 401, 'message' => http_codes(401)], 401); } try { $data = ['userId' => Auth::user()->id]; if (!($token = JWT::setToken($data))) { return Response::json(['error' => 'invalid_credentials'], 401); } } catch (Exception $e) { return Response::json(['error' => 'could_not_create_token'], 500); } return Response::json(['status' => 200, 'message' => http_codes(200), 'data' => $token], 200); }
private function getExceptionData($exception) { $data = []; $data['host'] = Request::server('HTTP_HOST'); $data['method'] = Request::method(); $data['fullUrl'] = Request::fullUrl(); if (php_sapi_name() === 'cli') { $data['host'] = parse_url(config('app.url'), PHP_URL_HOST); $data['method'] = 'CLI'; } $data['exception'] = $exception->getMessage(); $data['error'] = $exception->getTraceAsString(); $data['line'] = $exception->getLine(); $data['file'] = $exception->getFile(); $data['class'] = get_class($exception); $data['storage'] = array('SERVER' => Request::server(), 'GET' => Request::query(), 'POST' => $_POST, 'FILE' => Request::file(), 'OLD' => Request::hasSession() ? Request::old() : [], 'COOKIE' => Request::cookie(), 'SESSION' => Request::hasSession() ? Session::all() : [], 'HEADERS' => Request::header()); $data['storage'] = array_filter($data['storage']); $count = $this->config['count']; $data['exegutor'] = []; $data['file_lines'] = []; $file = new SplFileObject($data['file']); for ($i = -1 * abs($count); $i <= abs($count); $i++) { list($line, $exegutorLine) = $this->getLineInfo($file, $data['line'], $i); $data['exegutor'][] = $exegutorLine; $data['file_lines'][$data['line'] + $i] = $line; } // to make Symfony exception more readable if ($data['class'] == 'Symfony\\Component\\Debug\\Exception\\FatalErrorException') { preg_match("~^(.+)' in ~", $data['exception'], $matches); if (isset($matches[1])) { $data['exception'] = $matches[1]; } } return $data; }
public function facebookLogin(Request $request) { //get fb access token // verify fb access token // generate token for user // update token in db // return token for user // else return false $user_ac_token = \Illuminate\Support\Facades\Request::header('fbtoken'); //facebook access token $userEmail = $request->json()->get('email'); $info = json_decode(file_get_contents('https://graph.facebook.com/app/?access_token=' . $user_ac_token), true); if ($info['id'] == env('FB_APP_ID')) { $user = User::with('school')->where('email', '=', $userEmail)->first(); if ($user != null) { //login $user->auth_token = str_random(60); $user->save(); return Response::json(['result' => 'success', 'token' => $user->auth_token, 'user' => $user], 200); } else { $user = User::with('school')->find(User::create($request->all())->id); $user->auth_token = str_random(60); $user->save(); return Response::json(['result' => 'success', 'token' => $user->auth_token, 'user' => $user], 200); } } else { return Response::json(['result' => 'failed'], 400); } }
public function push_settings() { $auth_token = Request::header('Authorization'); $user = User::where('auth_token', '=', $auth_token)->first(); if ($user) { $data = file_get_contents('php://input'); $settingsInput = (array) json_decode($data); if ($settingsInput) { $user->push_eventos = $settingsInput['push_events']; $user->push_pagos = $settingsInput['push_fees']; $user->push_documents = $settingsInput['push_documents']; $user->push_reports = $settingsInput['push_reports']; $user->save(); $response = ['success' => 1]; $status_code = 200; return Response::json($response, $status_code); } else { $response = ['error' => 'Parámetro settings inválido (vacío/formato JSON incorrecto).']; $status_code = 400; return Response::json($response, $status_code); } } $response = ['error' => 'Error en la autenticación.']; $status_code = 401; return Response::json($response, $status_code); }
/** * Write a logout history item for this user * * @param \Illuminate\Auth\Events\Logout $event */ public static function handle(LogoutEvent $event) { $event->user->login_history()->save(new UserLoginHistory(['source' => Request::getClientIp(), 'user_agent' => Request::header('User-Agent'), 'action' => 'logout'])); $message = 'User logged out from ' . Request::getClientIp(); event('security.log', [$message, 'authentication']); return; }
/** * Check headers to see if we should localize the content, if so, create a new response and get it to do the * localization. * * @return ApiResponse */ public function getResponse() { $apiResponse = new ApiResponse(); if ($region = RequestFacade::header('Accept-Region')) { $apiResponse->setLocalizationRegion($region); } return $apiResponse; }
/** * [Log api] * @param [type] $url [description] * @param [type] $method [description] * @param [type] $request [description] * @param [type] $response [description] */ public static function Logging($url, $method, $request, $response) { $model = new Log(); $data = $model->create(['url' => $url, 'method' => $method, 'header' => json_encode(Request::header()), 'request' => json_encode(Request::all())]); $model = new Log(); $model = $model->findOrFail($data['id']); $model->update(['response' => json_encode($response)]); }
/** * Update the last login values and write a new * login history item * * @param $user */ public static function handle($user) { $user->last_login_source = Request::getClientIp(); $user->last_login = new DateTime(); $user->save(); $user->login_history()->save(new UserLoginHistory(['source' => Request::getClientIp(), 'user_agent' => Request::header('User-Agent'), 'action' => 'login'])); $message = 'User logged in from ' . Request::getClientIp(); Event::fire('security.log', [$message, 'authentication']); return; }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { // JWT Authentication and for getting data (e.g: userId, userName, ...etc) $jwt = Request::header('Token-Key'); try { $data = JWT::getToken($jwt); } catch (Exception $e) { return Response::json(['error' => $e->getMessage()], 511); } $request->merge(array("data" => $data)); return $next($request); }
/** * Handles exceptions with redirect. * * @param Exception $exception * @return Illuminate\Routing\Redirector */ public function handleException(Exception $exception) { // Get redirect $referer = Request::header('referer'); $url = empty($referer) ? route('users.signin') : $referer; // Add the fragment if defined on the route $options = Request::route()->getAction(); $fragment = array_get($options, 'fragment'); $url = $fragment ? $url . '#' . $fragment : $url; // Send redirect return Redirect::to($url)->with('message', $exception->getMessage())->with('code', $exception->getCode())->withErrors($exception->getBag())->withInput(); }
public function create(array $data = null) { if (is_null($data)) { return false; } // check null values $arr = $this->validate($data); // get publisher id $uid = Request::header('UID', 0); $arr = array_merge($arr, ['article_id' => $data['id'], 'created_by' => $uid, 'modified_by' => $uid]); return ArticleDomainData::updateOrCreate(['article_id' => $data['id']], $arr); }
public function roll_call() { $auth_token = Request::header('Authorization'); $user = User::where('auth_token', '=', $auth_token)->first(); if ($user) { $data = file_get_contents('php://input'); $rollCallInput = (array) json_decode($data); if ($rollCallInput) { try { $sessionID = $rollCallInput['session_id']; $volunteersInput = $rollCallInput['volunteers']; } catch (Exception $e) { $response = ['error' => 'Formato inválido: debe contener session_id, volunteers.']; $status_code = 404; return Response::json($response, $status_code); } foreach ($volunteersInput as $v) { $rollCallEntry = Asistencia::validarAsistencia($v->id, $sessionID)->first(); if (!$rollCallEntry) { $rollCallEntry = new Asistencia(); $rollCallEntry->idusers = $v->id; $rollCallEntry->ideventos = $sessionID; } $rollCallEntry->asistio = $v->attended; $rollCallEntry->calificacion = $v->rating; $rollCallEntry->comentario = $v->comment; $rollCallEntry->save(); } $rollCallDB = Asistencia::getUsersPorEvento($sessionID)->get(); $responseRollCall = []; foreach ($rollCallDB as $rollCallEntryDB) { $responseRollCall_element['id'] = $rollCallEntryDB->id; $responseRollCall_element['names'] = $rollCallEntryDB->nombres; $responseRollCall_element['last_name'] = $rollCallEntryDB->apellido_pat; $responseRollCall_element['attended'] = (bool) $rollCallEntryDB->asistio; $responseRollCall_element['rating'] = (int) $rollCallEntryDB->calificacion; $responseRollCall_element['comment'] = $rollCallEntryDB->comentario; $responseRollCall[] = $responseRollCall_element; } $response = ['success' => 1, 'session_id' => $sessionID, 'volunteers' => $responseRollCall]; $status_code = 200; return Response::json($response, $status_code); } else { $response = ['error' => 'Error en parámetros.']; $status_code = 404; return Response::json($response, $status_code); } } $response = ['error' => 'Error en la autenticación.']; $status_code = 401; return Response::json($response, $status_code); }
/** * List builds. * * @return void */ public function index() { $page = Input::get('page', 1); $perPage = 10; $isLock = $this->locker->isLock(); $pagiData = $this->build->byPage($page, $perPage); $builds = new Paginator($pagiData->items, $pagiData->totalItems, $perPage); $builds->setPath('/' . config('ngmy-stand-ci')['route_prefix'] . '/builds'); if (Request::header('X-PJAX')) { return View::make('stand-ci::builds.index_pjax', array('builds' => $builds, 'isLock' => $isLock)); } else { return View::make('stand-ci::builds.index', array('builds' => $builds, 'isLock' => $isLock)); } }
/** * Get the currently logged in user name. * * @return string */ public static function currentUserName() { if (function_exists('\\get_user_name')) { $username = \get_user_name(); } if (empty($username)) { $username = \get_current_user(); } if (empty($username)) { $username = Request::header('php-auth-user'); } if (empty($username)) { $username = '******'; } return $username; }
public function symfonyAction() { $ua = Request::header('User-Agent'); //Redirect to static Masarap page if no User Agent HTTP header was found if (!preg_match("@Masarap/@", $ua)) { return File::get(public_path() . '/masarap-symfony/index.html'); } // end if no Masarap User Agent $status_code = FORCE_UPDATE_STATUS_CODE; $data = array('status_code' => $status_code, 'message' => "[{$status_code}] Force Update.", 'app_version' => APP_VERSION, 'app_store' => APP_STORE_LINK, 'google_play' => PLAY_STORE_LINK); $response = new Response(json_encode($data)); $response->setStatusCode($status_code, "Force Update"); $response->headers->set('Content-Type', 'application/json'); $response->send(); exit; }
/** * This code has been adapted the code at http://www.tuxxin.com/php-mp4-streaming. */ public function getResponse() { $stream = fopen($this->asset->getFilename(), 'rb'); $size = $length = $this->asset->getFilesize(); $start = 0; $end = $size - 1; $code = 200; $headers = ['Content-Type' => $this->asset->getMimetype(), 'Accept-Ranges' => 'bytes']; if ($range = Request::header('Range')) { $c_start = $start; $c_end = $end; list(, $range) = explode('=', $range, 2); if (strpos($range, ',') !== false) { abort(416, null, ['Content-Range' => "bytes {$start}-{$end}/{$size}"]); } if ($range === '-') { $c_start = $size - substr($range, 1); } else { $range = explode('-', $range); $c_start = $range[0]; $c_end = isset($range[1]) && is_numeric($range[1]) ? $range[1] : $size; } $c_end = $c_end > $end ? $end : $c_end; if ($c_start > $c_end || $c_start > $size - 1 || $c_end >= $size) { abort(416, null, ['Content-Range' => "bytes {$start}-{$end}/{$size}"]); } $start = $c_start; $end = $c_end; $length = $end - $start + 1; fseek($stream, $start); $code = 206; } $headers['Content-Range'] = "bytes {$start}-{$end}/{$size}"; $headers['Content-Length'] = $length; return Response::stream(function () use($stream, $end) { $buffer = 1024 * 8; while (!feof($stream) && ($p = ftell($stream)) <= $end) { if ($p + $buffer > $end) { $buffer = $end - $p + 1; } set_time_limit(0); echo fread($stream, $buffer); flush(); } fclose($stream); }, $code, $headers); }
/** * Check user JWT token * * @return null|object * @throws Exception */ public static function get() { try { if (\Input::has("token")) { $token = \Input::get("token"); } else { $auth = \Illuminate\Support\Facades\Request::header('Auth'); $auth = explode(' ', $auth); $token = !empty($auth[1]) ? $auth[1] : null; } if (empty($token)) { return null; } $userToken = self::check($token); return $userToken; } catch (\Exception $e) { throw new Exception('Token error' . $e->getMessage()); } }
/** * Handles the request made to StyleCI by the GitHub API. * * @return \Illuminate\Http\JsonResponse */ public function handle() { $class = 'StyleCI\\StyleCI\\Events\\Repo\\GitHub\\GitHub' . ucfirst(camel_case(Request::header('X-GitHub-Event'))) . 'Event'; if (!class_exists($class)) { throw new BadRequestHttpException('Event not supported.'); } $data = Request::input(); $repo = Repo::find($data['repository']['id']); if (!$repo) { throw new BadRequestHttpException('Request integrity validation failed.'); } list($algo, $sig) = explode('=', Request::header('X-Hub-Signature')); $hash = hash_hmac($algo, Request::getContent(), $repo->token); if (!Str::equals($hash, $sig)) { throw new BadRequestHttpException('Request integrity validation failed.'); } event(new $class($repo, $data)); return new JsonResponse(['message' => 'Event successfully received.']); }
public function locations() { $auth_token = Request::header('Authorization'); $user = User::where('auth_token', '=', $auth_token)->first(); if ($user) { $colegios = Colegio::getActiveColegiosInfo()->get(); $colegios_array = []; foreach ($colegios as $c) { $colegios_element['id'] = $c->idcolegios; $colegios_element['name'] = $c->nombre; $colegios_element['latitude'] = (double) $c->latitud; $colegios_element['longitude'] = (double) $c->longitud; $colegios_array[] = $colegios_element; } $voluntarios = User::getVoluntarios()->get(); $voluntarios_array = []; foreach ($voluntarios as $v) { $voluntarios_element['id'] = $v->id; $voluntarios_element['names'] = $v->nombres; $voluntarios_element['last_name'] = $v->apellido_pat; $voluntarios_element['username'] = $v->num_documento; $voluntarios_element['email'] = $v->email; $perfiles = User::getPerfilesPorUsuario2($v->id)->get(); $perfiles_array = array(); foreach ($perfiles as $perfil) { $perfiles_array[] = ['id' => $perfil->idperfiles, 'name' => $perfil->nombre]; } $voluntarios_element['profiles'] = $perfiles_array; $voluntarios_element['latitude'] = (double) $v->latitud; $voluntarios_element['longitude'] = (double) $v->longitud; $voluntarios_array[] = $voluntarios_element; } return Response::json(['schools' => $colegios_array, 'volunteers' => $voluntarios_array], 200); } $response = ['error' => 'Error en la autenticación.']; $status_code = 401; return Response::json($response, $status_code); }
public function getResponse() { $size = $fullsize = $this->asset->getFilesize(); $stream = fopen($this->asset->getFilename(), 'r'); $code = 200; $headers = ['Content-type' => $this->asset->getMimetype()]; if ($range = Request::header('Range')) { $eqPos = strpos($range, '='); $toPos = strpos($range, '-'); $unit = substr($range, 0, $eqPos); $start = intval(substr($range, $eqPos + 1, $toPos)); $success = fseek($stream, $start); if ($success == 0) { $size = $fullsize - $start; $code = 206; $headers['Accept-Ranges'] = $unit; $headers['Content-Range'] = $unit . ' ' . $start . '-' . ($fullsize - 1) . '/' . $fullsize; } } $headers['Content-Length'] = $size; return Response::stream(function () use($stream) { fpassthru($stream); }, $code, $headers); }
/** * Generate a URL to a named route or returns a url to the users * previous URL if it exists. * * @param string $name * @param array $parameters * @param bool $absolute * @param \Illuminate\Routing\Route $route * * @return string */ function routeBack($name, $parameters = [], $absolute = true, $route = null) { if (Request::header('referer')) { return URL::previous(); } else { return route($name, $parameters, $absolute, $route); } }
/** * Connect action. * * @param string $provider * * @return mixed */ public function getConnect($provider = null) { if (empty($provider)) { App::abort(404); } $referer = Request::header('referer', '/'); $referer_parts = parse_url($referer); $onboth = array_get($referer_parts, 'path'); if (array_get($referer_parts, 'query')) { $onboth .= '?' . array_get($referer_parts, 'query'); } if (!Input::get('code') && !Input::get('oauth_token')) { Session::put('mmanos.social.onsuccess', Input::get('onsuccess', $onboth)); Session::put('mmanos.social.onerror', Input::get('onerror', $onboth)); } if (!Auth::check()) { return Redirect::to(Session::pull('mmanos.social.onerror', '/'))->with(Config::get('laravel-social::error_flash_var'), 'There was a problem connecting your account (1).'); } if (Input::get('denied') || Input::get('error')) { return Redirect::to(Session::pull('mmanos.social.onerror', '/'))->with(Config::get('laravel-social::error_flash_var'), 'There was a problem connecting your account (2).'); } $provider = ucfirst($provider); try { $service = Social::service($provider); if (Config::get('laravel-social::providers.' . strtolower($provider) . '.offline')) { $service->setAccessType('offline'); } } catch (Exception $e) { App::abort(404); } if (2 === Social::oauthSpec($provider)) { return $this->oauth2Connect($provider, $service); } else { return $this->oauth1Connect($provider, $service); } }
function __construct($repository) { $this->_repository = $repository; $this->_className = $this->getClassName(); $this->_viewNames = (object) $this->_viewNames; $this->_defaultViews = (object) $this->_defaultViews; $this->_defaultViews->target = strtolower($this->_className); if ($this->_dataCollectionName === "") { $this->_dataCollectionName = "{$this->_defaultViews->target}s"; } // If there are Referer, store it; otherwise use the _target property // We will force the redirection to last Paged position (referer) or the first page (no referer) $this->_referer = Request::header('referer') ? Request::header('referer') : $this->_defaultViews->target; // Start the Audit data changed array $this->_auditoria = array('data' => array('target' => $this->_viewNames->singular, 'id' => null, 'before' => null, 'after' => null)); // Crudbase Ajax \Orchestra\Asset::add('crudbase_jquery', "vendor/wemersonrv/crudbase/js/crudbase-jquery.js"); }
public function __construct() { // store the current request's api key $public_key = Request::header('X-Remedy-Auth'); $this->apiKey = ApiKey::where('public_key', $public_key)->first(); }
/** * Retrieve a header from the request. * * @param string $key * @param mixed $default * @return string */ public function header($key = null, $default = null) { return parent::header($key, $default); }
public function meeting_points() { $auth_token = Request::header('Authorization'); $user = User::where('auth_token', '=', $auth_token)->first(); if ($user) { $data = file_get_contents('php://input'); $meetingPointsInput = (array) json_decode($data); if ($meetingPointsInput) { try { $sessionID = $meetingPointsInput['session_id']; $points = $meetingPointsInput['meeting_points']; $newPoints = $meetingPointsInput['new_meeting_points']; } catch (Exception $e) { $response = ['error' => 'Formato inválido: debe contener session_id, meeting_points, new_meeting_points.']; $status_code = 404; return Response::json($response, $status_code); } foreach ($points as $p) { $dbpoint = PuntoReunion::find($p->id); if ($dbpoint) { $point_event = PuntoEvento::getPuntosPorEventoXPunto($sessionID, $dbpoint->idpuntos_reunion)->first(); if ($point_event && !$p->selected) { $point_event->delete(); } else { if (!$point_event && $p->selected) { $point_event = PuntoEvento::getPuntosPorEventoXPuntoTrashed($sessionID, $dbpoint->idpuntos_reunion)->first(); if ($point_event) { $point_event->restore(); } else { $point_event = new PuntoEvento(); $point_event->idpuntos_reunion = $dbpoint->idpuntos_reunion; $point_event->ideventos = $sessionID; $point_event->save(); } } } } } foreach ($newPoints as $newPoint) { $point = new PuntoReunion(); $point->direccion = $newPoint->address; $point->latitud = $newPoint->latitude; $point->longitud = $newPoint->longitude; $point->save(); $point_event = new PuntoEvento(); $point_event->idpuntos_reunion = $point->idpuntos_reunion; $point_event->ideventos = $sessionID; $point_event->save(); } $dbpoints = PuntoReunion::all(); $responsepoints = []; foreach ($dbpoints as $dbp) { $points_element['id'] = $dbp->idpuntos_reunion; $points_element['address'] = $dbp->direccion; $points_element['latitude'] = (double) $dbp->latitud; $points_element['longitude'] = (double) $dbp->longitud; $point_event = PuntoEvento::getPuntosPorEventoXPunto($sessionID, $dbp->idpuntos_reunion)->first(); if ($point_event) { $points_element['selected'] = true; } else { $points_element['selected'] = false; } $responsepoints[] = $points_element; } return Response::json(['success' => 1, 'session_id' => $sessionID, 'meeting_points' => $responsepoints], 200); } else { $response = ['error' => 'Parámetro points inválido (vacío/formato JSON incorrecto).']; $status_code = 401; return Response::json($response, $status_code); } } $response = ['error' => 'Error en la autenticación.']; $status_code = 401; return Response::json($response, $status_code); }
public function activity_reports() { $auth_token = Request::header('Authorization'); $user = User::where('auth_token', '=', $auth_token)->first(); if ($user) { $responseReports = []; $reports = []; $allReports = false; $myReports = false; $actions = User::getPermisosPorUsuarioId($user->id)->get(); foreach ($actions as $a) { if ($a->idpermisos == 21) { $allReports = true; break; } } if ($allReports) { $reports = Documento::getDocumentosPorTipo(2)->get(); } else { foreach ($actions as $a) { if ($a->idpermisos == 39) { $myReports = true; break; } } if ($myReports) { $sponsor = Padrino::getPadrinoByUserId($user->id)->first(); if ($sponsor) { $reports = DocumentosPadrino::getDocumentoIdsByPadrino($sponsor->idpadrinos)->get(); } else { $response = ['error' => 'El usuario no tiene información de padrino registrada.']; $status_code = 200; return Response::json($response, $status_code); } } else { $response = ['error' => 'El usuario no tiene permiso para ver reportes.']; $status_code = 200; return Response::json($response, $status_code); } } foreach ($reports as $r) { $responseReports_element['id'] = $r->iddocumentos; $responseReports_element['name'] = $r->titulo; $responseReports_element['url'] = $r->ruta . $r->nombre_archivo; $responseReports_element['size'] = $r->peso . ' KB'; $from = new DateTime(); $from->setTimestamp(strtotime($r->created_at)); $to = new DateTime('today'); $dias = $from->diff($to)->d; $responseReports_element['upload_date'] = 'Hace ' . $dias . ' día' . ($dias != 1 ? 's' : '') . ', ' . date('h:i A', $from->getTimestamp()); $responseReports[] = $responseReports_element; } $response = $responseReports; $status_code = 200; return Response::json($response, $status_code); } $response = ['error' => 'Error en la autenticación.']; $status_code = 401; return Response::json($response, $status_code); }