2018-03-06 13:44:29 +01:00
|
|
|
class Administration < ApplicationRecord
|
2016-02-23 16:51:24 +01:00
|
|
|
# Include default devise modules. Others available are:
|
|
|
|
# :confirmable, :lockable, :timeoutable and :omniauthable
|
2019-05-22 18:33:00 +02:00
|
|
|
devise :database_authenticatable, :rememberable, :trackable, :validatable, :omniauthable, :lockable, :async, omniauth_providers: [:github]
|
2017-12-20 15:27:33 +01:00
|
|
|
|
|
|
|
def self.from_omniauth(params)
|
|
|
|
find_by(email: params["info"]["email"])
|
|
|
|
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?
|
|
|
|
AdministrationMailer.new_admin_email(user.administrateur, self).deliver_later
|
|
|
|
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
|
2016-02-23 16:51:24 +01:00
|
|
|
end
|