Sha256: 7d50ef44bd83f55f10dd1ecfd7718b4cd9ad07c6faf37374449d277b1331a8d9

Contents?: true

Size: 1.01 KB

Versions: 8

Compression:

Stored size: 1.01 KB

Contents

module Refinery
  class UsersController < Devise::RegistrationsController

    # Protect these actions behind an admin login
    before_filter :redirect?, :only => [:new, :create]

    helper Refinery::Core::Engine.helpers
    layout 'refinery/layouts/login'

    def new
      @user = User.new
    end

    # This method should only be used to create the first Refinery user.
    def create
      @user = User.new(params[:user])

      if @user.create_first
        flash[:message] = "<h2>#{t('welcome', :scope => 'refinery.users.create', :who => @user.username).gsub(/\.$/, '')}.</h2>".html_safe

        sign_in(@user)
        redirect_back_or_default(refinery.admin_root_path)
      else
        render :new
      end
    end

    protected

    def redirect?
      if refinery_user?
        redirect_to refinery.admin_users_path
      elsif refinery_users_exist?
        redirect_to refinery.new_refinery_user_session_path
      end
    end

    def refinery_users_exist?
      Refinery::Role[:refinery].users.any?
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
refinerycms-authentication-2.0.10 app/controllers/refinery/users_controller.rb
refinerycms-authentication-2.0.9 app/controllers/refinery/users_controller.rb
refinerycms-authentication-2.0.8 app/controllers/refinery/users_controller.rb
refinerycms-authentication-2.0.7 app/controllers/refinery/users_controller.rb
refinerycms-authentication-2.0.6 app/controllers/refinery/users_controller.rb
refinerycms-authentication-2.0.5 app/controllers/refinery/users_controller.rb
refinerycms-authentication-2.0.4 app/controllers/refinery/users_controller.rb
refinerycms-authentication-2.0.3 app/controllers/refinery/users_controller.rb