當前位置: 首頁>>代碼示例>>PHP>>正文


PHP JWTAuth::toUser方法代碼示例

本文整理匯總了PHP中Tymon\JWTAuth\Facades\JWTAuth::toUser方法的典型用法代碼示例。如果您正苦於以下問題:PHP JWTAuth::toUser方法的具體用法?PHP JWTAuth::toUser怎麽用?PHP JWTAuth::toUser使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Tymon\JWTAuth\Facades\JWTAuth的用法示例。


在下文中一共展示了JWTAuth::toUser方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: __construct

 public function __construct()
 {
     $this->app_list_limit = env('APP_LIST_LIMIT', 50);
     $token = JWTAuth::getToken();
     if (!empty($token)) {
         $user = JWTAuth::toUser($token);
         $this->logged_user = User::find($user->id);
     }
 }
開發者ID:Worklemon,項目名稱:api,代碼行數:9,代碼來源:Request.php

示例2: login

 /**
  * Login user with credentials
  *
  * @param Request $request
  * @return \Illuminate\Http\JsonResponse
  */
 public function login(Request $request)
 {
     $credentials = $request->only('email', 'password');
     try {
         if (!($token = JWTAuth::attempt($credentials))) {
             return response()->json(['error' => 'invalid_credentials'], 401);
         }
     } catch (JWTException $e) {
         return response()->json(['error' => 'could_not_create_token'], 500);
     }
     $user = JWTAuth::toUser($token);
     return response()->json(compact('token', 'user'));
 }
開發者ID:rossfinn1,項目名稱:anvel-base-1,代碼行數:19,代碼來源:AuthController.php

示例3: postShow

 public function postShow()
 {
     if ($user = JWTAuth::toUser(JWTAuth::getToken())) {
         return response()->json(compact('user'));
     }
 }
開發者ID:developscript,項目名稱:laravel-with-angular,代碼行數:6,代碼來源:ProfileController.php

示例4: getState

 public function getState()
 {
     $token = JWTAuth::getToken();
     $user = JWTAuth::toUser($token);
     $unlocked = $user->devices()->unlocked();
     $device_state = $unlocked->count() == 0 ? 1 : 0;
     $data = ['state' => $device_state, 'username' => $user->first_name];
     $this->putStats($user);
     return Response::json($data);
 }
開發者ID:JolitaGrazyte,項目名稱:lockedornot,代碼行數:10,代碼來源:DeviceController.php

示例5: renewToken

 public function renewToken(Request $request)
 {
     // Simply refresh the new token
     try {
         $gcm_token = $request->get('gcm_token');
         $new_token = JWTAuth::parseToken()->refresh();
         // We have a google token, so let's set it
         if (null != $gcm_token) {
             $user = JWTAuth::toUser($new_token);
             $user->setGCMToken($gcm_token);
             $user->save();
         }
     } catch (TokenExpiredException $e) {
         return new Response(['error' => 'token_expired'], $e->getStatusCode());
     } catch (JWTException $e) {
         return new Response(['error' => 'token_invalid'], $e->getStatusCode());
     }
     return new Response(['token' => $new_token], Response::HTTP_OK);
 }
開發者ID:revolucaodosbytes,項目名稱:ahoy-api,代碼行數:19,代碼來源:AuthController.php

示例6: restricted

 public function restricted()
 {
     $token = JWTAuth::getToken();
     $user = JWTAuth::toUser($token);
     return Response::json(['data' => ['email' => $user->email, 'registered_at' => $user->created_at->toDateTimeString()]]);
 }
開發者ID:pavelmalai,項目名稱:virtualcsgo,代碼行數:6,代碼來源:AuthCtrl.php

示例7: view

    return view('spa');
});
/**
 * Registers a new user and returns a auth token
 */
Route::post('/signup', 'UserController@signup');
/**
 * Signs in a user using JWT
 */
Route::post('/signin', 'UserController@signin');
/**
 * Fetches a restricted resource from the same domain used for user authentication
 */
Route::get('/restricted', ['before' => 'jwt-auth', function () {
    $token = JWTAuth::getToken();
    $user = JWTAuth::toUser($token);
    return Response::json(['data' => ['email' => $user->email, 'registered_at' => $user->created_at->toDateTimeString(), 'role' => $user->role]]);
}]);
/**
 * Fetches a restricted resource from API subdomain using CORS
 */
Route::group(['domain' => '192.168.59.103', 'prefix' => 'api/v1', 'middleware' => 'jwt.auth'], function () {
    Route::get('/restricted', function () {
        try {
            JWTAuth::parseToken()->toUser();
        } catch (Exception $e) {
            return Response::json(['error' => $e->getMessage()], HttpResponse::HTTP_UNAUTHORIZED);
        }
        return ['data' => 'This has come from a dedicated API subdomain with restricted access.'];
    });
    Route::resource('/posts', 'PostController');
開發者ID:BaptisteDixneuf,項目名稱:laravel-angularjs-jwt,代碼行數:31,代碼來源:routes.php


注:本文中的Tymon\JWTAuth\Facades\JWTAuth::toUser方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。