Sha256: e252f46ec250807021ae2b4a8854aaa9f4a27a048381fcc6c286f0de4de09589

Contents?: true

Size: 1.41 KB

Versions: 10

Compression:

Stored size: 1.41 KB

Contents

module Kuztuscms
  class UsersController < KuztuscmsController
    before_filter :authenticate_for_cms!, :except => [:new, :create]

    # GET /users
    def index
      @users = User.all
    end

    # GET /users/1
    def show
      @user = User.find(params[:id])
    end

    # GET /users/new
    def new
      check_first_user
      @user = User.new
    end

    # GET /users/1/edit
    def edit
      @user = User.find(params[:id])
    end

    # POST /users
    def create
      check_first_user
      @user = User.new(params[:user])

      if @user.save
        if @first_user
          sign_in @user
          Settings.set 'devise-mailer-sender', @user.email
          redirect_to root_url
        else
          redirect_to @user, notice: 'User was successfully created.'
        end
      else
        render action: "new"
      end
    end

    # PUT /users/1
    def update
      @user = User.find(params[:id])

      if @user.update_attributes(params[:user])
        redirect_to @user, notice: 'User was successfully updated.'
      else
        render action: "edit"
      end
    end

    # DELETE /users/1
    def destroy
      @user = User.find(params[:id])
      @user.destroy

      redirect_to kuztuscms.users_url
    end

    private

      def check_first_user
        if User.count > 0
          authenticate_user!
          @first_user = false
        else
          @first_user = true
        end
      end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
kuztuscms-0.0.10 app/controllers/kuztuscms/users_controller.rb
kuztuscms-0.0.9 app/controllers/kuztuscms/users_controller.rb
kuztuscms-0.0.8 app/controllers/kuztuscms/users_controller.rb
kuztuscms-0.0.7 app/controllers/kuztuscms/users_controller.rb
kuztuscms-0.0.6 app/controllers/kuztuscms/users_controller.rb
kuztuscms-0.0.5 app/controllers/kuztuscms/users_controller.rb
kuztuscms-0.0.4 app/controllers/kuztuscms/users_controller.rb
kuztuscms-0.0.3 app/controllers/kuztuscms/users_controller.rb
kuztuscms-0.0.2 app/controllers/kuztuscms/users_controller.rb
kuztuscms-0.0.1 app/controllers/kuztuscms/users_controller.rb