Sha256: f6dce3e1cc32d96e91881bfb91238fff2a3dccd6fb5046d5fcf9ff25731c4f12

Contents?: true

Size: 1.09 KB

Versions: 6

Compression:

Stored size: 1.09 KB

Contents

module Fae
  class SetupController < ActionController::Base

    before_action :check_roles
    layout 'devise'

    def first_user
      @option = Fae::Option.instance
      return show_404 if Fae::User.live_super_admins.present?

      @user = Fae::User.new
    end

    def create_first_user
      @user         = Fae::User.new(user_params)
      super_admin   = Fae::Role.find_by_name('super admin')
      @user.role    = super_admin
      @user.active  = true

      if @user.save
        sign_in(@user)
        redirect_to fae.root_path
      else
        @option = Fae::Option.instance
        render action: 'first_user', error: t('fae.save_error')
      end
    end

    private

    def show_404
      render template: 'fae/pages/error404.html.slim', layout: 'fae/error.html.slim', status: :not_found
    end

    def user_params
      params.require(:user).permit(:email, :first_name, :last_name, :password, :password_confirmation)
    end

    def check_roles 
      if Fae::Role.all.empty?
        raise "Role 'super admin' does not exist in Fae::Role, run rake fae:seed_db"
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
fae-rails-1.5.0 app/controllers/fae/setup_controller.rb
fae-rails-1.4.1 app/controllers/fae/setup_controller.rb
fae-rails-1.4.0 app/controllers/fae/setup_controller.rb
fae-rails-1.3.1 app/controllers/fae/setup_controller.rb
fae-rails-1.3.0 app/controllers/fae/setup_controller.rb
fae-rails-1.2.5 app/controllers/fae/setup_controller.rb