A website template with lots of features, built with ruby on rails.

admin_panel_controller.rb 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. class AdminPanelController < ApplicationController
  2. layout 'admin'
  3. before_filter :authenticate_user
  4. def maintenance_mode
  5. end
  6. def index
  7. redirect_to admin_dashboard_path
  8. end
  9. def dashboard
  10. @users = User.all
  11. @posts = BlogPost.all
  12. @files = Upload.all
  13. @contact_messages = ContactMessage.all
  14. @new_messages = @contact_messages.where(:unread => true)
  15. end
  16. def posts
  17. @posts = BlogPost.all
  18. end
  19. def contact_messages
  20. @contact_messages = ContactMessage.order('created_at DESC').to_a
  21. end
  22. def show_contact_message
  23. @msg = ContactMessage.find(params[:id])
  24. end
  25. def subscribers
  26. @subscribers = Subscription.all
  27. end
  28. def export_subscribers_list
  29. @subscribers = Subscription.all
  30. respond_to do |format|
  31. format.html
  32. format.csv { render text: @subscribers.to_csv }
  33. end
  34. end
  35. def users
  36. @users = User.order('created_at DESC').all
  37. end
  38. def files
  39. @uploads = Upload.all
  40. end
  41. def site_config
  42. @config = Info.first
  43. end
  44. def site_config_update
  45. @config = Info.first
  46. respond_to do |format|
  47. if @config.update(info_params)
  48. format.html { redirect_to admin_config_path, notice: (t 'admin_panel.config_update_success') }
  49. format.json { head :no_content }
  50. else
  51. format.html { render action: 'site_config' }
  52. format.json { render json: @upload.errors, status: :unprocessable_entity }
  53. end
  54. end
  55. end
  56. def make_admin
  57. @user = User.find(params[:id])
  58. if @user.admin == true
  59. @user.admin = false
  60. status = "admin_panel.unmake_admin_success"
  61. else
  62. @user.admin = true
  63. status = "admin_panel.make_admin_success"
  64. end
  65. respond_to do |format|
  66. if @user.save
  67. format.html { redirect_to admin_users_path, notice: (t status) }
  68. format.json { head :no_content }
  69. else
  70. format.html { redirect_to admin_users_path, alert: (t 'admin_panel.make_admin_error') }
  71. format.json { head :no_content }
  72. end
  73. end
  74. end
  75. private
  76. # Never trust parameters from the scary internet, only allow the white list through.
  77. def info_params
  78. params.require(:info).permit(:website_name, :website_link, :tagline, :contact_email, :server_email, :default_language, :maintenance_mode, :maintenance_title, :maintenance_message)
  79. end
  80. def authenticate_user
  81. redirect_to root_path, alert: (t 'admin_panel.permission_denied') unless current_user && current_user.admin?
  82. end
  83. end