本文整理汇总了PHP中Symfony\Component\Security\Core\Exception\AuthenticationException::getMessageKey方法的典型用法代码示例。如果您正苦于以下问题:PHP AuthenticationException::getMessageKey方法的具体用法?PHP AuthenticationException::getMessageKey怎么用?PHP AuthenticationException::getMessageKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Security\Core\Exception\AuthenticationException
的用法示例。
在下文中一共展示了AuthenticationException::getMessageKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onAuthenticationFailure
/**
* {@inheritdoc}
*/
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
{
if ($request->isXmlHttpRequest()) {
return new JsonResponse(['success' => false, 'message' => $exception->getMessageKey()], 401);
}
return parent::onAuthenticationFailure($request, $exception);
}
示例2: start
public function start(Request $request, AuthenticationException $authException = null)
{
$apiProblem = new ApiProblem(Response::HTTP_UNAUTHORIZED);
$message = $authException ? $authException->getMessageKey() : 'Missing credentials';
$apiProblem->set('detail', $message);
return $this->responseFactory->createResponse($apiProblem);
}
示例3: onAuthenticationFailure
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
{
return new JsonResponse(
// you could translate the message
array('message' => $exception->getMessageKey()),
403
);
}
示例4: onAuthenticationFailure
/**
* NOTE: I chose to throw an HTTP Exception here to let the response be rendered elsewhere -
* separation of concerns and all... You could always return a JsonResponse here.
*/
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
{
$message = 'Invalid Credentials';
if ($exception instanceof CustomUserMessageAuthenticationException) {
$message = $exception->getMessageKey();
}
throw new HttpException(401, $message);
}
示例5: onAuthenticationFailure
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
{
if ($request->isXmlHttpRequest()) {
if ($this->env != 'dev') {
$msg = $this->translator->trans($exception->getMessageKey(), $exception->getMessageData(), 'security');
} else {
$msg = $exception->getMessage();
}
return new JsonResponse($msg, Response::HTTP_UNAUTHORIZED);
}
return parent::onAuthenticationFailure($request, $exception);
}
示例6: onAuthenticationFailure
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
{
if ($request->isXmlHttpRequest()) {
$message = $exception->getMessageKey();
$messageTrans = $this->translator->trans($message, array(), 'FOSUserBundle');
if ($messageTrans === $message) {
$messageTrans = $this->translator->trans($message, array(), 'security');
}
$data = array('message' => $messageTrans);
$response = new \Symfony\Component\HttpFoundation\JsonResponse($data, 400);
return $response;
} else {
return parent::onAuthenticationFailure($request, $exception);
}
}
示例7: onAuthenticationFailure
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
{
// TODO: Implement onAuthenticationFailure() method.
return new JsonResponse(array('message' => $exception->getMessageKey()), 403);
}
示例8:
function it_returns_json_response_if_request_is_xml_based(Request $request, AuthenticationException $authenticationException)
{
$request->isXmlHttpRequest()->willReturn(true);
$authenticationException->getMessageKey()->willReturn('Invalid credentials.');
$this->onAuthenticationFailure($request, $authenticationException)->shouldHaveType(JsonResponse::class);
}
示例9: onAuthenticationFailure
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
{
throw new \Exception();
return new Response(strtr($exception->getMessageKey(), $exception->getMessageData()), 403);
}
示例10: getMessageKey
public function getMessageKey()
{
return $this->messageKey !== null ? $this->messageKey : parent::getMessageKey();
}
示例11: createResponseFromException
/**
* Create a proper json response containing the error.
*
* @param AuthenticationException $authException The exception that started the authentication process.
*
* @return JsonResponse
*/
private function createResponseFromException(AuthenticationException $authException = null)
{
$data = ['status' => 'unauthorized'];
if ($authException) {
$data['message'] = $authException->getMessageKey();
}
return new JsonResponse($data, JsonResponse::HTTP_UNAUTHORIZED);
}
示例12: onAuthenticationFailure
/**
* Called when authentication executed, but failed (e.g. wrong username password).
*
* This should return the Response sent back to the user, like a
* RedirectResponse to the login page or a 403 response.
*
* If you return null, the request will continue, but the user will
* not be authenticated. This is probably not what you want to do.
*
* @param Request $request
* @param AuthenticationException $exception
*
* @return Response|null
*/
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
{
return new JsonResponse(['message' => $this->translator->trans($exception->getMessageKey(), $exception->getMessageData())], 403);
}
开发者ID:robertdumitrescu,项目名称:Interview-MusicCoursesApplication,代码行数:18,代码来源:TokenAuthenticatorService.php
示例13: onAuthenticationFailure
/**
* This is called when an interactive authentication attempt fails. This is
* called by authentication listeners inheriting from
* AbstractAuthenticationListener.
*
* @param Request $request
* @param AuthenticationException $exception
*
* @return Response The response to return, never null
*/
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
{
$data = array('code' => self::RESPONSE_FAILURE_CODE, 'message' => strtr($exception->getMessageKey(), $exception->getMessageData()));
return new JsonResponse($data, self::RESPONSE_FAILURE_CODE);
}
示例14: onAuthenticationFailure
/**
* @inheritDoc
*/
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
{
return new JsonResponse(['message' => $exception->getMessageKey()], 401);
}
示例15: onAuthenticationFailure
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
{
$data = array('message' => strtr($exception->getMessageKey(), $exception->getMessageData()));
return new JsonResponse($data, 403);
}