相关疑难解决方法(0)

检查.NET MVC中的AngularJS $资源请求服务器端

有没有办法判断请求是否是Angular(1.1.5)$资源请求.我正在为这种类型的请求寻找"Request.IsAjaxRequest()"方法.

我正在查看这个在HandleUnauthorizedRequest中重写AuthorizeAttribute我需要将上下文结果设置为某些json(如果是Ajax或角度请求或其他内容).

request asp.net-mvc-3 angularjs

13
推荐指数
1
解决办法
4774
查看次数

Symfony 2 FOS用户包Bootstrap模式AJAX登录

有没有人已经使用Symfony 2和FOS User Bundle在Bootstrap模式中构建了一个登录表单?

这就是我现在拥有的:

SRC/Webibli/UserBundle /资源/配置/ service.yml

authentication_handler:
    class:        Webibli\UserBundle\Handler\AuthenticationHandler
    arguments:    [@router, @security.context, @fos_user.user_manager, @service_container]
Run Code Online (Sandbox Code Playgroud)

应用程序/配置/ security.yml

form_login:
    provider: fos_userbundle
    success_handler: authentication_handler
    failure_handler: authentication_handler
Run Code Online (Sandbox Code Playgroud)

SRC/Webibli/UserBundle /处理器/ AuthenticationHandler.php

<?php

namespace Webibli\UserBundle\Handler;

use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface;
use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Router;
use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\Security\Core\Exception\AuthenticationException;


class AuthenticationHandler implements AuthenticationSuccessHandlerInterface, AuthenticationFailureHandlerInterface
{

    protected $router;
    protected $security;
    protected $userManager;
    protected $service_container;

    public function __construct(RouterInterface $router, SecurityContext $security, $userManager, $service_container)
    {
        $this->router = $router;
        $this->security = $security; …
Run Code Online (Sandbox Code Playgroud)

php ajax symfony twitter-bootstrap fosuserbundle

11
推荐指数
2
解决办法
2万
查看次数

从自定义身份验证处理程序调用默认处理程序

可能重复:
Symfony2 AJAX登录

我已经实现了一个自定义身份验证处理程序服务来处理AJAX登录请求,如下所示:https://stackoverflow.com/a/8312188/267705

但是我如何处理正常的登录请求?调用默认行为会很好,但我不知道,也没有找到如何做到这一点.

symfony

5
推荐指数
1
解决办法
1811
查看次数

在Symfony2中从AuthenticationHandler设置flashMessage

我遇到了FOSUserBundle的问题,因为每次我使用错误的凭据登录时,我都会得到完整的堆栈跟踪作为错误消息:

错误!异常'Symfony\Component\Security\Core\Exception\BadCredentialsException',在/ var/www/html/vendor/symfony/symfony/src/Symfony/Component/Security/Core/Authentication/Provider/UserAuthenticationProvider中显示消息'bad credentials'. PHP:90

这对我来说很难看,所以对用户来说非常难看.所以我正在考虑两个解决方案:改为AJAX登录,我正在努力,但它没有工作或我做错了(将在下面解释)并找到一种方法来改变那个丑陋的消息(我没有得到这个,所以任何建议都会有所帮助).

现在关于第一个解决方案,这就是我所做的:

  • 实现AuthenticationHandler:

    <?php
    
    namespace UsuarioBundle\Handler;
    
    use Symfony\Component\HttpFoundation\Response;
    use Symfony\Component\HttpFoundation\RedirectResponse;
    use Symfony\Bundle\FrameworkBundle\Routing\Router;
    use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
    use Symfony\Component\HttpFoundation\Request;
    use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface;
    use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface;
    use Symfony\Component\Security\Core\Exception\AuthenticationException;
    
    class AuthenticationHandler
        implements AuthenticationSuccessHandlerInterface,
        AuthenticationFailureHandlerInterface
    {
        private $router;
    
        public function __construct(Router $router)
        {
            $this->router = $router;
        }
    
        public function onAuthenticationSuccess(Request $request, TokenInterface $token)
        {
            if ($request->isXmlHttpRequest()) {
                // do I need something here?
            } else {
                // If the user tried to access a protected resource and was forces to login …
    Run Code Online (Sandbox Code Playgroud)

php ajax login symfony fosuserbundle

3
推荐指数
1
解决办法
2427
查看次数