Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Filters added to this controller apply to all controllers in the application.
- # Likewise, all the methods added will be available for all controllers.
- class ApplicationController < ActionController::Base
- helper :all # include all helpers, all the time
- protect_from_forgery # See ActionController::RequestForgeryProtection for details
- before_filter :check_login
- # Scrub sensitive parameters from your log
- # filter_parameter_logging :password
- def require_admin
- unless @act_user.admin
- flash[:error] = 'Nejste admin'
- redirect_to home_path
- end
- end
- def check_login
- case request.format
- when Mime::XML
- authenticate_or_request_with_http_basic do |email, password|
- usr = User.find_by_email email
- false unless usr
- if usr
- if usr.password == Digest::MD5.hexdigest(password)
- @act_user = usr
- end
- end
- end
- else
- unless session[:logged_user]
- flash[:error] = 'Nejprve je treba se prihlasit'
- redirect_to root_path
- return
- end
- @act_user = User.find session[:logged_user]
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement