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
|
|
|
|
2019-08-09 11:41:36 +02:00
|
|
|
user = User.find_by(email: email)
|
2018-10-30 15:31:13 +01:00
|
|
|
|
2019-08-09 11:41:36 +02:00
|
|
|
if user.nil?
|
|
|
|
# set confirmed_at otherwise admin confirmation doesnt work
|
|
|
|
# we somehow mess up using reset_password logic instead of
|
|
|
|
# confirmation_logic
|
|
|
|
# FIXME
|
|
|
|
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
|
2019-08-09 11:41:36 +02:00
|
|
|
)
|
|
|
|
end
|
2018-10-30 15:31:13 +01:00
|
|
|
|
2019-08-09 11:41:36 +02:00
|
|
|
if user.errors.empty?
|
|
|
|
if user.instructeur.nil?
|
|
|
|
Instructeur.create!(email: email, user: user)
|
|
|
|
end
|
|
|
|
|
|
|
|
if user.administrateur.nil?
|
|
|
|
administrateur = Administrateur.create!(email: email, active: false, user: user)
|
|
|
|
AdministrationMailer.new_admin_email(administrateur, self).deliver_later
|
|
|
|
user.invite_administrateur!(id)
|
|
|
|
end
|
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
|