Saturday, June 7, 2014

Re: Making browser save userneme & password

What I usually do:

- Check if the user is already logged in after the page loads.
In my case I always have a RPC call in my entry point like getUserSession() that returns null or a valid user.

- Wrap all form elements like you're already doing. But use a dummy action (action="javascript:").
This will avoid redirecting on form submission in development mode and production.

- No need to inject JSNI. Use the FormPanel's SubmitHandler directly for your RPC login.

- Save a session attribute in your RPC login (that you'll later query in your entry point)

- The tricky part: Window.Location.reload() 
I noticed that Chrome only asks to save the password when I hit refresh... So refresh it yourself!

Tested with Chrome / IE / FF.
Apparently doesn't work in mobile Safari and Chrome with iOS.
Works on mobile Chrome with Android.

Hope this helps.


Em terça-feira, 3 de junho de 2014 20h12min51s UTC-3, Blake escreveu:
Greetings,

I would like to have the browser save the username/password to my application.  I have searched and searched and found no solution that works on all of the standard browsers (Chrome, IE, Firefox, Safari).  Best I have been able to do (works on Firefox & IE) is:


....
<form id="login-form" action="login">
    <table>
        <tr>
            <td><button type="button">Continue as a guest</button> &nbsp;&nbsp;or &nbsp;&nbsp;Login ID:</td>
            <td> <input autocomplete="on" type="text" tabindex="0" name="username" id="username" placeholder=Email&nbsp;Address></td>
            <td>(email address)</td>
        </tr>
        <tr>
            <td align=right>Password:</td>
            <td><input autocomplete="on" type="password" tabindex="0" name="password" id="password" placeholder=Password></td>
            <td><button type="submit">Login</button></td>
        </tr>
    </table>
</form>
....


    private static final String FORM_ID = "login-form";
    private static final String USER_ID = "username";
    private static final String PASSWORD_ID = "password";

    
   private static void doLogin() {
        Window.alert("test 1");
    }

    private static native void injectLoginFunction() /*-{
        $wnd.login = function() {
            @booklion.client.login.Login::doLogin()();
        };
    }-*/;


    public void onModuleLoad() {
        injectLoginFunction();  // ok
        TextBox fUsername = TextBox.wrap(DOM.getElementById(USER_ID));
        fUsername.setStyleName("gwt-TextBox");
        PasswordTextBox fPassword = PasswordTextBox.wrap(DOM.getElementById(PASSWORD_ID));
        fPassword.setStyleName("gwt-PasswordTextBox");
        FormPanel fLoginForm = FormPanel.wrap(DOM.getElementById(FORM_ID), false); 
        fLoginForm.setAction("");  //  ok
        fLoginForm.addSubmitHandler(new FormPanel.SubmitHandler() { 

            @Override
            public void onSubmit(FormPanel.SubmitEvent event) {
                Window.alert("test 2");
            }
        });
        fLoginForm.getElement().setAttribute("onsubmit", "login();return false;");
    }


test 1 gets displayed - not test 2.  Firefox and IE offer to save the password.  Chrome and Safari do not.

Sure would appreciate some help.

Thanks.

Blake McBride

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment