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)
|
2018-04-11 17:14:47 +02:00
|
|
|
password = SecureRandom.hex
|
2018-01-11 14:17:50 +01:00
|
|
|
administrateur = Administrateur.new({
|
|
|
|
email: email,
|
2018-04-11 17:14:47 +02:00
|
|
|
active: false,
|
|
|
|
password: password,
|
|
|
|
password_confirmation: password
|
2018-01-11 14:17:50 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
if administrateur.save
|
2018-05-25 18:05:28 +02:00
|
|
|
AdministrationMailer.new_admin_email(administrateur, self).deliver_later
|
2018-05-31 18:07:19 +02:00
|
|
|
administrateur.invite!(id)
|
2018-10-30 15:31:13 +01:00
|
|
|
|
2019-08-08 17:37:29 +02:00
|
|
|
user = User.create({
|
2018-04-11 17:14:47 +02:00
|
|
|
email: email,
|
2018-06-06 16:35:22 +02:00
|
|
|
password: password,
|
2018-10-25 15:07:15 +02:00
|
|
|
confirmed_at: Time.zone.now
|
2018-04-11 17:14:47 +02:00
|
|
|
})
|
2018-10-30 15:31:13 +01:00
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
Instructeur.create({
|
2018-10-30 15:31:13 +01:00
|
|
|
email: email,
|
2019-08-08 17:37:29 +02:00
|
|
|
user: user
|
2018-10-30 15:31:13 +01:00
|
|
|
})
|
2018-01-11 14:17:50 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
administrateur
|
|
|
|
end
|
2016-02-23 16:51:24 +01:00
|
|
|
end
|