module UnsCore
  class ApplicationController < ActionController::Base
    include UnsCore::ApplicationHelper
    include Pundit

    layout :layout_choice

    protect_from_forgery with: :exception
    before_filter :ensure_signup_complete

    helper_method :current_user
    helper_method :user_can_edit
    helper_method :content_user

    def ensure_signup_complete
      return if action_name == 'finish_signup'

      if current_user
        unless current_user.email_verified?
          redirect_to finish_signup_path(current_user)
        end
      end
    end

    def content_user
      @content_user ||= ContentUser.new
      @content_user
    end

#    def default_url_options(opts = {})
#      opts.merge(:host => 'unsilo.io')
#    end

    def after_sign_in_path_for(resource)
      main_app.desktop_path
    end

    def layout_choice
      current_user ? current_user.theme : Rails.application.config.default_theme
    end
  end
end
