ishapi 0.1.8.134 → 0.1.8.139

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: a9055c8aee254cef203fa0ba8a7c82fd98d7c4b66870342d2286201ef7613dbd
4
- data.tar.gz: eee54217f1e118989c390a1e7b73c49284f441504f661f1d4b189da385436720
3
+ metadata.gz: f859dfaa7176b30b0d716bd2c3e87e8017a0655c1044fe9109385a84758e0abb
4
+ data.tar.gz: 5b95ae9d56c9dea97b71e1e3a9ee7c5929427d795a37afcdf5ab1674f0ba3383
5
5
  SHA512:
6
- metadata.gz: 38e5d8e9948fd4c50e4df5045e1a3e8c2e8789b45b6f8697cd7f8b6d966cf48f59869ea73399e596e75457eeca9ea351d0f488e0e8bb9ee6029f0001829e3ca9
7
- data.tar.gz: 0e633543d607411b971a437d9ad7f28f603a54754ff667ded394ac046fa9b2b64e4bdb2c0b1a1ae2ff1a8f13f6dc53ee0c284cd8148f7dbe0ba6acae1170bdfb
6
+ metadata.gz: 7b76b0d87c6442fe686c5bfd5c1b9e8a192806d1db91591935dc8b44978682e6fdcaa854bc05c4f89ec2a574e2ed8545c4495de5469d86695e214f4df1e4de30
7
+ data.tar.gz: 5c938518321b5e19c416ff292b9b1ee842d0e045fd1fbf14afcd9171bb925e9d34bca2c6018db2b028c5a758589b235f28512a971e28e2deb183015bc0233f94
data/README.md CHANGED
@@ -1,12 +1,19 @@
1
1
 
2
2
  # Develop
3
3
 
4
+ -=----- 20201228
5
+
6
+ Expects params[:jwtToken]
7
+ no... expects params[:accessToken]
8
+ somehow expects params[:jwt_token] ?
9
+
4
10
  # Test
5
11
 
6
12
  cd test/dummy
7
13
  be rspec spec
8
14
 
9
15
  # Install
16
+
10
17
  bundle
11
18
  gem build ishapi.gemspec
12
19
 
@@ -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
 
@@ -79,6 +72,7 @@ module Ishapi
79
72
  end
80
73
  end
81
74
  end
75
+
82
76
  ## Does not crap out if accessToken is missing
83
77
  def soft_check_long_term_token
84
78
  check_long_term_token soft=true
@@ -136,21 +130,9 @@ module Ishapi
136
130
  @current_user = current_user if Rails.env.test?
137
131
  end
138
132
 
139
- puts! @current_user, 'current_user'
140
- puts! @current_profile, 'current_profile'
141
-
142
133
  elsif 'jwt' == provider
143
- begin
144
- decoded = decode(params[:jwt_token])
145
- rescue JWT::ExpiredSignature
146
- # @TODO: refactor [ref-5]
147
- @current_user = User.new profile: Profile.new
148
- sign_in @current_user, scope: :user
149
- set_current_ability
150
- return
151
- end
134
+ decoded = decode(params[:jwt_token])
152
135
  @current_user = User.find decoded['user_id']
153
-
154
136
  else
155
137
  puts! 'check_multiprofile(): no access token'
156
138
  raise "ww1 - not implemented"
@@ -158,15 +140,22 @@ module Ishapi
158
140
 
159
141
  # @TODO: refactor [ref-5]
160
142
  sign_in @current_user, scope: :user
161
- set_current_ability
143
+ current_ability
162
144
  end
163
145
 
164
- # same as check_profile but doesn't error out when jwt_token is missing
146
+
147
+
148
+ # same as check_profile but doesn't error out when jwt_token is missing or expired
165
149
  def check_profile_optionally
166
150
  if !params[:jwt_token]
167
151
  @current_user = User.new profile: Profile.new
168
152
  else
169
- 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
170
159
  end
171
160
  end
172
161
 
@@ -178,10 +167,6 @@ module Ishapi
178
167
  # return check_multiprofile 'facebook'
179
168
  return check_multiprofile 'jwt'
180
169
 
181
- # puts! params, 'params'
182
- # puts! current_user, 'current_user'
183
- # puts! @current_user, '@current_user'
184
-
185
170
  accessToken = request.headers[:accessToken]
186
171
  accessToken ||= params[:fb_long_access_token]
187
172
  accessToken ||= params[:accessToken]
@@ -253,10 +238,9 @@ module Ishapi
253
238
  return token # ['access_token']
254
239
  end
255
240
 
256
- def set_current_ability
257
- # puts! current_user.email, '#set_current_ability() :: @current_user'
241
+ def current_ability
258
242
  @current_user ||= User.new({ profile: ::IshModels::UserProfile.new })
259
- @current_ability ||= ::Ishapi::Ability.new( @current_user )
243
+ @current_ability ||= Ishapi::Ability.new( @current_user )
260
244
  end
261
245
 
262
246
  def puts! a, b=''
@@ -264,6 +248,21 @@ module Ishapi
264
248
  puts a.inspect
265
249
  end
266
250
 
251
+ # jwt
252
+ def check_jwt
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
264
+ end
265
+
267
266
  # jwt
268
267
  def encode(payload, exp = 2.hours.from_now)
269
268
  payload[:exp] = exp.to_i
@@ -3,7 +3,8 @@ require_dependency "ishapi/application_controller"
3
3
  module Ishapi
4
4
  class GalleriesController < ApplicationController
5
5
 
6
- before_action :soft_check_long_term_token, only: [ :show ]
6
+ # before_action :soft_check_long_term_token, only: [ :show ]
7
+ before_action :check_jwt
7
8
 
8
9
  def index
9
10
  @galleries = Gallery.all
@@ -0,0 +1,12 @@
1
+
2
+ class Ishapi::My::GalleriesController < Ishapi::My::MyController
3
+
4
+ ## expects params[:jwt_token]
5
+ def index
6
+ authorize! :my_index, Gallery
7
+ @galleries = @current_user.profile.galleries.unscoped.where( is_trash: false ).order_by( created_at: :desc ).limit(20)
8
+ render 'ishapi/galleries/index'
9
+ end
10
+
11
+ end
12
+
@@ -8,20 +8,14 @@ module Ishapi
8
8
  before_action :check_profile
9
9
 
10
10
  def account
11
- puts! params, 'my account'
12
-
13
11
  @profile = current_user.profile
14
12
  authorize! :show, @profile
15
13
  end
16
14
 
17
-
18
15
  private
19
16
 
20
17
  def do_login
21
- puts! params, 'params'
22
-
23
18
  token = decode(params[:jwtToken])
24
- puts! token, 'token'
25
19
  @current_user = User.find(token["user_id"])
26
20
  end
27
21
 
@@ -3,7 +3,6 @@ class Ishapi::Ability
3
3
  include ::CanCan::Ability
4
4
 
5
5
  def initialize user
6
-
7
6
  #
8
7
  # signed in user
9
8
  #
@@ -18,6 +17,7 @@ class Ishapi::Ability
18
17
  true
19
18
  end
20
19
 
20
+ can [ :my_index ], Gallery
21
21
  can [ :show ], Gallery do |gallery|
22
22
  gallery.user_profile == user.profile
23
23
  end
@@ -11,7 +11,7 @@ json.array! @galleries do |gallery|
11
11
  json.subhead gallery.subhead
12
12
  json.username gallery.user_profile.name
13
13
  json.cityname gallery.city.name if gallery.city
14
- json.tagname gallery.tag.name_seo if gallery.tag
14
+ json.tag_names gallery.tags.map &:name_seo
15
15
  json.venuename gallery.venue.name if gallery.venue
16
16
  json.partial! 'ishapi/photos/index', :photos => gallery.photos
17
17
  end
@@ -29,6 +29,7 @@ Ishapi::Engine.routes.draw do
29
29
  get 'markers/view/:slug', to: 'maps#show_marker'
30
30
  get "/my/account", to: "my/my#account"
31
31
  namespace :my do
32
+ get 'galleries', to: 'galleries#index'
32
33
  get 'newsitems', to: 'newsitems#index'
33
34
  get 'reports', to: 'reports#index'
34
35
  get 'videos', to: 'videos#index'
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.134
4
+ version: 0.1.8.139
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-25 00:00:00.000000000 Z
11
+ date: 2021-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -204,6 +204,7 @@ files:
204
204
  - app/controllers/ishapi/invoices_controller.rb
205
205
  - app/controllers/ishapi/maps_controller.rb
206
206
  - app/controllers/ishapi/measurements_controller.rb
207
+ - app/controllers/ishapi/my/galleries_controller.rb
207
208
  - app/controllers/ishapi/my/my_controller.rb
208
209
  - app/controllers/ishapi/my/reports_controller.rb
209
210
  - app/controllers/ishapi/my/videos_controller.rb