demarches-normaliennes/app/models/administration.rb

31 lines
838 B
Ruby
Raw Normal View History

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
def invite_admin(email)
password = SecureRandom.hex
administrateur = Administrateur.new({
email: email,
active: false,
password: password,
password_confirmation: password
})
if administrateur.save
AdministrationMailer.new_admin_email(administrateur, self).deliver_later
administrateur.invite!
User.create({
email: email,
password: password
})
end
administrateur
end
2016-02-23 16:51:24 +01:00
end