From: Tom Hughes Date: Thu, 3 Sep 2020 22:53:57 +0000 (+0100) Subject: Convert password reset forms to use bootstrap X-Git-Tag: live~2438^2~1 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/21adea321b6c705b0e0eb7acc667566869b3015d Convert password reset forms to use bootstrap --- diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index b3596b376..aa115a228 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -146,11 +146,11 @@ class UsersController < ApplicationController def lost_password @title = t "users.lost_password.title" - if params[:user] && params[:user][:email] - user = User.visible.find_by(:email => params[:user][:email]) + if params[:email] + user = User.visible.find_by(:email => params[:email]) if user.nil? - users = User.visible.where("LOWER(email) = LOWER(?)", params[:user][:email]) + users = User.visible.where("LOWER(email) = LOWER(?)", params[:email]) user = users.first if users.count == 1 end diff --git a/app/views/users/lost_password.html.erb b/app/views/users/lost_password.html.erb index 3cfd8cc83..dfcaf32be 100644 --- a/app/views/users/lost_password.html.erb +++ b/app/views/users/lost_password.html.erb @@ -4,10 +4,7 @@

<%= t ".help_text" %>

-<%= form_tag :action => "lost_password" do %> -
- - <%= text_field("user", "email", :tabindex => 1) %> - <%= submit_tag t(".new password button"), :tabindex => 2 %> -
+<%= bootstrap_form_tag do |f| %> + <%= f.text_field :email, :label => t(".email address") %> + <%= f.primary t(".new password button") %> <% end %> diff --git a/app/views/users/reset_password.html.erb b/app/views/users/reset_password.html.erb index 6290cca96..99f07cab6 100644 --- a/app/views/users/reset_password.html.erb +++ b/app/views/users/reset_password.html.erb @@ -2,19 +2,9 @@

<%= t ".heading", :user => current_user.display_name %>

<% end %> -<%= error_messages_for current_user %> - -<%= form_tag do %> -<%= hidden_field_tag(:token, params[:token]) %> -
-
- - <%= password_field(:user, :pass_crypt, :value => "", :tabindex => 4) %> -
-
- - <%= password_field(:user, :pass_crypt_confirmation, :value => "", :tabindex => 5) %> -
- <%= submit_tag t(".reset"), :tabindex => 6 %> -
+<%= bootstrap_form_for current_user, :url => { :action => "reset_password" }, :html => { :method => :post } do |f| %> + <%= f.hidden_field :token, :name => "token", :value => params[:token] %> + <%= f.password_field :pass_crypt, :value => "" %> + <%= f.password_field :pass_crypt_confirmation, :value => "" %> + <%= f.primary t(".reset") %> <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 44501aa10..997500b3d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -126,6 +126,7 @@ en: description: "Description" languages: "Languages" pass_crypt: "Password" + pass_crypt_confirmation: "Confirm Password" help: trace: tagstring: comma delimited @@ -2257,8 +2258,6 @@ en: reset_password: title: "Reset password" heading: "Reset Password for %{user}" - password: "Password:" - confirm password: "Confirm Password:" reset: "Reset Password" flash changed: "Your password has been changed." flash token bad: "Did not find that token, check the URL maybe?" diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb index 1cd9c5dda..bffcfe5bd 100644 --- a/test/controllers/users_controller_test.rb +++ b/test/controllers/users_controller_test.rb @@ -814,7 +814,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest assert_difference "ActionMailer::Base.deliveries.size", 1 do perform_enqueued_jobs do - post user_forgot_password_path, :params => { :user => { :email => user.email } } + post user_forgot_password_path, :params => { :email => user.email } end end assert_response :redirect @@ -829,7 +829,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest # that has the same address in a different case assert_difference "ActionMailer::Base.deliveries.size", 1 do perform_enqueued_jobs do - post user_forgot_password_path, :params => { :user => { :email => user.email.upcase } } + post user_forgot_password_path, :params => { :email => user.email.upcase } end end assert_response :redirect @@ -844,7 +844,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest # for more than one user but not an exact match for either assert_no_difference "ActionMailer::Base.deliveries.size" do perform_enqueued_jobs do - post user_forgot_password_path, :params => { :user => { :email => user.email.titlecase } } + post user_forgot_password_path, :params => { :email => user.email.titlecase } end end assert_response :success @@ -856,7 +856,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest third_user = create(:user) assert_difference "ActionMailer::Base.deliveries.size", 1 do perform_enqueued_jobs do - post user_forgot_password_path, :params => { :user => { :email => third_user.email } } + post user_forgot_password_path, :params => { :email => third_user.email } end end assert_response :redirect @@ -871,7 +871,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest # same (case insensitively unique) address in a different case assert_difference "ActionMailer::Base.deliveries.size", 1 do perform_enqueued_jobs do - post user_forgot_password_path, :params => { :user => { :email => third_user.email.upcase } } + post user_forgot_password_path, :params => { :email => third_user.email.upcase } end end assert_response :redirect @@ -906,7 +906,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest post user_reset_password_path, :params => { :token => token.token, :user => { :pass_crypt => "new_password", :pass_crypt_confirmation => "different_password" } } assert_response :success assert_template :reset_password - assert_select "div#errorExplanation" + assert_select "div.invalid-feedback" # Test setting a new password post user_reset_password_path, :params => { :token => token.token, :user => { :pass_crypt => "new_password", :pass_crypt_confirmation => "new_password" } }