Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ManageController < ApplicationController
- before_filter :login_required
- require_role :user_manager
- def index
- redirect_to(:action => 'users')
- end
- def users
- @letters = ActiveRecord::Base.connection.select_one('SELECT GROUP_CONCAT(DISTINCT LEFT(last_name,1)) AS surnames, GROUP_CONCAT(DISTINCT LEFT(email,1)) AS emails, GROUP_CONCAT(DISTINCT LEFT(login,1)) AS logins FROM users;')
- @counts = {}
- ActiveRecord::Base.connection.select_all('SELECT state, COUNT(*) AS qty FROM users GROUP BY state;').each { |c| @counts[c['state']] = c['qty'].to_i }
- @latest_users = User.find(:all, :limit => 10, :order => 'created_at DESC')
- @latest_orders = Order.find(:all, :include => [:user, :subscriptions], :conditions => 'is_closed = 1', :order => 'orders.created_at DESC', :limit => 10)
- end
- def show_user
- @user = User.find(params[:id])
- end
- def set_user_password
- #TODO: do this directly, and remove from logs
- @user = User.find(params[:uid])
- if ( (@user.id > 1 && !@user.has_role?('user_manager')) || (@user.id == current_user.id)):
- @user.password = params[:pw]
- @user.password_confirmation = params[:pw]
- @user.save!
- flash[:notice] = 'Password changed.'
- else
- flash[:notice] = '<strong>ERROR</strong>: You cannot change this user\'s password.'
- end
- redirect_to(:action => 'show_user', :id => @user.id)
- end
- def kill_pending_user
- @user = User.find(params[:id])
- if (@user.state == 'pending'):
- @user.destroy
- flash[:notice] = 'User removed.'
- redirect_to(:action => 'users')
- else
- flash[:notice] = '<strong>ERROR</strong>: You cannot remove an active user.'
- redirect_to(:action => 'show_user', :id => @user.id)
- end
- end
- def clear_user_claim
- #TODO: check if the user has any listings or privacy products first...
- @property = Property.find_by_parcel_id(params[:id]) or raise ActiveRecord::RecordNotFound
- user_id = @property.user_id
- @property.user_id = 0
- @property.save!
- flash[:notice] = 'Claim removed.'
- redirect_to(:action => 'show_user', :id => user_id)
- end
- def filter
- ltr = (params[:id] == '0') ? '#' : params[:id][0,1].upcase
- @attributes = case (params[:facet])
- when 'by_login' : ['LEFT(users.login,1)','users.login ASC',"by Login (#{ltr}...)"]
- when 'by_email' : ['LEFT(users.email,1)','users.email ASC',"by Email (#{ltr}...)"]
- when 'by_surname' : ['LEFT(users.last_name,1)','users.last_name ASC',"by Surname (#{ltr}...)"]
- else nil
- end
- selection = (ltr == '#') ? "NOT REGEXP '[[:alpha:]]'" : " = '#{ltr}'"
- @users = User.find(:all, :include => :agent, :conditions => "users.id > 1 AND #{@attributes[0]}#{selection}", :order => @attributes[1])
- end
- end
Add Comment
Please, Sign In to add comment