-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial user creation process per #65
- Loading branch information
Showing
4 changed files
with
44 additions
and
55 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
app/controllers/concerto_devise/registrations_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters