Class: ForestLiana::ApplicationController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- ForestLiana::ApplicationController
show all
- Defined in:
- app/controllers/forest_liana/application_controller.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.papertrail? ⇒ Boolean
6
7
8
|
# File 'app/controllers/forest_liana/application_controller.rb', line 6
def self.papertrail?
Object.const_get('PaperTrail::Version').is_a?(Class) rescue false
end
|
Instance Method Details
#authenticate_user_from_jwt ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'app/controllers/forest_liana/application_controller.rb', line 60
def authenticate_user_from_jwt
if request.['Authorization']
begin
token = request.['Authorization'].split.second
@jwt_decoded_token = JWT.decode(token, ForestLiana.auth_secret, true, {
algorithm: 'HS256',
leeway: 30
}).try(:first)
rescue JWT::ExpiredSignature, JWT::VerificationError
render json: { error: 'expired_token' }, status: 401, serializer: nil
end
else
head :unauthorized
end
end
|
#forest_user ⇒ Object
32
33
34
|
# File 'app/controllers/forest_liana/application_controller.rb', line 32
def forest_user
@jwt_decoded_token
end
|
#route_not_found ⇒ Object
76
77
78
|
# File 'app/controllers/forest_liana/application_controller.rb', line 76
def route_not_found
head :not_found
end
|
#serialize_model(model, options = {}) ⇒ Object
36
37
38
39
40
41
|
# File 'app/controllers/forest_liana/application_controller.rb', line 36
def serialize_model(model, options = {})
options[:is_collection] = false
json = JSONAPI::Serializer.serialize(model, options)
force_utf8_encoding(json)
end
|
#serialize_models(models, options = {}) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'app/controllers/forest_liana/application_controller.rb', line 43
def serialize_models(models, options = {})
options[:is_collection] = true
json = JSONAPI::Serializer.serialize(models, options)
if options[:count]
json[:meta] = {} unless json[:meta]
json[:meta][:count] = options[:count]
end
if !options[:has_more].nil?
json[:meta] = {} unless json[:meta]
json[:meta][:has_more] = options[:has_more]
end
force_utf8_encoding(json)
end
|