Guest User

Untitled

a guest
Jul 24th, 2018
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 KB | None | 0 0
  1. class ManageController < ApplicationController
  2. before_filter :login_required
  3. require_role :user_manager
  4.  
  5. def index
  6. redirect_to(:action => 'users')
  7. end
  8.  
  9. def users
  10. @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;')
  11. @counts = {}
  12. ActiveRecord::Base.connection.select_all('SELECT state, COUNT(*) AS qty FROM users GROUP BY state;').each { |c| @counts[c['state']] = c['qty'].to_i }
  13.  
  14. @latest_users = User.find(:all, :limit => 10, :order => 'created_at DESC')
  15. @latest_orders = Order.find(:all, :include => [:user, :subscriptions], :conditions => 'is_closed = 1', :order => 'orders.created_at DESC', :limit => 10)
  16. end
  17.  
  18. def show_user
  19. @user = User.find(params[:id])
  20. end
  21.  
  22. def set_user_password
  23. #TODO: do this directly, and remove from logs
  24. @user = User.find(params[:uid])
  25. if ( (@user.id > 1 && !@user.has_role?('user_manager')) || (@user.id == current_user.id)):
  26. @user.password = params[:pw]
  27. @user.password_confirmation = params[:pw]
  28. @user.save!
  29. flash[:notice] = 'Password changed.'
  30. else
  31. flash[:notice] = '<strong>ERROR</strong>: You cannot change this user\'s password.'
  32. end
  33. redirect_to(:action => 'show_user', :id => @user.id)
  34. end
  35.  
  36. def kill_pending_user
  37. @user = User.find(params[:id])
  38. if (@user.state == 'pending'):
  39. @user.destroy
  40. flash[:notice] = 'User removed.'
  41. redirect_to(:action => 'users')
  42. else
  43. flash[:notice] = '<strong>ERROR</strong>: You cannot remove an active user.'
  44. redirect_to(:action => 'show_user', :id => @user.id)
  45. end
  46. end
  47.  
  48. def clear_user_claim
  49. #TODO: check if the user has any listings or privacy products first...
  50. @property = Property.find_by_parcel_id(params[:id]) or raise ActiveRecord::RecordNotFound
  51. user_id = @property.user_id
  52. @property.user_id = 0
  53. @property.save!
  54. flash[:notice] = 'Claim removed.'
  55. redirect_to(:action => 'show_user', :id => user_id)
  56. end
  57.  
  58. def filter
  59. ltr = (params[:id] == '0') ? '#' : params[:id][0,1].upcase
  60. @attributes = case (params[:facet])
  61. when 'by_login' : ['LEFT(users.login,1)','users.login ASC',"by Login (#{ltr}...)"]
  62. when 'by_email' : ['LEFT(users.email,1)','users.email ASC',"by Email (#{ltr}...)"]
  63. when 'by_surname' : ['LEFT(users.last_name,1)','users.last_name ASC',"by Surname (#{ltr}...)"]
  64. else nil
  65. end
  66.  
  67. selection = (ltr == '#') ? "NOT REGEXP '[[:alpha:]]'" : " = '#{ltr}'"
  68. @users = User.find(:all, :include => :agent, :conditions => "users.id > 1 AND #{@attributes[0]}#{selection}", :order => @attributes[1])
  69. end
  70.  
  71. end
Add Comment
Please, Sign In to add comment