BigW Consortium Gitlab

emails_controller.rb 736 Bytes
Newer Older
1
class Profiles::EmailsController < Profiles::ApplicationController
2 3 4 5 6 7
  def index
    @primary = current_user.email
    @emails = current_user.emails
  end

  def create
8
    @email = current_user.emails.new(email_params)
9

10 11 12 13 14
    if @email.save
      NotificationService.new.new_email(@email)
    else
      flash[:alert] = @email.errors.full_messages.first
    end
15 16 17 18 19 20 21 22

    redirect_to profile_emails_url
  end

  def destroy
    @email = current_user.emails.find(params[:id])
    @email.destroy

23
    current_user.update_secondary_emails!
24

25 26
    respond_to do |format|
      format.html { redirect_to profile_emails_url }
27
      format.js { head :ok }
28 29
    end
  end
30 31 32 33 34 35

  private

  def email_params
    params.require(:email).permit(:email)
  end
36
end