Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
621071ca
Commit
621071ca
authored
Nov 15, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor and simplify token authenticatable concern
parent
3ee8e019
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
6 deletions
+7
-6
app/models/concerns/token_authenticatable.rb
app/models/concerns/token_authenticatable.rb
+7
-6
No files found.
app/models/concerns/token_authenticatable.rb
View file @
621071ca
...
...
@@ -9,21 +9,18 @@ module TokenAuthenticatable
private
# rubocop:disable Lint/UselessAccessModifier
def
add_authentication_token_field
(
token_field
,
options
=
{})
@token_fields
||=
[]
unique
=
options
.
fetch
(
:unique
,
true
)
if
@token_fields
.
include?
(
token_field
)
if
token_authenticatable_fields
.
include?
(
token_field
)
raise
ArgumentError
.
new
(
"
#{
token_field
}
already configured via add_authentication_token_field"
)
end
@token_fields
<<
token_field
token_authenticatable_fields
.
push
(
token_field
)
attr_accessor
:cleartext_tokens
strategy
=
TokenAuthenticatableStrategies
::
Base
.
fabricate
(
self
,
token_field
,
options
)
if
unique
if
options
.
fetch
(
:unique
,
true
)
define_singleton_method
(
"find_by_
#{
token_field
}
"
)
do
|
token
|
strategy
.
find_token_authenticatable
(
token
)
end
...
...
@@ -51,5 +48,9 @@ module TokenAuthenticatable
strategy
.
reset_token!
(
self
)
end
end
def
token_authenticatable_fields
@token_authenticatable_fields
||=
[]
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment