本文整理汇总了PHP中Tymon\JWTAuth\Facades\JWTAuth::authenticate方法的典型用法代码示例。如果您正苦于以下问题:PHP JWTAuth::authenticate方法的具体用法?PHP JWTAuth::authenticate怎么用?PHP JWTAuth::authenticate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tymon\JWTAuth\Facades\JWTAuth
的用法示例。
在下文中一共展示了JWTAuth::authenticate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: login
public function login($data)
{
$credentials = ['email' => strtolower(array_get($data, 'email')), 'password' => array_get($data, 'password')];
if (!($token = $this->returnToken($credentials))) {
throw new Exception('No user with that email and password combination exists in our database.', 500);
}
return [JWTAuth::authenticate($token), $token];
}
示例2: authenticate
/**
* Authenticate the user using JWT.
*
* @param AuthJwtRequest $request
* @return $this|\Illuminate\Http\JsonResponse
*/
public function authenticate(AuthJwtRequest $request)
{
$credentials = $request->only(['email', 'password']);
// Attempt to verify the credentials and create a token for the user
if (!($token = JWTAuth::attempt($credentials))) {
$response = $this->response->error(ResponseCode::UNAUTHORIZED, trans('texts.invalid_credentials'));
} else {
$data = ['token' => $token, 'user' => JWTAuth::authenticate($token)];
$response = $this->response->ok($data);
}
return $response;
}
示例3: testNewCompany
public function testNewCompany()
{
$response = $this->json('POST', '/companies/auth/register', ['name' => 'test', 'email' => 'test@test.com', 'password_confirmation' => 'testtest', 'password' => 'testtest']);
$response->seeStatusCode(200);
$this->seeInDatabase("companies", ['name' => 'test', 'email' => 'test@test.com']);
$token = json_decode($response->response->content(), true);
$token = $token['token'];
/**
* @var $company \plunner\Company
*/
$company = JWTAuth::authenticate($token);
$this->assertEquals('test@test.com', $company->email);
}
示例4: boot
/**
* Bootstrap the application services.
*
* @param Request $request
*/
public function boot(Request $request)
{
view()->composer('index', function ($view) use($request) {
$jwt_token = $request->cookie('jwt');
if ($jwt_token) {
try {
$user = JWTAuth::authenticate($jwt_token);
$view->with('user', $user);
} catch (\Exception $e) {
}
}
});
}
示例5: createSession
/**
* Create Session for FE
* @param Request $request
*/
public function createSession(Request $request)
{
$session = md5(time());
$create = $request->all();
$create['session'] = $session;
$token = JWTAuth::getToken();
if ($token) {
try {
$user = JWTAuth::authenticate($token);
if ($user != false) {
$create['user_id'] = $user->id;
}
} catch (\Exception $e) {
}
}
$data = $this->dataRepository->insert($create);
if ($data instanceof MessageBag) {
return response()->json($data)->setStatusCode(412, 'Invalid session create');
}
return response()->json(['session' => $session])->setStatusCode(200, 'Session created');
}