2020-08-06 16:35:45 +02:00
|
|
|
# == Schema Information
|
|
|
|
#
|
2020-11-05 15:09:11 +01:00
|
|
|
# Table name: super_admins
|
2020-08-06 16:35:45 +02:00
|
|
|
#
|
2020-11-03 18:21:19 +01:00
|
|
|
# id :integer not null, primary key
|
|
|
|
# consumed_timestep :integer
|
|
|
|
# current_sign_in_at :datetime
|
|
|
|
# current_sign_in_ip :string
|
|
|
|
# email :string default(""), not null
|
|
|
|
# encrypted_otp_secret :string
|
|
|
|
# encrypted_otp_secret_iv :string
|
|
|
|
# encrypted_otp_secret_salt :string
|
|
|
|
# encrypted_password :string default(""), not null
|
|
|
|
# failed_attempts :integer default(0), not null
|
|
|
|
# last_sign_in_at :datetime
|
|
|
|
# last_sign_in_ip :string
|
|
|
|
# locked_at :datetime
|
|
|
|
# otp_required_for_login :boolean
|
|
|
|
# remember_created_at :datetime
|
|
|
|
# reset_password_sent_at :datetime
|
|
|
|
# reset_password_token :string
|
|
|
|
# sign_in_count :integer default(0), not null
|
|
|
|
# unlock_token :string
|
|
|
|
# created_at :datetime
|
|
|
|
# updated_at :datetime
|
2020-08-06 16:35:45 +02:00
|
|
|
#
|
2020-11-05 15:09:11 +01:00
|
|
|
class SuperAdmin < ApplicationRecord
|
2021-08-26 19:23:01 +02:00
|
|
|
include PasswordComplexityConcern
|
|
|
|
|
2023-03-02 13:47:48 +01:00
|
|
|
devise :rememberable, :trackable, :validatable, :lockable, :recoverable
|
|
|
|
if SUPER_ADMIN_OTP_ENABLED
|
|
|
|
devise :two_factor_authenticatable, :otp_secret_encryption_key => Rails.application.secrets.otp_secret_key
|
|
|
|
else
|
|
|
|
devise :database_authenticatable
|
|
|
|
end
|
2020-11-03 18:21:19 +01:00
|
|
|
|
2020-11-04 16:35:15 +01:00
|
|
|
def enable_otp!
|
2020-11-05 15:09:11 +01:00
|
|
|
self.otp_secret = SuperAdmin.generate_otp_secret
|
2020-11-04 16:35:15 +01:00
|
|
|
self.otp_required_for_login = true
|
|
|
|
save!
|
|
|
|
end
|
|
|
|
|
|
|
|
def disable_otp!
|
|
|
|
self.assign_attributes(
|
|
|
|
{
|
|
|
|
encrypted_otp_secret: nil,
|
|
|
|
encrypted_otp_secret_iv: nil,
|
|
|
|
encrypted_otp_secret_salt: nil,
|
|
|
|
consumed_timestep: nil,
|
|
|
|
otp_required_for_login: false
|
|
|
|
}
|
|
|
|
)
|
|
|
|
save!
|
|
|
|
end
|
2018-01-11 14:17:50 +01:00
|
|
|
|
|
|
|
def invite_admin(email)
|
2019-08-20 12:07:07 +02:00
|
|
|
user = User.create_or_promote_to_administrateur(email, SecureRandom.hex)
|
2018-01-11 14:17:50 +01:00
|
|
|
|
2019-08-20 12:07:07 +02:00
|
|
|
if user.valid?
|
|
|
|
user.invite_administrateur!(id)
|
2018-01-11 14:17:50 +01:00
|
|
|
end
|
|
|
|
|
2019-08-09 11:41:36 +02:00
|
|
|
user
|
2018-01-11 14:17:50 +01:00
|
|
|
end
|
2022-04-19 18:17:49 +02:00
|
|
|
|
|
|
|
def send_devise_notification(notification, *args)
|
|
|
|
devise_mailer.send(notification, self, *args).deliver_later
|
|
|
|
end
|
2016-02-23 16:51:24 +01:00
|
|
|
end
|