2019-07-02 18:15:03 +02:00
|
|
|
module Users
|
|
|
|
class ProfilController < UserController
|
2019-12-09 17:11:12 +01:00
|
|
|
before_action :redirect_if_instructeur,
|
|
|
|
only: :update_email,
|
|
|
|
if: -> { instructeur_signed_in? }
|
|
|
|
|
2018-08-23 18:53:35 +02:00
|
|
|
def show
|
|
|
|
end
|
|
|
|
|
|
|
|
def renew_api_token
|
2018-08-24 16:45:43 +02:00
|
|
|
@token = current_administrateur.renew_api_token
|
2018-08-24 14:19:44 +02:00
|
|
|
flash.now.notice = 'Votre jeton a été regénéré.'
|
|
|
|
render :show
|
2018-08-23 18:53:35 +02:00
|
|
|
end
|
2019-07-08 10:40:50 +02:00
|
|
|
|
|
|
|
def update_email
|
2019-12-09 16:50:30 +01:00
|
|
|
if current_user.update(update_email_params)
|
2019-07-08 10:40:50 +02:00
|
|
|
flash.notice = t('devise.registrations.update_needs_confirmation')
|
2019-12-09 16:50:30 +01:00
|
|
|
elsif current_user.errors&.details&.dig(:email)&.any? { |e| e[:error] == :taken }
|
|
|
|
UserMailer.account_already_taken(current_user, requested_email).deliver_later
|
2019-07-09 17:08:27 +02:00
|
|
|
# avoid leaking information about whether an account with this email exists or not
|
2019-07-08 10:40:50 +02:00
|
|
|
flash.notice = t('devise.registrations.update_needs_confirmation')
|
|
|
|
else
|
2019-12-09 16:50:30 +01:00
|
|
|
flash.alert = current_user.errors.full_messages
|
2019-07-08 10:40:50 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
redirect_to profil_path
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def update_email_params
|
|
|
|
params.require(:user).permit(:email)
|
|
|
|
end
|
2019-07-09 17:08:27 +02:00
|
|
|
|
|
|
|
def requested_email
|
|
|
|
update_email_params[:email]
|
|
|
|
end
|
2019-12-09 17:11:12 +01:00
|
|
|
|
|
|
|
def redirect_if_instructeur
|
|
|
|
redirect_to profil_path
|
|
|
|
end
|
2018-08-23 18:53:35 +02:00
|
|
|
end
|
|
|
|
end
|