当前位置: 首页>>代码示例>>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;未经允许,请勿转载。