本文整理汇总了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);
}
}
示例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'));
}
示例3: postShow
public function postShow()
{
if ($user = JWTAuth::toUser(JWTAuth::getToken())) {
return response()->json(compact('user'));
}
}
示例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);
}
示例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);
}
示例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()]]);
}
示例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');