mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-22 18:46:22 +00:00
57 lines
1.5 KiB
Ruby
57 lines
1.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# Usuarie de la plataforma
|
|
class Usuarie < ApplicationRecord
|
|
include Usuarie::Consent
|
|
|
|
devise :invitable, :database_authenticatable,
|
|
:recoverable, :rememberable, :validatable,
|
|
:confirmable, :lockable, :registerable
|
|
|
|
validates_uniqueness_of :email
|
|
validates_with EmailAddress::ActiveRecordValidator, field: :email
|
|
|
|
before_create :lang_from_locale!
|
|
|
|
has_many :roles
|
|
has_many :sites, through: :roles
|
|
has_many :blazer_audits, foreign_key: 'user_id', class_name: 'Blazer::Audit'
|
|
has_many :blazer_queries, foreign_key: 'creator_id', class_name: 'Blazer::Query'
|
|
|
|
def name
|
|
email.split('@', 2).first
|
|
end
|
|
|
|
# Encuentra el rol que tiene le usuarie en el sitio
|
|
def rol_for_site(site)
|
|
roles.find_by(site: site)
|
|
end
|
|
|
|
# XXX: Ver increment_and_lock
|
|
def can_sign_in?(password)
|
|
active_for_authentication? && valid_password?(password)
|
|
end
|
|
|
|
# XXX: Estamos duplicando la forma en que Devise bloquea acceso
|
|
# por intentos fallidos porque no tenemos forma de correr
|
|
# validate() desde la estrategia DatabaseAuthenticatable sin
|
|
# generar una redirección.
|
|
#
|
|
# lib/devise/models/lockable.rb
|
|
def increment_and_lock!
|
|
increment_failed_attempts
|
|
lock_access! if attempts_exceeded? && !access_locked?
|
|
end
|
|
|
|
def send_devise_notification(notification, *args)
|
|
I18n.with_locale(lang) do
|
|
devise_mailer.send(notification, self, *args).deliver_later
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def lang_from_locale!
|
|
self.lang = I18n.locale.to_s
|
|
end
|
|
end
|