Simplify invite_instructeur
This commit is contained in:
parent
97d0855d47
commit
98a24bea51
1 changed files with 7 additions and 13 deletions
|
@ -37,21 +37,15 @@ class Admin::InstructeursController < AdminController
|
|||
private
|
||||
|
||||
def invite_instructeur(email)
|
||||
user = User.find_by(email: email)
|
||||
|
||||
if user.nil?
|
||||
user = User.create(
|
||||
email: email,
|
||||
password: SecureRandom.hex,
|
||||
confirmed_at: Time.zone.now
|
||||
)
|
||||
end
|
||||
|
||||
if user.errors.empty?
|
||||
@instructeur = Instructeur.create(email: email, administrateurs: [current_administrateur])
|
||||
user.update!(instructeur: @instructeur)
|
||||
user = User.create_or_promote_to_instructeur(
|
||||
email,
|
||||
SecureRandom.hex,
|
||||
administrateurs: [current_administrateur]
|
||||
)
|
||||
|
||||
if user.valid?
|
||||
user.invite!
|
||||
|
||||
flash.notice = 'Instructeur ajouté'
|
||||
else
|
||||
flash.alert = user.errors.full_messages
|
||||
|
|
Loading…
Reference in a new issue