2019-07-02 18:15:03 +02:00
|
|
|
module Users
|
|
|
|
class ProfilController < UserController
|
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
|
|
|
|
if @current_user.update(update_email_params)
|
|
|
|
flash.notice = t('devise.registrations.update_needs_confirmation')
|
|
|
|
elsif @current_user.errors&.details&.dig(:email)&.any? { |e| e[:error] == :taken }
|
2019-07-09 17:08:27 +02:00
|
|
|
UserMailer.account_already_taken(@current_user, requested_email).deliver_later
|
|
|
|
# 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
|
|
|
|
flash.alert = @current_user.errors.full_messages
|
|
|
|
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
|
2018-08-23 18:53:35 +02:00
|
|
|
end
|
|
|
|
end
|