2

I have the following form which is placed on the page through AJAX (jQuery AJAX if that helps):

        <div id="login">
            <iframe src="/api/core/authSystem/authUser.php" id="temp" name="temp" style="display:none"></iframe>
            <form id="loginForm" target="temp" onSubmit="App.Auth.login(); return false;">
                Email: <input type="text" name="email" id="email" onkeydown='if(event.keyCode == 13){ this.submit; }' /><br />
                Password: <input type="password" name="password" id="password" onkeydown='if(event.keyCode == 13){ this.submit; }' /><br />
                <div class="errorMsg" id="loginError"></div>
                <div class="loginHelp l"><a href="#">Cant access your account?</a></div>
                <input class="button rounded r" type="submit" id="loginButton" value="Log In" />
            </form>
        </div>

Following the suggestions made in This Question I added the iframe and am targeting that. However, browsers still will not prompt users to save the password. Any idea why?

EDIT: I have just noticed that Firefox will ask to save the password, but will not actually place it into the form once you return to the login page.

Community
  • 1
  • 1
kz3
  • 785
  • 2
  • 10
  • 23
  • actually I found something that can help you: http://www.howtogeek.com/62980/how-to-force-your-browser-to-remember-passwords/ – ParPar Feb 16 '12 at 07:53
  • Seems that submitting to iframe no longer works in recent browsers. I haven't found other way yet. http://dev.vaadin.com/ticket/8405 – Oliv May 09 '12 at 07:30
  • Did you end up finding a solution? – denislexic Sep 15 '12 at 11:02
  • @KyleBanks, Why not you put your login form, email and password textbox in the iframe? – CallMeLaNN Oct 22 '12 at 03:53
  • I don't think login asynchronously useful unless you want to do something like there is a box `[Login email@domain.com ***** Submit]` and clicking submit will turn into `[Welcome username Logout]` without affecting the other area of the page. If the next flow is redirecting to other page, it seems like it can be done by just a normal login form requested synchronously. – CallMeLaNN Oct 22 '12 at 04:04
  • see this answer http://stackoverflow.com/a/6939039/186334 – CallMeLaNN Oct 22 '12 at 04:05

1 Answers1

0

You can try "double-submit" technique.

In short: on first submit cancel it, but trigger it again after successful auth and do not cancel it.

More detailed:

You need to rewrite your form like this:

<form id="loginForm" onSubmit="return App.Auth.login();" method="POST" action="/back-redirector">

/back-redirector just redirects back to the same page or to the main page. I am redirecting back to the same page.

And your App.Auth.login() function must return false when it is called first time, and return true if the first call has resulted in successful login.

Like this:

letTheLoginFormDoTheSubmit = false; 
// flag to show that login was successful 
// and we need to trigger password save prompt.

login: function() {
    if (letTheLoginFormDoTheSubmit) {
        return true;
    }
    // Do the login
    // Start ajax
    ajax(login, password, function() {
        // This function is called when AJAX has completed
        if (loginIsGood) {
            letTheLoginFormDoTheSubmit = true;
            loginForm.submit(); // trigger submit again
        });
    return false;
}

So what happens?

  1. When your login-function is called the first time it starts login sequence, and returns false to stop the usual form submit.
  2. Login function receives data, and if login is good it saves it on browser side, raises the flag "all good, trigger password save prompt" and submits the form again.
  3. But because flag is flying login-function does not do the login again it just lets the browser do form submit normally, and this triggers password save prompt.

Form is being submitted to the URL that just redirects browser back, and does not do any work.

Some caveats:

  • Page will be reloaded, so save your auth cookie somehow locally, or let the redirector know which is it, so redirector can include it in a redirect.
  • All form data may go through this second submit. To avoid this remove the relevant fields from the form, or remove the name attributes.
  • Redirector is needed on the server side.

But in overall it is not a major change to the login process and should trigger password-save prompt in every browser.

Dmitry Ulupov
  • 311
  • 2
  • 4
  • Seems like a nice idea but I start thinking, it +1 round trip and the second one is posting the form automatically & synchronously. I think user will see the same normal login behavior. Then why need to ajax login at first place if we can do the second one as early as the first one, synchronous login. – CallMeLaNN Oct 22 '12 at 03:52