jj-middleware 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/jj-middleware.gemspec +1 -0
- data/lib/jj/middleware/auth.rb +7 -8
- data/lib/jj/middleware/base.rb +2 -2
- data/lib/jj/middleware/onboarding.rb +42 -0
- data/lib/jj/middleware/session.rb +19 -0
- data/lib/jj/middleware.rb +1 -1
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0c8817a2816a94bcd4485e8eb2567487861ce42
|
4
|
+
data.tar.gz: 653ff3a437c77d6d042972f3759cea3f8cd3ab61
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1ee907a2e37923a147804fae15a720628bd38bbb7c8a9f95ed8ed5b76b4add1d8b112b33c272a6c99b1b01c7291ccb812254c4e343556b2a37da8b68d074e6a
|
7
|
+
data.tar.gz: 873935f4e6e40a7efb442f861bc9e7ed4c39ddccd015367224a2083d52bc3012fe14cf6f66a7aea4b5d72fe95076b15dd4f9752029fd769be04ddce4d228fe03
|
data/jj-middleware.gemspec
CHANGED
data/lib/jj/middleware/auth.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "jj/middleware/base"
|
2
|
+
require "jj/middleware/session"
|
2
3
|
|
3
4
|
module JJ
|
4
5
|
module Middleware
|
@@ -8,18 +9,16 @@ module JJ
|
|
8
9
|
end
|
9
10
|
|
10
11
|
def call(env)
|
11
|
-
|
12
|
+
sess = Session.new(env)
|
13
|
+
logged_in?(sess) ? @app.call(env) : redirect("/login")
|
12
14
|
end
|
13
15
|
|
14
16
|
private
|
15
17
|
|
16
|
-
def logged_in?(
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
def redirect
|
22
|
-
[302, { "Location" => "/login", "Content-Type" => "text/html" }, []]
|
18
|
+
def logged_in?(sess)
|
19
|
+
return false unless sess.exist?
|
20
|
+
user = sess.fetch("user")
|
21
|
+
user && user.id && user.email && user.data_api
|
23
22
|
end
|
24
23
|
end
|
25
24
|
end
|
data/lib/jj/middleware/base.rb
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
require "jj/middleware/base"
|
2
|
+
require "jj/middleware/session"
|
3
|
+
require "wes/data/api/creator_user"
|
4
|
+
|
5
|
+
module JJ
|
6
|
+
module Middleware
|
7
|
+
class Onboarding < Base
|
8
|
+
def initialize(app)
|
9
|
+
@app = app
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
sess = Session.new(env).fetch("user")
|
14
|
+
|
15
|
+
if sess.nil?
|
16
|
+
return redirect("/login")
|
17
|
+
end
|
18
|
+
|
19
|
+
unless user_exist?(sess.id)
|
20
|
+
create_user!(sess.id)
|
21
|
+
return redirect("/onboarding")
|
22
|
+
end
|
23
|
+
|
24
|
+
complete = sess.data_api["onboarding_complete"]
|
25
|
+
return redirect("/onboarding") unless complete
|
26
|
+
|
27
|
+
@app.call(env)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def create_user!(user_id)
|
33
|
+
Wes::Data::API::CreatorUser.create(:auth0_id => user_id)
|
34
|
+
end
|
35
|
+
|
36
|
+
def user_exist?(user_id)
|
37
|
+
user = Wes::Data::API::CreatorUser.find(:id, user_id)
|
38
|
+
user && (user.auth0_id == user_id)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module JJ
|
2
|
+
module Middleware
|
3
|
+
class Session
|
4
|
+
def initialize(env)
|
5
|
+
@env = env
|
6
|
+
end
|
7
|
+
|
8
|
+
def exist?
|
9
|
+
@env.key?("rack.session")
|
10
|
+
end
|
11
|
+
|
12
|
+
def fetch(key = nil)
|
13
|
+
@env["rack.session"].to_hash.tap do |s|
|
14
|
+
return s[key] unless key.nil?
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/jj/middleware.rb
CHANGED
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ''
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: wes-data-api
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '5'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '5'
|
83
97
|
description:
|
84
98
|
email:
|
85
99
|
- ''
|
@@ -92,6 +106,8 @@ files:
|
|
92
106
|
- lib/jj/middleware.rb
|
93
107
|
- lib/jj/middleware/auth.rb
|
94
108
|
- lib/jj/middleware/base.rb
|
109
|
+
- lib/jj/middleware/onboarding.rb
|
110
|
+
- lib/jj/middleware/session.rb
|
95
111
|
homepage: ''
|
96
112
|
licenses: []
|
97
113
|
metadata: {}
|