Guest User

Untitled

a guest
Jun 20th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. ## application_controller.rb
  2.  
  3. class ApplicationController < ActionController::Base
  4. helper :all # include all helpers, all the time
  5. protect_from_forgery # See ActionController::RequestForgeryProtection for details
  6. require 'brazilian-rails'
  7. layout 'application'
  8. include AuthenticatedSystem
  9. before_filter :valida_permissao
  10.  
  11. private
  12. def valida_permissao
  13. if controller_name == 'sessions' and not action_name == 'index'
  14. true
  15. else
  16. if logged_in?
  17. acao = Acao.find(:first, :conditions =>
  18. ["controller_name = ? and action_name = ?",
  19. controller_name, action_name])
  20. if current_user.acoes.include? acao
  21. true
  22. else
  23. render :text => "Acesso negado a " + controller_name + ' acao ' +
  24. action_name + '. Você não tem acesso a esta ação.'
  25. end
  26. else
  27. render :text => "Acesso negado a " + controller_name + ' acao ' +
  28. action_name + '. Você não está logado'
  29. end
  30. end
  31. end
  32. end
Add Comment
Please, Sign In to add comment