diff options
author | Marin Jankovski <marin@gitlab.com> | 2014-07-09 14:42:25 +0200 |
---|---|---|
committer | Marin Jankovski <marin@gitlab.com> | 2014-07-09 14:42:25 +0200 |
commit | 4024aa8e812a546b0d6c9110b6b8d36d327961fc (patch) | |
tree | dd30ff86512f48eb0ecce56ae2e40879fefd481d /app/models/concerns/token_authenticatable.rb | |
parent | 34cfd84ed253dbee59c3097b0d10d9ed112cac58 (diff) | |
download | gitlab-ce-4024aa8e812a546b0d6c9110b6b8d36d327961fc.tar.gz |
Try to keep token authenticable compatibility
Diffstat (limited to 'app/models/concerns/token_authenticatable.rb')
-rw-r--r-- | app/models/concerns/token_authenticatable.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/app/models/concerns/token_authenticatable.rb b/app/models/concerns/token_authenticatable.rb new file mode 100644 index 00000000000..9b88ec1cc38 --- /dev/null +++ b/app/models/concerns/token_authenticatable.rb @@ -0,0 +1,31 @@ +module TokenAuthenticatable + extend ActiveSupport::Concern + + module ClassMethods + def find_by_authentication_token(authentication_token = nil) + if authentication_token + where(authentication_token: authentication_token).first + end + end + end + + def ensure_authentication_token + if authentication_token.blank? + self.authentication_token = generate_authentication_token + end + end + + def reset_authentication_token! + self.authentication_token = generate_authentication_token + save + end + + private + + def generate_authentication_token + loop do + token = Devise.friendly_token + break token unless self.class.unscoped.where(authentication_token: token).first + end + end +end |