2012-03-20 18:11:28 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2012-05-02 10:18:07 +01:00
|
|
|
class Admin::UsersController < Admin::BaseController
|
2012-10-03 17:38:42 +01:00
|
|
|
include AvatarHelper
|
2012-05-02 10:18:07 +01:00
|
|
|
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]
|
2012-03-31 00:37:54 +01:00
|
|
|
@user.confirmed_at = Time.now.utc
|
2012-07-25 22:49:55 +01:00
|
|
|
if (@user.save rescue false)
|
2012-03-20 18:11:28 +00:00
|
|
|
flash[:notice] = t('flash.user.saved')
|
2012-05-02 10:18:07 +01:00
|
|
|
redirect_to admin_users_path
|
2012-03-20 18:11:28 +00:00
|
|
|
else
|
|
|
|
flash[:error] = t('flash.user.save_error')
|
2012-03-26 15:49:00 +01:00
|
|
|
flash[:warning] = @user.errors.full_messages.join('. ')
|
2012-03-20 18:11:28 +00:00
|
|
|
render :action => :new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-05-02 10:18:07 +01:00
|
|
|
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])
|
2012-10-03 17:38:42 +01:00
|
|
|
update_avatar(@user, params)
|
2012-03-20 18:11:28 +00:00
|
|
|
flash[:notice] = t('flash.user.saved')
|
2012-05-02 10:18:07 +01:00
|
|
|
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-05-02 10:18:07 +01:00
|
|
|
render :action => :edit
|
2012-03-20 18:11:28 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@user.destroy
|
|
|
|
flash[:notice] = t("flash.user.destroyed")
|
2012-05-02 10:18:07 +01:00
|
|
|
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'
|
|
|
|
@users = @users.send(@filter) if ['real', 'admin', 'banned'].include? @filter
|
2012-03-20 18:11:28 +00:00
|
|
|
@users = @users.order(order)
|
|
|
|
|
2012-05-02 10:18:07 +01:00
|
|
|
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
|
2012-03-22 17:11:12 +00:00
|
|
|
end
|