app.kluk.fr/app/models/user.rb

43 lines
988 B
Ruby
Raw Normal View History

2026-01-12 15:52:27 +01:00
class User < ApplicationRecord
has_secure_password
has_many :sessions, dependent: :destroy
2026-02-26 11:05:15 +01:00
has_many :moods, -> { order "recorded_at" }
2026-03-15 19:26:52 +01:00
has_many :modes
2026-03-19 21:21:28 +01:00
has_many :day_logs
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-02-20 10:30:12 +01:00
2026-03-14 16:31:00 +01:00
def current_mode
2026-02-20 10:30:12 +01:00
self.moods.last&.mode || "croisiere"
end
2026-01-12 15:52:27 +01:00
end