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]
|
|
|
|
|
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)
|
|
|
|
flash[:notice] = "Confirmation email sent to #{@email.email}"
|
|
|
|
else
|
|
|
|
flash[:alert] = "There was a problem sending the confirmation email"
|
|
|
|
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
|