rosa-build/app/controllers/admin/users_controller.rb

72 lines
2.0 KiB
Ruby
Raw Normal View History

2012-03-20 18:11:28 +00:00
# -*- encoding : utf-8 -*-
class Admin::UsersController < Admin::BaseController
include AvatarHelper
prepend_before_filter :find_user
2012-03-20 18:11:28 +00:00
def index
@filter = params[:filter] || 'all'
end
def new
end
def create
2012-03-22 14:50:15 +00:00
@user.role = params[:role]
@user.confirmed_at = Time.now.utc
if (@user.save rescue false)
2012-03-20 18:11:28 +00:00
flash[:notice] = t('flash.user.saved')
redirect_to admin_users_path
2012-03-20 18:11:28 +00:00
else
flash[:error] = t('flash.user.save_error')
flash[:warning] = @user.errors.full_messages.join('. ')
2012-03-20 18:11:28 +00:00
render :action => :new
end
end
def edit
2012-03-20 18:11:28 +00:00
end
def update
2012-03-22 14:50:15 +00:00
@user.role = params[:role]
2012-03-20 18:11:28 +00:00
if @user.update_without_password(params[:user])
update_avatar(@user, params)
2012-03-20 18:11:28 +00:00
flash[:notice] = t('flash.user.saved')
redirect_to admin_users_path
2012-03-20 18:11:28 +00:00
else
flash[:error] = t('flash.user.save_error')
flash[:warning] = @user.errors.full_messages.join('. ')
render :action => :edit
2012-03-20 18:11:28 +00:00
end
end
def destroy
@user.destroy
flash[:notice] = t("flash.user.destroyed")
redirect_to admin_users_path
2012-03-20 18:11:28 +00:00
end
def list
colName = ['users.name', 'users.uname', 'users.email']
sort_col = params[:iSortCol_0] || 0
sort_dir = params[:sSortDir_0]=="asc" ? 'asc' : 'desc'
order = "#{colName[sort_col.to_i]} #{sort_dir}"
@users = @users.paginate(:page => (params[:iDisplayStart].to_i/params[:iDisplayLength].to_i).to_i + 1, :per_page => params[:iDisplayLength])
@total_users = @users.count
if !params[:sSearch].blank? && search = "%#{params[:sSearch]}%"
@users = @users.where('users.name ILIKE ? or users.uname ILIKE ? or users.email ILIKE ?', search, search, search)
end
2012-03-21 18:02:58 +00:00
@filter = params[:filter] || 'all'
2012-12-06 18:04:39 +00:00
@users = @users.send(@filter) if ['real', 'admin', 'banned', 'tester'].include? @filter
2012-03-20 18:11:28 +00:00
@users = @users.order(order)
render :partial => 'users_ajax', :layout => false
end
protected
def find_user
@user = User.find_by_uname!(params[:id]) if params[:id]
2012-03-20 18:11:28 +00:00
end
end