This gives us more flexibility and allows us to use password authentication later. Also we don't need to build the login functionality ourself.
19 lines
519 B
Ruby
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
|