Cross Reference: access_token.rb
xref
: /
ontohub
/
app
/
models
/
access_token.rb
Home
History
Annotate
Line#
Navigate
Download
Search
only in
./
access_token.rb revision 5513a7cc4f5859d263e4cb66ae93e8dbfcf3681f
class
AccessToken
<
ActiveRecord
::
Base
LENGTH
=
20
belongs_to
:
repository
attr_accessible
:
expiration
, :
token
scope
:
unexpired
, ->
()
{
where
(
'expiration > ?'
,
Time.now
)
}
def
to_s
token
end
def
expired
?
expiration
<=
Time.now
end
def
self.create
_for
(
repository
)
a =
insecure_build_for
(
repository
)
until
!
a.nil
? &&
a.valid
?
a.save
!
a
end
protected
def
self.fresh
_expiration_date
Settings.access_token.expiration_minutes.minutes.from
_now
end
def
self.insecure
_build_for
(
repository
)
AccessToken.new
({
repository
:
repository
,
expiration
:
fresh_expiration_date
,
token
:
SecureRandom.hex
(
LENGTH
)
}, {
without_protection
:
true
})
end
end