1

私はかなり大きなコミュニティを symfony2 に移行しています。現在のユーザー テーブルには、ユーザー名に英数字以外の文字が含まれるユーザーが多数含まれています。新しいバージョンでは、[a-zA-Z0-9-] のみを各ユーザーのセマンティック URL などの利点のために許可します。

メール/パスでログインし、ユーザー名が設定されていないユーザーを捕まえることはできますか? ユーザー名を再選択できるページにリダイレクトしてもらいたいです。注意が必要なのは、正しいユーザー名を持っていない限り、サイト上の何も操作できないようにすることです。

fosuserbundle からイベントを考えましたが、適切なイベントが見つかりませんでした。

4

2 に答える 2

1

イベントを使用できます。ここで例を参照してください: http://symfony.com/doc/2.0/cookbook/event_dispatcher/before_after_filters.html

もちろん、ユーザー名を変更するアクションは、イベント リスナーによって無視されます。ログインやその他の匿名アクションと同様です。

イベントに response を設定することで、リダイレクトを含む任意の応答を返すことができます。

于 2012-11-20T00:24:45.980 に答える
0

ただのアイデア。AOP パラダイム (JMSAopBundle) はどうですか? コントローラーのポイントカットを定義します (ログイン コントローラーを除く)。

class PrivateEntityInformationPointcut implements PointcutInterface
{

    public function matchesClass(\ReflectionClass $class)
    {
        return $class->isSubclassOf('Your\Controller\Superclass')
            && $class->name !== 'Your\Controller\Access';
    }

    public function matchesMethod(\ReflectionMethod $method)
    {
        return true; // Any method
    }

}

次に、インターセプターはユーザー名を設定するためのページにリダイレクトする必要があります。

class DenyEntityAccessInterceptor implements MethodInterceptorInterface
{

    private $securityContext;

    private $logger;

    /**
     * @DI\InjectParams({
     *     "securityContext" = @DI\Inject("security.context"),
     *     "logger"          = @DI\Inject("logger"),
     * })
     */
    public function __construct(SecurityContext $securityContext,
        Logger $logger)
    {
        $this->securityContext = $securityContext;
        $this->logger          = $logger;
    }

    public function intercept(MethodInvocation $invocation)
    {
        // Check username, redirect using the router, log what's happening

        // It's OK
        return $invocation->proceed();
    }

}
于 2012-11-19T13:52:53.667 に答える