tinyforms/app/models/user.rb
Michael Bumann c478cfc7af Use sorcery for logins
This gives us more flexibility and allows us to use password authentication
later. Also we don't need to build the login functionality ourself.
2020-04-13 14:59:07 +02:00

19 lines
519 B
Ruby

class User < ApplicationRecord
authenticates_with_sorcery!
has_many :authentications, dependent: :destroy
has_many :forms, dependent: :destroy
def deactivate!(reason = nil)
# currently we only use deactivate if we get an authentication exception appending data to a spreadsheet
authentications.last&.update(expires_at: Time.current)
end
def active?
authentications.any? { |a| !a.expired? }
end
def google_authorization
authentications.for(:google).last.google_authorization
end
end