Exemple #1
2
 /**
  * Handle a registration request for the application.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function postRegister(Request $request)
 {
     $validator = $this->validator($request->all());
     if ($validator->fails()) {
         $this->throwValidationException($request, $validator);
     }
     $token = JWTAuth::fromUser($this->create($request->all()), $this->customClaims());
     $response = new JsonResponse(['token' => $token], 200);
     $response->header('Authorization', 'Bearer ' . $token);
     return $response;
 }
Exemple #2
1
 private function jsonResponse($status, $arguments)
 {
     $content = isset($arguments[0]) ? $arguments[0] : '';
     $headers = isset($arguments[1]) ? $arguments[1] : $this->_jsonHeaders;
     $headers = array_merge($this->_jsonHeaders, $headers);
     $options = isset($arguments[2]) ? $arguments[2] : $this->_jsonOptions;
     $response = new IlluminateJsonResponse($content, $status, [], $options);
     foreach ($headers as $key => $value) {
         $response->header($key, $value, true);
     }
     return $response;
 }
 /**
  * Add headers needed for CORS.
  *
  * @return $this
  */
 private function addCorsHeaders()
 {
     if (isset($_SERVER['SERVER_SOFTWARE']) && preg_match('/nginx/', $_SERVER['SERVER_SOFTWARE'])) {
         $accessControlAllowCredentials = 'false';
         if (env('ACCESS_CONTROL_ALLOW_HEADERS')) {
             $accessControlAllowCredentials = 'true';
         }
         $this->response->header('Access-Control-Allow-Origin', env('ACCESS_CONTROL_ALLOW_ORIGIN'));
         $this->response->header('Access-Control-Allow-Credentials', $accessControlAllowCredentials);
         $this->response->header('Access-Control-Allow-Methods', env('ACCESS_CONTROL_ALLOW_METHODS'));
         $this->response->header('Access-Control-Allow-Headers', env('ACCESS_CONTROL_ALLOW_HEADERS'));
     }
     return $this;
 }
 /**
  * Send the response after the user was authenticated.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  bool  $throttles
  * @param  string  $token
  * @return \Illuminate\Http\Response
  */
 protected function handleUserWasAuthenticated(Request $request, $throttles, $token)
 {
     if ($throttles) {
         $this->clearLoginAttempts($request);
     }
     if (method_exists($this, 'authenticated')) {
         return $this->authenticated($request, $token);
     }
     $response = new JsonResponse(['token' => $token], 200);
     $response->header('Authorization', 'Bearer ' . $token);
     return $response;
 }
Exemple #5
0
 /**
  * Reset the given user's password.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function postReset(Request $request)
 {
     $this->validate($request, array_merge($this->validator(), ['token' => 'required', 'password' => 'required|confirmed|min:6']));
     $usernames = $this->loginUsername();
     if (!is_array($usernames)) {
         $usernames = [$usernames];
     }
     $credentials = $request->only(array_merge($usernames, ['password', 'password_confirmation', 'token']));
     $token = '';
     $response = Password::reset($credentials, function ($user, $password) use(&$token) {
         $token = $this->resetPassword($user, $password);
     });
     switch ($response) {
         case Password::PASSWORD_RESET:
             $response = new JsonResponse(['token' => $token], 200);
             $response->header('Authorization', 'Bearer ' . $token);
             return $response;
         default:
             return new JsonResponse(['error' => trans($response)], 422);
     }
 }