Esempio n. 1
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @param  string|null  $guard
  * @return mixed
  */
 public function handle($request, Closure $next, $guard = null)
 {
     if ($this->auth->guard($guard)->guest()) {
         return response()->json(['success' => false, 'errors' => ['Your token is invalid']], 400);
     }
     return $next($request);
 }
Esempio n. 2
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @param  string|null  $guard
  * @return mixed
  */
 public function handle($request, Closure $next, $guard = null)
 {
     if ($this->auth->guard($guard)->guest()) {
         return response('Unauthorized.', 401);
     }
     return $next($request);
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @param  string|null  $guard
  * @return mixed
  */
 public function handle($request, Closure $next, $guard = null)
 {
     if ($this->auth->guard($guard)->guest()) {
         return response(['success' => false, 'message' => 'Unauthorized.']);
     }
     return $next($request);
 }
Esempio n. 4
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @param  string|null  $guard
  * @return mixed
  */
 public function handle($request, Closure $next, $guard = null)
 {
     if ($this->auth->guard($guard)->guest()) {
         return redirect('login');
     }
     return $next($request);
 }
Esempio n. 5
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @param  string|null  $guard
  * @return mixed
  */
 public function handle($request, Closure $next, $guard = null)
 {
     if ($this->auth->guard($guard)->guest()) {
         throw new UnauthorizedHttpException('Authorization');
     }
     return $next($request);
 }
Esempio n. 6
0
 /**
  * Determine if the user is logged in to any of the given guards.
  *
  * @param  array  $guards
  * @return void
  *
  * @throws \Illuminate\Auth\AuthenticationException
  */
 protected function authenticate(array $guards)
 {
     if (empty($guards)) {
         return $this->auth->authenticate();
     }
     foreach ($guards as $guard) {
         if ($this->auth->guard($guard)->check()) {
             return $this->auth->shouldUse($guard);
         }
     }
     throw new AuthenticationException('Unauthenticated.', $guards);
 }
Esempio n. 7
0
 /**
  * Determine if the user is logged in to any of the given guards.
  *
  * @param  array  $guards
  * @return void
  *
  * @throws \Illuminate\Auth\AuthenticationException
  */
 protected function authenticate(array $guards)
 {
     if (count($guards) <= 1) {
         $this->auth->guard(array_first($guards))->authenticate();
         return $this->auth->shouldUse($guard);
     }
     foreach ($guards as $guard) {
         if ($this->auth->guard($guard)->check()) {
             return $this->auth->shouldUse($guard);
         }
     }
     throw new AuthenticationException();
 }
Esempio n. 8
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @param  string|null  $guard
  * @return mixed
  */
 public function handle($request, Closure $next, $guard = null)
 {
     if ($guard === '*') {
         $guard = null;
         $defaultGuard = $this->auth->guard();
         if ($defaultGuard instanceof UniversalGuard) {
             $guard = $defaultGuard->universalUserLogin($this->auth);
         }
     }
     if ($guard === false || $this->auth->guard($guard)->guest()) {
         return response('Unauthorized.', 401);
     }
     if ($guard !== null) {
         $this->auth->setDefaultDriver($guard);
     }
     return $next($request);
 }
 /**
  * Boot the authentication services for the application.
  *
  * @return void
  */
 public function boot()
 {
     // Here you may define how you wish users to be authenticated for your Lumen
     // application. The callback which receives the incoming request instance
     // should return either a User instance or null. You're free to obtain
     // the User instance via an API token or any other method necessary.
     $this->app['auth']->viaRequest('api', function ($request) {
         try {
             if (!($user = $this->auth->user())) {
                 return null;
             }
         } catch (Exception $e) {
             return null;
         }
         return $user;
     });
 }
Esempio n. 10
0
 /**
  * Login In User
  *
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function authenticate(Request $request)
 {
     $validator = $this->getValidationFactory()->make($request->toArray(), ['credential' => 'required', 'password' => 'required|min:6']);
     if ($validator->fails()) {
         return response()->json(['error' => $validator->errors()]);
     }
     $field = filter_var($request->input('credential'), FILTER_VALIDATE_EMAIL) ? 'email' : 'username';
     $request->merge([$field => $request->input('credential')]);
     if (!$this->auth->attempt($request->only($field, 'password'))) {
         return response()->json(['error' => 'invalid_username_or_password']);
     }
     dispatch(new GenerateTokenJob($this->auth->user(), true));
     /** @var User $user */
     $user = $this->auth->user()->load('codes', 'codes.product', 'codes.product.extras', 'codes.product.profile');
     /**
      * inject product combination if not admin
      */
     $this->injectProductCombo($user);
     /**
      * Give all Products to admins
      */
     $this->adminFunction($user);
     return response()->json($user);
 }
 public function logout(Auth $auth)
 {
     $auth->guard($this->getAttribute('guard'))->logout();
     return redirect('/' . $this->getAttribute('guard'));
 }
Esempio n. 12
0
 public function logout(Auth $auth)
 {
     $auth->guard($this->guard)->logout();
     return redirect('/user');
 }
Esempio n. 13
0
 /**
  * Display Generator Page
  */
 public function logout()
 {
     $this->auth->logout();
     return redirect()->route('login');
 }
Esempio n. 14
0
 /**
  * @inheritdoc
  */
 public function universalUserLogin(AuthFactory $auth)
 {
     try {
         $guard = Authorizer::getResourceOwnerType();
     } catch (\Exception $e) {
         $guard = null;
     }
     if ($guard === null) {
         return false;
     }
     $user = $auth->guard($guard)->user();
     if ($user === null) {
         $guard = false;
     }
     return $guard;
 }
 /**
  * Create a new filter instance.
  *
  * @param  AuthFactory $auth
  */
 public function __construct(AuthFactory $auth)
 {
     $this->guard = $auth->guard('backend');
 }
Esempio n. 16
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @param  string  $ability
  * @param  array|null  $models
  * @return mixed
  *
  * @throws \Illuminate\Auth\AuthenticationException
  * @throws \Illuminate\Auth\Access\AuthorizationException
  */
 public function handle($request, Closure $next, $ability, ...$models)
 {
     $this->auth->authenticate();
     $this->gate->authorize($ability, $this->getGateArguments($request, $models));
     return $next($request);
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @param  string|null  $guard
  * @return mixed
  */
 public function handle($request, Closure $next, $guard = null)
 {
     return $this->auth->guard($guard)->basic() ?: $next($request);
 }
 public function logout(Auth $auth)
 {
     $auth->guard($this->guard)->logout();
     return redirect($this->redirectAfterLogout);
 }
 /**
  * Log the user out of the application.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return void
  *
  * @throws \Illuminate\Auth\AuthenticationException
  */
 protected function logout($request)
 {
     $this->auth->logout();
     $request->session()->flush();
     throw new AuthenticationException();
 }
Esempio n. 20
0
 /**
  * Create a new basic controller instance.
  *
  * @param \Illuminate\Contracts\Auth\Factory $auth
  *
  * @return void
  */
 public function __construct(AuthFactory $auth)
 {
     $this->currentUser = $auth->user();
     $this->setValidationFactory(app(ValidationFactory::class));
     view()->share(['currentUser' => $this->currentUser]);
 }