2026-01-12 15:52:27 +01:00
|
|
|
class User < ApplicationRecord
|
|
|
|
|
has_secure_password
|
|
|
|
|
has_many :sessions, dependent: :destroy
|
2026-01-28 16:34:06 +01:00
|
|
|
has_many :moods
|
2026-01-12 15:52:27 +01:00
|
|
|
|
|
|
|
|
normalizes :email_address, with: ->(e) { e.strip.downcase }
|
2026-01-12 19:24:51 +01:00
|
|
|
|
|
|
|
|
generates_token_for :invitation, expires_in: 5.days do
|
|
|
|
|
invitation_accepted_at
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def invite_user!(email)
|
|
|
|
|
invited_user = User.create!(
|
|
|
|
|
email_address: email,
|
|
|
|
|
password: SecureRandom.hex(16) # temporary password
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Send invitation email using the generated token
|
|
|
|
|
token = invited_user.generate_token_for(:invitation)
|
|
|
|
|
UserMailer.invitation_email(invited_user, token).deliver_later
|
|
|
|
|
|
|
|
|
|
invited_user
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def self.find_by_invitation_token(token)
|
|
|
|
|
find_by_token_for(:invitation, token)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def invitation_token
|
|
|
|
|
generate_token_for(:invitation)
|
|
|
|
|
end
|
2026-01-29 17:05:34 +01:00
|
|
|
|
|
|
|
|
def history
|
2026-02-07 12:09:06 +01:00
|
|
|
MoodCalendarService.generate_calendar(moods)
|
2026-01-29 17:05:34 +01:00
|
|
|
end
|
2026-01-12 15:52:27 +01:00
|
|
|
end
|