- drop Bulma and Font Awesome, plain CSS built on charte.css - dashboard: GitHub-like calendar grouped by year, selected day panel (sticky side column on desktop, bottom bar on mobile), keyboard navigation - public page: today's mood and last months fit in one screen, journal hidden - day log page: mode picker as pills, illustration follows the chosen mode - login, password and invitation screens in French, global flash messages - add User#current_mode_since Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
57 lines
1.4 KiB
Ruby
57 lines
1.4 KiB
Ruby
class User < ApplicationRecord
|
|
has_secure_password
|
|
has_many :sessions, dependent: :destroy
|
|
has_many :moods, -> { order "recorded_at" }
|
|
has_many :modes
|
|
has_many :day_logs
|
|
|
|
normalizes :email_address, with: ->(e) { e.strip.downcase }
|
|
|
|
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
|
|
|
|
def history
|
|
MoodCalendarService.generate_calendar(self)
|
|
end
|
|
|
|
def current_mode
|
|
self.moods.last&.mode || "croisiere"
|
|
end
|
|
|
|
# Le jour où l'humeur actuelle a commencé : le plus ancien des derniers
|
|
# enregistrements consécutifs dans le mode actuel.
|
|
def current_mode_since
|
|
since = nil
|
|
moods.reorder(recorded_at: :desc).pluck(:mode_id, :recorded_at).each do |mode_id, recorded_at|
|
|
break if since && mode_id != since[:mode_id]
|
|
since = { mode_id: mode_id, day: recorded_at.to_date }
|
|
end
|
|
since&.dig(:day)
|
|
end
|
|
|
|
def current_day_log
|
|
self.day_logs.find_by(day: Date.today)
|
|
end
|
|
end
|