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
7
8
9
|
# File 'app/controllers/forest_liana/application_controller.rb', line 7
def self.papertrail?
Object.const_get('PaperTrail::Version').is_a?(Class) rescue false
end
|
Instance Method Details
#authenticate_user_from_jwt ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'app/controllers/forest_liana/application_controller.rb', line 61
def authenticate_user_from_jwt
begin
if request.['Authorization'] || params['sessionToken']
if request.['Authorization']
token = request.['Authorization'].split.second
else
token = params['sessionToken']
end
@jwt_decoded_token = JWT.decode(token, ForestLiana.auth_secret, true,
{ algorithm: 'HS256', leeway: 30 }).try(:first)
else
head :unauthorized
end
rescue JWT::ExpiredSignature, JWT::VerificationError
render json: { error: 'expired_token' }, status: :unauthorized,
serializer: nil
rescue
head :unauthorized
end
end
|
#forest_user ⇒ Object
33
34
35
|
# File 'app/controllers/forest_liana/application_controller.rb', line 33
def forest_user
@jwt_decoded_token
end
|
#route_not_found ⇒ Object
83
84
85
|
# File 'app/controllers/forest_liana/application_controller.rb', line 83
def route_not_found
head :not_found
end
|
#serialize_model(record, options = {}) ⇒ Object
37
38
39
40
41
42
|
# File 'app/controllers/forest_liana/application_controller.rb', line 37
def serialize_model(record, options = {})
options[:is_collection] = false
json = JSONAPI::Serializer.serialize(record, options)
force_utf8_encoding(json)
end
|
#serialize_models(records, options = {}) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'app/controllers/forest_liana/application_controller.rb', line 44
def serialize_models(records, options = {})
options[:is_collection] = true
json = JSONAPI::Serializer.serialize(records, 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
|