jj-middleware 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 38fb290ecb6f605486f23e35ddc6fa3cdd3e6530
4
- data.tar.gz: fde74d97db7ac62ad15040f9db749fa1f60e0b1c
3
+ metadata.gz: e959ec144f88497c8f742f16d23957964a96aa41
4
+ data.tar.gz: c5cf533b9a706ef8fe6c1c0dce1142314abc0eb8
5
5
  SHA512:
6
- metadata.gz: ef8a942992cfd666fe9a2cef527c0cc708f337c793d4405db2a2dbb9bdbb11e2a3ee6a2da609d84887086636dfd072315b8676a2406ef99cd0184d5bd07a9416
7
- data.tar.gz: 2958b78c8324a2fdc9f7ede80cfb0be618ef86368afcc6e0e8efe6229d9429db11b2632c91b65a670778ca49ab6f650a86c7f94d8d080a2aba683b32cc1e9a91
6
+ metadata.gz: b5dec34b315931c2e3ac67bc20acfe672f56d4a6d14d3ff6cfa3d86c04a035aa50d7df9e63c810d6dbd79b2a4465ea51a17f0aaa6ae1f7eeba102017e43b5a42
7
+ data.tar.gz: 852538ad599e95875aea8353789d50e06da36f659d184279f8b0524fe61d4e9b0c539d9aa5cb1a5f28294de72717343eb8b185513cdcc172d82cdb1f16763e3d
data/lib/jj/middleware.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module JJ
2
2
  module Middleware
3
- VERSION = "0.3.0".freeze
3
+ VERSION = "0.3.1".freeze
4
4
  end
5
5
  end
@@ -16,9 +16,23 @@ module JJ
16
16
  private
17
17
 
18
18
  def logged_in?(sess)
19
- return false unless sess.exist?
19
+ unless sess.exist?
20
+ log.warn("[JJ::Auth] Session does not exist.")
21
+ return false
22
+ end
23
+
20
24
  user = sess.fetch("user")
21
- user && user.id && user.email && user.model
25
+ if user.nil?
26
+ log.warn("[JJ::Auth] User key doesn't exist in session.")
27
+ return false
28
+ end
29
+
30
+ unless user.id && user.email && user.model
31
+ log.warn("[JJ::Auth] User ID/Email/Model doesn't exist in session.")
32
+ return false
33
+ end
34
+
35
+ true
22
36
  end
23
37
  end
24
38
  end
@@ -1,8 +1,14 @@
1
+ require "logger"
2
+
1
3
  module JJ
2
4
  module Middleware
3
5
  class Base
4
6
  protected
5
7
 
8
+ def log
9
+ @log ||= ::Logger.new STDOUT
10
+ end
11
+
6
12
  def redirect(path, code = 302)
7
13
  [code, { "Location" => path, "Content-Type" => "text/html" }, []]
8
14
  end
@@ -13,15 +13,21 @@ module JJ
13
13
  sess = Session.new(env).fetch("user")
14
14
 
15
15
  if sess.nil?
16
+ log.warn("[JJ::Onboarding] Session does not exist.")
16
17
  return redirect("/login")
17
18
  end
18
19
 
19
20
  unless user_exist?(sess.id)
21
+ log.info("[JJ::Onboarding] User record not yet created.")
20
22
  create_user!(sess.id)
23
+ log.info("[JJ::Onboarding] Redirect to Onboarding.")
21
24
  return redirect("/onboarding")
22
25
  end
23
26
 
24
- return redirect("/onboarding") unless sess.model.onboarded
27
+ unless sess.model.onboarded
28
+ log.info("[JJ::Onboarding] User yet to complete onboarding.")
29
+ return redirect("/onboarding")
30
+ end
25
31
 
26
32
  @app.call(env)
27
33
  end
@@ -30,6 +36,7 @@ module JJ
30
36
 
31
37
  def create_user!(user_id)
32
38
  Wes::Data::API::CreatorUser.create(:auth0_id => user_id)
39
+ log.info("[JJ::Onboarding] Created user record.")
33
40
  end
34
41
 
35
42
  def user_exist?(user_id)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jj-middleware
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-20 00:00:00.000000000 Z
11
+ date: 2016-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler