jj-middleware 0.3.1 → 0.4.0

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: e959ec144f88497c8f742f16d23957964a96aa41
4
- data.tar.gz: c5cf533b9a706ef8fe6c1c0dce1142314abc0eb8
3
+ metadata.gz: 54113726efff4acd9e0bc11693bb9e6e420cc6d4
4
+ data.tar.gz: 38d9b764429f1d9ecd643d94c28587ca53d406ba
5
5
  SHA512:
6
- metadata.gz: b5dec34b315931c2e3ac67bc20acfe672f56d4a6d14d3ff6cfa3d86c04a035aa50d7df9e63c810d6dbd79b2a4465ea51a17f0aaa6ae1f7eeba102017e43b5a42
7
- data.tar.gz: 852538ad599e95875aea8353789d50e06da36f659d184279f8b0524fe61d4e9b0c539d9aa5cb1a5f28294de72717343eb8b185513cdcc172d82cdb1f16763e3d
6
+ metadata.gz: ae7b8fec145fd36d705c99147e52deae4b6428b164b6a86f2b2bdcf7fb0801f08f28654dbd29dbfb8c5a81d3281fb22ccce075d8c2e6b9fd84e9252c51dafdbf
7
+ data.tar.gz: 8f26c9470e0579cb39b7d87a0096612e16f7ded51ba3a2bf4941db02fad4686e7eaf01d79937ca1870dce3d6498cb8c4c4caedf66bcbc6679d14a113f0337528
data/lib/jj/middleware.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module JJ
2
2
  module Middleware
3
- VERSION = "0.3.1".freeze
3
+ VERSION = "0.4.0".freeze
4
4
  end
5
5
  end
@@ -27,8 +27,8 @@ module JJ
27
27
  return false
28
28
  end
29
29
 
30
- unless user.id && user.email && user.model
31
- log.warn("[JJ::Auth] User ID/Email/Model doesn't exist in session.")
30
+ unless user.id && user.email
31
+ log.warn("[JJ::Auth] User ID/Email doesn't exist in session.")
32
32
  return false
33
33
  end
34
34
 
@@ -10,21 +10,17 @@ module JJ
10
10
  end
11
11
 
12
12
  def call(env)
13
- sess = Session.new(env).fetch("user")
13
+ sess = Session.new(env)
14
+ user = sess.fetch("user")
14
15
 
15
- if sess.nil?
16
- log.warn("[JJ::Onboarding] Session does not exist.")
17
- return redirect("/login")
18
- end
19
-
20
- unless user_exist?(sess.id)
16
+ unless user_exist?(user.id)
21
17
  log.info("[JJ::Onboarding] User record not yet created.")
22
- create_user!(sess.id)
23
- log.info("[JJ::Onboarding] Redirect to Onboarding.")
18
+ record = create_user!(user.id)
19
+ sess.set_model(record)
24
20
  return redirect("/onboarding")
25
21
  end
26
22
 
27
- unless sess.model.onboarded
23
+ unless user.model.onboarded
28
24
  log.info("[JJ::Onboarding] User yet to complete onboarding.")
29
25
  return redirect("/onboarding")
30
26
  end
@@ -35,8 +31,8 @@ module JJ
35
31
  private
36
32
 
37
33
  def create_user!(user_id)
38
- Wes::Data::API::CreatorUser.create(:auth0_id => user_id)
39
34
  log.info("[JJ::Onboarding] Created user record.")
35
+ Wes::Data::API::CreatorUser.create(:auth0_id => user_id)
40
36
  end
41
37
 
42
38
  def user_exist?(user_id)
@@ -14,6 +14,10 @@ module JJ
14
14
  return s[key] unless key.nil?
15
15
  end
16
16
  end
17
+
18
+ def set_model(record)
19
+ @env["rack.session"].to_hash["user"].model = record
20
+ end
17
21
  end
18
22
  end
19
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jj-middleware
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''