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

admin_panel_controller.rb 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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.find_all_by_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').all
  21. end
  22. def show_contact_message
  23. @msg = ContactMessage.find(params[:id])
  24. end
  25. def users
  26. @users = User.order('created_at DESC').all
  27. end
  28. def files
  29. @uploads = Upload.all
  30. end
  31. def site_config
  32. @config = Info.first
  33. end
  34. def site_config_update
  35. @config = Info.first
  36. respond_to do |format|
  37. if @config.update(info_params)
  38. format.html { redirect_to admin_config_path, notice: (t 'admin_panel.config_update_success') }
  39. format.json { head :no_content }
  40. else
  41. format.html { render action: 'site_config' }
  42. format.json { render json: @upload.errors, status: :unprocessable_entity }
  43. end
  44. end
  45. end
  46. def make_admin
  47. @user = User.find(params[:id])
  48. if @user.admin == true
  49. @user.admin = false
  50. status = "admin_panel.unmake_admin_success"
  51. else
  52. @user.admin = true
  53. status = "admin_panel.make_admin_success"
  54. end
  55. respond_to do |format|
  56. if @user.save
  57. format.html { redirect_to admin_users_path, notice: (t status) }
  58. format.json { head :no_content }
  59. else
  60. format.html { redirect_to admin_users_path, alert: (t 'admin_panel.make_admin_error') }
  61. format.json { head :no_content }
  62. end
  63. end
  64. end
  65. private
  66. # Never trust parameters from the scary internet, only allow the white list through.
  67. def info_params
  68. params.require(:info).permit(:website_name, :website_link, :tagline, :contact_email, :server_email, :default_language, :maintenance_mode, :maintenance_title, :maintenance_message)
  69. end
  70. def authenticate_user
  71. redirect_to root_path, alert: (t 'admin_panel.permission_denied') unless current_user && current_user.admin?
  72. end
  73. end