Saved browser password is not loaded on page load

I have a Ruby on Rails application. I am using Devise for authentication. I have set a 30 minute timeout for users to auto-register users after 30 minutes of browser inactivity. The problem I am facing is that when the session logs out after timeout after 30 minutes, it goes to the login screen and the browser email and password are displayed in the login text boxes. But when I click the login button, it doesn't log me to the app. When the page is reloaded after a failed login, I can login as usual. When I checked the issue further, I found that the email and password values ​​are zero even though they are displayed on the browser screen.

The login form code is shown below:

 <%= form_for(resource, :as => resource_name, :url => session_path(resource_name,:role => "super_admin")) do |f| %>

    <%= f.email_field :email, :placeholder => "EMAIL", :data => { :'placeholder' => 'EMAIL'}, :class => 'with_holder' %>


    <%= f.password_field :password, :placeholder => "PASSWORD", :class => 'disablecopypaste with_holder' , :data => { :'placeholder' => 'PASSWORD'}%>

  <% if devise_mapping.rememberable? -%>

          <%= f.check_box :remember_me %>


  <% end -%>


    <a id="save_post" href="javascript:void(0);">LOG IN</a>





<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %>
      <%= link_to "FORGOT PASSWORD?", new_password_path(resource_name, :role => 'super_admin') %>
  <% end -%>

      

Am I doing something wrong here? It would be very helpful if anyone can help me with this problem

+3


source to share


2 answers


Finally figured out what the problem is. The problem was submitting the form, the form was not submitting with the normal method. It is dispatched from a JS method that catches the click event <a id="save_post" href="javascript:void(0);">LOG IN</a>

and POST the action to its parent form.

The problem was that the form was not loaded at the time of the click and hence it was returning blank strings for the email and password fields. Once I changed the way the form was submitted in the usual way, i.e. by placing the form submit button

<%= f.submit "LOG IN", :id => "login_submit" %>

      



it works fine

Since the button is also an element inside the form, it will only load after other elements inside the form have loaded, so it will not return blank lines when the button is clicked.

+2


source


If you see your email and password on the login form when you reload the page, this is browser behavior, not your application. This could be because your login has an autocomplete attribute and you selected Save password in your browser. Try installing autocomplete=off

to your input to see if it helps



+2


source







All Articles