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