/**
  * Check Credentials and Log user In
  *
  * @param LoginRequest|Request $request
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function post(LoginRequest $request)
 {
     $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 redirect()->back()->withInput()->withErrors('Username or Password Not Found');
     }
     /* || $request->get('user_type', '') == 'user'*/
     if ($this->auth->user()->is('user')) {
         return redirect()->route('web.index');
     }
     return redirect()->route('home');
 }
 /**
  * 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;
     });
 }
 /**
  * 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);
 }
Esempio n. 4
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]);
 }