2009-05-22 16:14:07 +02:00
|
|
|
class UsersController < ApplicationController
|
2011-01-12 08:09:52 +01:00
|
|
|
before_filter :check_public_access
|
2009-05-22 16:14:07 +02:00
|
|
|
before_filter :require_no_user, :only => [:new, :create]
|
2009-06-02 00:08:57 +02:00
|
|
|
before_filter :require_user, :only => [:show, :edit, :update, :destroy]
|
2010-04-13 00:40:47 +02:00
|
|
|
skip_filter :setup
|
2009-05-22 16:14:07 +02:00
|
|
|
|
|
|
|
def new
|
|
|
|
@user = User.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@user = User.new(params[:user])
|
|
|
|
if @user.save
|
2010-04-13 00:40:47 +02:00
|
|
|
if User.all.length == 1
|
|
|
|
@user.roles << Role.create(:name => 'admin')
|
|
|
|
end
|
2009-05-22 16:14:07 +02:00
|
|
|
flash[:notice] = "Account registered!"
|
2010-04-13 00:40:47 +02:00
|
|
|
redirect_back_or_default new_collection_path
|
2009-05-22 16:14:07 +02:00
|
|
|
else
|
|
|
|
render :action => :new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
@user = @current_user
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
@user = @current_user
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@user = @current_user # makes our views "cleaner" and more consistent
|
|
|
|
if @user.update_attributes(params[:user])
|
|
|
|
flash[:notice] = "Account updated!"
|
2009-06-09 00:30:22 +02:00
|
|
|
redirect_to account_path
|
2009-05-22 16:14:07 +02:00
|
|
|
else
|
|
|
|
render :action => :edit
|
|
|
|
end
|
|
|
|
end
|
2009-06-02 00:08:57 +02:00
|
|
|
|
|
|
|
def destroy
|
|
|
|
@user = @current_user
|
|
|
|
if @user.destroy
|
|
|
|
redirect_to users_path
|
|
|
|
else
|
|
|
|
redirect_to @user
|
|
|
|
end
|
|
|
|
end
|
2009-05-22 16:14:07 +02:00
|
|
|
end
|