From: Andy Allan Date: Wed, 16 Sep 2020 08:43:21 +0000 (+0200) Subject: Merge pull request #2809 from tomhughes/bootstrap X-Git-Tag: live~3013 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/f70ec189894ef6bc37355cad7990420065a0b2cb?hp=70c4a750d75aaca611a0efe0cc8d5e1732fc6b36 Merge pull request #2809 from tomhughes/bootstrap Convert some more 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/friendships/make_friend.html.erb b/app/views/friendships/make_friend.html.erb index e781f7b25..3dcdd6d64 100644 --- a/app/views/friendships/make_friend.html.erb +++ b/app/views/friendships/make_friend.html.erb @@ -2,9 +2,9 @@

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

<% end %> -<%= form_tag(nil, :class => "standard-form") do %> +<%= bootstrap_form_tag do |f| %> <% if params[:referer] -%> - <%= hidden_field_tag("referer", params[:referer]) %> + <%= f.hidden_field :referer, :value => params[:referer] %> <% end -%> - <%= submit_tag t(".button") %> + <%= f.primary t(".button") %> <% end %> diff --git a/app/views/friendships/remove_friend.html.erb b/app/views/friendships/remove_friend.html.erb index caaec120b..f5c2b9c0c 100644 --- a/app/views/friendships/remove_friend.html.erb +++ b/app/views/friendships/remove_friend.html.erb @@ -2,9 +2,9 @@

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

<% end %> -<%= form_tag(nil, :class => "standard-form") do %> +<%= bootstrap_form_tag do |f| %> <% if params[:referer] -%> - <%= hidden_field_tag("referer", params[:referer]) %> + <%= f.hidden_field :referer, :value => params[:referer] %> <% end -%> - <%= submit_tag t(".button") %> + <%= f.primary t(".button") %> <% end %> diff --git a/app/views/oauth/authorize.html.erb b/app/views/oauth/authorize.html.erb index 5fd3c2fee..8576ea3ab 100644 --- a/app/views/oauth/authorize.html.erb +++ b/app/views/oauth/authorize.html.erb @@ -4,16 +4,15 @@

<%= t(".request_access_html", :app_name => link_to(@token.client_application.name, @token.client_application.url), :user => link_to(current_user.display_name, user_path(current_user))) %>

-<%= form_tag authorize_url do %> - <%= hidden_field_tag "oauth_token", @token.token %> - <%- if params[:oauth_callback] -%> - <%= hidden_field_tag "oauth_callback", params[:oauth_callback] %> - <%- end -%> -

<%= t ".allow_to" %>

- -

<%= submit_tag t(".grant_access") %>

+<%= bootstrap_form_tag do |f| %> + <%= f.hidden_field :oauth_token, :value => @token.token %> + <% if params[:oauth_callback] -%> + <%= f.hidden_field :oauth_callback, :value => params[:oauth_callback] %> + <% end -%> + <%= f.form_group :permissions, :label => { :text => t(".allow_to") } do %> + <% @token.client_application.permissions.each do |perm| -%> + <%= f.check_box perm, :value => "yes", :checked => @token.read_attribute(perm), :label => t(".#{perm}") %> + <% end -%> + <% end -%> + <%= f.primary t(".grant_access") %> <% end %> diff --git a/app/views/users/confirm.html.erb b/app/views/users/confirm.html.erb index 4ea5ac5c5..fde545546 100644 --- a/app/views/users/confirm.html.erb +++ b/app/views/users/confirm.html.erb @@ -12,10 +12,10 @@

<%= t ".press confirm button" %>

- <%= form_tag({}, { :id => "confirm", :class => "standard-form" }) do %> - - - "> + <%= bootstrap_form_tag :html => { :id => "confirm" } do |f| %> + <%= f.hidden_field :display_name, :value => params[:display_name] %> + <%= f.hidden_field :confirm_string, :value => params[:confirm_string] %> + <%= f.primary t(".button") %> <% end %> <% else %>

diff --git a/app/views/users/confirm_email.html.erb b/app/views/users/confirm_email.html.erb index ba2726d42..49b279c8f 100644 --- a/app/views/users/confirm_email.html.erb +++ b/app/views/users/confirm_email.html.erb @@ -10,7 +10,7 @@

<%= t ".press confirm button" %>

-<%= form_tag({}, { :id => "confirm", :class => "standard-form" }) do %> - - "> +<%= bootstrap_form_tag :html => { :id => "confirm" } do |f| %> + <%= f.hidden_field :confirm_string, :value => params[:confirm_string] %> + <%= f.primary t(".button") %> <% end %> diff --git a/app/views/users/logout.html.erb b/app/views/users/logout.html.erb index 41493e824..3ae4d14f6 100644 --- a/app/views/users/logout.html.erb +++ b/app/views/users/logout.html.erb @@ -2,7 +2,7 @@

<%= t ".heading" %>

<% end %> -<%= form_tag({ :action => "logout" }, { :class => "standard-form" }) do %> - <%= hidden_field_tag("referer", h(params[:referer])) %> - <%= submit_tag t(".logout_button") %> +<%= bootstrap_form_tag do |f| %> + <%= f.hidden_field :referer, :value => params[:referer] %> + <%= f.primary t(".logout_button") %> <% 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 91ef7222f..bffcfe5bd 100644 --- a/test/controllers/users_controller_test.rb +++ b/test/controllers/users_controller_test.rb @@ -422,7 +422,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest get logout_path assert_response :success assert_template :logout - assert_select "input[name=referer][value=?]", "" + assert_select "input[name=referer]:not([value])" end def test_logout_fallback_with_referer @@ -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" } }