本文整理汇总了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]);
}
示例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)]);
}
示例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'));
}
示例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]);
}
示例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;
}
示例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);
}
示例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;
}
示例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'));
}
示例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));
}
示例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'));
}
示例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'));
}
}
示例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'));
}
示例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'));
}
示例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.');
}
示例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'));
}