Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarin Jankovski <marin@gitlab.com>2014-07-09 16:42:25 +0400
committerMarin Jankovski <marin@gitlab.com>2014-07-09 16:42:25 +0400
commit4024aa8e812a546b0d6c9110b6b8d36d327961fc (patch)
treedd30ff86512f48eb0ecce56ae2e40879fefd481d /app/models/concerns/token_authenticatable.rb
parent34cfd84ed253dbee59c3097b0d10d9ed112cac58 (diff)
Try to keep token authenticable compatibility
Diffstat (limited to 'app/models/concerns/token_authenticatable.rb')
-rw-r--r--app/models/concerns/token_authenticatable.rb31
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