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

admin_panel_controller.rb 2.0KB

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