Module: Usman::ApiHelper
- Included in:
- Usman::Api::V1::BaseController
- Defined in:
- app/helpers/usman/api_helper.rb
Instance Method Summary collapse
- #current_device ⇒ Object
- #current_user ⇒ Object
- #require_admin_auth_token ⇒ Object
- #require_api_token ⇒ Object
- #require_auth_token ⇒ Object
- #require_super_admin_auth_token ⇒ Object
Instance Method Details
#current_device ⇒ Object
8 9 10 11 12 13 |
# File 'app/helpers/usman/api_helper.rb', line 8 def current_device # Return if @current_device is already initialized else check if the device exists with the api token present in request header @current_device ||= authenticate_with_http_token { |token, | Device.find_by(api_token: token)} @current_registration = @current_device.registration if @current_device @current_user = @current_registration.user if @current_registration end |
#current_user ⇒ Object
3 4 5 6 |
# File 'app/helpers/usman/api_helper.rb', line 3 def current_user # Return if @current_user is already initialized else check if the user exists with the auth token present in request header @current_user ||= authenticate_with_http_token { |token, | User.find_by(auth_token: token)} end |
#require_admin_auth_token ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/helpers/usman/api_helper.rb', line 56 def require_admin_auth_token current_user unless @current_user && @current_user.is_admin? proc_code = Proc.new do ("authentication.permission_denied", :error) raise AuthenticationError end render_json_response(proc_code) return end end |
#require_api_token ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/helpers/usman/api_helper.rb', line 27 def require_api_token current_device unless @current_device proc_code = Proc.new do @success = false @errors = { heading: I18n.translate("api.general.permission_denied.heading"), message: I18n.translate("api.general.permission_denied.message") } end render_json_response(proc_code) return else @current_user = @current_device.try(:registration).try(:user) end end |
#require_auth_token ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/helpers/usman/api_helper.rb', line 15 def require_auth_token current_user unless @current_user proc_code = Proc.new do ("authentication.permission_denied", :error) raise AuthenticationError end render_json_response(proc_code) return end end |
#require_super_admin_auth_token ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/helpers/usman/api_helper.rb', line 44 def require_super_admin_auth_token current_user unless @current_user && @current_user.is_super_admin? proc_code = Proc.new do ("authentication.permission_denied", :error) raise AuthenticationError end render_json_response(proc_code) return end end |