diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-11-15 16:12:07 +0100 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-11-15 16:12:07 +0100 |
commit | 621071ca5b7ecb21b9baf6d9a2b32758371b7128 (patch) | |
tree | d0b92ed99a55ef0ab5738ecb09d8a1b61ff469a7 /app | |
parent | 3ee8e01923c9452afe9ae21c2135aa8a7eb82f89 (diff) | |
download | gitlab-ce-621071ca5b7ecb21b9baf6d9a2b32758371b7128.tar.gz |
Refactor and simplify token authenticatable concern
Diffstat (limited to 'app')
-rw-r--r-- | app/models/concerns/token_authenticatable.rb | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/app/models/concerns/token_authenticatable.rb b/app/models/concerns/token_authenticatable.rb index fd8b4d70532..ca5329a3615 100644 --- a/app/models/concerns/token_authenticatable.rb +++ b/app/models/concerns/token_authenticatable.rb @@ -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 |