Merge pull request #8125 from jibees/5782-add-i18n-for-devise

Add devise-i18n and handle i18nization for devise controllers
This commit is contained in:
Andy Brett
2021-09-08 11:48:12 -07:00
committed by GitHub
6 changed files with 96 additions and 35 deletions

View File

@@ -49,6 +49,7 @@ gem 'paypal-sdk-merchant', '1.117.2'
gem 'stripe'
gem 'devise'
gem 'devise-i18n'
gem 'devise-encryptable'
gem 'devise-token_authenticatable'
gem 'jwt', '~> 2.2'

View File

@@ -245,6 +245,8 @@ GEM
warden (~> 1.2.3)
devise-encryptable (0.2.0)
devise (>= 2.1.0)
devise-i18n (1.10.0)
devise (>= 4.8.0)
devise-token_authenticatable (1.1.0)
devise (>= 4.0.0, < 5.0.0)
diff-lcs (1.4.4)
@@ -714,6 +716,7 @@ DEPENDENCIES
debugger-linecache
devise
devise-encryptable
devise-i18n
devise-token_authenticatable
dfc_provider!
dotenv-rails

View File

@@ -1,5 +1,7 @@
= form_for @spree_user, :as => :spree_user, :url => spree.spree_user_password_path, :method => :put do |f|
= render :partial => 'spree/shared/error_messages', :locals => { :target => @spree_user }
.row
.small-12.medium-10.large-6.columns.medium-centered.large-centered
= render :partial => 'spree/shared/error_messages', :locals => { :target => @spree_user }
%fieldset
.row
.small-12.medium-6.large-4.columns.medium-centered.large-centered

View File

@@ -26,6 +26,7 @@ en:
spree/user:
password: "Password"
password_confirmation: "Password confirmation"
reset_password_token: Reset password token
enterprise_fee:
fee_type: Fee Type
spree/order:
@@ -61,6 +62,8 @@ en:
attributes:
email:
taken: "There's already an account for this email. Please login or reset your password."
reset_password_token:
invalid: is invalid
spree/order:
no_card: There are no authorised credit cards available to charge
spree/credit_card:
@@ -116,6 +119,9 @@ en:
community_forum_url: "Community forum URL"
customer_instructions: "Customer instructions"
devise:
passwords:
spree_user:
cannot_be_blank: "User password cannot be blank. Please enter a password."
confirmations:
send_instructions: "You will receive an email with instructions about how to confirm your account in a few minutes."
failed_to_send: "An error occurred whilst sending your confirmation email."

View File

@@ -1,34 +0,0 @@
# frozen_string_literal: true
require "spec_helper"
feature "Confirm invitation as manager" do
include UIComponentHelper
include OpenFoodNetwork::EmailHelper
describe "confirm email and set password" do
let(:email) { "test@example.org" }
let(:user) { Spree::User.create(email: email, unconfirmed_email: email, password: "secret") }
before do
setup_email
user.reset_password_token = Devise.friendly_token
user.reset_password_sent_at = Time.now.utc
user.save!
end
it "lets the user set a password" do
visit spree.spree_user_confirmation_path(confirmation_token: user.confirmation_token)
expect(user.reload.confirmed?).to be true
expect(page).to have_text I18n.t(:change_my_password)
fill_in "Password", with: "my secret"
fill_in "Password Confirmation", with: "my secret"
click_button
expect(page).to have_no_text "Reset password token has expired"
expect(page).to be_logged_in_as user
end
end
end

View File

@@ -0,0 +1,83 @@
# frozen_string_literal: true
require "system_helper"
describe "User password confirm/reset page" do
include UIComponentHelper
include OpenFoodNetwork::EmailHelper
let(:email) { "test@example.org" }
let(:user) { Spree::User.create(email: email, unconfirmed_email: email, password: "secret") }
describe "can set a password" do
before do
user.reset_password_token = Devise.friendly_token
user.reset_password_sent_at = Time.now.utc
user.save!
end
it "lets the user set a password" do
visit spree.spree_user_confirmation_path(confirmation_token: user.confirmation_token)
expect(user.reload.confirmed?).to be true
expect(page).to have_text I18n.t(:change_my_password)
fill_in "Password", with: "my secret"
fill_in "Password Confirmation", with: "my secret"
click_button
expect(page).to have_no_text "Reset password token has expired"
expect(page).to be_logged_in_as user
end
end
describe "can reset its own password" do
let(:reset_password_token) { user.regenerate_reset_password_token }
it "has the right error when password aren't the same" do
visit spree.edit_spree_user_password_path(reset_password_token: reset_password_token)
expect(page).to have_text "Change my password"
fill_in "Password", with: "my secret"
fill_in "Password Confirmation", with: "my secret1"
click_button
expect(page).to have_text "Password confirmation doesn't match Password"
end
it "has the right error message whend reset token is invalid" do
visit spree.edit_spree_user_password_path(reset_password_token: "#{reset_password_token}-i")
fill_in "Password", with: "my secret"
fill_in "Password Confirmation", with: "my secret"
click_button
expect(page).to have_text "Reset password token is invalid"
end
it "has the right error message whend reset token is invalid" do
reset_password_token = user.regenerate_reset_password_token
user.reset_password_sent_at = 2.days.ago
user.save!
visit spree.edit_spree_user_password_path(reset_password_token: reset_password_token)
fill_in "Password", with: "my secret"
fill_in "Password Confirmation", with: "my secret"
click_button
expect(page).to have_text "Reset password token has expired, please request a new one"
end
it "can actually reset its own password" do
visit spree.edit_spree_user_password_path(reset_password_token: reset_password_token)
fill_in "Password", with: "my secret"
fill_in "Password Confirmation", with: "my secret"
click_button
expect(page).to have_text "Your password has been changed successfully"
end
end
end