2026-01-12 19:24:51 +01:00
|
|
|
|
class InvitationsController < ApplicationController
|
|
|
|
|
|
before_action :set_user_by_token, only: %i[ edit update ]
|
|
|
|
|
|
allow_unauthenticated_access
|
|
|
|
|
|
|
|
|
|
|
|
def edit
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def update
|
|
|
|
|
|
password_params = params.expect(user: [ :password, :password_confirmation ])
|
|
|
|
|
|
|
|
|
|
|
|
if @user.update(password_params.merge(invitation_accepted_at: Time.current))
|
2026-09-29 07:35:53 +02:00
|
|
|
|
redirect_to root_path, notice: "Compte activé. Bienvenue !"
|
2026-01-12 19:24:51 +01:00
|
|
|
|
else
|
2026-09-29 07:35:53 +02:00
|
|
|
|
redirect_to invitation_path(params[:token]), alert: "Les deux mots de passe ne sont pas identiques."
|
2026-01-12 19:24:51 +01:00
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
|
|
def set_user_by_token
|
|
|
|
|
|
@user = User.find_by_invitation_token(params[:token])
|
|
|
|
|
|
rescue ActiveSupport::MessageVerifier::InvalidSignature
|
2026-09-29 07:35:53 +02:00
|
|
|
|
redirect_to root_path, alert: "Ce lien d’invitation n’est plus valable."
|
2026-01-12 19:24:51 +01:00
|
|
|
|
end
|
|
|
|
|
|
end
|