/** * @param none * @throws none * @returns void */ public function before() { $result = array(); // users need to be logged in to access this controller if (!\Sentry::check()) { $result = array('message' => 'You need to be logged in to access that page.', 'url' => '/admin/login'); // Don't show this message if url is just 'admin' if (\Uri::string() == 'admin/admin/index') { unset($result['message']); } \Session::set('redirect_to', \Uri::admin('current')); } else { if (!\Sentry::user()->is_admin()) { $result = array('message' => 'Access denied. You need to be a member of staff to access that page.', 'url' => '/admin/login'); \Session::set('redirect_to', \Uri::admin('current')); } } if (!empty($result)) { if (\Input::is_ajax()) { \Messages::error('You need to be logged in to complete this action.'); echo \Messages::display('left', false); exit; } else { if (isset($result['message'])) { \Messages::warning($result['message']); } \Response::redirect($result['url']); } } parent::before(); }
public function action_update() { // If not logged in redirect to home if (!\Auth::check()) { \Messages::info(__('user.login.not-logged')); \Response::redirect_back(); } // was the login form posted? if (\Input::method() == 'POST') { // check the credentials. if (\Auth::instance()->validate_user(\Auth::get_email(), \Input::param('password'))) { if (\Input::param('new_password') === \Input::param('confirm_password')) { \Auth::change_password(\Input::param('password'), \Input::param('new_password')); // inform the user the password change was successful \Messages::success(__('user.login.changed')); \Response::redirect_back(); } \Messages::warning(__('user.login.mismatch-password')); } else { // login failed, show an error message \Messages::error(__('user.login.bad-password')); } \Response::redirect_back('/backend/account/index/password'); } // display the password reset page $this->template->content = View::forge('user/password/update'); }
/** * Function for easy update a ORM object * * @param ORM $object ORM object to update * @param array $messages Array of custom messages */ public function update(ORM $object, array $messages = array()) { // Check if is a valid object if (!$object->loaded()) { Messages::warning(isset($messages['warning']) ? $messages['warning'] : 'El elemento que intentas modificar no existe o fue eliminado.'); $this->go(); } // Only if Request is POST if ($this->request->method() == Request::POST) { // Catch ORM_Validation try { // Set object values and update $object->values($this->request->post())->update(); // If object is saved.... if ($object->saved()) { // Success message & redirect Messages::success(isset($messages['success']) ? $messages['success'] : 'El elemento fue modificado correctamente.'); $this->go(); } } catch (ORM_Validation_Exception $e) { // Error message if (isset($messages['error'])) { Messages::error($messages['error']); } // Validation messages Messages::validation($e); } } }
function show(Airline $airline) { $activeFlights = $airline->flights()->whereIn('state', [0, 1, 3, 4])->join('pilots', 'flights.vatsim_id', '=', 'pilots.vatsim_id')->with(['departure' => function ($departure) { $departure->remember(15); }, 'arrival' => function ($arrival) { $arrival->remember(15); }])->select('flights.*', 'pilots.name')->orderBy('departure_time', 'desc')->remember(15)->get(); $historicFlights = $airline->flights()->whereState(2)->join('pilots', 'flights.vatsim_id', '=', 'pilots.vatsim_id')->with(['departure' => function ($departure) { $departure->remember(15); }, 'arrival' => function ($arrival) { $arrival->remember(15); }])->select('flights.*', 'pilots.name')->orderBy('departure_time', 'desc')->take(25)->remember(15)->get(); if ($airline->duration == 0) { $airline->duration = $airline->flights()->whereState(2)->remember(120)->sum('duration'); $airline->save(); } if ($airline->duration > 0) { $pilots = $airline->flights()->whereState(2)->leftJoin('pilots', 'flights.vatsim_id', '=', 'pilots.vatsim_id')->select('pilots.*', DB::raw('SUM(flights.duration) AS duration'))->orderBy('duration', 'desc')->groupBy('flights.vatsim_id')->take(5)->remember(120)->get()->transform(function ($pilot) use($airline) { return array('name' => $pilot->name, 'duration' => $pilot->duration, 'percent' => number_format($pilot->duration / $airline->duration * 100, 1)); }); $pilots->add(array('name' => 'Others', 'duration' => $airline->duration - $pilots->sum('duration'), 'percent' => number_format(($airline->duration - $pilots->sum('duration')) / $airline->duration * 100, 1))); $pilots = $pilots->toArray(); foreach ($pilots as &$pilot) { $pilot = array($pilot['name'], $pilot['duration']); } $aircraft = $airline->flights()->whereState(2)->whereNotNull('aircraft_id')->where('aircraft_id', '!=', '')->with(['aircraft' => function ($aircraft) { $aircraft->remember(120); }])->select('aircraft_id', DB::raw('SUM(duration) AS duration'))->orderBy('duration', 'desc')->groupBy('aircraft_id')->take(5)->remember(120)->get()->transform(function ($aircraft) use($airline) { return array('name' => $aircraft->aircraft->implode('name', '<br />'), 'duration' => $aircraft->duration, 'percent' => number_format($aircraft->duration / $airline->duration * 100, 1)); }); $aircraft->add(array('name' => 'Other', 'duration' => $airline->duration - $aircraft->sum('duration'), 'percent' => number_format(($airline->duration - $aircraft->sum('duration')) / $airline->duration * 100, 1))); $aircraft = $aircraft->toArray(); foreach ($aircraft as &$airplane) { $airplane = array($airplane['name'], $airplane['duration']); } } else { $pilots = array(); $aircraft = array(); } $pilots = piechartData($pilots)['javascript']; $aircraft = piechartData($aircraft)['javascript']; if (!in_array($airline->icao, Cache::get('legacy.airlines', []))) { Queue::push('LegacyUpdateAirline', array('airline' => $airline->icao), 'legacy'); Messages::warning('Data for this airline may be missing. It is being processed by year. Depending on the popularity of the airline, it could take minutes to hours before it is done.')->one(); } $this->javascript('assets/javascript/jquery.flot.min.js'); $this->javascript('assets/javascript/jquery.flot.pie.min.js'); $this->autoRender(compact('airline', 'historicFlights', 'pilots', 'aircraft', 'activeFlights'), $airline->icao . ' - ' . $airline->name); }
public function before() { parent::before(); // Get action, module and controller name $this->actionName = \Request::active()->action; $this->moduleName = \Request::active()->module; $this->controllerName = strtolower(str_replace('Controller_', '', \Request::active()->controller)); $this->controllerName = str_replace($this->moduleName . '\\', '', $this->controllerName); // Check Auth Access if (!\Auth::check()) { \Messages::warning(__('user.login.not-logged')); // \Response::redirect('user/service/index/login'); } $this->template->title = "RN | Admin"; }
public function before() { parent::before(); // Get action, module and controller name $this->actionName = \Request::active()->action; $this->moduleName = \Request::active()->module; $this->controllerName = strtolower(str_replace('Controller_', '', \Request::active()->controller)); $this->controllerName = str_replace($this->moduleName . '\\', '', $this->controllerName); // Check Auth Access if (!\Auth::check()) { \Messages::warning(__('user.login.not-logged')); \Response::redirect('user/service/index/login'); } $this->_user = Model_User::find($this->_userId); // Set Navigation $this->template->title = "RN | Wall Street Journal"; // Set global $this->dataGlobal['title'] = \Config::get('application.seo.backend.title'); }
public function action_social_disconnect($provider) { // we have a UID and logged in? Just attach this authentication to a user if (\Auth::check()) { list(, $user_id) = \Auth::instance()->get_user_id(); $entry = Model_Users_Providers::query()->where('parent_id', $user_id)->and_where_open()->where('provider', $provider)->and_where_close()->get_one(); if ($entry) { $entry->delete(); // attachment went ok so we'll redirect Messages::success('Social Media Account Unlinked'); Response::redirect_back(); } else { Messages::warning('Social Mediea Account not found'); Response::redirect_back(); } } return false; }