debian-mirror-gitlab/app/controllers/profiles/emails_controller.rb

58 lines
1.7 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2015-09-11 14:41:01 +05:30
class Profiles::EmailsController < Profiles::ApplicationController
2018-03-17 18:26:18 +05:30
before_action :find_email, only: [:destroy, :resend_confirmation_instructions]
2022-01-26 12:08:38 +05:30
before_action -> { check_rate_limit!(:profile_add_new_email, scope: current_user, redirect_back: true) },
only: [:create]
before_action -> { check_rate_limit!(:profile_resend_email_confirmation, scope: current_user, redirect_back: true) },
only: [:resend_confirmation_instructions]
2018-03-17 18:26:18 +05:30
2021-01-03 14:25:43 +05:30
feature_category :users
2022-07-16 23:28:13 +05:30
urgency :low, [:index]
2021-01-03 14:25:43 +05:30
2014-09-02 18:07:02 +05:30
def index
2018-03-17 18:26:18 +05:30
@primary_email = current_user.email
@emails = current_user.emails.order_id_desc
2014-09-02 18:07:02 +05:30
end
def create
2018-03-17 18:26:18 +05:30
@email = Emails::CreateService.new(current_user, email_params.merge(user: current_user)).execute
unless @email.errors.blank?
2015-09-11 14:41:01 +05:30
flash[:alert] = @email.errors.full_messages.first
end
2014-09-02 18:07:02 +05:30
redirect_to profile_emails_url
end
def destroy
2018-03-17 18:26:18 +05:30
Emails::DestroyService.new(current_user, user: current_user).execute(@email)
2015-04-26 12:48:37 +05:30
2014-09-02 18:07:02 +05:30
respond_to do |format|
2018-11-18 11:00:15 +05:30
format.html { redirect_to profile_emails_url, status: :found }
2016-06-02 11:05:42 +05:30
format.js { head :ok }
2014-09-02 18:07:02 +05:30
end
end
2018-03-17 18:26:18 +05:30
def resend_confirmation_instructions
if Emails::ConfirmService.new(current_user, user: current_user).execute(@email)
2019-09-04 21:01:54 +05:30
flash[:notice] = _("Confirmation email sent to %{email}") % { email: @email.email }
2018-03-17 18:26:18 +05:30
else
2019-09-04 21:01:54 +05:30
flash[:alert] = _("There was a problem sending the confirmation email")
2018-03-17 18:26:18 +05:30
end
redirect_to profile_emails_url
end
2014-09-02 18:07:02 +05:30
private
def email_params
params.require(:email).permit(:email)
end
2018-03-17 18:26:18 +05:30
def find_email
@email = current_user.emails.find(params[:id])
end
2014-09-02 18:07:02 +05:30
end
2022-03-02 08:16:31 +05:30
Profiles::EmailsController.prepend_mod