From 0de556e1f6a306bd1c7e63cf11039efc57ac292c Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Fri, 21 Aug 2015 15:33:06 +0200 Subject: [PATCH] Added little documentation. --- app/models/token.rb | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/app/models/token.rb b/app/models/token.rb index 54bdb3a68..6b3efb539 100644 --- a/app/models/token.rb +++ b/app/models/token.rb @@ -1,9 +1,46 @@ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ class Token < ActiveRecord::Base - before_create :generate_token + before_create :generate_token + belongs_to :user - belongs_to :user +=begin + +create new token + + token = Token.create( action: 'PasswordReset', user_id: user.id ) + +returns + + the token + +create new persistent token + + token = Token.create( + action: 'CalendarSubscriptions', + persistent: true, + user_id: user.id, + ) + +in case if you use it via an controller, e. g. you can verify via "curl -H "Authorization: Token token=33562a00d7eda2a7c2fb639b91c6bcb8422067b6" http://... + +returns + + the token + +=end + +=begin + +check token + + user = Token.check( action: 'PasswordReset', name: 'TheTokenItSelf' ) + +returns + + user for who this token was created + +=end def self.check( data ) @@ -30,7 +67,7 @@ class Token < ActiveRecord::Base def generate_token loop do - self.name = SecureRandom.hex(20) + self.name = SecureRandom.hex(30) break if !Token.exists?( name: name ) end