2016-02-08 18:16:18 +01:00
|
|
|
class InvitesController < ApplicationController
|
2018-03-22 09:31:07 +01:00
|
|
|
before_action :ensure_user_signed_in
|
2016-09-13 12:17:56 +02:00
|
|
|
|
2016-02-08 18:16:18 +01:00
|
|
|
def create
|
2016-12-13 14:22:54 +01:00
|
|
|
email = params[:email].downcase
|
|
|
|
|
2018-03-22 09:31:07 +01:00
|
|
|
invite = InviteUser.create(
|
|
|
|
dossier: current_user.dossiers.find(params[:dossier_id]),
|
|
|
|
user: User.find_by(email: email),
|
|
|
|
email: email,
|
|
|
|
email_sender: current_user.email
|
|
|
|
)
|
2016-02-08 18:16:18 +01:00
|
|
|
|
|
|
|
if invite.valid?
|
2018-01-11 19:04:39 +01:00
|
|
|
if invite.user.present?
|
2018-05-25 18:05:28 +02:00
|
|
|
InviteMailer.invite_user(invite).deliver_later
|
2018-01-11 19:04:39 +01:00
|
|
|
else
|
2018-05-25 18:05:28 +02:00
|
|
|
InviteMailer.invite_guest(invite).deliver_later
|
2018-01-11 19:04:39 +01:00
|
|
|
end
|
2016-02-08 18:16:18 +01:00
|
|
|
|
|
|
|
flash.notice = "Invitation envoyée (#{invite.email})"
|
|
|
|
else
|
2017-07-13 09:46:13 +02:00
|
|
|
flash.alert = invite.errors.full_messages
|
2016-02-08 18:16:18 +01:00
|
|
|
end
|
|
|
|
|
2018-01-15 10:02:10 +01:00
|
|
|
redirect_to url_for(controller: 'users/recapitulatif', action: :show, dossier_id: params['dossier_id'])
|
2016-02-08 18:16:18 +01:00
|
|
|
end
|
2016-09-13 12:17:56 +02:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-03-22 09:31:07 +01:00
|
|
|
def ensure_user_signed_in
|
2018-03-22 09:15:32 +01:00
|
|
|
if !user_signed_in?
|
2018-01-11 19:04:39 +01:00
|
|
|
return redirect_to root_path
|
|
|
|
end
|
2016-09-13 12:17:56 +02:00
|
|
|
end
|
2016-02-08 18:16:18 +01:00
|
|
|
end
|