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
|
2018-05-26 00:06:40 +02:00
|
|
|
devise :database_authenticatable, :rememberable, :trackable, :validatable, :omniauthable, :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-04-11 17:14:47 +02:00
|
|
|
User.create({
|
|
|
|
email: email,
|
2018-06-06 16:35:22 +02:00
|
|
|
password: password,
|
|
|
|
confirmed_at: DateTime.now
|
2018-04-11 17:14:47 +02:00
|
|
|
})
|
2018-01-11 14:17:50 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
administrateur
|
|
|
|
end
|
2016-02-23 16:51:24 +01:00
|
|
|
end
|