Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rescheduled 🗓️
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
c3lingo
rescheduled 🗓️
Commits
c0d01ee0
Verified
Commit
c0d01ee0
authored
3 months ago
by
Felix Eckhofer
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/models/user.rb
+11
-0
11 additions, 0 deletions
app/models/user.rb
config/initializers/devise.rb
+2
-2
2 additions, 2 deletions
config/initializers/devise.rb
with
13 additions
and
2 deletions
app/models/user.rb
+
11
−
0
View file @
c0d01ee0
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
config/initializers/devise.rb
+
2
−
2
View file @
c0d01ee0
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment