1

I have a tutorial page, and need a global redirect that will send to user to /tutoroal if they don't pass a DB check: User->passedTutorial()

Can I make this with a route configuration calling a controller/model method ?

d.raev
  • 9,216
  • 8
  • 58
  • 79

2 Answers2

2

This sounds more like a security context/question. Have you considered creating a custom role, eg ROLE_USER_PASSED?

You could then either check for this role in security.yml or annotate your controllers with @Security("has_role('ROLE_USER_PASSED')")

kero
  • 10,647
  • 5
  • 41
  • 51
  • That sounds good, I checked that option, but is there a way to make a redirect if the check fails ? – d.raev May 18 '16 at 14:55
  • Yes, a quick search shows that an authentication handler should be able to do this (see [this answer](https://stackoverflow.com/questions/8308050/how-to-disable-redirection-after-login-check-in-symfony-2)) – kero May 18 '16 at 19:27
0

You can do that using @Security annotation like described there: http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/security.html.

Particularly:

/**
 * @Security("user.passedTutorial()")
 */

UPD.

Finally problem can be solved using expression in access_control section of security.yml: http://symfony.com/doc/current/cookbook/security/access_control.html#securing-by-an-expression

By doing so it's still needed to implement access_denied_handler in used firewall (http://symfony.com/doc/current/reference/configuration/security.html) so that it will check the request/user again and perform redirect.

Dmitry Grachikov
  • 316
  • 3
  • 11
  • this will just restrict the access to a single controller, I need a way to redirect from any controller, to a single page (if the check fails) – d.raev May 19 '16 at 10:48
  • Got it. Then you can still use expression like describe there http://symfony.com/doc/current/cookbook/security/access_control.html#securing-by-an-expression. – Dmitry Grachikov May 22 '16 at 08:17
  • this lokks great @Dmitry, I will try it next week. If you can edit your answer and add a working exmple, I will be happy to accept it – d.raev May 22 '16 at 10:29