API de comptabilité horaire.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

authenticable.rb 461B

12345678910111213141516171819202122
  1. module Authenticable
  2. def current_user
  3. return @current_user if @current_user
  4. header = request.headers['Authorization']
  5. return nil if header.nil?
  6. decoded = JsonWebToken.decode(header)
  7. @current_user = User.find(decoded[:user_id]) rescue ActiveRecord::RecordNotFound
  8. end
  9. protected
  10. def check_login
  11. head :forbidden unless self.current_user
  12. end
  13. def is_admin?
  14. head :forbidden unless self.current_user.is_admin
  15. end
  16. end