summaryrefslogtreecommitdiff
path: root/app/models/session.rb
blob: 7d39c9c7fb245f48797152d394f1dfbd1c975494 (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
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 authenticate!(session_key)
      Session.find(session_key)
    end
  end
end