Beispiel #1
1
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $pipe = $request->pipe;
     if ($pipe) {
         $finalServer = $this->resolver->resolve($pipe);
         if ($finalServer != $request->getHttpHost()) {
             return redirect(str_replace($request->getHttpHost(), $finalServer, $request->getUri()), 307);
         }
     }
     return $next($request);
 }
Beispiel #2
1
 /**
  * @param Request $request
  * @return \BladeView|bool|\Illuminate\Http\RedirectResponse|\Illuminate\View\View|\Symfony\Component\HttpFoundation\Response
  */
 public function authLogin(Request $request)
 {
     $authService = new authService();
     $host = explode('.', $request->getHttpHost());
     $role = $host[0];
     $email = $request->input('email', false);
     $password = $request->input('password', false);
     $postAjax = $request->ajax();
     try {
         $results = $authService->login($email, $password, $role);
         if (!$postAjax) {
             if ($results['ok']) {
                 return redirect()->intended('/');
             } else {
                 return view('auth.login', $results);
             }
         } else {
             return response()->json($results);
         }
     } catch (\Exception $e) {
         // @codeCoverageIgnoreStart
         $return['error'] = $e->getMessage();
         // @codeCoverageIgnoreEnd
     }
     return view('auth.login');
 }
Beispiel #3
1
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $host = preg_replace('"^\\w+://(www\\.)?"i', '', \Config::get('app.url'));
     $test = str_replace($host, '', $request->getHttpHost());
     preg_match("'^([^\\.]+)\\.\$'", $test, $m);
     static::subdomen(@$m[1]);
     return $next($request);
 }
Beispiel #4
1
 /**
  * This middleware forces the entire application to use SSL. We like that, because it's secure.
  *
  * Shamelessly copied from: http://stackoverflow.com/questions/28402726/laravel-5-redirect-to-https
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $force = env('FORCE_DOMAIN', null);
     if ($force != null && $request->getHttpHost() != $force) {
         return redirect()->to(env('APP_URL') . '/' . ($request->path() == '/' ? '' : $request->path()));
     }
     return $next($request);
 }
Beispiel #5
1
 /**
  * Handle an incoming request.
  *
  * The following filter simply retrieves the current account based on the request information
  * and then sets this value for future retrieval. If no account can be found for the request,
  * then two things need to happen:
  *
  * 1. Check to see if ANY accounts have been configured if no accounts exist then
  * 2. Ask the user if they'd like to setup the default (first) account. This is required
  *    for new installations.
  * 3. If an account does exist but does not match the domain, then we throw an account
  *    not found exception and deal with that later.
  *
  * @throws AccountNotFoundException
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $account = CurrentAccount::determine($request->getHttpHost());
     if (!$account) {
         $count = $this->accountService->totalNumberOfAccounts();
         if ($count === 0) {
             return redirect()->route('install');
         }
         throw new AccountNotFoundException();
     }
     CurrentAccount::set($account);
     return $next($request);
 }
 /**
  * Resolve locale using domain name
  *
  * @return mixed
  */
 public function resolve()
 {
     $httpHost = $this->request->getHttpHost();
     $domains = explode('.', $httpHost);
     $level = config('localizer.domain.level', 3);
     return ($total = count($domains)) >= $level ? $domains[$total - $level] : null;
 }
Beispiel #7
0
 /**
  * Returns an URL adapted to locale
  *
  * @param  string $locale
  * @return string
  */
 private function localizedURL($locale)
 {
     // Default language doesn't get a special subdomain
     $locale = $locale !== $this->defaultLocale ? strtolower($locale) . '.' : '';
     // URL elements
     $uri = $this->request->getRequestUri();
     $scheme = $this->request->getScheme();
     // Get host
     $array = explode('.', $this->request->getHttpHost());
     $host = (array_key_exists(count($array) - 2, $array) ? $array[count($array) - 2] : '') . '.' . $array[count($array) - 1];
     // Create URL from template
     $url = str_replace(['[scheme]', '[locale]', '[host]', '[uri]'], [$scheme, $locale, $host, $uri], $this->config['locale_url']);
     return url($url);
 }
Beispiel #8
0
 public function setRequestData(\App\Action $action, \Illuminate\Http\Request $request)
 {
     if (!$action->app) {
         $action->app = $request->getHttpHost();
     }
     if (!$action->http_referrer_raw) {
         $action->http_referrer_raw = $request->header('Referer');
     }
     if (!$action->user_agent_raw) {
         $action->user_agent_raw = $request->header('User-Agent');
     }
     if (!$action->ip) {
         // TODO make sure this accounts for CDNs/proxies
         $action->ip = $request->ip();
     }
     // TODO location
 }
Beispiel #9
0
 /**
  * Returns an URL adapted to $locale
  *
  * @throws SupportedLocalesNotDefined
  * @throws UnsupportedLocaleException
  *
  * @param  string|boolean $locale     Locale to adapt, false to remove locale
  * @param  string|false   $url        URL to adapt in the current language. If not passed, the current url would be
  *                                    taken.
  * @param  array          $attributes Attributes to add to the route, if empty, the system would try to extract
  *                                    them from the url.
  *
  *
  * @return string|false                URL translated, False if url does not exist
  */
 public function getLocalizedURL($locale = null, $url = null, $attributes = [])
 {
     // Use default if not set
     if ($locale === null) {
         $locale = $this->getCurrentLocale();
     }
     // Get request Uri
     if (empty($url)) {
         $url = $this->request->getRequestUri();
     } else {
         $parts = parse_url($url);
         $url = $parts['path'] . (isset($parts['query']) ? '?' . $parts['query'] : '');
     }
     $scheme = $this->request->getScheme();
     $locale = $locale && $locale !== $this->getDefaultLocale() ? "{$locale}." : '';
     // Get host
     $array = explode('.', $this->request->getHttpHost());
     $host = (array_key_exists(count($array) - 2, $array) ? $array[count($array) - 2] : '') . '.' . $array[count($array) - 1];
     return app('url')->to("{$scheme}://{$locale}{$host}{$url}", $attributes);
 }
Beispiel #10
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if ($this->auth->guest()) {
         if ($request->ajax()) {
             return response('Unauthorized.', 401);
         } else {
             return redirect()->guest('auth/login');
         }
     } else {
         $host = explode('.', $request->getHttpHost());
         $role = $host[0];
         $user = $this->auth->user();
         if ($role == KACANA_USER_ROLE_ADMIN && $user->role == KACANA_USER_ROLE_ADMIN || $role == KACANA_USER_ROLE_PARTNER && $user->role == KACANA_USER_ROLE_PARTNER || $role != KACANA_USER_ROLE_PARTNER && $role != KACANA_USER_ROLE_ADMIN) {
             return $next($request);
         } else {
             \Auth::logout();
             return redirect()->to('auth/login')->with('__error_code_login_one_check__', KACANA_AUTH_LOGIN_ERROR_NOT_PERMISSION);
         }
     }
 }
Beispiel #11
0
 /**
  * @param Request $request
  * @return \BladeView|bool|\Illuminate\Http\RedirectResponse|\Illuminate\View\View|\Symfony\Component\HttpFoundation\Response
  */
 public function signup(Request $request)
 {
     $authService = new authService();
     $emailService = new mailService();
     $name = $request->input('name', '');
     $email = $request->input('email', '');
     $phone = $request->input('phone', '');
     $password = $request->input('password', '');
     $confirmPassword = $request->input('confirmPassword', '');
     $postAjax = $request->ajax();
     $host = explode('.', $request->getHttpHost());
     $roleLink = $host[0];
     try {
         if ($request->isMethod('post')) {
             $results = $authService->signup($name, $email, $phone, $password, $confirmPassword);
             if ($results['ok']) {
                 $user = $results['data'];
                 if ($roleLink != KACANA_AUTH_ADMIN_NAME) {
                     \Auth::loginUsingId($user->id, true);
                 }
                 $emailService->sendEmailNewUser($email);
             }
             if ($postAjax) {
                 return response()->json($results);
             } else {
                 if ($results['ok']) {
                     return redirect()->intended('/');
                 } else {
                     return view('auth.signup', $results);
                 }
             }
         }
     } catch (\Exception $e) {
         // @codeCoverageIgnoreStart
         $return['error'] = $e->getMessage();
         // @codeCoverageIgnoreEnd
     }
     return view('auth.signup');
 }
Beispiel #12
0
 /**
  * Returns the HTTP host being requested.
  * 
  * The port name will be appended to the host if it's non-standard.
  *
  * @return string 
  * @static 
  */
 public static function getHttpHost()
 {
     //Method inherited from \Symfony\Component\HttpFoundation\Request
     return \Illuminate\Http\Request::getHttpHost();
 }
 /**
  * Get top level domain.
  *
  * @return string
  */
 public function getTld()
 {
     return substr(strrchr($this->request->getHttpHost(), '.'), 0);
 }