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
Léo-Paul Géneau
gitlab-ce
Commits
3ee8e019
Commit
3ee8e019
authored
Nov 15, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract token authenticatable strategy fabrication
parent
f1a74a65
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
7 deletions
+12
-7
app/models/concerns/token_authenticatable.rb
app/models/concerns/token_authenticatable.rb
+2
-7
app/models/concerns/token_authenticatable_strategies/base.rb
app/models/concerns/token_authenticatable_strategies/base.rb
+10
-0
No files found.
app/models/concerns/token_authenticatable.rb
View file @
3ee8e019
...
@@ -20,13 +20,8 @@ module TokenAuthenticatable
...
@@ -20,13 +20,8 @@ module TokenAuthenticatable
attr_accessor
:cleartext_tokens
attr_accessor
:cleartext_tokens
strategy
=
if
options
[
:digest
]
strategy
=
TokenAuthenticatableStrategies
::
Base
TokenAuthenticatableStrategies
::
Digest
.
new
(
self
,
token_field
,
options
)
.
fabricate
(
self
,
token_field
,
options
)
elsif
options
[
:encrypted
]
TokenAuthenticatableStrategies
::
Encrypted
.
new
(
self
,
token_field
,
options
)
else
TokenAuthenticatableStrategies
::
Insecure
.
new
(
self
,
token_field
,
options
)
end
if
unique
if
unique
define_singleton_method
(
"find_by_
#{
token_field
}
"
)
do
|
token
|
define_singleton_method
(
"find_by_
#{
token_field
}
"
)
do
|
token
|
...
...
app/models/concerns/token_authenticatable_strategies/base.rb
View file @
3ee8e019
...
@@ -43,6 +43,16 @@ module TokenAuthenticatableStrategies
...
@@ -43,6 +43,16 @@ module TokenAuthenticatableStrategies
options
[
:fallback
]
==
true
options
[
:fallback
]
==
true
end
end
def
self
.
fabricate
(
instance
,
field
,
options
)
if
options
[
:digest
]
TokenAuthenticatableStrategies
::
Digest
.
new
(
instance
,
field
,
options
)
elsif
options
[
:encrypted
]
TokenAuthenticatableStrategies
::
Encrypted
.
new
(
instance
,
field
,
options
)
else
TokenAuthenticatableStrategies
::
Insecure
.
new
(
instance
,
field
,
options
)
end
end
protected
protected
def
write_new_token
(
instance
)
def
write_new_token
(
instance
)
...
...
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