Skip to content
Snippets Groups Projects
Verified Commit c0d01ee0 authored by Felix Eckhofer's avatar Felix Eckhofer :man_dancing:
Browse files

Allow user to have non-lowercase names

Login still works regardless of case!
parent bef7e6dc
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,17 @@ class User < ApplicationRecord
after_initialize :set_avatar_color
# Custom method to allow user to sign-in with any case while still storing the "correct" case in the database
def self.find_for_database_authentication(warden_conditions)
conditions = warden_conditions.dup
if (login = conditions.delete(:name))
where(conditions.to_h).where(["lower(name) = :value", { value: login.downcase }]).first
else
logger.warn("Authentication did not query :name as expected, login will only work with exact case!")
where(conditions.to_h).first
end
end
def errors
super.tap { |errors| errors.delete(:password, :blank) if password.nil? }
end
......
......@@ -58,12 +58,12 @@ Devise.setup do |config|
# Configure which authentication keys should be case-insensitive.
# These keys will be downcased upon creating or modifying a user and when used
# to authenticate or find a user. Default is :email.
config.case_insensitive_keys = [:name]
config.case_insensitive_keys = [:email]
# Configure which authentication keys should have whitespace stripped.
# These keys will have whitespace before and after removed upon creating or
# modifying a user and when used to authenticate or find a user. Default is :email.
config.strip_whitespace_keys = [:name]
config.strip_whitespace_keys = [:email, :name]
# Tell if authentication through request.params is enabled. True by default.
# It can be set to an array that will enable params authentication only for the
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment