/** * Creates the view object for the HTML client. * * @param \Aimeos\MW\Config\Iface $config Configuration object * @param array $templatePaths List of base path names with relative template paths as key/value pairs * @param string|null $locale Code of the current language or null for no translation * @return \Aimeos\MW\View\Iface View object */ public function create(\Aimeos\MW\Config\Iface $config, array $templatePaths, $locale = null) { $params = $fixed = array(); if ($locale !== null) { $params = Route::current()->parameters() + Input::all(); $fixed = $this->getFixedParams(); $i18n = app('\\Aimeos\\Shop\\Base\\I18n')->get(array($locale)); $translation = $i18n[$locale]; } else { $translation = new \Aimeos\MW\Translation\None('en'); } $view = new \Aimeos\MW\View\Standard($templatePaths); $helper = new \Aimeos\MW\View\Helper\Translate\Standard($view, $translation); $view->addHelper('translate', $helper); $helper = new \Aimeos\MW\View\Helper\Url\Laravel5($view, app('url'), $fixed); $view->addHelper('url', $helper); $helper = new \Aimeos\MW\View\Helper\Param\Standard($view, $params); $view->addHelper('param', $helper); $helper = new \Aimeos\MW\View\Helper\Config\Standard($view, $config); $view->addHelper('config', $helper); $sepDec = $config->get('client/html/common/format/seperatorDecimal', '.'); $sep1000 = $config->get('client/html/common/format/seperator1000', ' '); $helper = new \Aimeos\MW\View\Helper\Number\Standard($view, $sepDec, $sep1000); $view->addHelper('number', $helper); $helper = new \Aimeos\MW\View\Helper\Request\Laravel5($view, Request::instance()); $view->addHelper('request', $helper); $helper = new \Aimeos\MW\View\Helper\Csrf\Standard($view, '_token', csrf_token()); $view->addHelper('csrf', $helper); return $view; }
public static function validateRoute() { $route = Route::current(); $route_name = $route->getName(); if (!$route_name) { $route_name = $route->getActionName(); } $params = $route->parametersWithoutNulls(); $ids = []; if ($params) { $param = current($params); if (is_numeric($param)) { $ids[] = $param; } } $result = AclFacade::check($route_name, $ids); if (!$result) { $error_message = "No Permission for {$route_name}"; if ($ids) { $error_message .= " for id: {$ids[0]}"; } throw new NoPermissionsException($error_message); } return $result; }
function __construct() { // share current route in all views View::share('current_url', Route::current()->getPath()); // share current logged in user details all views View::share('current_user', $this->current_user()); }
/** * Handle an incoming request. * This Middleware checks for a 'tailnumber' parameter and converts it to all uppercase if it exists. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @param String $permission * @param String $enforce_same_crew * @return mixed */ public function handle($request, Closure $next) { if (Route::current()->hasParameter('tailnumber')) { Route::current()->setParameter('tailnumber', strtoupper(Route::current()->getParameter('tailnumber'))); } return $next($request); }
/** * Controller constructor * * @param jsonRPCClient $bitcoin_core * @param ZebraCURL $curl * @return void */ public function __construct(jsonRPCClient $bitcoin_core, ZebraCURL $curl) { $this->curl = $curl; $this->bitcoin_core = $bitcoin_core; if ($guid = Route::current()->getParameter('guid')) { $this->user = $this->attemptAuth($guid); $this->bitcoin_core->setRpcConnection($this->user->rpc_connection); } }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $group = Route::current()->parameter('groups'); $user = Auth::user(); if ($user->id != $group->owner->id) { flash()->error('Unauthorised Request'); return redirect()->action('UsersController@show', [$user->profile_link]); } return $next($request); }
public static function routeinfo() { $route = Route::current(); if (preg_match("/\\//", $route->uri())) { list($action) = explode('/', $route->uri()); } elseif ('/' === $route->uri()) { $action = 'home'; } else { $action = $route->uri(); } return (object) ['action' => $action, 'params' => $route->parameters(), 'uri' => $route->uri()]; }
private function updateRole(Request $request, User $user) { $validator = Validator::make($request->all(), ['role' => 'required']); if ($validator->fails()) { return redirect(route(Route::currentRouteName()))->withErrors($validator->errors()); } else { $user->update($request->all()); Session::flash('success', "Le profil utilisateur a bien été mis à jour."); } if ($param = Route::current()->getParameter('id')) { return redirect()->route(Route::currentRouteName(), $param); } return redirect()->route(Route::currentRouteName()); }
public static function routeinfo() { $route = Route::current(); if (preg_match("/conferences\\/\\{year\\?\\}\\/\\{conference\\?\\}/i", $route->uri()) && count($route->parameters()) > 0) { $action = 'conference'; } elseif (preg_match("/\\/(.+)/", $route->uri())) { list($action) = explode('/', $route->uri()); } elseif ('/' === $route->uri()) { $action = 'home'; } else { $action = $route->uri(); } // dd((object)['action' => $action, 'params' => $route->parameters(), 'uri' => $route->uri()]); return (object) ['action' => $action, 'params' => $route->parameters(), 'uri' => $route->uri()]; }
/** * Checks if the user with the given ID is in the specified group * * @param string $userid Unique user ID * @param string|array $groupcodes Unique user/customer group codes that are allowed * @return boolean True if user is part of the group, false if not */ public function checkGroup($userid, $groupcodes) { $site = Route::current() ? Route::input('site', Input::get('site', 'default')) : 'default'; $context = $this->context->get(false); $context->setLocale($this->locale->getBackend($context, $site)); $manager = \Aimeos\MShop\Factory::createManager($context, 'customer/group'); $search = $manager->createSearch(); $search->setConditions($search->compare('==', 'customer.group.code', (array) $groupcodes)); $groupItems = $manager->searchItems($search); $manager = \Aimeos\MShop\Factory::createManager($context, 'customer/lists'); $search = $manager->createSearch(); $expr = array($search->compare('==', 'customer.lists.parentid', $userid), $search->compare('==', 'customer.lists.refid', array_keys($groupItems)), $search->compare('==', 'customer.lists.domain', 'customer/group')); $search->setConditions($search->combine('&&', $expr)); $search->setSlice(0, 1); return (bool) count($manager->searchItems($search)); }
/** * Returns the current auth type set via route or the default value * * @return string * @throws \Exception */ public function currentType() { if (Route::current()) { $action = Route::current()->getAction(); if (isset($action['auth'])) { $actionAuth = $action['auth']; if (is_array($actionAuth)) { return end($actionAuth); } return $actionAuth; } } if ($this->app['config']['auth.default'] === null) { throw new \Exception('No auth name given and no default setting for MultiAuth found!'); } return $this->app['config']['auth.default']; }
/** * 找回密码 * @param [type] $p3 找回密码类型 - employee , agency * @return [type] [description] */ public function forget($p3 = null) { $email = rq('email'); $ins = Route::current()->parameter('p3'); $row = M($ins)->where('email', $email)->first(); if ($row) { // 发送邮件 $hash = hash_password($row->email . time()); Mail::send('emails.reminder', ['user' => $row, 'hash' => $hash], function ($m) use($row) { $m->to($row->email, $row->name)->subject('密码重置'); }); // 发送log Event::fire(new LogEvent('reminder', 'auth', ['type' => $ins, 'user' => $row, 'hash' => $hash])); return ss('邮件已发送'); } else { return ss('无相关用户', 0); } }
/** * Using service container in constructor to instantiate a class * * @param Article $article */ public function __construct(Article $article) { $this->article = $article; $this->blog = AdminFunctionType::where('code', 'blog')->select('admin_function_type_id')->first(); $this->destinationPath = 'uploads'; if (Auth::user() != "") { $this->user = Auth::user(); } else { $this->route_parameter = Route::current()->parameters(); $this->user = User::findOrFail($this->route_parameter['user_id']); } $this->categories = $this->user->categories()->orderBy('name')->get(); $this->article_index_url = 'admin/article'; foreach ($this->categories as $category) { $this->article_amount[$category->category_id] = $category->articles()->count(); $this->total += $category->articles()->count(); } $this->article_amount['total'] = $this->total; }
/** * Handle an incoming request. * This Middleware checks the current user's Permissions array for $permission. * If this user has the specified $permission, let them through. * Otherwise, redirect to the main page. * * The optional 2nd argument determines whether or not to require that this user * has the same crew_id as the page being requested. * i.e. When $enforce_same_crew is TRUE, a user with crew_id=2 cannot access /crews/1/status * * NOTE * Users with the 'global_admin' permission will ALWAYS be allowed through this middleware. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @param String $permission * @param String $enforce_same_crew * @return mixed */ public function handle($request, Closure $next, $permission, $enforce_same_crew = false) { // Convert $enforce_same_crew from a string to a boolean // The case-insensitive string "true" is converted to boolean TRUE. // Any other string value is converted to boolean FALSE. $enforce_same_crew = $enforce_same_crew === strtolower('true'); // Filter and redirect if ($request->user()->isGlobalAdmin()) { // Do not redirect - this user will be allowed through } elseif (!$request->user()->hasPermission($permission)) { // This user did not have the $permission string in his User.permissions array return redirect()->back(); } elseif ($enforce_same_crew && Route::current()->getParameter('id') != $request->user()->crew_id) { // This user's crew_id does not match the crew_id of the requested page (AND the $enforce_same_crew flag was set to TRUE) return redirect()->back()->withErrors("You can't change data that belongs to a different crew"); } // $request->session()->flash('perms',$permission); // Debugging output return $next($request); }
private function saveProduct(Request $request, Product $product) { $validator = Product::validate($request->all()); if ($validator->fails()) { return redirect(route(Route::currentRouteName()))->withErrors($validator->errors()); } else { if (!is_null($product->id)) { $product->update($request->all()); Session::flash('success', "Le produit a bien été mis à jour."); } else { $product->fill($request->all()); $product->save(); Session::flash('success', "Le produit a bien été crée."); } } if ($param = Route::current()->getParameter('id')) { return redirect()->route(Route::currentRouteName(), $param); } return redirect()->route(Route::currentRouteName()); }
/** * Current route link * * @param array $get_params * @return string */ public static function getCurrentRouteLink($get_params = []) { $current_action = \Illuminate\Support\Facades\Route::current()->getAction(); $controller = '\\' . $current_action['controller']; $parameters = \Illuminate\Support\Facades\Route::current()->parameters(); return action($controller, $parameters) . ($get_params ? '?' . http_build_query($get_params) : ''); }
public function rightsFilter($user, \Illuminate\Routing\Route $route) { $this->action = $route->getName(); return Permission::check($user, $this->action, Route::current()->parameters()); }
function __construct() { // share current route in all views View::share('current_url', Route::current()->getPath()); }
protected function isActive($route_name) { $l = strlen('platform.admin.' . $route_name); return 'platform.admin.' . $route_name == substr(Route::current()->getName(), 0, $l); }
/** * Adds the "url" helper to the view object * * @param \Aimeos\MW\View\Iface $view View object * @return \Aimeos\MW\View\Iface Modified view object */ protected function addUrl(\Aimeos\MW\View\Iface $view) { $fixed = array(); if (Route::current()) { if (($value = Route::input('site')) !== null) { $fixed['site'] = $value; } if (($value = Route::input('locale')) !== null) { $fixed['locale'] = $value; } if (($value = Route::input('currency')) !== null) { $fixed['currency'] = $value; } } $helper = new \Aimeos\MW\View\Helper\Url\Laravel5($view, app('url'), $fixed); $view->addHelper('url', $helper); return $view; }
/** * [getUrlActual description] * @return [type] [description] */ protected function getUrlActual() { $routes = Route::current()->getCompiled()->getStaticPrefix(); return $routes; }
public static function isActive($item) { if (!is_null($item->route)) { return Route::current()->getName() == $item->route; } if (!is_null($item->action)) { return Route::current()->getActionName() == $item->action; } if (!is_null($item->url)) { $currentPath = trim(Request::path(), '/'); $path = trim(parse_url($item->url, PHP_URL_PATH), '/'); return starts_with($currentPath, $path); } return false; }
/** * Redirect to page 1 if the paginator is empty. * @param \Illuminate\Pagination\LengthAwarePaginator $paginator * @return \Illuminate\Support\Facades\Redirect */ protected function checkPagination(LengthAwarePaginator $paginator) { if ($paginator->count() == 0 && !is_null(Input::get('page')) && (int) Input::get('page') != 1) { App::abort(Response::HTTP_TEMPORARY_REDIRECT, '', ['Location' => route(Route::current()->getName(), Input::except('page') + ['page' => 1])]); } }
/** * @access public * @return \Illuminate\Support\Facades\View */ public function showRecord() { // get parameters from url route $parameters = $this->request->route()->parameters(); $parameters['urlParameters'] = $parameters; // check if create route has modal // is necessary to have modal paramenter in all routes for proper operation if (Route::current()->hasParameter('modal')) { // check if this element is modal, to mark in your url petition if (isset($parameters['modal']) && $parameters['modal'] == 1) { $parameters['urlParameters']['modal'] = 1; } else { $parameters['urlParameters']['modal'] = 0; } } // set path variable to save in cookie, search param datatable component, // after creating urlParameters to don't send value, to URL create $parameters['path'] = $this->request->path(); $parameters['resource'] = $this->resource; $parameters['action'] = 'show'; $parameters['package'] = $this->package; $parameters['folder'] = $this->folder; $parameters['routeSuffix'] = $this->routeSuffix; $parameters['icon'] = $this->icon; $parameters['objectTrans'] = isset($this->objectTrans) && $this->objectTrans != null ? Miscellaneous::getObjectTransValue($parameters, $this->objectTrans) : null; // check if object has multiple language if (isset($parameters['lang'])) { $parameters['object'] = call_user_func($this->model . '::getTranslationRecord', ['id' => $parameters['id'], 'lang' => $parameters['lang']]); $parameters['lang'] = $parameters['object']->lang; } else { // check if is implements getRecord function in model, for objects with joins if (method_exists($this->model, 'getRecord')) { $parameters['object'] = call_user_func($this->model . '::getRecord', $parameters); } else { $parameters['object'] = call_user_func($this->model . '::builder')->find($parameters['id']); } } $parameters = $this->showCustomRecord($parameters); if (is_object($parameters) && get_class($parameters) == \Illuminate\Http\RedirectResponse::class) { return $parameters; } // check if response is json format or not if (isset($parameters['api']) && $parameters['api']) { return response()->json($parameters['object']); } // set viewParamentes on parameters for throw to view $parameters['viewParameters'] = $this->viewParameters; // check if exist show view, default all request go to form view if (view()->exists($this->package . '::' . $this->folder . '.show', $parameters)) { return view($this->package . '::' . $this->folder . '.show', $parameters); } else { return view($this->package . '::' . $this->folder . '.form', $parameters); } }
/** * Get permission id or null * * @return int|null */ protected function getPermissionId() { try { return (int) Route::current()->parameters()['permission']; } catch (\Exception $e) { return null; } }
/** * Current route link * * @param array $get_params * @return string */ public static function getCurrentRouteLink($get_params = []) { $current_action = \Illuminate\Support\Facades\Route::current()->getAction(); $controller = $current_action['controller']; $namespace = $current_action['namespace']; $parameters = \Illuminate\Support\Facades\Route::current()->parameters(); $controller_namespace_stripped = trim(str_replace($namespace, '', $controller), '\\'); return action($controller_namespace_stripped, $parameters) . ($get_params ? '?' . http_build_query($get_params) : ''); }
public function createMenuItem($title, $action, $parameters = null, $sub = null, $active = false) { $item = new \stdClass(); $item->title = $title; if (null == $action) { $item->active = $active; $item->url = null; } elseif (Permission::check($this->user, $action, $parameters)) { // $item->url = URL::action($action); if (Route::current()->getName() == $action) { $item->active = true; } else { $item->active = false; } } else { //此用户无权限 return null; } $item->submenu = $sub; return $item; }
/** * Returns the locale item for the current request * * @param \Aimeos\MShop\Context\Item\Iface $context Context object * @return \Aimeos\MShop\Locale\Item\Iface Locale item object */ protected function getLocale(\Aimeos\MShop\Context\Item\Iface $context) { if ($this->locale === null) { if (Route::current() !== null) { $site = Route::input('site', 'default'); $lang = Route::input('locale', ''); $currency = Route::input('currency', ''); } else { $site = 'default'; $lang = $currency = ''; } $disableSites = $this->config->has('shop.disableSites'); $localeManager = \Aimeos\MShop\Locale\Manager\Factory::createManager($context); $this->locale = $localeManager->bootstrap($site, $lang, $currency, $disableSites); } return $this->locale; }
/** * Returns current controller action * * @return string */ protected function getAction() { return Route::current()->getParameter('action') ? Route::current()->getParameter('action') : 'index'; }