Advertisement
Guest User

Untitled

a guest
Jun 5th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.17 KB | None | 0 0
  1. # Filters added to this controller apply to all controllers in the application.
  2. # Likewise, all the methods added will be available for all controllers.
  3.  
  4. class ApplicationController < ActionController::Base
  5.   helper :all # include all helpers, all the time
  6.   protect_from_forgery # See ActionController::RequestForgeryProtection for details
  7.   before_filter :check_login
  8.  
  9.   # Scrub sensitive parameters from your log
  10.   # filter_parameter_logging :password
  11.  
  12.   def require_admin
  13.     unless @act_user.admin
  14.       flash[:error] = 'Nejste admin'
  15.       redirect_to home_path
  16.     end
  17.   end
  18.  
  19.   def check_login
  20.     case request.format
  21.     when Mime::XML
  22.       authenticate_or_request_with_http_basic do |email, password|
  23.         usr  = User.find_by_email email
  24.         false unless usr
  25.         if usr
  26.         if usr.password == Digest::MD5.hexdigest(password)
  27.             @act_user = usr
  28.           end
  29.         end        
  30.       end      
  31.     else
  32.       unless session[:logged_user]
  33.         flash[:error] = 'Nejprve je treba se prihlasit'
  34.         redirect_to root_path
  35.         return
  36.       end      
  37.       @act_user = User.find session[:logged_user]
  38.     end
  39.   end
  40.  
  41. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement