Sha256: 6ccb8fe3bb8b2a76684d24633a43b95d751ff9f0310639580f6283baadf93294

Contents?: true

Size: 1.32 KB

Versions: 8

Compression:

Stored size: 1.32 KB

Contents

module Shoppe
  class UsersController < Shoppe::ApplicationController
  
    before_filter { @active_nav = :users }
    before_filter { params[:id] && @user = Shoppe::User.find(params[:id]) }
    before_filter(:only => [:create, :update, :destroy]) do
      if Shoppe.settings.demo_mode?
        raise Shoppe::Error, "You cannot make changes to users in demo mode. Sorry about that."
      end
    end
  
    def index
      @users = Shoppe::User.all
    end
  
    def new
      @user = Shoppe::User.new
    end
  
    def create
      @user = Shoppe::User.new(safe_params)
      if @user.save
        redirect_to :users, :flash => {:notice => "User has been created successfully"}
      else
        render :action => "new"
      end
    end
  
    def edit
    end
  
    def update
      if @user.update(safe_params)
        redirect_to [:edit, @user], :flash => {:notice => "User has been updated successfully"}
      else
        render :action => "edit"
      end
    end
  
    def destroy
      raise Shoppe::Error, "You cannot remove yourself" if @user == current_user
      @user.destroy
      redirect_to :users, :flash => {:notice => "User has been removed successfully"}
    end
  
    private
  
    def safe_params
      params[:user].permit(:first_name, :last_name, :email_address, :password, :password_confirmation)
    end
  
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
shoppe-1.0.2 app/controllers/shoppe/users_controller.rb
shoppe-1.0.1 app/controllers/shoppe/users_controller.rb
shoppe-1.0.0 app/controllers/shoppe/users_controller.rb
shoppe-0.0.21 app/controllers/shoppe/users_controller.rb
shoppe-0.0.20 app/controllers/shoppe/users_controller.rb
shoppe-0.0.19 app/controllers/shoppe/users_controller.rb
shoppe-0.0.18 app/controllers/shoppe/users_controller.rb
shoppe-0.0.17 app/controllers/shoppe/users_controller.rb