FEATURE: invite_code is case-insensitive

Previously we required exact casing for invite code, this can cause a lot
of confusion. Relax the requirement.
This commit is contained in:
Sam Saffron 2020-03-26 13:44:02 +11:00
parent b2aa203e67
commit ecbccab159
No known key found for this signature in database
GPG Key ID: B9606168D2FFD9F5
3 changed files with 5 additions and 4 deletions

View File

@ -425,7 +425,7 @@ class UsersController < ApplicationController
return fail_with("login.email_too_long")
end
if SiteSetting.require_invite_code && SiteSetting.invite_code != params[:invite_code]
if SiteSetting.require_invite_code && SiteSetting.invite_code.strip.downcase != params[:invite_code].strip.downcase
return fail_with("login.wrong_invite_code")
end

View File

@ -1529,7 +1529,7 @@ en:
markdown_typographer_quotation_marks: "List of double and single quotes replacement pairs"
post_undo_action_window_mins: "Number of minutes users are allowed to undo recent actions on a post (like, flag, etc)."
must_approve_users: "Staff must approve all new user accounts before they are allowed to access the site."
invite_code: "User must type this code to be allowed account registration, ignored when empty"
invite_code: "User must type this code to be allowed account registration, ignored when empty (case-insensitive)"
approve_suspect_users: "Add suspicious users to the review queue. Suspicious users have entered a bio/website but have no reading activity."
pending_users_reminder_delay: "Notify moderators if new users have been waiting for approval for longer than this many hours. Set to -1 to disable notifications."
maximum_session_age: "User will remain logged in for n hours since last visit"

View File

@ -618,7 +618,7 @@ describe UsersController do
it 'requires invite code when specified' do
expect(SiteSetting.require_invite_code).to eq(false)
SiteSetting.invite_code = "abc"
SiteSetting.invite_code = "abc def"
expect(SiteSetting.require_invite_code).to eq(true)
post_user(invite_code: "abcd")
@ -626,7 +626,8 @@ describe UsersController do
json = JSON.parse(response.body)
expect(json["success"]).to eq(false)
post_user(invite_code: "abc")
# case insensitive and stripped of leading/ending spaces
post_user(invite_code: " AbC deF ")
expect(response.status).to eq(200)
json = JSON.parse(response.body)
expect(json["success"]).to eq(true)