diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-11-15 16:08:28 +0100 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-11-15 16:08:28 +0100 |
commit | 3ee8e01923c9452afe9ae21c2135aa8a7eb82f89 (patch) | |
tree | 450fed992dbc62d38c2d4c607f40443faacaed89 /app/models/concerns | |
parent | f1a74a656bcede06d082e351d6261e43a88a0df7 (diff) | |
download | gitlab-ce-3ee8e01923c9452afe9ae21c2135aa8a7eb82f89.tar.gz |
Extract token authenticatable strategy fabrication
Diffstat (limited to 'app/models/concerns')
-rw-r--r-- | app/models/concerns/token_authenticatable.rb | 9 | ||||
-rw-r--r-- | app/models/concerns/token_authenticatable_strategies/base.rb | 10 |
2 files changed, 12 insertions, 7 deletions
diff --git a/app/models/concerns/token_authenticatable.rb b/app/models/concerns/token_authenticatable.rb index f881d119a17..fd8b4d70532 100644 --- a/app/models/concerns/token_authenticatable.rb +++ b/app/models/concerns/token_authenticatable.rb @@ -20,13 +20,8 @@ module TokenAuthenticatable attr_accessor :cleartext_tokens - strategy = if options[:digest] - TokenAuthenticatableStrategies::Digest.new(self, token_field, options) - elsif options[:encrypted] - TokenAuthenticatableStrategies::Encrypted.new(self, token_field, options) - else - TokenAuthenticatableStrategies::Insecure.new(self, token_field, options) - end + strategy = TokenAuthenticatableStrategies::Base + .fabricate(self, token_field, options) if unique define_singleton_method("find_by_#{token_field}") do |token| diff --git a/app/models/concerns/token_authenticatable_strategies/base.rb b/app/models/concerns/token_authenticatable_strategies/base.rb index 53b09ffd4d9..a722616756a 100644 --- a/app/models/concerns/token_authenticatable_strategies/base.rb +++ b/app/models/concerns/token_authenticatable_strategies/base.rb @@ -43,6 +43,16 @@ module TokenAuthenticatableStrategies options[:fallback] == true 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 def write_new_token(instance) |