Skip to content

Commit

Permalink
Initial user creation process per #65
Browse files Browse the repository at this point in the history
  • Loading branch information
augustf committed May 3, 2012
1 parent 25bc48c commit 8384638
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 55 deletions.
26 changes: 26 additions & 0 deletions app/controllers/concerto_devise/registrations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#Overriding the Devise Registrations controller for fun and profit
class ConcertoDevise::RegistrationsController < Devise::RegistrationsController

def create
build_resource
#If there are no users, the first one created will be an admin
if User.all.empty?
resource.is_admin = true
end
if resource.save
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_navigational_format?
sign_in(resource_name, resource)
respond_with resource, :location => after_sign_up_path_for(resource)
else
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
expire_session_data_after_sign_in!
respond_with resource, :location => after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords resource
respond_with resource
end
end

end
69 changes: 16 additions & 53 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,85 +1,48 @@
class UsersController < ApplicationController
load_and_authorize_resource
respond_to :html, :json

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

respond_to do |format|
format.html # index.html.erb
format.json { render :json => @users }
end
respond_with(@users = User.all)
end

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

respond_to do |format|
format.html # show.html.erb
format.json { render :json => @user }
end
respond_with(@user = User.find(params[:id]))
end

# GET /users/new
# GET /users/new.json
def new
@user = User.new

respond_to do |format|
format.html # new.html.erb
format.json { render :json => @user }
end
end

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

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

respond_to do |format|
if @user.save
format.html { redirect_to @user, :notice => t(:user_created) }
format.json { render :json => @user, :status => :created, :location => @user }
else
format.html { render :action => "new" }
format.json { render :json => @user.errors, :status => :unprocessable_entity }
end
end
respond_with(@user, :location => users_url)
end


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

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

respond_to do |format|
if @user.update_attributes(params[:user])
format.html { redirect_to @user, :notice => t(:user_updated) }
format.json { head :ok }
else
format.html { render :action => "edit" }
format.json { render :json => @user.errors, :status => :unprocessable_entity }
end
if @user.update_attributes(params[:user])
flash[:notice] = t(:user_updated)
end
respond_with(@user)
end

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

respond_to do |format|
format.html { redirect_to users_url }
format.json { head :ok }
end
respond_with(@user)
end

end
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Application < Rails::Application
#exempt these methods from the initial install check to prevent redirect loops
config.to_prepare do
Devise::RegistrationsController.skip_before_filter :check_for_initial_install
Concerto::UsersController.skip_before_filter :check_for_initial_install
ConcertoDevise::RegistrationsController.skip_before_filter :check_for_initial_install
end


Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# End really dangerous routes.


devise_for :users
devise_for :users, :controllers => {:registrations => 'concerto_devise/registrations'}
resources :users

resources :media, :only => [:show]
Expand Down

0 comments on commit 8384638

Please sign in to comment.