Skip to content

Commit

Permalink
Support new password/login validation errors added in Rodauth 2.19
Browse files Browse the repository at this point in the history
  • Loading branch information
janko committed Dec 23, 2021
1 parent f1edb4b commit 098bfe0
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 7 deletions.
12 changes: 12 additions & 0 deletions lib/rodauth/i18n/login_password_requirements_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ def password_does_not_meet_requirements_message
i18n_translate(__method__, super) + "#{" (#{password_requirement_message})" if password_requirement_message}"
end

def password_too_long_message
i18n_translate(__method__, super, password_maximum_length: password_maximum_length)
end

def password_too_many_bytes_message
i18n_translate(__method__, super, password_maximum_bytes: password_maximum_bytes)
end

def password_too_short_message
i18n_translate(__method__, super, password_minimum_length: password_minimum_length)
end
Expand All @@ -32,6 +40,10 @@ def login_too_long_message
i18n_translate(__method__, super, login_maximum_length: login_maximum_length)
end

def login_too_many_bytes_message
i18n_translate(__method__, super, login_maximum_bytes: login_maximum_bytes)
end

def login_too_short_message
i18n_translate(__method__, super, login_minimum_length: login_minimum_length)
end
Expand Down
3 changes: 3 additions & 0 deletions locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ en:
login_notice_flash: You have been logged in
login_page_title: Login
login_too_long_message: maximum %{login_maximum_length} characters
login_too_many_bytes_message: maximum %{login_maximum_bytes} bytes
login_too_short_message: minimum %{login_minimum_length} characters
logins_do_not_match_message: logins do not match
logout_button: Logout
Expand Down Expand Up @@ -114,6 +115,8 @@ en:
password_not_enough_character_groups_message: does not include uppercase letters, lowercase letters, and numbers
password_same_as_previous_password_message: same as previous password
password_too_many_repeating_characters_message: contains too many of the same character in a row
password_too_long_message: maximum %{password_maximum_length} characters
password_too_many_bytes_message: maximum %{password_maximum_bytes} bytes
password_too_short_message: minimum %{password_minimum_length} characters
passwords_do_not_match_message: passwords do not match
recovery_auth_button: Authenticate via Recovery Code
Expand Down
3 changes: 3 additions & 0 deletions locales/hr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ hr:
login_does_not_meet_requirements_message: neispravna email adresa, ne ispunjava uvjete
login_label: Email adresa
login_too_long_message: najviše %{login_maximum_length} znakova
login_too_many_bytes_message: najviše %{login_maximum_bytes} bajtova
login_too_short_message: najmanje %{login_minimum_length} znakova
password_confirm_label: Potvrda lozinke
password_does_not_meet_requirements_message: neispravna lozinka, ne ispunjava uvjete
password_label: Lozinka
password_too_long_message: najviše %{password_maximum_length} znakova
password_too_many_bytes_message: najviše %{password_maximum_bytes} bajtova
password_too_short_message: najmanje %{password_minimum_length} znakova
# ...
2 changes: 1 addition & 1 deletion rodauth-i18n.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
spec.files = Dir["README.md", "LICENSE.txt", "CHANGELOG.md", "lib/**/*", "locales/**/*", "*.gemspec"]
spec.require_paths = ["lib"]

spec.add_dependency "rodauth", "~> 2.0"
spec.add_dependency "rodauth", "~> 2.19"
spec.add_dependency "i18n", "~> 1.0"

spec.add_development_dependency "minitest"
Expand Down
96 changes: 90 additions & 6 deletions test/login_password_requirements_base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,114 @@
assert_includes page.text, "Potvrda lozinke"
end

it "translates validation errors" do
it "translates password too short message" do
rodauth do
enable :i18n, :create_account
require_login_confirmation? false
require_password_confirmation? false
password_minimum_length 3
i18n_locale { :hr }
end
roda do |r|
r.rodauth
end

visit "/create-account"
fill_in "Email adresa", with: "user@example.com"
fill_in "Lozinka", with: "a"
click_on "Stvori korisnički račun"
assert_includes page.text, "neispravna lozinka, ne ispunjava uvjete (najmanje 3 znakova)"
end

it "translates password too long message" do
rodauth do
enable :i18n, :create_account
require_login_confirmation? false
require_password_confirmation? false
password_maximum_length 72
i18n_locale { :hr }
end
roda do |r|
r.rodauth
end

visit "/create-account"
fill_in "Email adresa", with: "user@example.com"
fill_in "Lozinka", with: "a" * 73
click_on "Stvori korisnički račun"
assert_includes page.text, "neispravna lozinka, ne ispunjava uvjete (najviše 72 znakova)"
end

it "translates password too many bytes message" do
rodauth do
enable :i18n, :create_account
require_login_confirmation? false
require_password_confirmation? false
password_maximum_bytes 72
i18n_locale { :hr }
end
roda do |r|
r.rodauth
end

visit "/create-account"
fill_in "Email adresa", with: "user@example.com"
fill_in "Lozinka", with: "a" * 73
click_on "Stvori korisnički račun"
assert_includes page.text, "neispravna lozinka, ne ispunjava uvjete (najviše 72 bajtova)"
end

it "translates login too short message" do
rodauth do
enable :i18n, :create_account
require_login_confirmation? false
require_password_confirmation? false
login_minimum_length 3
i18n_locale { :hr }
end
roda do |r|
r.rodauth
r.root { view content: "" }
end

visit "/create-account"
fill_in "Email adresa", with: "a"
click_on "Stvori korisnički račun"
assert_includes page.text, "neispravna email adresa, ne ispunjava uvjete (najmanje 3 znakova)"
end

fill_in "Email adresa", with: "a" * 300
it "translates login too long message" do
rodauth do
enable :i18n, :create_account
require_login_confirmation? false
require_password_confirmation? false
login_maximum_length 255
i18n_locale { :hr }
end
roda do |r|
r.rodauth
end

visit "/create-account"
fill_in "Email adresa", with: "a" * 256
click_on "Stvori korisnički račun"
assert_includes page.text, "neispravna email adresa, ne ispunjava uvjete (najviše 255 znakova)"
end

fill_in "Email adresa", with: "user@example.com"
fill_in "Lozinka", with: "s"
it "translates login too many bytes message" do
rodauth do
enable :i18n, :create_account
require_login_confirmation? false
require_password_confirmation? false
login_maximum_bytes 100
i18n_locale { :hr }
end
roda do |r|
r.rodauth
end

visit "/create-account"
fill_in "Email adresa", with: "a" * 101
click_on "Stvori korisnički račun"
assert_includes page.text, "neispravna lozinka, ne ispunjava uvjete (najmanje 6 znakova)"
assert_includes page.text, "neispravna email adresa, ne ispunjava uvjete (najviše 100 bajtova)"
end
end

0 comments on commit 098bfe0

Please sign in to comment.