blob: 33656079c67ce1536081fadfe06e3882b3d40a4e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
class Session < ActiveRecord::Base
belongs_to :user
def access(request)
if save
{
value: self.id,
httponly: true,
secure: Rails.env.production? || Rails.env.staging?,
expires: 2.weeks.from_now
}
else
raise "heck"
end
end
def revoke!
update_attribute(:revoked_at, Time.now.utc)
end
class << self
def active
where(revoked_at: nil)
end
def authenticate!(session_key)
active.find(session_key)
end
end
end
|