ishapi 0.1.8.135 → 0.1.8.140

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7d4ac76a945cecc499cbcd7702b5fa87065bbc551b68681871f8dd8e049d7434
4
- data.tar.gz: 27faa2c48c19a47d7b46572c4ce3c7ff052737df6840e3ee22d930f65be37752
3
+ metadata.gz: 664c57181dacaa8682f95923ceee4bea1b41d0e1aaf3c576fecbcf82f02350b9
4
+ data.tar.gz: f7643a6a16fab2abe799e056901ca73ec9561070bf9d03ddac6a4358a9af1e96
5
5
  SHA512:
6
- metadata.gz: 814a536e1e9f406bc707576da08b8265fcb6a72637b97b5ebd077c459943dec930f7172fbdf28469fb59f5d3057d3796f37ff3ad75db312fa9754b6628c5641b
7
- data.tar.gz: da987ea35b0a763299fa30997546b3ebbee28229dfef11193f78ba668c1ab195e5742ad4de73fd06346c54a9cd1e698b9d1c1ad40a515c65ad8d669797eaa7fd
6
+ metadata.gz: b2765fabf05e20faa94bfec7ee0ae593b18dacc55e6eb52b63deca84eb625e0f850f09aa7f59a9d7e8e2bc59b97b23dd4d642d37e23ecff68d84859f1b65a0fd
7
+ data.tar.gz: 36f3c49f167b8eb451df2d88e2d9a3a5b8dd2a1eb9c92ba7fd67580f5bee4a461c25dfe7b314bb52aa1288ec25261d5890ccc8200fbd511f63127b4361d661c9
@@ -5,18 +5,13 @@ module Ishapi
5
5
  protect_from_forgery :prepend => true, :with => :exception
6
6
  layout :false
7
7
 
8
- # before_action :check_profile, except: [ :test ]
9
- # before_action :set_current_ability
10
-
11
- check_authorization
8
+ check_authorization except: [ :long_term_token ]
12
9
  skip_before_action :verify_authenticity_token
13
10
 
14
11
  def test
15
12
  end
16
13
 
17
14
  def long_term_token
18
- authorize! :long_term_token, ::Ishapi
19
-
20
15
  accessToken = request.headers[:accessToken]
21
16
  accessToken ||= params[:accessToken]
22
17
 
@@ -31,8 +26,6 @@ module Ishapi
31
26
  @me = @graph.get_object( 'me', :fields => 'email' )
32
27
  @current_user = User.where( :email => @me['email'] ).first
33
28
 
34
- puts! @current_user, '#long_term_token @current_user'
35
-
36
29
  # send the jwt to client
37
30
  @jwt_token = encode(user_id: @current_user.id.to_s)
38
31
 
@@ -56,8 +49,6 @@ module Ishapi
56
49
  private
57
50
 
58
51
  def append_long_term_token
59
- puts! nil, 'append_long_term_token'
60
-
61
52
  if @long_term_token
62
53
  response.body = JSON.parse(response.body).merge({ long_term_token: @long_term_token }).to_json
63
54
  end
@@ -139,12 +130,8 @@ module Ishapi
139
130
  @current_user = current_user if Rails.env.test?
140
131
  end
141
132
 
142
- puts! @current_user, 'current_user'
143
- puts! @current_profile, 'current_profile'
144
-
145
133
  elsif 'jwt' == provider
146
134
  decoded = decode(params[:jwt_token])
147
- puts! decoded, 'decoded'
148
135
  @current_user = User.find decoded['user_id']
149
136
  else
150
137
  puts! 'check_multiprofile(): no access token'
@@ -153,17 +140,22 @@ module Ishapi
153
140
 
154
141
  # @TODO: refactor [ref-5]
155
142
  sign_in @current_user, scope: :user
156
- set_current_ability
143
+ current_ability
157
144
  end
158
145
 
159
146
 
160
147
 
161
- # same as check_profile but doesn't error out when jwt_token is missing
148
+ # same as check_profile but doesn't error out when jwt_token is missing or expired
162
149
  def check_profile_optionally
163
150
  if !params[:jwt_token]
164
151
  @current_user = User.new profile: Profile.new
165
152
  else
166
- check_profile
153
+ begin
154
+ check_profile
155
+ rescue JWT::ExpiredSignature
156
+ Rails.logger.info("JWT::ExpiredSignature")
157
+ @current_user = User.new profile: Profile.new
158
+ end
167
159
  end
168
160
  end
169
161
 
@@ -175,10 +167,6 @@ module Ishapi
175
167
  # return check_multiprofile 'facebook'
176
168
  return check_multiprofile 'jwt'
177
169
 
178
- # puts! params, 'params'
179
- # puts! current_user, 'current_user'
180
- # puts! @current_user, '@current_user'
181
-
182
170
  accessToken = request.headers[:accessToken]
183
171
  accessToken ||= params[:fb_long_access_token]
184
172
  accessToken ||= params[:accessToken]
@@ -250,10 +238,9 @@ module Ishapi
250
238
  return token # ['access_token']
251
239
  end
252
240
 
253
- def set_current_ability
254
- # puts! current_user.email, '#set_current_ability() :: @current_user'
241
+ def current_ability
255
242
  @current_user ||= User.new({ profile: ::IshModels::UserProfile.new })
256
- @current_ability ||= ::Ishapi::Ability.new( @current_user )
243
+ @current_ability ||= Ishapi::Ability.new( @current_user )
257
244
  end
258
245
 
259
246
  def puts! a, b=''
@@ -263,10 +250,17 @@ module Ishapi
263
250
 
264
251
  # jwt
265
252
  def check_jwt
266
- decoded = decode(params[:jwt_token])
267
- puts! decoded, 'decoded'
268
- @current_user = User.find decoded['user_id']
269
- set_current_ability
253
+ begin
254
+ decoded = decode(params[:jwt_token])
255
+ puts! decoded, 'decoded'
256
+ @current_user = User.find decoded['user_id']
257
+ rescue JWT::ExpiredSignature
258
+ Rails.logger.info("JWT::ExpiredSignature")
259
+ rescue JWT::DecodeError
260
+ Rails.logger.info("JWT::DecodeError")
261
+ end
262
+ @current_user ||= User.new
263
+ current_ability
270
264
  end
271
265
 
272
266
  # jwt
@@ -14,7 +14,7 @@ json.partial! 'ishapi/application/meta', :item => gallery
14
14
  if gallery.is_premium
15
15
  json.premium_tier gallery.premium_tier
16
16
  json.is_premium gallery.premium_tier > 0
17
- json.is_purchased current_user.profile.has_premium_purchase( gallery )
17
+ json.is_purchased current_user&.profile&.has_premium_purchase( gallery )
18
18
  json.partial! 'ishapi/photos/index', :photos => [ gallery.photos[0] ]
19
19
  else
20
20
  json.partial! 'ishapi/photos/index', :photos => gallery.photos
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ishapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8.135
4
+ version: 0.1.8.140
5
5
  platform: ruby
6
6
  authors:
7
7
  - piousbox
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-31 00:00:00.000000000 Z
11
+ date: 2021-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails