1 # == Schema Information
3 # Table name: user_tokens
5 # id :bigint(8) not null, primary key
6 # user_id :bigint(8) not null
7 # token :string not null
8 # expiry :datetime not null
13 # user_tokens_token_idx (token) UNIQUE
14 # user_tokens_user_id_idx (user_id)
18 # user_tokens_user_id_fkey (user_id => users.id)
21 class UserToken < ApplicationRecord
24 scope :unexpired, -> { where("expiry >= now()") }
26 after_initialize :set_defaults
35 self.token = OSM.make_token if token.blank?
36 self.expiry = 1.week.from_now if expiry.blank?