symfony - if Security denies access for a Certain Role , Trigger a Jquery Function in Symfony3 -




i have notification popup want trigger if security denies access role_user use path admin_only , configured , works perfectly, on :

security.yml

 access_control:     - { path: ^/login$, role: is_authenticated_anonymously }     - { path: ^/admin_only, role: role_admin }  access_denied_url: /home 

and have jquery function on twig file rendering /home action let's call accessdeniedjq. question how check , ( action in controller or on twig ) redirection has happened , access denied , in other words how check if exception raised jq function starts.

when framework internal redirect (or can't know if there http redirect) best bet use url query string let code aware of it.

here suggestion append similar redirected=true in url become /home?redirected=true

using function taken answer @ jquery querystring url

function geturlvars() {     var vars = [], hash;     var hashes = window.location.href.slice(window.location.href.indexof('?') + 1).split('&');     for(var = 0; < hashes.length; i++)     {         hash = hashes[i].split('=');         vars.push(hash[0]);         vars[hash[0]] = hash[1];     }     return vars; } 

i can detect page redirected , act accordingly:

if(geturlvars().redirected){     alert('you not allowed there, got redirected!'); } 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -