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


PHP JWTAuth::fromUser方法代碼示例

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


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

示例1: register

 public function register(RegisterRequest $request)
 {
     $newUser = ['email' => $request->get('email'), 'password' => Hash::make($request->get('password'))];
     $user = $this->user->create($newUser);
     $token = JWTAuth::fromUser($user);
     return $this->apiResponse(200, ['message' => TOKEN_CREATED, 'token' => $token]);
 }
開發者ID:Worklemon,項目名稱:api,代碼行數:7,代碼來源:AuthController.php

示例2: index

 public function index(FacebookAuthentication $request, FacebookGraphClient $client, FacebookUserResolver $resolver)
 {
     $data = $client->init($request->token)->getUser(['id', 'email', 'first_name', 'last_name']);
     $user = $resolver->findOrCreateUser($data);
     $customClaims = ['name' => $user->name, 'email' => $user->email, 'role' => $user->role, 'gravatar' => $user->gravatar];
     return api_response(200, ['token' => JWTAuth::fromUser($user, $customClaims)]);
 }
開發者ID:adiachenko,項目名稱:catchy_api,代碼行數:7,代碼來源:FacebookController.php

示例3: register

 public function register(UserRequest $request)
 {
     $newUser = ['name' => $request->get('name'), 'email' => $request->get('email'), 'password' => bcrypt($request->get('password'))];
     $user = User::create($newUser);
     $token = JWTAuth::fromUser($user);
     return response()->json(compact('token'));
 }
開發者ID:everdaniel,項目名稱:vue-starter-laravel-api,代碼行數:7,代碼來源:AuthController.php

示例4: postRegister

 public function postRegister(Request $request)
 {
     $validator = $this->validator($request->all());
     if ($validator->fails()) {
         $this->throwValidationException($request, $validator);
     }
     $token = JWTAuth::fromUser($this->create($request->all()));
     return response()->json(['token' => $token]);
 }
開發者ID:developscript,項目名稱:laravel-with-angular,代碼行數:9,代碼來源:RegistersTokens.php

示例5: headers

 /**
  * Return request headers needed to interact with the API.
  *
  * @return Array array of headers.
  */
 protected function headers($user = null)
 {
     $headers = ['Accept' => 'application/json'];
     if (!is_null($user)) {
         $token = JWTAuth::fromUser($user);
         JWTAuth::setToken($token);
         $headers['Authorization'] = 'Bearer ' . $token;
     }
     return $headers;
 }
開發者ID:poiuty,項目名稱:midas,代碼行數:15,代碼來源:TestCase.php

示例6: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $user_created = $this->userRepository->create($request->all());
     if ($user_created instanceof MessageBag) {
         return response()->json($user_created)->setStatusCode(412, 'Invalid User');
     }
     $id = $user_created->id;
     $token = JWTAuth::fromUser($user_created);
     return response()->json(['id' => $id, 'uri' => url('profile', ['id' => $id])] + compact('token'))->setStatusCode(201);
 }
開發者ID:fredlawl,項目名稱:planebox-api,代碼行數:15,代碼來源:ProfileController.php

示例7: postRegister

 /**
  * 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;
 }
開發者ID:thecsea,項目名稱:jwt-auth,代碼行數:17,代碼來源:RegistersUsers.php

示例8: postSignup

 public function postSignup(Request $request)
 {
     $credentials = $request->only('username', 'password');
     try {
         $user = Ulibier::create($credentials);
     } catch (Exception $e) {
         return response()->json(['error' => 'User already exists.'], 409);
     }
     $token = JWTAuth::fromUser($user);
     return response()->json(compact('token'));
 }
開發者ID:hungphongbk,項目名稱:ulibi,代碼行數:11,代碼來源:AuthController.php

示例9: handle

 /**
  * Handle the event.
  *
  * @param  Login $event
  * @return void
  */
 public function handle(Login $event)
 {
     $tokenId = base64_encode(mcrypt_create_iv(32, MCRYPT_DEV_URANDOM));
     $issuedAt = Carbon::now()->timestamp;
     $notBefore = $issuedAt;
     $expire = $notBefore + 6 * 60 * 60;
     // Adding 6 hours
     // Create the token
     $config = ['iat' => $issuedAt, 'jti' => $tokenId, 'iss' => config('app.url'), 'nbf' => $notBefore, 'exp' => $expire, 'data' => ['userId' => $event->user->id]];
     Session::put('jwt', JWTAuth::fromUser($event->user, $config));
 }
開發者ID:devLopez,項目名稱:deployer-1,代碼行數:17,代碼來源:CreateJwt.php

示例10: signup

 public function signup()
 {
     $credentials = Input::only('email', 'password', 'name');
     try {
         $user = User::create($credentials);
     } catch (Exception $e) {
         return Response::json(['error' => 'User already exists.'], HttpResponse::HTTP_CONFLICT);
     }
     $token = JWTAuth::fromUser($user);
     return Response::json(compact('token'));
 }
開發者ID:BaptisteDixneuf,項目名稱:laravel-angularjs-jwt,代碼行數:11,代碼來源:UserController.php

示例11: store

 /**
  * Store a newly created User in storage.
  *
  * @param Request $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     Validator::make($request->all(), ['name' => 'required|max:255', 'email' => 'required|email|max:255|unique:users', 'password' => 'required|confirmed|min:6', 'role_id' => 'required|numeric']);
     $user = User::create(['name' => $request['name'], 'email' => $request['email'], 'role_id' => $request['role_id'], 'password' => bcrypt($request['password'])]);
     $user->jwt_token = JWTAuth::fromUser($user);
     if ($user->save()) {
         return response()->json(compact('user'));
     } else {
         $message = 'Something went wrong, please try again!';
         return response()->json(compact('message'));
     }
 }
開發者ID:bradsmithcan,項目名稱:laravel_api,代碼行數:18,代碼來源:AdminController.php

示例12: authenticate

 public function authenticate(Request $request)
 {
     $credentials = $request->only('email', 'password');
     if (!Auth::attempt($credentials)) {
         return response()->json(['error' => 'invalid_credentials'], 401);
     }
     $user = Auth::user();
     $token = JWTAuth::fromUser($user);
     $userData = ['name' => $user->name, 'admin' => $user->admin];
     // if no errors are encountered we can return a JWT
     return response()->json(compact('token', 'userData'));
 }
開發者ID:burimshala,項目名稱:todoozer,代碼行數:12,代碼來源:AuthController.php

示例13: register

 public function register()
 {
     $email = Input::get('email');
     $password = Hash::make(Input::get('password'));
     try {
         $user = User::create(['email' => $email, 'password' => $password]);
     } catch (Exception $e) {
         return Response::json(['error' => 'User already exists.'], HttpResponse::HTTP_CONFLICT);
     }
     $token = JWTAuth::fromUser($user);
     return Response::json(compact('token'));
 }
開發者ID:pavelmalai,項目名稱:virtualcsgo,代碼行數:12,代碼來源:AuthCtrl.php

示例14: postForgot

 public function postForgot(Request $request)
 {
     $this->validate($request, ['email' => 'required|email']);
     $user = User::where('email', $request->email)->first();
     if (!$user) {
         return redirect()->back()->withErrors(['email' => 'Your email address not registered.']);
     }
     $token = JWTAuth::fromUser($user);
     $data = ['user' => $user, 'token' => $token];
     Mail::send('emails.password', $data, function ($message) use($user) {
         $message->from(env('MAIL_USERNAME'), env('APP_NAME'))->to($user->email, $user->fullname)->subject('Reset Password');
     });
     return redirect('auth/password/forgot')->withSuccess('Please check your email, we have sent request confirmation.');
 }
開發者ID:ninjamonz,項目名稱:laravel_catalog_example,代碼行數:14,代碼來源:PasswordController.php

示例15: signup

 protected function signup(Request $request)
 {
     $credentials = $request->only('email', 'password', 'name');
     $credentials['password'] = bcrypt($credentials['password']);
     try {
         $user = User::create($credentials);
     } catch (\Tymon\JWTAuth\Exceptions\JWTException $e) {
         return response()->json(['error' => 'Could not create user.'], 409);
     } catch (\QueryException $e) {
         return response()->json(['error' => 'Email already exists.'], 409);
     }
     $token = JWTAuth::fromUser($user);
     return response()->json(compact('token'));
 }
開發者ID:scautura,項目名稱:PACG-Characters,代碼行數:14,代碼來源:AuthController.php


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