Sha256: 15b858faeb0756063c6400da30b81d44dcb97abd6080fd2ade69e22840c141b4

Contents?: true

Size: 1.38 KB

Versions: 5

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

module Masks
  # @visibility private
  class EmailsController < ApplicationController
    require_mask type: :session, only: :new
    before_action :require_sudo, only: :create

    def new
      @emails = current_actor.emails

      respond_to { |format| format.html { render(:new) } }
    end

    def create
      @email = current_actor.emails.build(email: email_param.strip)

      if @email.valid?
        @email.notify!(masked_session)
      else
        flash[:errors] = @email.errors.full_messages
      end

      respond_to { |format| format.html { redirect_to emails_path } }
    end

    def notify
      @email = current_actor.emails.find_by(email: email_param.strip)
      @email.notify!(masked_session) if @email.expired?

      respond_to { |format| format.html { redirect_to emails_path } }
    end

    def delete
      @email = current_actor.emails.find_by(email: email_param)
      @email&.destroy

      respond_to { |format| format.html { redirect_to emails_path } }
    end

    def verify
      @email = current_actor.emails.find_by(token: params[:email])
      @email&.verify! if @email&.valid?
    end

    private

    def email_param
      params.dig(:email, :value)
    end

    def require_sudo
      return if current_mask.type == "sudo" && passed?

      flash[:errors] = ["enter a valid password"]

      redirect_to emails_path
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
masks-0.4.0 app/controllers/masks/emails_controller.rb
masks-0.3.2 app/controllers/masks/emails_controller.rb
masks-0.3.1 app/controllers/masks/emails_controller.rb
masks-0.3.0 app/controllers/masks/emails_controller.rb
masks-0.2.0 app/controllers/masks/emails_controller.rb