Added little documentation.

This commit is contained in:
Martin Edenhofer 2015-08-21 15:33:06 +02:00
parent c3be77edd4
commit 0de556e1f6

View file

@ -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