Added little documentation.
This commit is contained in:
parent
c3be77edd4
commit
0de556e1f6
1 changed files with 40 additions and 3 deletions
|
@ -2,9 +2,46 @@
|
||||||
|
|
||||||
class Token < ActiveRecord::Base
|
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 )
|
def self.check( data )
|
||||||
|
|
||||||
# fetch token
|
# fetch token
|
||||||
|
@ -30,7 +67,7 @@ class Token < ActiveRecord::Base
|
||||||
def generate_token
|
def generate_token
|
||||||
|
|
||||||
loop do
|
loop do
|
||||||
self.name = SecureRandom.hex(20)
|
self.name = SecureRandom.hex(30)
|
||||||
|
|
||||||
break if !Token.exists?( name: name )
|
break if !Token.exists?( name: name )
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue