0

I need your advice on a functionality I'm trying to implement.

I create a modal view in order to login my users.

enter image description here

When I click on connect button ("se connecter" in French), I call FOSUser login path in Ajax in order to verify if login/password is right :

$.ajax({
        type: 'post',
        data: inputs,
        url: '{{ path("fos_user_security_check", {'username': '', 'password': ''}) }}',
        success: function(data) {

If the login/password is right, in Ajax data, I get a html page content (from a RedirectResponse in FOSUser login handler), something like this :

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    ...
</head>
<body>
...

I need to display this content properly. I could do a :

document.write(data);

It works, but It creates a blank view, then display the content, this is not very good !

I could reload my login form :

$("#formLogin").submit();

But it submits the login form 2 times, so this is not really what I want !

I could reload page but it means I don't take care of my data return by the FOSUser login handler, and I don't want to, I override the onAuthenticationSuccess to not redirect user on some page when he is logging to.

I'm a bit lost here, I really want to do something nice, properly, smooth for user ! Even if it takes time. I have no idea what to do, maybe a fade effect to display new content ? animations ? etc.

I hope I'm clear in my explanations. TY

Aximem
  • 714
  • 8
  • 27
  • You need to write a event listener to return json (or whatever) response instead of redirect response, like this: http://stackoverflow.com/a/28947727/3675759 – malcolm Aug 30 '16 at 17:59
  • Hi Thanks for your comment, indeed this is better, I will use JSONResponse, but my main question was How can I do something smooth for user with Ajax data. I mean something life hiding modal and changing content of current (without reloading view) or fade in new content etc. I have no idea how to do this, event with a JSONResponse ! – Aximem Aug 30 '16 at 18:19
  • Malcolm, I used your solution, with a JsonResponse, i returned complete url in JSON and do a window.location.replace(data['url']); It works but I'm still asking if there is a way to do a better thing than a redirection ! I'm still thinking of a fade effect or something else etc. – Aximem Sep 01 '16 at 07:55

0 Answers0